1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "common/util.h"
24 #include "gui/widget.h"
25 #include "gui/dialog.h"
26 #include "gui/gui-manager.h"
27
28 #include "gui/Tooltip.h"
29 #include "gui/ThemeEval.h"
30
31 namespace GUI {
32
33
Tooltip()34 Tooltip::Tooltip() :
35 Dialog(-1, -1, -1, -1), _maxWidth(-1), _parent(NULL), _xdelta(0), _ydelta(0) {
36
37 _backgroundType = GUI::ThemeEngine::kDialogBackgroundTooltip;
38 }
39
setup(Dialog * parent,Widget * widget,int x,int y)40 void Tooltip::setup(Dialog *parent, Widget *widget, int x, int y) {
41 assert(widget->hasTooltip());
42
43 _parent = parent;
44
45 _maxWidth = g_gui.xmlEval()->getVar("Globals.Tooltip.MaxWidth", 100);
46 _xdelta = g_gui.xmlEval()->getVar("Globals.Tooltip.XDelta", 0);
47 _ydelta = g_gui.xmlEval()->getVar("Globals.Tooltip.YDelta", 0);
48
49 const Graphics::Font *tooltipFont = g_gui.theme()->getFont(ThemeEngine::kFontStyleTooltip);
50
51 _wrappedLines.clear();
52 _w = tooltipFont->wordWrapText(widget->getTooltip(), _maxWidth - 4, _wrappedLines) + 4;
53 _h = (tooltipFont->getFontHeight() + 2) * _wrappedLines.size() + 4;
54
55 _x = MIN<int16>(parent->_x + x + _xdelta, g_gui.getWidth() - _w - 3);
56 _y = MIN<int16>(parent->_y + y + _ydelta, g_gui.getHeight() - _h - 3);
57 #ifdef USE_TTS
58 if (ConfMan.hasKey("tts_enabled", "scummvm") &&
59 ConfMan.getBool("tts_enabled", "scummvm")) {
60 Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
61 if (ttsMan == nullptr)
62 return;
63 ttsMan->say(widget->getTooltip(), Common::TextToSpeechManager::QUEUE_NO_REPEAT);
64 }
65 #endif
66 }
67
drawDialog(DrawLayer layerToDraw)68 void Tooltip::drawDialog(DrawLayer layerToDraw) {
69 int num = 0;
70 int h = g_gui.theme()->getFontHeight(ThemeEngine::kFontStyleTooltip) + 2;
71
72 Dialog::drawDialog(layerToDraw);
73
74 int16 textX = _x + 3; // including 2px padding and 1px original code shift
75 int16 textY = _y + 3;
76 for (Common::StringArray::const_iterator i = _wrappedLines.begin(); i != _wrappedLines.end(); ++i, ++num) {
77 g_gui.theme()->drawText(
78 Common::Rect(textX, textY + num * h, textX + _w, textY + (num + 1) * h),
79 *i,
80 ThemeEngine::kStateEnabled,
81 Graphics::kTextAlignLeft,
82 ThemeEngine::kTextInversionNone,
83 0,
84 false,
85 ThemeEngine::kFontStyleTooltip,
86 ThemeEngine::kFontColorNormal,
87 false
88 );
89 }
90 }
91
92 }
93