ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

Tooltip.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/util.h"
00024 #include "gui/widget.h"
00025 #include "gui/dialog.h"
00026 #include "gui/gui-manager.h"
00027 
00028 #include "gui/Tooltip.h"
00029 #include "gui/ThemeEval.h"
00030 
00031 namespace GUI {
00032 
00033 
00034 Tooltip::Tooltip() :
00035     Dialog(-1, -1, -1, -1), _maxWidth(-1), _parent(NULL), _xdelta(0), _ydelta(0) {
00036 
00037     _backgroundType = GUI::ThemeEngine::kDialogBackgroundTooltip;
00038 }
00039 
00040 void Tooltip::setup(Dialog *parent, Widget *widget, int x, int y) {
00041     assert(widget->hasTooltip());
00042 
00043     _parent = parent;
00044 
00045     _maxWidth = g_gui.xmlEval()->getVar("Globals.Tooltip.MaxWidth", 100);
00046     _xdelta = g_gui.xmlEval()->getVar("Globals.Tooltip.XDelta", 0);
00047     _ydelta = g_gui.xmlEval()->getVar("Globals.Tooltip.YDelta", 0);
00048 
00049     const Graphics::Font *tooltipFont = g_gui.theme()->getFont(ThemeEngine::kFontStyleTooltip);
00050 
00051     _wrappedLines.clear();
00052     _w = tooltipFont->wordWrapText(widget->getTooltip(), _maxWidth - 4, _wrappedLines);
00053     _h = (tooltipFont->getFontHeight() + 2) * _wrappedLines.size();
00054 
00055     _x = MIN<int16>(parent->_x + x + _xdelta, g_gui.getWidth() - _w - 3);
00056     _y = MIN<int16>(parent->_y + y + _ydelta, g_gui.getHeight() - _h - 3);
00057 }
00058 
00059 void Tooltip::drawDialog(DrawLayer layerToDraw) {
00060     int num = 0;
00061     int h = g_gui.theme()->getFontHeight(ThemeEngine::kFontStyleTooltip) + 2;
00062 
00063     Dialog::drawDialog(layerToDraw);
00064 
00065     for (Common::StringArray::const_iterator i = _wrappedLines.begin(); i != _wrappedLines.end(); ++i, ++num) {
00066         g_gui.theme()->drawText(
00067             Common::Rect(_x + 1, _y + 1 + num * h, _x + 1 + _w, _y + 1 + (num + 1) * h),
00068             *i,
00069             ThemeEngine::kStateEnabled,
00070             Graphics::kTextAlignLeft,
00071             ThemeEngine::kTextInversionNone,
00072             0,
00073             false,
00074             ThemeEngine::kFontStyleTooltip,
00075             ThemeEngine::kFontColorNormal,
00076             false
00077         );
00078     }
00079 }
00080 
00081 }


Generated on Sat May 18 2019 05:01:27 for ResidualVM by doxygen 1.7.1
curved edge   curved edge