mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-28 08:33:36 +00:00
mouse event scale to new window size
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user