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);
53 	_h = (tooltipFont->getFontHeight() + 2) * _wrappedLines.size();
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 }
58 
drawDialog()59 void Tooltip::drawDialog() {
60 	int num = 0;
61 	int h = g_gui.theme()->getFontHeight(ThemeEngine::kFontStyleTooltip) + 2;
62 
63 	Dialog::drawDialog();
64 
65 	for (Common::StringArray::const_iterator i = _wrappedLines.begin(); i != _wrappedLines.end(); ++i, ++num) {
66 		g_gui.theme()->drawText(
67 			Common::Rect(_x + 1, _y + 1 + num * h, _x + 1 +_w, _y + 1+ (num + 1) * h), *i,
68 			ThemeEngine::kStateEnabled,
69 			Graphics::kTextAlignLeft,
70 			ThemeEngine::kTextInversionNone,
71 			0,
72 			false,
73 			ThemeEngine::kFontStyleTooltip,
74 			ThemeEngine::kFontColorNormal,
75 			false
76 		);
77 	}
78 }
79 
80 }
81