[Scummvm-cvs-logs] SF.net SVN: scummvm:[54337] scummvm/trunk/gui

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Thu Nov 18 19:17:00 CET 2010


Revision: 54337
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54337&view=rev
Author:   lordhoto
Date:     2010-11-18 18:17:00 +0000 (Thu, 18 Nov 2010)

Log Message:
-----------
GUI: Simplify Tooltip implementation.

Formerly there was much special handling for the Tooltip dialog in
GuiManager::runLoop. This was replaced by overloading the event handling
functions in Tooltip. Also the Tooltip was adapted to be run like every
other normal dialog.

Modified Paths:
--------------
    scummvm/trunk/gui/Tooltip.cpp
    scummvm/trunk/gui/Tooltip.h
    scummvm/trunk/gui/gui-manager.cpp
    scummvm/trunk/gui/gui-manager.h

Modified: scummvm/trunk/gui/Tooltip.cpp
===================================================================
--- scummvm/trunk/gui/Tooltip.cpp	2010-11-18 17:56:21 UTC (rev 54336)
+++ scummvm/trunk/gui/Tooltip.cpp	2010-11-18 18:17:00 UTC (rev 54337)
@@ -40,40 +40,21 @@
 	_backgroundType = GUI::ThemeEngine::kDialogBackgroundTooltip;
 }
 
-void Tooltip::mustClose() {
-	if (isVisible())
-		Dialog::close();
-}
+void Tooltip::setup(Dialog *parent, Widget *widget, int x, int y) {
+	assert(widget->getTooltip());
 
-bool Tooltip::tooltipModal(int x, int y) {
-	Widget *wdg;
+	_maxWidth = g_gui.xmlEval()->getVar("Globals.Tooltip.MaxWidth", 100);
+	_xdelta = g_gui.xmlEval()->getVar("Globals.Tooltip.XDelta", 0);
+	_ydelta = g_gui.xmlEval()->getVar("Globals.Tooltip.YDelta", 0);
 
-	if (!g_gui.getTopDialog())
-		return false;
-
-	wdg = g_gui.getTopDialog()->findWidget(x, y);
-
-	if (!wdg || !wdg->getTooltip())
-		return false;
-
-	if (_maxWidth == -1) {
-		_maxWidth = g_gui.xmlEval()->getVar("Globals.Tooltip.MaxWidth", 100);
-		_xdelta = g_gui.xmlEval()->getVar("Globals.Tooltip.XDelta", 0);
-		_ydelta = g_gui.xmlEval()->getVar("Globals.Tooltip.YDelta", 0);
-	}
-
 	const Graphics::Font *tooltipFont = g_gui.theme()->getFont(ThemeEngine::kFontStyleTooltip);
 
 	_wrappedLines.clear();
-	_w = tooltipFont->wordWrapText(wdg->getTooltip(), _maxWidth - 4, _wrappedLines);
+	_w = tooltipFont->wordWrapText(widget->getTooltip(), _maxWidth - 4, _wrappedLines);
 	_h = (tooltipFont->getFontHeight() + 2) * _wrappedLines.size();
 
-	_x = MIN<int16>(g_gui.getTopDialog()->_x + x + _xdelta, g_gui.getWidth() - _w - 3);
-	_y = MIN<int16>(g_gui.getTopDialog()->_y + y + _ydelta, g_gui.getHeight() - _h - 3);
-
-	open();
-
-	return true;
+	_x = MIN<int16>(parent->_x + x + _xdelta, g_gui.getWidth() - _w - 3);
+	_y = MIN<int16>(parent->_y + y + _ydelta, g_gui.getHeight() - _h - 3);
 }
 
 void Tooltip::drawDialog() {

Modified: scummvm/trunk/gui/Tooltip.h
===================================================================
--- scummvm/trunk/gui/Tooltip.h	2010-11-18 17:56:21 UTC (rev 54336)
+++ scummvm/trunk/gui/Tooltip.h	2010-11-18 18:17:00 UTC (rev 54337)
@@ -26,20 +26,25 @@
 #define GUI_TOOLTIP_H
 
 #include "gui/dialog.h"
+#include "gui/widget.h"
 
 namespace GUI {
 
 class Tooltip : public Dialog {
 public:
 	Tooltip();
-	~Tooltip() {}
 
+	void setup(Dialog *parent, Widget *widget, int x, int y);
+
 	void drawDialog();
-	bool tooltipModal(int x, int y);
-	void mustClose();
+protected:
+	virtual void handleMouseDown(int x, int y, int button, int clickCount) { close(); }
+	virtual void handleMouseUp(int x, int y, int button, int clickCount) { close(); }
+	virtual void handleMouseWheel(int x, int y, int direction) { close(); }
+	virtual void handleKeyDown(Common::KeyState state) { close(); }
+	virtual void handleKeyUp(Common::KeyState state) { close(); }
+	virtual void handleMouseMoved(int x, int y, int button) { close(); }
 
-protected:
-	Common::String _text;
 	int _maxWidth;
 	int _xdelta, _ydelta;
 

Modified: scummvm/trunk/gui/gui-manager.cpp
===================================================================
--- scummvm/trunk/gui/gui-manager.cpp	2010-11-18 17:56:21 UTC (rev 54336)
+++ scummvm/trunk/gui/gui-manager.cpp	2010-11-18 18:17:00 UTC (rev 54337)
@@ -51,8 +51,8 @@
 };
 
 // Constructor
-GuiManager::GuiManager() : _redrawStatus(kRedrawDisabled), _tooltipCheck(false),
-	   _stateIsSaved(false), _cursorAnimateCounter(0), _cursorAnimateTimer(0) {
+GuiManager::GuiManager() : _redrawStatus(kRedrawDisabled), _stateIsSaved(false),
+    _cursorAnimateCounter(0), _cursorAnimateTimer(0) {
 	_theme = 0;
 	_useStdCursor = false;
 
@@ -81,13 +81,10 @@
 			error("Failed to load any GUI theme, aborting");
 		}
 	}
-
-	_tooltip = 0;
 }
 
 GuiManager::~GuiManager() {
 	delete _theme;
-	delete _tooltip;
 }
 
 #ifdef ENABLE_KEYMAPPER
@@ -270,6 +267,8 @@
 	eventMan->getKeymapper()->pushKeymap("gui");
 #endif
 
+	bool tooltipCheck = false;
+
 	while (!_dialogStack.empty() && activeDialog == getTopDialog()) {
 		redraw();
 
@@ -291,7 +290,6 @@
 
 		Common::Event event;
 
-		bool eventTookplace = false;
 		while (eventMan->pollEvent(event)) {
 
 			// The top dialog can change during the event loop. In that case, flush all the
@@ -314,11 +312,9 @@
 			switch (event.type) {
 			case Common::EVENT_KEYDOWN:
 				activeDialog->handleKeyDown(event.kbd);
-				eventTookplace = true;
 				break;
 			case Common::EVENT_KEYUP:
 				activeDialog->handleKeyUp(event.kbd);
-				eventTookplace = true;
 				break;
 			case Common::EVENT_MOUSEMOVE:
 				activeDialog->handleMouseMoved(mouse.x, mouse.y, 0);
@@ -329,13 +325,11 @@
 					_lastMousePosition.time = _system->getMillis();
 				}
 
-				_tooltipCheck = true;
-				eventTookplace = true;
+				tooltipCheck = true;
 				break;
 			// We don't distinguish between mousebuttons (for now at least)
 			case Common::EVENT_LBUTTONDOWN:
 			case Common::EVENT_RBUTTONDOWN:
-				eventTookplace = true;
 				button = (event.type == Common::EVENT_LBUTTONDOWN ? 1 : 2);
 				time = _system->getMillis();
 				if (_lastClick.count && (time < _lastClick.time + kDoubleClickDelay)
@@ -352,22 +346,18 @@
 				break;
 			case Common::EVENT_LBUTTONUP:
 			case Common::EVENT_RBUTTONUP:
-				eventTookplace = true;
 				button = (event.type == Common::EVENT_LBUTTONUP ? 1 : 2);
 				activeDialog->handleMouseUp(mouse.x, mouse.y, button, _lastClick.count);
 				break;
 			case Common::EVENT_WHEELUP:
-				eventTookplace = true;
 				activeDialog->handleMouseWheel(mouse.x, mouse.y, -1);
 				break;
 			case Common::EVENT_WHEELDOWN:
-				eventTookplace = true;
 				activeDialog->handleMouseWheel(mouse.x, mouse.y, 1);
 				break;
 			case Common::EVENT_QUIT:
 				return;
 			case Common::EVENT_SCREEN_CHANGED:
-				eventTookplace = true;
 				screenChange();
 				break;
 			default:
@@ -375,22 +365,16 @@
 			}
 		}
 
-		if (_tooltipCheck && _lastMousePosition.time + kTooltipDelay < _system->getMillis()) {
-			if (_tooltip == 0)
-				_tooltip = new Tooltip();
-
-			_tooltipCheck = false;
-			_tooltip->tooltipModal(_lastMousePosition.x, _lastMousePosition.y);
-			activeDialog = getTopDialog();
+		if (tooltipCheck && _lastMousePosition.time + kTooltipDelay < _system->getMillis()) {
+			Widget *wdg = activeDialog->findWidget(_lastMousePosition.x, _lastMousePosition.y);
+			if (wdg && wdg->getTooltip()) {
+				Tooltip *tooltip = new Tooltip();
+				tooltip->setup(activeDialog, wdg, _lastMousePosition.x, _lastMousePosition.y);
+				tooltip->runModal();
+				delete tooltip;
+			}
 		}
 
-		if (eventTookplace && _tooltip) {
-			_tooltip->mustClose();
-			delete _tooltip;
-			_tooltip = 0;
-			activeDialog = getTopDialog();
-		}
-
 		// Delay for a moment
 		_system->delayMillis(10);
 	}
@@ -403,7 +387,7 @@
 		_theme->disable();
 		restoreState();
 		_useStdCursor = false;
-	}	
+	}
 }
 
 #pragma mark -

Modified: scummvm/trunk/gui/gui-manager.h
===================================================================
--- scummvm/trunk/gui/gui-manager.h	2010-11-18 17:56:21 UTC (rev 54336)
+++ scummvm/trunk/gui/gui-manager.h	2010-11-18 18:17:00 UTC (rev 54337)
@@ -41,7 +41,6 @@
 
 class Dialog;
 class ThemeEval;
-class Tooltip;
 
 #define g_gui	(GUI::GuiManager::instance())
 
@@ -61,7 +60,6 @@
  */
 class GuiManager : public Common::Singleton<GuiManager> {
 	friend class Dialog;
-	friend class Tooltip;
 	friend class Common::Singleton<SingletonBaseType>;
 	GuiManager();
 	~GuiManager();
@@ -117,9 +115,6 @@
 
 	bool		_useStdCursor;
 
-	Tooltip *_tooltip;
-	bool _tooltipCheck;
-
 	// position and time of last mouse click (used to detect double clicks)
 	struct {
 		int16 x, y;	// Position of mouse when the click occurred


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list