Handling buttons on key up

This commit is contained in:
Zoe Roux
2021-06-18 12:42:51 +02:00
parent 673d4f446d
commit 8d9432c1f4
6 changed files with 18 additions and 10 deletions
@@ -55,24 +55,24 @@ namespace BBM
bool MenuControllableSystem::_mouseOnButton(const Vector2f &mousePos, WAL::ViewEntity<OnClickComponent, OnHoverComponent, OnIdleComponent, PositionComponent, Drawable2DComponent> &entity) const
{
auto &positionComponent = entity.get<PositionComponent>();
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.get<Drawable2DComponent>().drawable.get());
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(entity.get<Drawable2DComponent>().drawable.get());
Vector2f buttonPos(positionComponent.getX(), positionComponent.getY());
Vector2f dimensions;
if (texture) {
if (auto *texture = dynamic_cast<RAY::Texture *>(entity.get<Drawable2DComponent>().drawable.get())) {
dimensions.x = texture->getDimensions().x;
dimensions.y = texture->getDimensions().y;
} else if (text) {
}
else if (auto *text = dynamic_cast<RAY2D::Text *>(entity.get<Drawable2DComponent>().drawable.get())) {
dimensions.y = text->getFontSize();
dimensions.x = text->getString().size() * (text->getFontSize());
} else
}
else
return false;
return ((buttonPos.x <= mousePos.x && mousePos.x <= buttonPos.x + dimensions.x)
&& (buttonPos.y <= mousePos.y && mousePos.y <= buttonPos.y + dimensions.y));
&& (buttonPos.y <= mousePos.y && mousePos.y <= buttonPos.y + dimensions.y));
}
void MenuControllableSystem::onSelfUpdate(std::chrono::nanoseconds dtime)
void MenuControllableSystem::onSelfUpdate(std::chrono::nanoseconds)
{
RAY::Vector2 rayMousePos = RAYControl::Mouse::getCursorPosition();
RAY::Vector2 winSize = RAY::Window::getInstance().getDimensions();