From e3b6b87b11173b4c08f66c02744b9adf38ce3a0d Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Thu, 17 Jun 2021 11:39:55 +0200 Subject: [PATCH] menu controllable: when the mouse doesn't move: the keyboard event overlaod mouse's --- .../MenuControllable/MenuControllableSystem.cpp | 12 +++++++++--- .../MenuControllable/MenuControllableSystem.hpp | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/sources/System/MenuControllable/MenuControllableSystem.cpp b/sources/System/MenuControllable/MenuControllableSystem.cpp index 29eee5b6..24787a3d 100644 --- a/sources/System/MenuControllable/MenuControllableSystem.cpp +++ b/sources/System/MenuControllable/MenuControllableSystem.cpp @@ -18,8 +18,9 @@ namespace BBM { MenuControllableSystem::MenuControllableSystem(WAL::Wal &wal) : System(wal), - _currentButton() - {} + _currentButton(), _oldMousePosition(-1, -1) + { + } void MenuControllableSystem::_updateCurrentButton(bool selected, Vector2f move) { @@ -66,7 +67,7 @@ namespace BBM dimensions.y = texture->getDimensions().y; } else if (text) { dimensions.y = text->getFontSize(); - dimensions.x = text->getString().size() * (text->getLetterSpacing() + text->getFontSize()); + dimensions.x = text->getString().size() * (text->getFontSize()); } else return false; return ((buttonPos.x <= mousePos.x && mousePos.x <= buttonPos.x + dimensions.x) @@ -82,6 +83,8 @@ namespace BBM auto &buttons = _wal.getScene()->view(); + if (this->_oldMousePosition == Vector2f(-1, -1)) + this->_oldMousePosition = relativeMousePos; if (this->_currentButton && this->_currentButton->_scene.getID() != this->_wal.getScene()->getID()) { this->_currentButton->getComponent().onEvent(*this->_currentButton, this->_wal); this->_currentButton = nullptr; @@ -98,6 +101,9 @@ namespace BBM this->_updateCurrentButton(controllable.select, controllable.move); return; } + if (relativeMousePos == this->_oldMousePosition && !RAYControl::Mouse::isPressed(RAYControl::Mouse::Button::MOUSE_BUTTON_LEFT)) + return; + this->_oldMousePosition = relativeMousePos; for (auto &entity: buttons) { if (_mouseOnButton(relativeMousePos, entity)) { if (this->_currentButton) diff --git a/sources/System/MenuControllable/MenuControllableSystem.hpp b/sources/System/MenuControllable/MenuControllableSystem.hpp index 45e7c8fb..7462a358 100644 --- a/sources/System/MenuControllable/MenuControllableSystem.hpp +++ b/sources/System/MenuControllable/MenuControllableSystem.hpp @@ -20,6 +20,9 @@ namespace BBM //! @brief index of the current button selected WAL::Entity *_currentButton; + //! @brief position of the mouse at the precedent scene (to know which controller event to watch) + Vector2f _oldMousePosition; + //! @brief update current button reference //! @param selected lets know if te new selected button is 'pressed' void _updateCurrentButton(bool selected, Vector2f move);