diff options
author | Paul Gilbert | 2015-06-30 08:29:09 -0400 |
---|---|---|
committer | Paul Gilbert | 2015-06-30 08:29:09 -0400 |
commit | 2664ee63141a18283984e2e1c9325a1362c2133c (patch) | |
tree | 916e7247aad3ea51b1e1b067c9710d0cb85098a0 | |
parent | 9ef857bc6fdad24420872aa9dab91505cb6acfbf (diff) | |
download | scummvm-rg350-2664ee63141a18283984e2e1c9325a1362c2133c.tar.gz scummvm-rg350-2664ee63141a18283984e2e1c9325a1362c2133c.tar.bz2 scummvm-rg350-2664ee63141a18283984e2e1c9325a1362c2133c.zip |
SHERLOCK: RT: Create a tooltip base clsas
-rw-r--r-- | engines/sherlock/screen.cpp | 28 | ||||
-rw-r--r-- | engines/sherlock/screen.h | 5 | ||||
-rw-r--r-- | engines/sherlock/tattoo/widget_base.cpp | 2 | ||||
-rw-r--r-- | engines/sherlock/tattoo/widget_base.h | 3 | ||||
-rw-r--r-- | engines/sherlock/tattoo/widget_inventory.cpp | 4 | ||||
-rw-r--r-- | engines/sherlock/tattoo/widget_inventory.h | 2 | ||||
-rw-r--r-- | engines/sherlock/tattoo/widget_tooltip.cpp | 38 | ||||
-rw-r--r-- | engines/sherlock/tattoo/widget_tooltip.h | 21 |
8 files changed, 91 insertions, 12 deletions
diff --git a/engines/sherlock/screen.cpp b/engines/sherlock/screen.cpp index 4c6e0ef748..e20c1b5182 100644 --- a/engines/sherlock/screen.cpp +++ b/engines/sherlock/screen.cpp @@ -367,6 +367,34 @@ void Screen::slamRect(const Common::Rect &r) { } } +void Screen::slamRect(const Common::Rect &r, const Common::Point ¤tScroll) { + if (r.width() && r.height() > 0) { + Common::Rect srcRect = r, destRect = r; + srcRect.translate(currentScroll.x, currentScroll.y); + + if (destRect.left < 0) { + srcRect.left += -destRect.left; + destRect.left = 0; + } + if (destRect.top < 0) { + srcRect.top += -destRect.top; + destRect.top = 0; + } + if (destRect.right > SHERLOCK_SCREEN_WIDTH) { + srcRect.right -= (destRect.left - SHERLOCK_SCREEN_WIDTH); + destRect.right = SHERLOCK_SCREEN_WIDTH; + } + if (destRect.bottom > SHERLOCK_SCREEN_HEIGHT) { + srcRect.bottom -= (destRect.bottom - SHERLOCK_SCREEN_HEIGHT); + destRect.bottom = SHERLOCK_SCREEN_HEIGHT; + } + + if (srcRect.isValidRect()) + blitFrom(*_backBuffer, Common::Point(destRect.left, destRect.top), srcRect); + } +} + + void Screen::flushImage(ImageFrame *frame, const Common::Point &pt, int16 *xp, int16 *yp, int16 *width, int16 *height) { Common::Point imgPos = pt + frame->_offset; diff --git a/engines/sherlock/screen.h b/engines/sherlock/screen.h index a98c6d7acc..6146e4f177 100644 --- a/engines/sherlock/screen.h +++ b/engines/sherlock/screen.h @@ -166,6 +166,11 @@ public: void slamRect(const Common::Rect &r); /** + * Copies a given area to the screen + */ + void slamRect(const Common::Rect &r, const Common::Point ¤tScroll); + + /** * Copy an image from the back buffer to the screen, taking care of both the * new area covered by the shape as well as the old area, which must be restored */ diff --git a/engines/sherlock/tattoo/widget_base.cpp b/engines/sherlock/tattoo/widget_base.cpp index b3c089bf6a..b958053286 100644 --- a/engines/sherlock/tattoo/widget_base.cpp +++ b/engines/sherlock/tattoo/widget_base.cpp @@ -61,7 +61,7 @@ void WidgetBase::erase() { screen._backBuffer1.blitFrom(screen._backBuffer2, Common::Point(oldBounds.left, oldBounds.top), oldBounds); screen.blitFrom(screen._backBuffer1, Common::Point(_oldBounds.left, _oldBounds.top), oldBounds); - // Reset the old bounds so + // Reset the old bounds so it won't be erased again _oldBounds = Common::Rect(0, 0, 0, 0); } } diff --git a/engines/sherlock/tattoo/widget_base.h b/engines/sherlock/tattoo/widget_base.h index 2e57e74d83..f5ac2ea52b 100644 --- a/engines/sherlock/tattoo/widget_base.h +++ b/engines/sherlock/tattoo/widget_base.h @@ -36,11 +36,10 @@ class ImageFile; namespace Tattoo { class WidgetBase { -private: - Common::Rect _oldBounds; protected: SherlockEngine *_vm; Common::Rect _bounds; + Common::Rect _oldBounds; Surface _surface; bool _outsideMenu; diff --git a/engines/sherlock/tattoo/widget_inventory.cpp b/engines/sherlock/tattoo/widget_inventory.cpp index 30a8c3cf10..b4a6daabc2 100644 --- a/engines/sherlock/tattoo/widget_inventory.cpp +++ b/engines/sherlock/tattoo/widget_inventory.cpp @@ -36,7 +36,7 @@ namespace Tattoo { #define MAX_INV_COMMANDS 10 // Maximum elements in dialog WidgetInventoryTooltip::WidgetInventoryTooltip(SherlockEngine *vm, WidgetInventory *owner) : - WidgetBase(vm), _owner(owner) { + WidgetTooltipBase(vm), _owner(owner) { } void WidgetInventoryTooltip::setText(const Common::String &str) { @@ -48,7 +48,7 @@ void WidgetInventoryTooltip::setText(const Common::String &str) { } int width = _surface.stringWidth(str) + 2; - int height; + int height = 0; Common::String line1 = str, line2; // See if we need to split it into two lines diff --git a/engines/sherlock/tattoo/widget_inventory.h b/engines/sherlock/tattoo/widget_inventory.h index 99086ad801..77caddf86b 100644 --- a/engines/sherlock/tattoo/widget_inventory.h +++ b/engines/sherlock/tattoo/widget_inventory.h @@ -37,7 +37,7 @@ namespace Tattoo { class WidgetInventory; -class WidgetInventoryTooltip: public WidgetBase { +class WidgetInventoryTooltip: public WidgetTooltipBase { private: WidgetInventory *_owner; Common::Rect _oldInvGraphicBounds, _invGraphicBounds; diff --git a/engines/sherlock/tattoo/widget_tooltip.cpp b/engines/sherlock/tattoo/widget_tooltip.cpp index 69df7e0ede..5c4478d32b 100644 --- a/engines/sherlock/tattoo/widget_tooltip.cpp +++ b/engines/sherlock/tattoo/widget_tooltip.cpp @@ -31,7 +31,43 @@ namespace Tattoo { #define MAX_TOOLTIP_WIDTH 150 -WidgetTooltip::WidgetTooltip(SherlockEngine *vm) : WidgetBase(vm) { +void WidgetTooltipBase::draw() { + Screen &screen = *_vm->_screen; + const Common::Point ¤tScroll = getCurrentScroll(); + + // If there was a previously drawn frame in a different position that hasn't yet been erased, then erase it + if (_oldBounds.width() > 0 && _oldBounds != _bounds) + erase(); + + if (_bounds.width() > 0 && !_surface.empty()) { + // Blit the affected area to the screen + screen.slamRect(_bounds, currentScroll); + + // Draw the widget directly onto the screen. Unlike other widgets, we don't draw to the back buffer, + // since nothing should be drawing on top of tooltips, so there's no need to store in the back buffer + screen.transBlitFrom(_surface, Common::Point(_bounds.left, _bounds.top)); + + // Store a copy of the drawn area for later erasing + _oldBounds = _bounds; + } +} + +void WidgetTooltipBase::erase() { + Screen &screen = *_vm->_screen; + const Common::Point ¤tScroll = getCurrentScroll(); + + if (_oldBounds.width() > 0) { + // Restore the affected area from the back buffer to the screen + screen.slamRect(_oldBounds, currentScroll); + + // Reset the old bounds so it won't be erased again + _oldBounds = Common::Rect(0, 0, 0, 0); + } +} + +/*----------------------------------------------------------------*/ + +WidgetTooltip::WidgetTooltip(SherlockEngine *vm) : WidgetTooltipBase (vm) { } void WidgetTooltip::setText(const Common::String &str) { diff --git a/engines/sherlock/tattoo/widget_tooltip.h b/engines/sherlock/tattoo/widget_tooltip.h index 32e54ed2bb..38d3ad9efd 100644 --- a/engines/sherlock/tattoo/widget_tooltip.h +++ b/engines/sherlock/tattoo/widget_tooltip.h @@ -33,12 +33,23 @@ class SherlockEngine; namespace Tattoo { -class WidgetTooltip: public WidgetBase { -protected: +class WidgetTooltipBase : public WidgetBase { +public: + WidgetTooltipBase(SherlockEngine *vm) : WidgetBase(vm) {} + virtual ~WidgetTooltipBase() {} + /** - * Overriden from base class, since tooltips have a completely transparent background - */ - virtual void drawBackground() {} + * Erase any previous display of the widget on the screen + */ + virtual void erase(); + + /** + * Update the display of the widget on the screen + */ + virtual void draw(); +}; + +class WidgetTooltip: public WidgetTooltipBase { public: WidgetTooltip(SherlockEngine *vm); virtual ~WidgetTooltip() {} |