MCPcopy Create free account
hub / github.com/AbyssEngine/AbyssEngineOld / handleMouse

Method handleMouse

src/Abyss/UI/Button.h:26–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24 Streams::SoundEffect _clickSound;
25
26 void handleMouse(const int x, const int y) {
27 const auto mouseState = Singletons::getMouseProvider().getMouseState();
28 int mouseX, mouseY;
29 mouseState.getPosition(mouseX, mouseY);
30 const auto leftMousePressed = mouseState.isButtonPressed(Enums::MouseButton::Left);
31
32 mouseX -= x;
33 mouseY -= y;
34 const auto isMouseOver = mouseX >= _def.clickableRect.x && mouseX <= _def.clickableRect.x + _def.clickableRect.w && mouseY >= _def.clickableRect.y &&
35 mouseY <= _def.clickableRect.y + _def.clickableRect.h;
36
37 if (isMouseOver && !leftMousePressed && _hasFocus) {
38 _onClick();
39 _hasFocus = false;
40 _state = ButtonState::Normal; // TODO: Disabled state
41 }
42
43 if (isMouseOver && leftMousePressed && !_hasFocus && _canFocus) {
44 _hasFocus = true;
45 _clickSound.play();
46 }
47
48 if (!_hasFocus)
49 _canFocus = !leftMousePressed;
50
51 if (!leftMousePressed) {
52 _hasFocus = false;
53 _canFocus = true;
54 }
55
56 _state = isMouseOver && leftMousePressed && _canFocus ? ButtonState::Pressed : ButtonState::Normal;
57 }
58
59 public:
60 explicit Button(const ButtonDef &buttonDef, const std::string_view text, const Concepts::FontRenderer &fontRenderer, std::function<void()> onClick)

Callers

nothing calls this directly

Calls 3

getPositionMethod · 0.80
isButtonPressedMethod · 0.80
playMethod · 0.45

Tested by

no test coverage detected