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
This commit is contained in:
parent
a9dcb11c54
commit
8cd20c70a9
4 changed files with 32 additions and 67 deletions
|
@ -40,40 +40,21 @@ Tooltip::Tooltip() :
|
|||
_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;
|
||||
|
||||
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() {
|
||||
|
|
|
@ -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:
|
||||
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;
|
||||
|
||||
|
|
|
@ -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 (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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue