MenuResult Slider::handleEvent(sf::Event & Event, sf::Vector2f MousePos) { if (_Enabled) { if (Event.type == sf::Event::MouseButtonPressed) { if (pointInRectangle(getRect(), MousePos)) { setSlider(MousePos.x); _MouseButtonPressed = true; } } else if (Event.type == sf::Event::MouseButtonReleased) { _MouseButtonPressed = false; } else if (Event.type == sf::Event::MouseMoved) { if (pointInRectangle(getRect(), MousePos)) { _Hovering = true; } else { _Hovering = false; } if (_MouseButtonPressed) { _Hovering = true; setSlider(MousePos.x); } _Focused = false; } } return _Action; }
MenuResult ComboBox::handleEvent(sf::Event & newEvent, sf::Vector2f mousePos) { if (_Enabled) { if (newEvent.type == sf::Event::MouseMoved) { _HoveringLeft = pointInRectangle(_ButtonLeft.getGlobalBounds(), mousePos); _HoveringRight = pointInRectangle(_ButtonRight.getGlobalBounds(), mousePos); _Hovering = _HoveringLeft || _HoveringRight; } if (newEvent.type == sf::Event::MouseButtonPressed) { if (pointInRectangle(_ButtonLeft.getGlobalBounds(), mousePos)) { _CurrentItem = (_CurrentItem - 1 < 0) ? _Items.size() - 1 : _CurrentItem - 1; } else if (pointInRectangle(_ButtonRight.getGlobalBounds(), mousePos)) { _CurrentItem = (_CurrentItem + 1 >= _Items.size()) ? 0 : _CurrentItem + 1; } _Text.setString(_Items[_CurrentItem]); centerText(); } } return MenuResult::Nothing; }
// touch bool pointInside(short x, short y){ return pointInRectangle(x, y, real->x, real->y, real->width, real->height); }