aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorJohannes Schickel2010-11-18 18:17:00 +0000
committerJohannes Schickel2010-11-18 18:17:00 +0000
commit8cd20c70a9f179acf2980ee2c4557fae05295d30 (patch)
treea4fa191a2b241278fa0a987d2204a9926f501dc7 /gui
parenta9dcb11c54274053152ca7e657bc4d19afb26e92 (diff)
downloadscummvm-rg350-8cd20c70a9f179acf2980ee2c4557fae05295d30.tar.gz
scummvm-rg350-8cd20c70a9f179acf2980ee2c4557fae05295d30.tar.bz2
scummvm-rg350-8cd20c70a9f179acf2980ee2c4557fae05295d30.zip
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. svn-id: r54337
Diffstat (limited to 'gui')
-rw-r--r--gui/Tooltip.cpp35
-rw-r--r--gui/Tooltip.h15
-rw-r--r--gui/gui-manager.cpp44
-rw-r--r--gui/gui-manager.h5
4 files changed, 32 insertions, 67 deletions
diff --git a/gui/Tooltip.cpp b/gui/Tooltip.cpp
index 457f53d011..7dec12d522 100644
--- a/gui/Tooltip.cpp
+++ b/gui/Tooltip.cpp
@@ -40,40 +40,21 @@ Tooltip::Tooltip() :
_backgroundType = GUI::ThemeEngine::kDialogBackgroundTooltip;
}
-void Tooltip::mustClose() {
- if (isVisible())
- Dialog::close();
-}
-
-bool Tooltip::tooltipModal(int x, int y) {
- Widget *wdg;
-
- if (!g_gui.getTopDialog())
- return false;
-
- wdg = g_gui.getTopDialog()->findWidget(x, y);
+void Tooltip::setup(Dialog *parent, Widget *widget, int x, int y) {
+ assert(widget->getTooltip());
- 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);
- }
+ _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() {
diff --git a/gui/Tooltip.h b/gui/Tooltip.h
index 02eb01d0d0..d228ca8a49 100644
--- a/gui/Tooltip.h
+++ b/gui/Tooltip.h
@@ -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 drawDialog();
- bool tooltipModal(int x, int y);
- void mustClose();
+ void setup(Dialog *parent, Widget *widget, int x, int y);
+ void drawDialog();
protected:
- Common::String _text;
+ 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(); }
+
int _maxWidth;
int _xdelta, _ydelta;
diff --git a/gui/gui-manager.cpp b/gui/gui-manager.cpp
index 4e33c446eb..83f9a52028 100644
--- a/gui/gui-manager.cpp
+++ b/gui/gui-manager.cpp
@@ -51,8 +51,8 @@ enum {
};
// 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 @@ GuiManager::GuiManager() : _redrawStatus(kRedrawDisabled), _tooltipCheck(false),
error("Failed to load any GUI theme, aborting");
}
}
-
- _tooltip = 0;
}
GuiManager::~GuiManager() {
delete _theme;
- delete _tooltip;
}
#ifdef ENABLE_KEYMAPPER
@@ -270,6 +267,8 @@ void GuiManager::runLoop() {
eventMan->getKeymapper()->pushKeymap("gui");
#endif
+ bool tooltipCheck = false;
+
while (!_dialogStack.empty() && activeDialog == getTopDialog()) {
redraw();
@@ -291,7 +290,6 @@ void GuiManager::runLoop() {
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 @@ void GuiManager::runLoop() {
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 @@ void GuiManager::runLoop() {
_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 @@ void GuiManager::runLoop() {
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,20 +365,14 @@ void GuiManager::runLoop() {
}
}
- if (_tooltipCheck && _lastMousePosition.time + kTooltipDelay < _system->getMillis()) {
- if (_tooltip == 0)
- _tooltip = new Tooltip();
-
- _tooltipCheck = false;
- _tooltip->tooltipModal(_lastMousePosition.x, _lastMousePosition.y);
- activeDialog = getTopDialog();
- }
-
- if (eventTookplace && _tooltip) {
- _tooltip->mustClose();
- delete _tooltip;
- _tooltip = 0;
- 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;
+ }
}
// Delay for a moment
@@ -403,7 +387,7 @@ void GuiManager::runLoop() {
_theme->disable();
restoreState();
_useStdCursor = false;
- }
+ }
}
#pragma mark -
diff --git a/gui/gui-manager.h b/gui/gui-manager.h
index 6c0a93d985..a6c90bfe8d 100644
--- a/gui/gui-manager.h
+++ b/gui/gui-manager.h
@@ -41,7 +41,6 @@ namespace GUI {
class Dialog;
class ThemeEval;
-class Tooltip;
#define g_gui (GUI::GuiManager::instance())
@@ -61,7 +60,6 @@ typedef Common::FixedStack<Dialog *> DialogStack;
*/
class GuiManager : public Common::Singleton<GuiManager> {
friend class Dialog;
- friend class Tooltip;
friend class Common::Singleton<SingletonBaseType>;
GuiManager();
~GuiManager();
@@ -117,9 +115,6 @@ protected:
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