aboutsummaryrefslogtreecommitdiff
path: root/engines/startrek/graphics.cpp
diff options
context:
space:
mode:
authorFilippos Karapetis2019-10-29 00:13:57 +0200
committerFilippos Karapetis2019-10-29 02:58:36 +0200
commitb2d1cfa12669b4273d8be8fd4fd99e6b02db10ec (patch)
treef47fb99fb510c860b76f1bc1be2168928c30f25f /engines/startrek/graphics.cpp
parentf93bbfd7cae334d242760f6d3681b4ae318fa981 (diff)
downloadscummvm-rg350-b2d1cfa12669b4273d8be8fd4fd99e6b02db10ec.tar.gz
scummvm-rg350-b2d1cfa12669b4273d8be8fd4fd99e6b02db10ec.tar.bz2
scummvm-rg350-b2d1cfa12669b4273d8be8fd4fd99e6b02db10ec.zip
STARTREK: Refactored mouse cursor and bitmap handling
- Reduced usage of SharedPtr - Simplified the mouse cursor code (normal, locked, stack handling) - Simplified the background handling code - Initialize the mouse cursor after the graphics are initialized
Diffstat (limited to 'engines/startrek/graphics.cpp')
-rw-r--r--engines/startrek/graphics.cpp118
1 files changed, 34 insertions, 84 deletions
diff --git a/engines/startrek/graphics.cpp b/engines/startrek/graphics.cpp
index f56d7d3707..e1073e2c50 100644
--- a/engines/startrek/graphics.cpp
+++ b/engines/startrek/graphics.cpp
@@ -61,14 +61,7 @@ Graphics::Graphics(StarTrekEngine *vm) : _vm(vm), _egaMode(false) {
memset(_lutData, 0, 256 * 3);
_paletteFadeLevel = 0;
- _mouseLocked = false;
- _mouseToBeShown = false;
- _mouseToBeHidden = false;
- _mouseWarpX = -1;
- _mouseWarpY = -1;
-
- setMouseBitmap(loadBitmap("pushbtn"));
- CursorMan.showMouse(true);
+ _lockedMousePos = Common::Point(-1, -1);
}
Graphics::~Graphics() {
@@ -79,9 +72,8 @@ Graphics::~Graphics() {
delete _font;
}
-
-void Graphics::setBackgroundImage(SharedPtr<Bitmap> bitmap) {
- _backgroundImage = SharedPtr<Bitmap>(new Bitmap(*bitmap));
+void Graphics::setBackgroundImage(Bitmap *bitmap) {
+ _backgroundImage = SharedPtr<Bitmap>(bitmap);
}
void Graphics::drawBitmapToBackground(const Common::Rect &origRect, const Common::Rect &drawRect, Bitmap *bitmap) {
@@ -246,68 +238,43 @@ byte Graphics::getPriValue(int x, int y) {
return b >> 4;
}
-SharedPtr<Bitmap> Graphics::loadBitmap(Common::String basename) {
- return SharedPtr<Bitmap>(new Bitmap(SharedPtr<Common::MemoryReadStreamEndian>(_vm->loadFile(basename + ".BMP"))));
+Bitmap *Graphics::loadBitmap(Common::String basename) {
+ return new Bitmap(SharedPtr<Common::MemoryReadStreamEndian>(_vm->loadFile(basename + ".BMP")));
}
Common::Point Graphics::getMousePos() {
- if (_mouseWarpX != -1)
- return Common::Point(_mouseWarpX, _mouseWarpY);
-
return _vm->_system->getEventManager()->getMousePos();
}
-void Graphics::setMouseBitmap(SharedPtr<Bitmap> bitmap) {
- _mouseBitmap = bitmap;
-
- if (_mouseLocked)
- _lockedMouseSprite.setBitmap(_mouseBitmap);
+void Graphics::setMouseBitmap(Bitmap *bitmap) {
+ CursorMan.pushCursor(
+ bitmap->pixels,
+ bitmap->width,
+ bitmap->height,
+ bitmap->xoffset,
+ bitmap->yoffset,
+ 0
+ );
}
-void Graphics::lockMousePosition(int16 x, int16 y) {
- if (_mouseLocked) {
- if (x != _lockedMouseSprite.pos.x || y != _lockedMouseSprite.pos.y) {
- _lockedMouseSprite.pos.x = x;
- _lockedMouseSprite.pos.y = y;
- _lockedMouseSprite.bitmapChanged = true;
- }
- return;
- }
-
- _mouseLocked = true;
- _mouseToBeHidden = true;
- _mouseToBeShown = false;
-
- _lockedMouseSprite = Sprite();
- _lockedMouseSprite.setBitmap(_mouseBitmap);
- _lockedMouseSprite.drawPriority = 15;
- _lockedMouseSprite.drawPriority2 = 16;
- _lockedMouseSprite.pos.x = x;
- _lockedMouseSprite.pos.y = y;
-
- addSprite(&_lockedMouseSprite);
+void Graphics::popMouseBitmap() {
+ CursorMan.popCursor();
}
-void Graphics::unlockMousePosition() {
- if (!_mouseLocked)
- return;
-
- _mouseLocked = false;
- _mouseToBeShown = true;
- _mouseToBeHidden = false;
+void Graphics::toggleMouse(bool visible) {
+ CursorMan.showMouse(visible);
+}
- _lockedMouseSprite.dontDrawNextFrame();
- drawAllSprites(false);
- delSprite(&_lockedMouseSprite);
+void Graphics::lockMousePosition(int16 x, int16 y) {
+ _lockedMousePos = Common::Point(x, y);
}
-SharedPtr<Bitmap> Graphics::getMouseBitmap() {
- return _mouseBitmap;
+void Graphics::unlockMousePosition() {
+ _lockedMousePos = Common::Point(-1, -1);
}
void Graphics::warpMouse(int16 x, int16 y) {
- _mouseWarpX = x;
- _mouseWarpY = y;
+ _vm->_system->warpMouse(x, y);
}
void Graphics::drawSprite(const Sprite &sprite, ::Graphics::Surface *surface) {
@@ -621,24 +588,8 @@ void Graphics::forceDrawAllSprites(bool updateScreenFlag) {
}
void Graphics::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;
- }
+ if (_lockedMousePos.x != -1)
+ _vm->_system->warpMouse(_lockedMousePos.x, _lockedMousePos.y);
_vm->_console->onFrame();
_vm->_system->updateScreen();
@@ -649,8 +600,6 @@ Sprite *Graphics::getSpriteAt(int16 x, int16 y) {
for (int i = _numSprites - 1; i >= 0; i--) {
Sprite *sprite = _sprites[i];
- if (sprite == &_lockedMouseSprite)
- continue;
if (sprite->drawMode == 1) // Invisible
continue;
@@ -723,16 +672,17 @@ byte *Graphics::getFontGfx(char c) {
return _font->getCharData(c & 0xff);
}
-
void Graphics::copyBackgroundScreen() {
- drawDirectToScreen(_backgroundImage);
+ _vm->_system->copyRectToScreen(
+ _backgroundImage->pixels,
+ _backgroundImage->width,
+ _backgroundImage->xoffset,
+ _backgroundImage->yoffset,
+ _backgroundImage->width,
+ _backgroundImage->height
+ );
}
-void Graphics::drawDirectToScreen(SharedPtr<Bitmap> bitmap) {
- _vm->_system->copyRectToScreen(bitmap->pixels, bitmap->width, bitmap->xoffset, bitmap->yoffset, bitmap->width, bitmap->height);
-}
-
-
void Graphics::loadEGAData(const char *filename) {
// Load EGA palette data
if (!_egaMode)