diff options
-rw-r--r-- | engines/startrek/graphics.cpp | 58 | ||||
-rw-r--r-- | engines/startrek/graphics.h | 12 | ||||
-rw-r--r-- | engines/startrek/menu.cpp | 20 | ||||
-rw-r--r-- | engines/startrek/text.cpp | 6 |
4 files changed, 71 insertions, 25 deletions
diff --git a/engines/startrek/graphics.cpp b/engines/startrek/graphics.cpp index 8142c4d187..a51999e4d3 100644 --- a/engines/startrek/graphics.cpp +++ b/engines/startrek/graphics.cpp @@ -52,6 +52,10 @@ Graphics::Graphics(StarTrekEngine *vm) : _vm(vm), _egaMode(false) { _paletteFadeLevel = 0; _mouseLocked = false; + _mouseToBeShown = false; + _mouseToBeHidden = false; + _mouseWarpX = -1; + _mouseWarpY = -1; setMouseBitmap(loadBitmap("pushbtn")); CursorMan.showMouse(true); @@ -180,17 +184,21 @@ SharedPtr<Bitmap> Graphics::loadBitmap(Common::String basename) { } Common::Point Graphics::getMousePos() { + if (_mouseWarpX != -1) + return Common::Point(_mouseWarpX, _mouseWarpY); + return _vm->_system->getEventManager()->getMousePos(); } +/** + * The change to the mouse's bitmap won't take effect until drawAllSprites is called + * again. + */ void Graphics::setMouseBitmap(SharedPtr<Bitmap> bitmap) { _mouseBitmap = bitmap; - _vm->_system->setMouseCursor(bitmap->pixels, bitmap->width, bitmap->height, bitmap->xoffset, bitmap->yoffset, 0); - if (_mouseLocked) { + if (_mouseLocked) _lockedMouseSprite.setBitmap(_mouseBitmap); - drawAllSprites(false); - } } /** @@ -206,13 +214,13 @@ void Graphics::lockMousePosition(int16 x, int16 y) { _lockedMouseSprite.pos.x = x; _lockedMouseSprite.pos.y = y; _lockedMouseSprite.bitmapChanged = true; - drawAllSprites(false); } return; } - CursorMan.showMouse(false); _mouseLocked = true; + _mouseToBeHidden = true; + _mouseToBeShown = false; _lockedMouseSprite = Sprite(); _lockedMouseSprite.setBitmap(_mouseBitmap); @@ -222,7 +230,6 @@ void Graphics::lockMousePosition(int16 x, int16 y) { _lockedMouseSprite.pos.y = y; addSprite(&_lockedMouseSprite); - drawAllSprites(false); } void Graphics::unlockMousePosition() { @@ -230,13 +237,23 @@ void Graphics::unlockMousePosition() { return; _mouseLocked = false; - CursorMan.showMouse(true); + _mouseToBeShown = true; + _mouseToBeHidden = false; _lockedMouseSprite.dontDrawNextFrame(); - drawAllSprites(); + drawAllSprites(false); delSprite(&_lockedMouseSprite); } +SharedPtr<Bitmap> Graphics::getMouseBitmap() { + return _mouseBitmap; +} + +void Graphics::warpMouse(int16 x, int16 y) { + _mouseWarpX = x; + _mouseWarpY = y; +} + void Graphics::drawSprite(const Sprite &sprite) { int left = sprite.drawX; int top = sprite.drawY; @@ -510,8 +527,29 @@ void Graphics::drawAllSprites(bool updateScreen) { spr->lastDrawRect = spr->drawRect; } - if (updateScreen) + if (updateScreen) { + // Check if there are any pending updates to the mouse. + if (_mouseBitmap != _mouseBitmapLastFrame) { + _mouseBitmapLastFrame = _mouseBitmap; + _vm->_system->setMouseCursor(_mouseBitmap->pixels, _mouseBitmap->width, _mouseBitmap->height, _mouseBitmap->xoffset, _mouseBitmap->yoffset, 0); + } + if (_mouseToBeShown) { + CursorMan.showMouse(true); + _mouseToBeShown = false; + } + else if (_mouseToBeHidden) { + CursorMan.showMouse(false); + _mouseToBeHidden = false; + } + + if (_mouseWarpX != -1) { + _vm->_system->warpMouse(_mouseWarpX, _mouseWarpY); + _mouseWarpX = -1; + _mouseWarpY = -1; + } + _vm->_system->updateScreen(); + } } void Graphics::addSprite(Sprite *sprite) { diff --git a/engines/startrek/graphics.h b/engines/startrek/graphics.h index cba5ddfacd..f58e444a61 100644 --- a/engines/startrek/graphics.h +++ b/engines/startrek/graphics.h @@ -70,6 +70,8 @@ public: void setMouseBitmap(SharedPtr<Bitmap> bitmap); void lockMousePosition(int16 x, int16 y); void unlockMousePosition(); + SharedPtr<Bitmap> getMouseBitmap(); + void warpMouse(int16 x, int16 y); void drawSprite(const Sprite &sprite); void drawSprite(const Sprite &sprite, const Common::Rect &rect); @@ -102,13 +104,21 @@ private: Sprite *_sprites[MAX_SPRITES]; int _numSprites; + // Any changes to the mouse image are buffered until the next time "drawAllSprites" is + // called (since the original game treats it like a sprite). + bool _mouseToBeShown; + bool _mouseToBeHidden; + int16 _mouseWarpX, _mouseWarpY; + SharedPtr<Bitmap> _mouseBitmapLastFrame; + SharedPtr<Bitmap> _mouseBitmap; + // These are used as a workaround for when the mouse position must be locked. // The mouse is turned into a native game sprite when this happens. bool _mouseLocked; Sprite _lockedMouseSprite; + public: - SharedPtr<Bitmap> _mouseBitmap; }; } diff --git a/engines/startrek/menu.cpp b/engines/startrek/menu.cpp index da5b11e2c0..acd41549f3 100644 --- a/engines/startrek/menu.cpp +++ b/engines/startrek/menu.cpp @@ -165,7 +165,7 @@ void StarTrekEngine::chooseMousePositionFromSprites(Sprite *sprites, int numSpri mousePos.y = mouseY2; } - _system->warpMouse(mousePos.x, mousePos.y); + _gfx->warpMouse(mousePos.x, mousePos.y); } @@ -202,7 +202,7 @@ void StarTrekEngine::showOptionsMenu(int x, int y) { _mouseControllingShip = false; Common::Point oldMousePos = _gfx->getMousePos(); - SharedPtr<Bitmap> oldMouseBitmap = _gfx->_mouseBitmap; + SharedPtr<Bitmap> oldMouseBitmap = _gfx->getMouseBitmap(); _gfx->setMouseBitmap(_gfx->loadBitmap("options")); loadMenuButtons("options", x, y); @@ -235,7 +235,7 @@ void StarTrekEngine::showOptionsMenu(int x, int y) { _gfx->setMouseBitmap(oldMouseBitmap); if (event != MENUEVENT_LCLICK_OFFBUTTON && event != MENUEVENT_RCLICK_OFFBUTTON) - _system->warpMouse(oldMousePos.x, oldMousePos.y); + _gfx->warpMouse(oldMousePos.x, oldMousePos.y); // Can't use OPTIONBUTTON constants since the button retvals differ from the button @@ -331,7 +331,7 @@ int StarTrekEngine::showActionMenu() { int menuWidth = menuSprite.bitmap->width; int menuHeight = menuSprite.bitmap->height; - _system->warpMouse(pos.x + menuWidth / 2, pos.y + menuHeight / 2); + _gfx->warpMouse(pos.x + menuWidth / 2, pos.y + menuHeight / 2); _gfx->addSprite(&menuSprite); menuSprite.pos = pos; @@ -409,8 +409,6 @@ mousePosChanged: _gfx->lockMousePosition(lockMousePoint.x, lockMousePoint.y); else _gfx->unlockMousePosition(); - - _system->updateScreen(); } break; @@ -485,11 +483,11 @@ lookupNextAction: // Warp mouse to the position of the selected action if (nextAction == ACTION_WALK) - _system->warpMouse(pos.x + menuWidth / 2, pos.y + menuHeight / 2); + _gfx->warpMouse(pos.x + menuWidth / 2, pos.y + menuHeight / 2); else { assert((action >= ACTION_WALK && action <= ACTION_TALK) || action == ACTION_OPTIONS); const Common::Point &p = actionPositions[action == ACTION_OPTIONS ? 4 : action - 2]; - _system->warpMouse(pos.x + p.x, pos.y + p.y); + _gfx->warpMouse(pos.x + p.x, pos.y + p.y); } goto mousePosChanged; @@ -500,14 +498,14 @@ lookupNextAction: } } - _gfx->unlockMousePosition(); - playSoundEffectIndex(0x10); menuSprite.dontDrawNextFrame(); _gfx->drawAllSprites(); _gfx->delSprite(&menuSprite); + _gfx->unlockMousePosition(); + if (action == ACTION_OPTIONS) { showOptionsMenu(50, 50); action = ACTION_WALK; @@ -519,7 +517,7 @@ lookupNextAction: addEventToQueue(event); // Add left-click event back to queue so Kirk can walk there } else - _system->warpMouse(oldMousePos.x, oldMousePos.y); + _gfx->warpMouse(oldMousePos.x, oldMousePos.y); chooseMouseBitmapForAction(action, false); _keyboardControlsMouse = keyboardControlledMouse; diff --git a/engines/startrek/text.cpp b/engines/startrek/text.cpp index ed060c7624..239e4f5206 100644 --- a/engines/startrek/text.cpp +++ b/engines/startrek/text.cpp @@ -247,9 +247,9 @@ int StarTrekEngine::showText(TextGetterFunc textGetter, uintptr var, int xoffset loadMenuButtons("textbtns", xoffset + 0x96, yoffset - 0x11); Common::Point oldMousePos = _gfx->getMousePos(); - SharedPtr<Bitmap> oldMouseBitmap = _gfx->_mouseBitmap; + SharedPtr<Bitmap> oldMouseBitmap = _gfx->getMouseBitmap(); - _system->warpMouse(xoffset + 0xde, yoffset - 0x08); + _gfx->warpMouse(xoffset + 0xde, yoffset - 0x08); _gfx->setMouseBitmap(_gfx->loadBitmap("pushbtn")); bool tmpMouseControllingShip = _mouseControllingShip; @@ -399,7 +399,7 @@ reloadText: } _gfx->setMouseBitmap(oldMouseBitmap); - _system->warpMouse(oldMousePos.x, oldMousePos.y); + _gfx->warpMouse(oldMousePos.x, oldMousePos.y); _mouseControllingShip = tmpMouseControllingShip; unloadMenuButtons(); |