2010-07-23 19:36:47 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2010-07-23 19:36:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/util.h"
|
|
|
|
#include "gui/widget.h"
|
|
|
|
#include "gui/dialog.h"
|
2010-11-16 10:19:01 +00:00
|
|
|
#include "gui/gui-manager.h"
|
2010-07-23 19:36:47 +00:00
|
|
|
|
|
|
|
#include "gui/Tooltip.h"
|
|
|
|
#include "gui/ThemeEval.h"
|
|
|
|
|
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
|
2010-10-12 02:18:11 +00:00
|
|
|
Tooltip::Tooltip() :
|
2020-01-05 16:48:04 +00:00
|
|
|
Dialog(-1, -1, -1, -1), _maxWidth(-1), _parent(nullptr), _xdelta(0), _ydelta(0) {
|
2010-07-23 19:36:47 +00:00
|
|
|
|
|
|
|
_backgroundType = GUI::ThemeEngine::kDialogBackgroundTooltip;
|
|
|
|
}
|
|
|
|
|
2010-11-18 18:17:00 +00:00
|
|
|
void Tooltip::setup(Dialog *parent, Widget *widget, int x, int y) {
|
2012-06-20 01:31:50 +00:00
|
|
|
assert(widget->hasTooltip());
|
2010-07-23 19:36:47 +00:00
|
|
|
|
2015-03-21 16:41:44 +00:00
|
|
|
_parent = parent;
|
|
|
|
|
2010-11-18 18:17:00 +00:00
|
|
|
_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);
|
2010-07-23 19:36:47 +00:00
|
|
|
|
|
|
|
const Graphics::Font *tooltipFont = g_gui.theme()->getFont(ThemeEngine::kFontStyleTooltip);
|
|
|
|
|
|
|
|
_wrappedLines.clear();
|
2019-07-31 08:19:36 +00:00
|
|
|
_w = tooltipFont->wordWrapText(widget->getTooltip(), _maxWidth - 4, _wrappedLines) + 4;
|
|
|
|
_h = (tooltipFont->getFontHeight() + 2) * _wrappedLines.size() + 4;
|
2010-07-23 19:36:47 +00:00
|
|
|
|
2010-11-18 18:17:00 +00:00
|
|
|
_x = MIN<int16>(parent->_x + x + _xdelta, g_gui.getWidth() - _w - 3);
|
|
|
|
_y = MIN<int16>(parent->_y + y + _ydelta, g_gui.getHeight() - _h - 3);
|
2020-05-09 17:58:51 +00:00
|
|
|
|
|
|
|
if (g_gui.useRTL())
|
2020-05-14 23:44:23 +00:00
|
|
|
_x = g_system->getOverlayWidth() - _w - _x + g_gui.getOverlayOffset();
|
2020-05-09 17:58:51 +00:00
|
|
|
|
2019-07-29 10:16:21 +00:00
|
|
|
#ifdef USE_TTS
|
|
|
|
if (ConfMan.hasKey("tts_enabled", "scummvm") &&
|
|
|
|
ConfMan.getBool("tts_enabled", "scummvm")) {
|
|
|
|
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
|
|
|
|
if (ttsMan == nullptr)
|
|
|
|
return;
|
2020-06-17 18:29:45 +00:00
|
|
|
ttsMan->say(widget->getTooltip(), Common::TextToSpeechManager::QUEUE_NO_REPEAT);
|
2019-07-29 10:16:21 +00:00
|
|
|
}
|
|
|
|
#endif
|
2010-07-23 19:36:47 +00:00
|
|
|
}
|
|
|
|
|
2018-01-07 09:39:22 +00:00
|
|
|
void Tooltip::drawDialog(DrawLayer layerToDraw) {
|
2010-07-23 19:36:47 +00:00
|
|
|
int num = 0;
|
|
|
|
int h = g_gui.theme()->getFontHeight(ThemeEngine::kFontStyleTooltip) + 2;
|
|
|
|
|
2018-01-07 09:39:22 +00:00
|
|
|
Dialog::drawDialog(layerToDraw);
|
2010-07-23 19:36:47 +00:00
|
|
|
|
2020-05-11 10:59:44 +00:00
|
|
|
int16 textX = g_gui.useRTL() ? _x - 3 : _x + 3; // including 2px padding and 1px original code shift
|
2019-07-31 08:19:36 +00:00
|
|
|
int16 textY = _y + 3;
|
2020-05-11 10:59:44 +00:00
|
|
|
|
2020-05-19 17:45:17 +00:00
|
|
|
Graphics::TextAlign textAlignment = g_gui.useRTL() ? Graphics::kTextAlignRight : Graphics::kTextAlignLeft;
|
2020-05-13 22:33:35 +00:00
|
|
|
|
2020-06-13 16:42:25 +00:00
|
|
|
for (Common::U32StringArray::const_iterator i = _wrappedLines.begin(); i != _wrappedLines.end(); ++i, ++num) {
|
2020-05-13 22:33:35 +00:00
|
|
|
g_gui.theme()->drawText(
|
|
|
|
Common::Rect(textX, textY + num * h, textX + _w, textY + (num + 1) * h),
|
|
|
|
*i,
|
|
|
|
ThemeEngine::kStateEnabled,
|
|
|
|
textAlignment,
|
|
|
|
ThemeEngine::kTextInversionNone,
|
|
|
|
0,
|
|
|
|
false,
|
|
|
|
ThemeEngine::kFontStyleTooltip,
|
|
|
|
ThemeEngine::kFontColorNormal,
|
|
|
|
false
|
|
|
|
);
|
2010-07-23 19:36:47 +00:00
|
|
|
}
|
2020-06-05 23:33:43 +00:00
|
|
|
}
|
2010-07-23 19:36:47 +00:00
|
|
|
|
|
|
|
}
|