mouse event scale to new window size

This commit is contained in:
arthur.jamet
2021-06-16 20:41:56 +02:00
parent bd758d858c
commit 84dfc16be1
2 changed files with 6 additions and 6 deletions
@@ -51,14 +51,12 @@ namespace BBM
this->_currentButton->getComponent<OnClickComponent>().onEvent(*this->_currentButton, this->_wal);
}
bool MenuControllableSystem::_mouseOnButton(WAL::ViewEntity<OnClickComponent, OnHoverComponent, OnIdleComponent, PositionComponent, Drawable2DComponent> &entity) const
bool MenuControllableSystem::_mouseOnButton(const Vector2f &mousePos, WAL::ViewEntity<OnClickComponent, OnHoverComponent, OnIdleComponent, PositionComponent, Drawable2DComponent> &entity) const
{
auto &positionComponent = entity.get<PositionComponent>();
RAY::Vector2 rayMousePos = RAYControl::Mouse::getCursorPosition();
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 mousePos(rayMousePos.x, rayMousePos.y);
Vector2f dimensions;
WAL::Entity *newButton = nullptr;
@@ -77,7 +75,9 @@ namespace BBM
void MenuControllableSystem::onSelfUpdate()
{
RAY::Vector2 rayMousePos = RAYControl::Mouse::getCursorPosition();
RAY::Vector2 winSize = RAY::Window::getInstance().getDimensions();
Vector2f relativeMousePos(rayMousePos.x * 1920 / winSize.x, rayMousePos.y * 1080 / winSize.y);
auto &controllableView = this->_wal.getScene()->view<ControllableComponent>();
auto &buttons = _wal.getScene()->view<OnClickComponent, OnHoverComponent, OnIdleComponent, PositionComponent, Drawable2DComponent>();
@@ -99,7 +99,7 @@ namespace BBM
return;
}
for (auto &entity: buttons) {
if (_mouseOnButton(entity)) {
if (_mouseOnButton(relativeMousePos, entity)) {
if (this->_currentButton)
this->_currentButton->getComponent<OnIdleComponent>().onEvent(*this->_currentButton, this->_wal);
this->_currentButton = &(*entity);
@@ -25,7 +25,7 @@ namespace BBM
void _updateCurrentButton(bool selected, Vector2f move);
//! @return true if mouse on entity
bool _mouseOnButton(WAL::ViewEntity<OnClickComponent, OnHoverComponent, OnIdleComponent, PositionComponent, Drawable2DComponent> &entity) const;
bool _mouseOnButton(const Vector2f &mousePos, WAL::ViewEntity<OnClickComponent, OnHoverComponent, OnIdleComponent, PositionComponent, Drawable2DComponent> &entity) const;
public:
//! @brief time (in millisecond) since last check
std::chrono::time_point<std::chrono::steady_clock> now;