fix: Register mouse click on mouse button up

This commit is contained in:
Vsevolod Kremianskii 2021-01-20 15:37:54 +07:00
parent 769e138d72
commit 53b8563b48
2 changed files with 9 additions and 2 deletions

View file

@ -188,8 +188,14 @@ bool GUI::handle(const SDL_Event &event) {
}
break;
}
case SDL_MOUSEBUTTONDOWN: {
case SDL_MOUSEBUTTONDOWN:
if (event.button.button == SDL_BUTTON_LEFT) {
_leftMouseDown = true;
}
break;
case SDL_MOUSEBUTTONUP:
if (_leftMouseDown && event.button.button == SDL_BUTTON_LEFT) {
_leftMouseDown = false;
glm::ivec2 ctrlCoords(event.button.x - _controlOffset.x, event.button.y - _controlOffset.y);
Control *control = getControlAt(ctrlCoords.x, ctrlCoords.y, [](const Control &ctrl) { return ctrl.isClickable(); });
if (control) {
@ -198,7 +204,6 @@ bool GUI::handle(const SDL_Event &event) {
}
}
break;
}
case SDL_MOUSEWHEEL:
if (_focus && _focus->handleMouseWheel(event.wheel.x, event.wheel.y)) return true;

View file

@ -114,6 +114,8 @@ protected:
// END User input
private:
bool _leftMouseDown { false };
GUI(const GUI &) = delete;
GUI &operator=(const GUI &) = delete;