menu controllable: when the mouse doesn't move: the keyboard event overlaod mouse's

This commit is contained in:
arthur.jamet
2021-06-17 11:39:55 +02:00
parent a1ad9a57ac
commit e3b6b87b11
2 changed files with 12 additions and 3 deletions
@@ -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<OnClickComponent, OnHoverComponent, OnIdleComponent, PositionComponent, Drawable2DComponent>();
if (this->_oldMousePosition == Vector2f(-1, -1))
this->_oldMousePosition = relativeMousePos;
if (this->_currentButton && this->_currentButton->_scene.getID() != this->_wal.getScene()->getID()) {
this->_currentButton->getComponent<OnIdleComponent>().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)
@@ -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);