diff --git a/engines/stark/ui/actionmenu.cpp b/engines/stark/ui/actionmenu.cpp index 911cdfa991f..c974d64d001 100644 --- a/engines/stark/ui/actionmenu.cpp +++ b/engines/stark/ui/actionmenu.cpp @@ -70,7 +70,7 @@ void ActionMenu::open(Resources::ItemVisual *item, const Common::Point &itemRela _visible = true; - Common::Point screenMousePos = getScreenMousePosition(); + Common::Point screenMousePos = _cursor->getMousePosition(true); _position = Common::Rect::center(screenMousePos.x, screenMousePos.y, 160, 111); _itemRelativePos = itemRelativePos; @@ -103,7 +103,7 @@ void ActionMenu::close() { void ActionMenu::onRender() { GameInterface *game = StarkServices::instance().gameInterface; - Common::Point mousePos = getMousePosition(); + Common::Point mousePos = getRelativeMousePosition(); _background->render(Common::Point(0, 0), false); @@ -140,9 +140,9 @@ void ActionMenu::onMouseMove(const Common::Point &pos) { } if (hoveringAction) { - setCursor(Cursor::kActive); + _cursor->setCursorType(Cursor::kActive); } else { - setCursor(Cursor::kDefault); + _cursor->setCursorType(Cursor::kDefault); } } diff --git a/engines/stark/ui/inventorywindow.cpp b/engines/stark/ui/inventorywindow.cpp index 3a278f0fc27..aaaf35cd432 100644 --- a/engines/stark/ui/inventorywindow.cpp +++ b/engines/stark/ui/inventorywindow.cpp @@ -153,9 +153,9 @@ void InventoryWindow::onMouseMove(const Common::Point &pos) { if (_selectedInventoryItem == -1) { if (hoveredItem) { - _cursor->setCursorType(Cursor::CursorType::kActive); + _cursor->setCursorType(Cursor::kActive); } else { - _cursor->setCursorType(Cursor::CursorType::kDefault); + _cursor->setCursorType(Cursor::kDefault); } } else { GameInterface *game = StarkServices::instance().gameInterface; diff --git a/engines/stark/ui/topmenu.cpp b/engines/stark/ui/topmenu.cpp index ac7af15f060..0017dbed895 100644 --- a/engines/stark/ui/topmenu.cpp +++ b/engines/stark/ui/topmenu.cpp @@ -69,8 +69,8 @@ void TopMenu::onRender() { void TopMenu::onMouseMove(const Common::Point &pos) { if (_widgetsVisible) { - setCursor(Cursor::kActive); - setCursorHint(getMouseHintAtPosition(pos)); + _cursor->setCursorType(Cursor::kActive); + _cursor->setMouseHint(getMouseHintAtPosition(pos)); } } diff --git a/engines/stark/ui/window.cpp b/engines/stark/ui/window.cpp index 5a658abbc1b..a3fbc48fccc 100644 --- a/engines/stark/ui/window.cpp +++ b/engines/stark/ui/window.cpp @@ -66,30 +66,18 @@ bool Window::isVisible() const { return _visible; } -Common::Point Window::getMousePosition() const { +Common::Point Window::getRelativeMousePosition() const { Common::Point mousePos = _cursor->getMousePosition(_unscaled); return mousePos - Common::Point(_position.left, _position.top); } -Common::Point Window::getScreenMousePosition() const { - return _cursor->getMousePosition(_unscaled); -} - -void Window::setCursor(Cursor::CursorType type) { - _cursor->setCursorType(type); -} - -void Window::setCursorHint(const Common::String &hint) { - _cursor->setMouseHint(hint); -} - void Window::handleMouseMove() { if (!_visible) { return; } if (isMouseInside()) { - onMouseMove(getMousePosition()); + onMouseMove(getRelativeMousePosition()); } } @@ -99,7 +87,7 @@ void Window::handleClick() { } if (isMouseInside()) { - onClick(getMousePosition()); + onClick(getRelativeMousePosition()); } } @@ -109,7 +97,7 @@ void Window::handleRightClick() { } if (isMouseInside()) { - onRightClick(getMousePosition()); + onRightClick(getRelativeMousePosition()); } } diff --git a/engines/stark/ui/window.h b/engines/stark/ui/window.h index ed7ad8595c9..c4e17ec68c0 100644 --- a/engines/stark/ui/window.h +++ b/engines/stark/ui/window.h @@ -39,18 +39,37 @@ namespace Resources { typedef Common::Array ActionArray; } +/** + * A window is a portion of the game screen. + * + * A window can handle events happening in its screen portion, + * as well as render graphics to that same screen portion. + * + * Coordinates inside a window are relative to its top left corner. + * Rendering happens in a viewport matching the window's screen portion. + * + */ class Window { public: Window(Gfx::Driver *gfx, Cursor *cursor); virtual ~Window(); + /** Called by the user interface when the mouse moves inside the window */ void handleMouseMove(); + + /** Called by the user interface when the mouse is clicked inside the window */ void handleClick(); + + /** Called by the user interface when the mouse is right clicked inside the window */ void handleRightClick(); + /** Called by the user interface in the render phase of the game loop */ void render(); + /** Is the mouse inside the window? */ bool isMouseInside() const; + + /** Is the window visible */ bool isVisible() const; protected: @@ -59,11 +78,7 @@ protected: virtual void onRightClick(const Common::Point &pos) {}; virtual void onRender() = 0; - void setCursor(Cursor::CursorType type); - void setCursorHint(const Common::String &hint); - - Common::Point getMousePosition() const; - Common::Point getScreenMousePosition() const; + Common::Point getRelativeMousePosition() const; Gfx::Driver *_gfx; Cursor *_cursor;