[Scummvm-cvs-logs] scummvm master -> 2664ee63141a18283984e2e1c9325a1362c2133c
dreammaster
dreammaster at scummvm.org
Tue Jun 30 14:30:07 CEST 2015
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
2664ee6314 SHERLOCK: RT: Create a tooltip base clsas
Commit: 2664ee63141a18283984e2e1c9325a1362c2133c
https://github.com/scummvm/scummvm/commit/2664ee63141a18283984e2e1c9325a1362c2133c
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2015-06-30T08:29:09-04:00
Commit Message:
SHERLOCK: RT: Create a tooltip base clsas
Changed paths:
engines/sherlock/screen.cpp
engines/sherlock/screen.h
engines/sherlock/tattoo/widget_base.cpp
engines/sherlock/tattoo/widget_base.h
engines/sherlock/tattoo/widget_inventory.cpp
engines/sherlock/tattoo/widget_inventory.h
engines/sherlock/tattoo/widget_tooltip.cpp
engines/sherlock/tattoo/widget_tooltip.h
diff --git a/engines/sherlock/screen.cpp b/engines/sherlock/screen.cpp
index 4c6e0ef..e20c1b5 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 a98c6d7..6146e4f 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 b3c089b..b958053 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 2e57e74..f5ac2ea 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 30a8c3c..b4a6daa 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 99086ad..77caddf 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 69df7e0..5c4478d 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 32e54ed..38d3ad9 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() {}
More information about the Scummvm-git-logs
mailing list