diff --git a/engines/twine/debug.cpp b/engines/twine/debug.cpp index 7aace2d2576..54df6327b1d 100644 --- a/engines/twine/debug.cpp +++ b/engines/twine/debug.cpp @@ -426,12 +426,11 @@ void Debug::debugProcessWindow() { if (_engine->shouldQuit()) { break; } - MouseStatusStruct mouseData; - _engine->_input->getMousePositions(&mouseData); + const Common::Point &point = _engine->_input->getMousePositions(); if (_engine->_input->toggleActionIfActive(TwinEActionType::DebugMenuActivate)) { int type = 0; - if ((type = debugProcessButton(mouseData.x, mouseData.y)) != NO_ACTION) { // process menu item + if ((type = debugProcessButton(point.x, point.y)) != NO_ACTION) { // process menu item if (debugTypeUseMenu(type)) { _engine->_screens->copyScreen(_engine->workVideoBuffer, _engine->frontVideoBuffer); _engine->copyBlockPhys(205, 55, 634, 474); diff --git a/engines/twine/input.cpp b/engines/twine/input.cpp index 3cc30fe7e75..047c5e22949 100644 --- a/engines/twine/input.cpp +++ b/engines/twine/input.cpp @@ -153,22 +153,15 @@ void Input::readKeys() { } } -void Input::getMousePositions(MouseStatusStruct *mouseData) { - Common::Point point = g_system->getEventManager()->getMousePos(); - mouseData->x = point.x; - mouseData->y = point.y; -} - -bool Input::isMouseHovering(int32 left, int32 top, int32 right, int32 bottom) const { - Common::Point point = g_system->getEventManager()->getMousePos(); - return point.x >= left && point.x <= right && point.y >= top && point.y <= bottom; +Common::Point Input::getMousePositions() const { + return g_system->getEventManager()->getMousePos(); } bool Input::isMouseHovering(const Common::Rect &rect) const { if (!_engine->cfgfile.Mouse) { return false; } - Common::Point point = g_system->getEventManager()->getMousePos(); + Common::Point point = getMousePositions(); return point.x >= rect.left && point.x <= rect.right && point.y >= rect.top && point.y <= rect.bottom; } diff --git a/engines/twine/input.h b/engines/twine/input.h index 22da5d5bb28..d12e097a4c4 100644 --- a/engines/twine/input.h +++ b/engines/twine/input.h @@ -83,11 +83,6 @@ enum TwinEActionType { Max }; -struct MouseStatusStruct { - int32 x = 0; - int32 y = 0; -}; - /** * @brief Activates the given key map id that is registered in the meta engine */ @@ -129,7 +124,6 @@ public: */ bool isActionActive(TwinEActionType actionType, bool onlyFirstTime = true) const; - bool isMouseHovering(int32 left, int32 top, int32 right, int32 bottom) const; bool isMouseHovering(const Common::Rect &rect) const; /** @@ -148,7 +142,7 @@ public: * Gets mouse positions * @param mouseData structure that contains mouse position info */ - void getMousePositions(MouseStatusStruct *mouseData); + Common::Point getMousePositions() const; /** * @brief Updates the internal action states diff --git a/engines/twine/interface.cpp b/engines/twine/interface.cpp index d596b05b0bc..c80ef721585 100644 --- a/engines/twine/interface.cpp +++ b/engines/twine/interface.cpp @@ -152,6 +152,10 @@ void Interface::drawLine(int32 startWidth, int32 startHeight, int32 endWidth, in } } +void Interface::blitBox(const Common::Rect &rect, const Graphics::ManagedSurface &source, int32 leftDest, int32 topDest, Graphics::ManagedSurface &dest) { + blitBox(rect.left, rect.top, rect.right, rect.bottom, source, leftDest, topDest, dest); +} + void Interface::blitBox(int32 left, int32 top, int32 right, int32 bottom, const Graphics::ManagedSurface &source, int32 leftDest, int32 topDest, Graphics::ManagedSurface &dest) { const int8 *s = (const int8 *)source.getBasePtr(left, top); int8 *d = (int8 *)dest.getBasePtr(left, top); @@ -175,6 +179,10 @@ void Interface::blitBox(int32 left, int32 top, int32 right, int32 bottom, const } } +void Interface::drawTransparentBox(const Common::Rect &rect, int32 colorAdj) { + drawTransparentBox(rect.left, rect.top, rect.right, rect.bottom, colorAdj); +} + void Interface::drawTransparentBox(int32 left, int32 top, int32 right, int32 bottom, int32 colorAdj) { if (left > SCREEN_TEXTLIMIT_RIGHT) { return; @@ -259,6 +267,10 @@ void Interface::drawSplittedBox(int32 left, int32 top, int32 right, int32 bottom } } +void Interface::setClip(const Common::Rect &rect) { + setClip(rect.left, rect.top, rect.right, rect.bottom); +} + void Interface::setClip(int32 left, int32 top, int32 right, int32 bottom) { if (left < 0) { left = 0; diff --git a/engines/twine/interface.h b/engines/twine/interface.h index c8ced700422..dde51f6d9da 100644 --- a/engines/twine/interface.h +++ b/engines/twine/interface.h @@ -81,7 +81,7 @@ public: * @param dest destination screen buffer, in this case front buffer */ void blitBox(int32 left, int32 top, int32 right, int32 bottom, const Graphics::ManagedSurface &source, int32 leftDest, int32 topDest, Graphics::ManagedSurface &dest); - + void blitBox(const Common::Rect &rect, const Graphics::ManagedSurface &source, int32 leftDest, int32 topDest, Graphics::ManagedSurface &dest); /** * Draws inside buttons transparent area * @param left start width to draw the button @@ -91,11 +91,13 @@ public: * @param colorAdj index to adjust the transparent box color */ void drawTransparentBox(int32 left, int32 top, int32 right, int32 bottom, int32 colorAdj); + void drawTransparentBox(const Common::Rect &rect, int32 colorAdj); void drawSplittedBox(int32 left, int32 top, int32 right, int32 bottom, uint8 colorIndex); void drawSplittedBox(const Common::Rect &rect, uint8 colorIndex); void setClip(int32 left, int32 top, int32 right, int32 bottom); + void setClip(const Common::Rect &rect); void saveClip(); // saveTextWindow void loadClip(); // loadSavedTextWindow void resetClip(); diff --git a/engines/twine/menu.cpp b/engines/twine/menu.cpp index 84381ae618d..ae989039f19 100644 --- a/engines/twine/menu.cpp +++ b/engines/twine/menu.cpp @@ -243,62 +243,62 @@ void Menu::drawBox(int32 left, int32 top, int32 right, int32 bottom) { drawBox(Common::Rect(left, top, right, bottom)); } -void Menu::drawButtonGfx(const MenuSettings *menuSettings, int32 left, int32 top, int32 right, int32 bottom, int32 buttonId, const char *dialText, bool hover) { +void Menu::drawButtonGfx(const MenuSettings *menuSettings, const Common::Rect &rect, int32 buttonId, const char *dialText, bool hover) { if (hover) { if (menuSettings == &volumeMenuState && buttonId <= MenuButtonTypes::kMasterVolume && buttonId >= MenuButtonTypes::kMusicVolume) { int32 newWidth = 0; switch (buttonId) { case MenuButtonTypes::kMusicVolume: { const int volume = _engine->_system->getMixer()->getVolumeForSoundType(Audio::Mixer::kMusicSoundType); - newWidth = _engine->_screens->crossDot(left, right, Audio::Mixer::kMaxMixerVolume, volume); + newWidth = _engine->_screens->crossDot(rect.left, rect.right, Audio::Mixer::kMaxMixerVolume, volume); break; } case MenuButtonTypes::kSoundVolume: { const int volume = _engine->_system->getMixer()->getVolumeForSoundType(Audio::Mixer::kSFXSoundType); - newWidth = _engine->_screens->crossDot(left, right, Audio::Mixer::kMaxMixerVolume, volume); + newWidth = _engine->_screens->crossDot(rect.left, rect.right, Audio::Mixer::kMaxMixerVolume, volume); break; } case MenuButtonTypes::kCDVolume: { const AudioCDManager::Status status = _engine->_system->getAudioCDManager()->getStatus(); - newWidth = _engine->_screens->crossDot(left, right, Audio::Mixer::kMaxMixerVolume, status.volume); + newWidth = _engine->_screens->crossDot(rect.left, rect.right, Audio::Mixer::kMaxMixerVolume, status.volume); break; } case MenuButtonTypes::kLineVolume: { const int volume = _engine->_system->getMixer()->getVolumeForSoundType(Audio::Mixer::kSpeechSoundType); - newWidth = _engine->_screens->crossDot(left, right, Audio::Mixer::kMaxMixerVolume, volume); + newWidth = _engine->_screens->crossDot(rect.left, rect.right, Audio::Mixer::kMaxMixerVolume, volume); break; } case MenuButtonTypes::kMasterVolume: { const int volume = _engine->_system->getMixer()->getVolumeForSoundType(Audio::Mixer::kPlainSoundType); - newWidth = _engine->_screens->crossDot(left, right, Audio::Mixer::kMaxMixerVolume, volume); + newWidth = _engine->_screens->crossDot(rect.left, rect.right, Audio::Mixer::kMaxMixerVolume, volume); break; } } - processPlasmaEffect(left, top, 80); + processPlasmaEffect(rect.left, rect.top, 80); if (!(_engine->getRandomNumber() % 5)) { plasmaEffectPtr[_engine->getRandomNumber() % 140 * 10 + 1900] = 255; } - _engine->_interface->drawSplittedBox(newWidth, top, right, bottom, 68); + _engine->_interface->drawSplittedBox(newWidth, rect.top, rect.right, rect.bottom, 68); } else { - processPlasmaEffect(left, top, 64); + processPlasmaEffect(rect.left, rect.top, 64); if (!(_engine->getRandomNumber() % 5)) { plasmaEffectPtr[_engine->getRandomNumber() % 320 * 10 + 6400] = 255; } } } else { - _engine->_interface->blitBox(left, top, right, bottom, _engine->workVideoBuffer, left, top, _engine->frontVideoBuffer); - _engine->_interface->drawTransparentBox(left, top, right, bottom, 4); + _engine->_interface->blitBox(rect, _engine->workVideoBuffer, rect.left, rect.top, _engine->frontVideoBuffer); + _engine->_interface->drawTransparentBox(rect, 4); } - drawBox(left, top, right, bottom); + drawBox(rect); _engine->_text->setFontColor(15); _engine->_text->setFontParameters(2, 8); const int32 textSize = _engine->_text->getTextSize(dialText); - _engine->_text->drawText((SCREEN_WIDTH / 2) - (textSize / 2), top + 7, dialText); + _engine->_text->drawText((SCREEN_WIDTH / 2) - (textSize / 2), rect.top + 7, dialText); - _engine->copyBlockPhys(left, top, right, bottom); + _engine->copyBlockPhys(rect); } int16 Menu::drawButtons(MenuSettings *menuSettings, bool hover) { @@ -360,24 +360,21 @@ int16 Menu::drawButtons(MenuSettings *menuSettings, bool hover) { } const int32 menuItemId = menuSettings->getButtonState(i); const char *text = menuSettings->getButtonText(_engine->_text, i); - const uint16 mainMenuButtonWidthHalf = 550 / 2; - const uint16 mainMenuButtonHeightHalf = 50 / 2; - const int32 left = (SCREEN_WIDTH / 2) - mainMenuButtonWidthHalf; - const int32 right = (SCREEN_WIDTH / 2) + mainMenuButtonWidthHalf; - const int32 top = topHeight - mainMenuButtonHeightHalf; - const int32 bottom = topHeight + mainMenuButtonHeightHalf; + const int32 border = 45; + const int32 mainMenuButtonHeightHalf = 25; + const Common::Rect rect(border, topHeight - mainMenuButtonHeightHalf, SCREEN_WIDTH - border, topHeight + mainMenuButtonHeightHalf); if (hover) { if (i == buttonNumber) { - drawButtonGfx(menuSettings, left, top, right, bottom, menuItemId, text, hover); + drawButtonGfx(menuSettings, rect, menuItemId, text, hover); } } else { if (i == buttonNumber) { - drawButtonGfx(menuSettings, left, top, right, bottom, menuItemId, text, true); + drawButtonGfx(menuSettings, rect, menuItemId, text, true); } else { - drawButtonGfx(menuSettings, left, top, right, bottom, menuItemId, text, false); + drawButtonGfx(menuSettings, rect, menuItemId, text, false); } } - if (_engine->_input->isMouseHovering(left, top, right, bottom)) { + if (_engine->_input->isMouseHovering(rect)) { mouseActiveButton = i; } diff --git a/engines/twine/menu.h b/engines/twine/menu.h index 63258e125b6..37d1f080958 100644 --- a/engines/twine/menu.h +++ b/engines/twine/menu.h @@ -150,7 +150,7 @@ private: * @param dialText * @param hover flag to know if should draw as a hover button or not */ - void drawButtonGfx(const MenuSettings *menuSettings, int32 left, int32 top, int32 right, int32 bottom, int32 buttonId, const char *dialText, bool hover); + void drawButtonGfx(const MenuSettings *menuSettings, const Common::Rect &rect, int32 buttonId, const char *dialText, bool hover); void plasmaEffectRenderFrame(); /** * Process the menu button draw diff --git a/engines/twine/menuoptions.cpp b/engines/twine/menuoptions.cpp index ef94dd2673c..e2e4eaf2154 100644 --- a/engines/twine/menuoptions.cpp +++ b/engines/twine/menuoptions.cpp @@ -127,12 +127,9 @@ void MenuOptions::drawSelectableCharacter(int32 x, int32 y) { const int32 buttonDistanceY = halfButtonHeight * 2 + 5; const int32 centerX = x * buttonDistanceX + borderLeft; const int32 centerY = y * buttonDistanceY + borderTop; - const int32 left = centerX - halfButtonWidth; - const int32 right = centerX + halfButtonWidth; - const int32 top = centerY - halfButtonHeight; - const int32 bottom = centerY + halfButtonHeight; + const Common::Rect rect(centerX - halfButtonWidth, centerY - halfButtonHeight, centerX + halfButtonWidth, centerY + halfButtonHeight); - if (_engine->_input->isMouseHovering(left, top, right, bottom)) { + if (_engine->_input->isMouseHovering(rect)) { setOnScreenKeyboard(x, y); } @@ -147,13 +144,13 @@ void MenuOptions::drawSelectableCharacter(int32 x, int32 y) { const bool selected = _onScreenKeyboardX == x && _onScreenKeyboardY == y; if (selected) { - _engine->_interface->drawSplittedBox(left, top, right, bottom, 91); + _engine->_interface->drawSplittedBox(rect, 91); } else { - _engine->_interface->blitBox(left, top, right, bottom, _engine->workVideoBuffer, left, top, _engine->frontVideoBuffer); - _engine->_interface->drawTransparentBox(left, top, right, bottom, 4); + _engine->_interface->blitBox(rect, _engine->workVideoBuffer, rect.left, rect.top, _engine->frontVideoBuffer); + _engine->_interface->drawTransparentBox(rect, 4); } - _engine->_menu->drawBox(left, top, right, bottom); + _engine->_menu->drawBox(rect); _engine->_text->setFontColor(15); const uint8 character = (uint8)allowedCharIndex[idx]; @@ -161,7 +158,7 @@ void MenuOptions::drawSelectableCharacter(int32 x, int32 y) { const int32 textY = centerY - _engine->_text->getCharHeight(character) / 2; _engine->_text->drawText(textX, textY, buffer); - _engine->copyBlockPhys(left, top, right, bottom); + _engine->copyBlockPhys(rect); } void MenuOptions::setOnScreenKeyboard(int x, int y) { diff --git a/engines/twine/redraw.cpp b/engines/twine/redraw.cpp index fba19411604..f1c08afe542 100644 --- a/engines/twine/redraw.cpp +++ b/engines/twine/redraw.cpp @@ -102,6 +102,10 @@ void Redraw::addRedrawCurrentArea(int32 left, int32 top, int32 right, int32 bott numOfRedrawBox++; } +void Redraw::addRedrawArea(const Common::Rect &rect) { + addRedrawArea(rect.left, rect.top, rect.right, rect.bottom); +} + void Redraw::addRedrawArea(int32 left, int32 top, int32 right, int32 bottom) { if (left < SCREEN_TEXTLIMIT_LEFT) { left = SCREEN_TEXTLIMIT_LEFT; @@ -640,9 +644,10 @@ void Redraw::redrawEngineActions(int32 bgRedraw) { // fullRedraw } case koInventoryItem: { const int32 item = overlay->info0; + const Common::Rect rect(10, 10, 69, 69); - _engine->_interface->drawSplittedBox(10, 10, 69, 69, 0); - _engine->_interface->setClip(10, 10, 69, 69); + _engine->_interface->drawSplittedBox(rect, 0); + _engine->_interface->setClip(rect); _engine->_renderer->prepareIsoModel(_engine->_resources->inventoryTable[item]); _engine->_renderer->setCameraPosition(40, 40, 128, 200, 200); @@ -651,8 +656,8 @@ void Redraw::redrawEngineActions(int32 bgRedraw) { // fullRedraw overlayRotation += 1; // overlayRotation += 8; _engine->_renderer->renderIsoModel(0, 0, 0, 0, overlayRotation, 0, _engine->_resources->inventoryTable[item]); - _engine->_menu->drawBox(10, 10, 69, 69); - addRedrawArea(10, 10, 69, 69); + _engine->_menu->drawBox(rect); + addRedrawArea(rect); _engine->_gameState->initEngineProjections(); break; } diff --git a/engines/twine/redraw.h b/engines/twine/redraw.h index 0b595f95743..7f50d9446fb 100644 --- a/engines/twine/redraw.h +++ b/engines/twine/redraw.h @@ -24,6 +24,7 @@ #define TWINE_REDRAW_H #include "common/scummsys.h" +#include "common/rect.h" namespace TwinE { @@ -139,6 +140,7 @@ public: * @param bottom end height to redraw the region */ void addRedrawArea(int32 left, int32 top, int32 right, int32 bottom); + void addRedrawArea(const Common::Rect &rect); /** * Flip currentRedrawList regions in the screen