STARK: Document and simplify the Window class

This commit is contained in:
Bastien Bouclet 2015-07-14 13:17:54 +02:00
parent 62d6b27f02
commit 874279eac4
5 changed files with 32 additions and 29 deletions

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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));
}
}

View File

@ -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());
}
}

View File

@ -39,18 +39,37 @@ namespace Resources {
typedef Common::Array<uint32> 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;