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(nullptr), _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) + 4;
00053     _h = (tooltipFont->getFontHeight() + 2) * _wrappedLines.size() + 4;
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 #ifdef USE_TTS
00058     if (ConfMan.hasKey("tts_enabled", "residualvm") &&
00059             ConfMan.getBool("tts_enabled", "residualvm")) {
00060         Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
00061         if (ttsMan == nullptr)
00062             return;
00063         ttsMan->say(widget->getTooltip(), Common::TextToSpeechManager::QUEUE_NO_REPEAT);
00064     }
00065 #endif
00066 }
00067 
00068 void Tooltip::drawDialog(DrawLayer layerToDraw) {
00069     int num = 0;
00070     int h = g_gui.theme()->getFontHeight(ThemeEngine::kFontStyleTooltip) + 2;
00071 
00072     Dialog::drawDialog(layerToDraw);
00073 
00074     int16 textX = _x + 3; // including 2px padding and 1px original code shift
00075     int16 textY = _y + 3;
00076     for (Common::StringArray::const_iterator i = _wrappedLines.begin(); i != _wrappedLines.end(); ++i, ++num) {
00077         g_gui.theme()->drawText(
00078             Common::Rect(textX, textY + num * h, textX + _w, textY + (num + 1) * h),
00079             *i,
00080             ThemeEngine::kStateEnabled,
00081             Graphics::kTextAlignLeft,
00082             ThemeEngine::kTextInversionNone,
00083             0,
00084             false,
00085             ThemeEngine::kFontStyleTooltip,
00086             ThemeEngine::kFontColorNormal,
00087             false
00088         );
00089     }
00090 }
00091 
00092 }


Generated on Sat May 23 2020 05:00:45 for ResidualVM by doxygen 1.7.1
curved edge   curved edge