2007-05-30 21:56:52 +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.
|
2002-07-05 16:56:53 +00:00
|
|
|
*
|
2021-12-26 17:47:58 +00:00
|
|
|
* 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2002-07-05 16:56:53 +00:00
|
|
|
*
|
|
|
|
* 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
|
2021-12-26 17:47:58 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2002-07-05 16:56:53 +00:00
|
|
|
*/
|
|
|
|
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/scummsys.h"
|
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/rect.h"
|
|
|
|
#include "common/textconsole.h"
|
2011-12-13 02:33:28 +00:00
|
|
|
#include "common/translation.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "graphics/pixelformat.h"
|
2021-04-04 21:57:30 +00:00
|
|
|
#include "graphics/svg.h"
|
2003-11-02 18:57:20 +00:00
|
|
|
#include "gui/widget.h"
|
2010-11-16 10:19:01 +00:00
|
|
|
#include "gui/gui-manager.h"
|
2002-07-05 16:56:53 +00:00
|
|
|
|
2008-08-07 10:53:33 +00:00
|
|
|
#include "gui/ThemeEval.h"
|
|
|
|
|
2012-05-03 16:32:08 +00:00
|
|
|
#include "gui/dialog.h"
|
2019-11-13 20:09:21 +00:00
|
|
|
#include "gui/widgets/popup.h"
|
2020-03-22 14:19:56 +00:00
|
|
|
#include "gui/widgets/scrollcontainer.h"
|
2012-05-03 16:32:08 +00:00
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
2020-07-01 20:08:10 +00:00
|
|
|
Widget::Widget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &tooltip)
|
2010-06-15 10:52:35 +00:00
|
|
|
: GuiObject(x, y, w, h), _type(0), _boss(boss), _tooltip(tooltip),
|
2020-05-22 14:31:19 +00:00
|
|
|
_flags(0), _hasFocus(false), _state(ThemeEngine::kStateEnabled) {
|
2006-03-07 05:39:52 +00:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2020-07-01 20:08:10 +00:00
|
|
|
Widget::Widget(GuiObject *boss, const Common::String &name, const Common::U32String &tooltip)
|
2010-06-15 10:52:35 +00:00
|
|
|
: GuiObject(name), _type(0), _boss(boss), _tooltip(tooltip),
|
2020-05-22 14:31:19 +00:00
|
|
|
_flags(0), _hasFocus(false), _state(ThemeEngine::kStateDisabled) {
|
2006-03-07 05:39:52 +00:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::init() {
|
2021-12-07 13:29:53 +00:00
|
|
|
_next = _boss->addChild(this);
|
2018-01-06 13:40:02 +00:00
|
|
|
_needsRedraw = true;
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:38:30 +00:00
|
|
|
Widget::~Widget() {
|
|
|
|
delete _next;
|
2020-01-05 16:48:04 +00:00
|
|
|
_next = nullptr;
|
2007-11-04 03:38:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::setFlags(int flags) {
|
|
|
|
updateState(_flags, _flags | flags);
|
|
|
|
_flags |= flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::clearFlags(int flags) {
|
|
|
|
updateState(_flags, _flags & ~flags);
|
|
|
|
_flags &= ~flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::updateState(int oldFlags, int newFlags) {
|
|
|
|
if (newFlags & WIDGET_ENABLED) {
|
2008-11-10 11:24:55 +00:00
|
|
|
_state = ThemeEngine::kStateEnabled;
|
2007-11-04 03:38:30 +00:00
|
|
|
if (newFlags & WIDGET_HILITED)
|
2008-11-10 11:24:55 +00:00
|
|
|
_state = ThemeEngine::kStateHighlight;
|
2012-05-03 16:32:08 +00:00
|
|
|
if (newFlags & WIDGET_PRESSED)
|
|
|
|
_state = ThemeEngine::kStatePressed;
|
2007-11-04 03:38:30 +00:00
|
|
|
} else {
|
2008-11-10 11:24:55 +00:00
|
|
|
_state = ThemeEngine::kStateDisabled;
|
2007-11-04 03:38:30 +00:00
|
|
|
}
|
2003-11-07 14:50:32 +00:00
|
|
|
}
|
|
|
|
|
2018-01-06 13:40:02 +00:00
|
|
|
void Widget::markAsDirty() {
|
|
|
|
_needsRedraw = true;
|
|
|
|
|
|
|
|
Widget *w = _firstWidget;
|
|
|
|
while (w) {
|
|
|
|
w->markAsDirty();
|
|
|
|
w = w->next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void Widget::draw() {
|
2021-06-08 09:17:46 +00:00
|
|
|
Common::Rect oldClip;
|
2002-09-08 16:00:13 +00:00
|
|
|
if (!isVisible() || !_boss->isVisible())
|
2002-07-05 16:56:53 +00:00
|
|
|
return;
|
2003-11-08 23:22:16 +00:00
|
|
|
|
2018-01-06 13:40:02 +00:00
|
|
|
if (_needsRedraw) {
|
|
|
|
int oldX = _x, oldY = _y;
|
2002-07-05 16:56:53 +00:00
|
|
|
|
2018-01-06 13:40:02 +00:00
|
|
|
// Account for our relative position in the dialog
|
|
|
|
_x = getAbsX();
|
|
|
|
_y = getAbsY();
|
2002-07-07 13:14:34 +00:00
|
|
|
|
2021-06-08 09:17:46 +00:00
|
|
|
Common::Rect activeRect = g_gui.theme()->getClipRect();
|
2021-12-09 10:23:37 +00:00
|
|
|
Common::Rect clip = _boss->getClipRect().findIntersectingRect(activeRect);
|
|
|
|
oldClip = g_gui.theme()->swapClipRect(clip);
|
2020-05-29 10:55:59 +00:00
|
|
|
|
2020-05-07 21:21:22 +00:00
|
|
|
if (g_gui.useRTL()) {
|
2020-05-13 22:41:39 +00:00
|
|
|
_x = g_system->getOverlayWidth() - _x - _w;
|
|
|
|
|
2020-05-27 13:46:10 +00:00
|
|
|
if (this->_name.contains("GameOptions") || this->_name.contains("GlobalOptions") || this->_name.contains("Browser") || this->_name.empty()) {
|
|
|
|
/** The dialogs named above are the stacked dialogs for which the left+right paddings need to be adjusted for RTL.
|
|
|
|
The _name is empty for some special widgets - like RemapWidgets, NavBars, ScrollBars and they need to be adjusted too.
|
|
|
|
*/
|
2020-05-13 22:41:39 +00:00
|
|
|
_x = _x + g_gui.getOverlayOffset();
|
|
|
|
}
|
2020-05-07 21:21:22 +00:00
|
|
|
|
2021-12-09 10:23:37 +00:00
|
|
|
clip.moveTo(_x, clip.top);
|
|
|
|
g_gui.theme()->swapClipRect(clip);
|
2020-05-29 10:55:59 +00:00
|
|
|
}
|
2018-01-27 07:59:53 +00:00
|
|
|
|
2018-01-06 13:40:02 +00:00
|
|
|
// Draw border
|
|
|
|
if (_flags & WIDGET_BORDER) {
|
2019-12-28 09:43:58 +00:00
|
|
|
g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h),
|
2018-01-27 07:59:53 +00:00
|
|
|
ThemeEngine::kWidgetBackgroundBorder);
|
2018-01-06 13:40:02 +00:00
|
|
|
_x += 4;
|
|
|
|
_y += 4;
|
|
|
|
_w -= 8;
|
|
|
|
_h -= 8;
|
|
|
|
}
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2018-01-06 13:40:02 +00:00
|
|
|
// Now perform the actual widget draw
|
|
|
|
drawWidget();
|
2002-07-07 13:14:34 +00:00
|
|
|
|
2018-01-27 07:59:53 +00:00
|
|
|
|
2018-01-06 13:40:02 +00:00
|
|
|
// Restore x/y
|
|
|
|
if (_flags & WIDGET_BORDER) {
|
|
|
|
_x -= 4;
|
|
|
|
_y -= 4;
|
|
|
|
_w += 8;
|
|
|
|
_h += 8;
|
|
|
|
}
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2018-01-06 13:40:02 +00:00
|
|
|
_x = oldX;
|
|
|
|
_y = oldY;
|
|
|
|
|
|
|
|
_needsRedraw = false;
|
|
|
|
}
|
2003-11-02 22:31:20 +00:00
|
|
|
|
|
|
|
// Draw all children
|
|
|
|
Widget *w = _firstWidget;
|
|
|
|
while (w) {
|
|
|
|
w->draw();
|
|
|
|
w = w->_next;
|
|
|
|
}
|
2021-07-27 18:19:04 +00:00
|
|
|
if (!oldClip.isEmpty()) {
|
2021-06-08 09:17:46 +00:00
|
|
|
g_gui.theme()->swapClipRect(oldClip);
|
2021-07-27 18:19:04 +00:00
|
|
|
}
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
2003-11-02 18:57:20 +00:00
|
|
|
Widget *Widget::findWidgetInChain(Widget *w, int x, int y) {
|
|
|
|
while (w) {
|
|
|
|
// Stop as soon as we find a widget that contains the point (x,y)
|
2016-07-12 16:37:57 +00:00
|
|
|
if (x >= w->_x && x < w->_x + w->_w && y >= w->_y && y < w->_y + w->getHeight())
|
2003-11-02 18:57:20 +00:00
|
|
|
break;
|
|
|
|
w = w->_next;
|
|
|
|
}
|
|
|
|
if (w)
|
|
|
|
w = w->findWidget(x - w->_x, y - w->_y);
|
|
|
|
return w;
|
|
|
|
}
|
2003-11-02 14:50:53 +00:00
|
|
|
|
2006-04-19 01:05:28 +00:00
|
|
|
Widget *Widget::findWidgetInChain(Widget *w, const char *name) {
|
|
|
|
while (w) {
|
|
|
|
if (w->_name == name) {
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
w = w->_next;
|
|
|
|
}
|
2020-01-05 16:48:04 +00:00
|
|
|
return nullptr;
|
2006-04-19 01:05:28 +00:00
|
|
|
}
|
2007-11-04 03:38:30 +00:00
|
|
|
|
2017-04-06 20:50:16 +00:00
|
|
|
bool Widget::containsWidgetInChain(Widget *w, Widget *search) {
|
|
|
|
while (w) {
|
|
|
|
if (w == search || w->containsWidget(search))
|
|
|
|
return true;
|
|
|
|
w = w->_next;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-12-27 14:36:28 +00:00
|
|
|
void Widget::setEnabled(bool e) {
|
2009-04-11 17:12:17 +00:00
|
|
|
if ((_flags & WIDGET_ENABLED) != e) {
|
|
|
|
if (e)
|
|
|
|
setFlags(WIDGET_ENABLED);
|
|
|
|
else
|
|
|
|
clearFlags(WIDGET_ENABLED);
|
|
|
|
|
2018-01-06 15:13:29 +00:00
|
|
|
g_gui.scheduleTopDialogRedraw();
|
2009-04-11 17:12:17 +00:00
|
|
|
}
|
2008-12-27 14:36:28 +00:00
|
|
|
}
|
|
|
|
|
2007-10-28 12:02:09 +00:00
|
|
|
bool Widget::isEnabled() const {
|
2007-10-28 16:10:05 +00:00
|
|
|
return ((_flags & WIDGET_ENABLED) != 0);
|
2007-10-28 12:02:09 +00:00
|
|
|
}
|
2006-04-19 01:05:28 +00:00
|
|
|
|
2008-12-27 14:36:28 +00:00
|
|
|
void Widget::setVisible(bool e) {
|
|
|
|
if (e)
|
|
|
|
clearFlags(WIDGET_INVISIBLE);
|
|
|
|
else
|
|
|
|
setFlags(WIDGET_INVISIBLE);
|
|
|
|
}
|
|
|
|
|
2006-03-07 13:41:36 +00:00
|
|
|
bool Widget::isVisible() const {
|
|
|
|
return !(_flags & WIDGET_INVISIBLE);
|
|
|
|
}
|
|
|
|
|
2020-06-01 12:49:16 +00:00
|
|
|
bool Widget::useRTL() const {
|
2020-05-07 21:21:22 +00:00
|
|
|
return _useRTL;
|
2020-05-07 20:16:13 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 16:07:51 +00:00
|
|
|
uint8 Widget::parseHotkey(const Common::U32String &label) {
|
2010-06-15 10:47:31 +00:00
|
|
|
if (!label.contains('~'))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
int state = 0;
|
|
|
|
uint8 hotkey = 0;
|
|
|
|
|
|
|
|
for (uint i = 0; i < label.size() && state != 3; i++) {
|
|
|
|
switch (state) {
|
|
|
|
case 0:
|
|
|
|
if (label[i] == '~')
|
|
|
|
state = 1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (label[i] != '~') {
|
|
|
|
state = 2;
|
|
|
|
hotkey = label[i];
|
|
|
|
} else
|
|
|
|
state = 0;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (label[i] == '~')
|
|
|
|
state = 3;
|
|
|
|
else
|
|
|
|
state = 0;
|
|
|
|
break;
|
2019-10-03 05:03:46 +00:00
|
|
|
default:
|
|
|
|
break;
|
2010-06-15 10:47:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state == 3)
|
|
|
|
return hotkey;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-06-10 16:07:51 +00:00
|
|
|
Common::U32String Widget::cleanupHotkey(const Common::U32String &label) {
|
2020-06-22 17:59:25 +00:00
|
|
|
Common::U32String res("");
|
2010-06-15 10:47:31 +00:00
|
|
|
|
2020-06-21 16:30:13 +00:00
|
|
|
for (Common::U32String::const_iterator itr = label.begin(); itr != label.end(); itr++) {
|
|
|
|
if (*itr != '~') {
|
|
|
|
res += *itr;
|
|
|
|
}
|
|
|
|
}
|
2010-07-21 18:17:51 +00:00
|
|
|
|
2020-06-21 16:30:13 +00:00
|
|
|
return res;
|
2010-07-21 18:17:51 +00:00
|
|
|
}
|
2010-06-15 10:47:31 +00:00
|
|
|
|
2020-06-17 18:29:45 +00:00
|
|
|
void Widget::read(const Common::U32String &str) {
|
2019-07-12 10:52:18 +00:00
|
|
|
if (ConfMan.hasKey("tts_enabled", "scummvm") &&
|
|
|
|
ConfMan.getBool("tts_enabled", "scummvm")) {
|
2019-07-16 04:09:36 +00:00
|
|
|
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
|
|
|
|
if (ttsMan == nullptr)
|
|
|
|
return;
|
|
|
|
ttsMan->say(str);
|
2019-07-12 10:52:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2021-09-30 16:17:49 +00:00
|
|
|
StaticTextWidget::StaticTextWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &text, Graphics::TextAlign align, const Common::U32String &tooltip, ThemeEngine::FontStyle font, Common::Language lang, bool useEllipsis)
|
2020-06-29 22:10:13 +00:00
|
|
|
: Widget(boss, x, y, w, h, tooltip) {
|
2020-06-18 21:40:43 +00:00
|
|
|
setFlags(WIDGET_ENABLED);
|
|
|
|
_type = kStaticTextWidget;
|
|
|
|
_label = text;
|
2020-06-21 21:22:56 +00:00
|
|
|
_align = Graphics::convertTextAlignH(align, g_gui.useRTL() && _useRTL);
|
2020-10-24 23:38:05 +00:00
|
|
|
setFont(font, lang);
|
2022-04-01 12:51:55 +00:00
|
|
|
_fontColor = ThemeEngine::FontColor::kFontColorNormal;
|
2021-09-30 16:17:49 +00:00
|
|
|
_useEllipsis = useEllipsis;
|
2020-06-18 21:40:43 +00:00
|
|
|
}
|
|
|
|
|
2021-09-30 16:17:49 +00:00
|
|
|
StaticTextWidget::StaticTextWidget(GuiObject *boss, const Common::String &name, const Common::U32String &text, const Common::U32String &tooltip, ThemeEngine::FontStyle font, Common::Language lang, bool useEllipsis)
|
2010-06-15 10:52:35 +00:00
|
|
|
: Widget(boss, name, tooltip) {
|
2018-01-06 13:40:02 +00:00
|
|
|
setFlags(WIDGET_ENABLED | WIDGET_CLEARBG);
|
2006-03-07 05:39:52 +00:00
|
|
|
_type = kStaticTextWidget;
|
|
|
|
_label = text;
|
2020-06-21 21:22:56 +00:00
|
|
|
_align = Graphics::convertTextAlignH(g_gui.xmlEval()->getWidgetTextHAlign(name), g_gui.useRTL() && _useRTL);
|
2020-10-24 23:38:05 +00:00
|
|
|
setFont(font, lang);
|
2022-04-01 12:51:55 +00:00
|
|
|
_fontColor = ThemeEngine::FontColor::kFontColorNormal;
|
2021-09-30 16:17:49 +00:00
|
|
|
_useEllipsis = useEllipsis;
|
2006-03-07 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void StaticTextWidget::setValue(int value) {
|
2011-06-01 22:07:18 +00:00
|
|
|
_label = Common::String::format("%d", value);
|
2002-07-27 00:05:46 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 16:07:51 +00:00
|
|
|
void StaticTextWidget::setLabel(const Common::U32String &label) {
|
2012-01-29 20:17:01 +00:00
|
|
|
if (_label != label) {
|
|
|
|
_label = label;
|
|
|
|
|
2018-01-06 13:40:02 +00:00
|
|
|
markAsDirty();
|
2012-01-29 20:17:01 +00:00
|
|
|
}
|
2005-04-16 17:53:18 +00:00
|
|
|
}
|
|
|
|
|
2008-11-12 14:30:16 +00:00
|
|
|
void StaticTextWidget::setAlign(Graphics::TextAlign align) {
|
2020-06-21 21:22:56 +00:00
|
|
|
align = Graphics::convertTextAlignH(align, g_gui.useRTL() && _useRTL);
|
2016-03-25 01:34:35 +00:00
|
|
|
if (_align != align){
|
|
|
|
_align = align;
|
|
|
|
|
2018-01-06 13:40:02 +00:00
|
|
|
markAsDirty();
|
2016-03-25 01:34:35 +00:00
|
|
|
}
|
2005-04-16 17:53:18 +00:00
|
|
|
}
|
|
|
|
|
2022-05-02 12:10:22 +00:00
|
|
|
void StaticTextWidget::setFontColor(const ThemeEngine::FontColor color) {
|
2022-04-01 12:51:55 +00:00
|
|
|
_fontColor = color;
|
|
|
|
}
|
2005-04-16 17:53:18 +00:00
|
|
|
|
2007-11-04 03:38:30 +00:00
|
|
|
void StaticTextWidget::drawWidget() {
|
2018-01-27 07:59:53 +00:00
|
|
|
g_gui.theme()->drawText(
|
|
|
|
Common::Rect(_x, _y, _x + _w, _y + _h),
|
2022-04-01 12:51:55 +00:00
|
|
|
_label, _state, _align, ThemeEngine::kTextInversionNone, 0, _useEllipsis, _font, _fontColor
|
2016-06-20 15:10:37 +00:00
|
|
|
);
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
2020-10-24 23:38:05 +00:00
|
|
|
void StaticTextWidget::setFont(ThemeEngine::FontStyle font, Common::Language lang) {
|
|
|
|
_font = font;
|
|
|
|
|
|
|
|
if (lang == Common::UNK_LANG)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (g_gui.theme()->loadExtraFont(font, lang))
|
|
|
|
_font = GUI::ThemeEngine::kFontStyleLangExtra;
|
|
|
|
}
|
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2022-05-15 10:16:29 +00:00
|
|
|
ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &label, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey, const Common::U32String &lowresLabel)
|
2010-06-15 10:52:35 +00:00
|
|
|
: StaticTextWidget(boss, x, y, w, h, cleanupHotkey(label), Graphics::kTextAlignCenter, tooltip), CommandSender(boss),
|
2019-11-13 20:09:21 +00:00
|
|
|
_cmd(cmd), _hotkey(hotkey), _duringPress(false) {
|
2022-05-23 21:36:56 +00:00
|
|
|
_lowresLabel = cleanupHotkey(lowresLabel);
|
2010-06-15 10:47:31 +00:00
|
|
|
|
2022-05-23 21:36:56 +00:00
|
|
|
if (hotkey == 0) {
|
|
|
|
_highresHotkey = parseHotkey(label);
|
|
|
|
_hotkey = _highresHotkey;
|
|
|
|
_lowresHotkey = parseHotkey(lowresLabel);
|
|
|
|
} else {
|
|
|
|
_highresHotkey = hotkey;
|
|
|
|
_lowresHotkey = hotkey;
|
|
|
|
}
|
2010-06-15 10:47:31 +00:00
|
|
|
|
2012-05-07 06:54:32 +00:00
|
|
|
setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
|
2002-07-08 11:55:55 +00:00
|
|
|
_type = kButtonWidget;
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
2022-05-15 10:16:29 +00:00
|
|
|
ButtonWidget::ButtonWidget(GuiObject *boss, const Common::String &name, const Common::U32String &label, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey, const Common::U32String &lowresLabel)
|
2010-07-21 18:17:51 +00:00
|
|
|
: StaticTextWidget(boss, name, cleanupHotkey(label), tooltip), CommandSender(boss),
|
2019-11-13 20:09:21 +00:00
|
|
|
_cmd(cmd), _hotkey(hotkey), _duringPress(false) {
|
2022-05-23 21:36:56 +00:00
|
|
|
_lowresLabel = cleanupHotkey(lowresLabel);
|
2022-05-15 10:16:29 +00:00
|
|
|
|
2022-05-23 21:36:56 +00:00
|
|
|
if (hotkey == 0) {
|
|
|
|
_highresHotkey = parseHotkey(label);
|
|
|
|
_hotkey = _highresHotkey;
|
|
|
|
_lowresHotkey = parseHotkey(lowresLabel);
|
|
|
|
} else {
|
|
|
|
_highresHotkey = hotkey;
|
|
|
|
_lowresHotkey = hotkey;
|
|
|
|
}
|
2022-05-15 10:16:29 +00:00
|
|
|
|
2012-05-07 06:54:32 +00:00
|
|
|
setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
|
2006-03-07 05:39:52 +00:00
|
|
|
_type = kButtonWidget;
|
|
|
|
}
|
|
|
|
|
2019-12-28 09:43:58 +00:00
|
|
|
void ButtonWidget::getMinSize(int &minWidth, int &minHeight) {
|
|
|
|
const Graphics::Font &font = g_gui.getFont(_font);
|
|
|
|
|
|
|
|
minWidth = font.getStringWidth(_label);
|
|
|
|
minHeight = font.getFontHeight();
|
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount) {
|
2016-03-23 19:24:43 +00:00
|
|
|
if (isEnabled() && _duringPress && x >= 0 && x < _w && y >= 0 && y < _h) {
|
2016-04-13 12:02:33 +00:00
|
|
|
setUnpressedState();
|
2012-07-13 15:17:58 +00:00
|
|
|
sendCommand(_cmd, 0);
|
2012-05-03 16:32:08 +00:00
|
|
|
}
|
2016-03-23 19:24:43 +00:00
|
|
|
_duringPress = false;
|
2012-05-03 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonWidget::handleMouseDown(int x, int y, int button, int clickCount) {
|
2016-03-23 19:24:43 +00:00
|
|
|
_duringPress = true;
|
2012-05-03 16:32:08 +00:00
|
|
|
setPressedState();
|
2002-07-12 16:24:11 +00:00
|
|
|
}
|
2002-07-07 23:37:47 +00:00
|
|
|
|
2016-06-22 09:02:46 +00:00
|
|
|
void ButtonWidget::drawWidget() {
|
2022-05-15 10:16:29 +00:00
|
|
|
g_gui.theme()->drawButton(Common::Rect(_x, _y, _x + _w, _y + _h), getLabel(), _state, getFlags());
|
2002-10-19 01:22:41 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 16:07:51 +00:00
|
|
|
void ButtonWidget::setLabel(const Common::U32String &label) {
|
2011-08-06 09:12:34 +00:00
|
|
|
StaticTextWidget::setLabel(cleanupHotkey(label));
|
|
|
|
}
|
|
|
|
|
2020-07-03 21:43:05 +00:00
|
|
|
void ButtonWidget::setLabel(const Common::String &label) {
|
|
|
|
ButtonWidget::setLabel(Common::U32String(label));
|
|
|
|
}
|
|
|
|
|
2022-05-15 10:16:29 +00:00
|
|
|
void ButtonWidget::setLowresLabel(const Common::U32String &label) {
|
2022-05-23 21:36:56 +00:00
|
|
|
_lowresLabel = cleanupHotkey(label);
|
2022-05-15 10:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const Common::U32String &ButtonWidget::getLabel() {
|
|
|
|
bool useLowres = false;
|
|
|
|
if (!_lowresLabel.empty())
|
2022-05-23 21:36:56 +00:00
|
|
|
useLowres = g_system->getOverlayWidth() <= 320;
|
|
|
|
_hotkey = useLowres ? _lowresHotkey : _highresHotkey;
|
2022-05-15 10:16:29 +00:00
|
|
|
return useLowres ? _lowresLabel : _label;
|
|
|
|
}
|
|
|
|
|
2011-12-13 03:26:00 +00:00
|
|
|
ButtonWidget *addClearButton(GuiObject *boss, const Common::String &name, uint32 cmd, int x, int y, int w, int h) {
|
2011-12-13 02:33:28 +00:00
|
|
|
ButtonWidget *button;
|
|
|
|
|
|
|
|
#ifndef DISABLE_FANCY_THEMES
|
|
|
|
if (g_gui.xmlEval()->getVar("Globals.ShowSearchPic") == 1 && g_gui.theme()->supportsImages()) {
|
2011-12-13 03:26:00 +00:00
|
|
|
if (!name.empty())
|
2020-07-01 18:01:48 +00:00
|
|
|
button = new PicButtonWidget(boss, name, _("Clear value"), cmd);
|
2011-12-13 03:26:00 +00:00
|
|
|
else
|
2020-07-01 18:01:48 +00:00
|
|
|
button = new PicButtonWidget(boss, x, y, w, h, _("Clear value"), cmd);
|
2011-12-13 02:33:28 +00:00
|
|
|
((PicButtonWidget *)button)->useThemeTransparency(true);
|
2021-04-06 21:20:47 +00:00
|
|
|
((PicButtonWidget *)button)->setGfxFromTheme(ThemeEngine::kImageEraser, kPicButtonStateEnabled, false);
|
2011-12-13 02:33:28 +00:00
|
|
|
} else
|
|
|
|
#endif
|
2011-12-13 03:26:00 +00:00
|
|
|
if (!name.empty())
|
2020-07-01 18:01:48 +00:00
|
|
|
button = new ButtonWidget(boss, name, Common::U32String("C"), _("Clear value"), cmd);
|
2011-12-13 03:26:00 +00:00
|
|
|
else
|
2020-07-01 18:01:48 +00:00
|
|
|
button = new ButtonWidget(boss, x, y, w, h, Common::U32String("C"), _("Clear value"), cmd);
|
2011-12-13 02:33:28 +00:00
|
|
|
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
2012-05-03 16:32:08 +00:00
|
|
|
void ButtonWidget::setHighLighted(bool enable) {
|
|
|
|
(enable) ? setFlags(WIDGET_HILITED) : clearFlags(WIDGET_HILITED);
|
2018-01-06 13:40:02 +00:00
|
|
|
markAsDirty();
|
2012-05-03 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonWidget::setPressedState() {
|
|
|
|
setFlags(WIDGET_PRESSED);
|
2016-04-13 10:08:36 +00:00
|
|
|
clearFlags(WIDGET_HILITED);
|
2018-01-06 13:40:02 +00:00
|
|
|
markAsDirty();
|
2012-05-03 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 12:02:33 +00:00
|
|
|
void ButtonWidget::setUnpressedState() {
|
2012-05-03 16:32:08 +00:00
|
|
|
clearFlags(WIDGET_PRESSED);
|
2018-01-06 13:40:02 +00:00
|
|
|
markAsDirty();
|
2012-05-03 16:32:08 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 23:37:47 +00:00
|
|
|
#pragma mark -
|
2019-11-13 20:09:21 +00:00
|
|
|
|
2022-05-15 10:16:29 +00:00
|
|
|
DropdownButtonWidget::DropdownButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &label, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey, const Common::U32String &lowresLabel) :
|
|
|
|
ButtonWidget(boss, x, y, w, h, label, tooltip, cmd, hotkey, lowresLabel) {
|
2019-11-13 20:09:21 +00:00
|
|
|
setFlags(getFlags() | WIDGET_TRACK_MOUSE);
|
|
|
|
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
2022-05-15 10:16:29 +00:00
|
|
|
DropdownButtonWidget::DropdownButtonWidget(GuiObject *boss, const Common::String &name, const Common::U32String &label, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey, const Common::U32String &lowresLabel) :
|
|
|
|
ButtonWidget(boss, name, label, tooltip, cmd, hotkey, lowresLabel) {
|
2019-11-13 20:09:21 +00:00
|
|
|
setFlags(getFlags() | WIDGET_TRACK_MOUSE);
|
|
|
|
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DropdownButtonWidget::reset() {
|
|
|
|
_inDropdown = false;
|
|
|
|
_inButton = false;
|
|
|
|
_dropdownWidth = g_gui.xmlEval()->getVar("Globals.DropdownButton.Width", 13);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DropdownButtonWidget::isInDropDown(int x, int y) const {
|
|
|
|
Common::Rect dropdownRect(_w - _dropdownWidth, 0, _w, _h);
|
|
|
|
return dropdownRect.contains(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DropdownButtonWidget::handleMouseMoved(int x, int y, int button) {
|
|
|
|
if (_entries.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Detect which part of the button the cursor is over
|
|
|
|
bool inDropdown = isInDropDown(x, y);
|
|
|
|
bool inButton = Common::Rect(_w, _h).contains(x, y) && !inDropdown;
|
|
|
|
|
|
|
|
if (inDropdown != _inDropdown) {
|
|
|
|
_inDropdown = inDropdown;
|
|
|
|
markAsDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inButton != _inButton) {
|
|
|
|
_inButton = inButton;
|
|
|
|
markAsDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DropdownButtonWidget::handleMouseUp(int x, int y, int button, int clickCount) {
|
|
|
|
if (isEnabled() && !_entries.empty() && _duringPress && isInDropDown(x, y)) {
|
|
|
|
|
|
|
|
PopUpDialog popupDialog(this, "DropdownDialog", x + getAbsX(), y + getAbsY());
|
|
|
|
popupDialog.setPosition(getAbsX(), getAbsY() + _h);
|
|
|
|
popupDialog.setLineHeight(_h);
|
|
|
|
popupDialog.setPadding(_dropdownWidth, _dropdownWidth);
|
|
|
|
|
|
|
|
for (uint i = 0; i < _entries.size(); i++) {
|
|
|
|
popupDialog.appendEntry(_entries[i].label);
|
|
|
|
}
|
|
|
|
|
|
|
|
int newSel = popupDialog.runModal();
|
|
|
|
if (newSel != -1) {
|
|
|
|
sendCommand(_entries[newSel].cmd, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
setUnpressedState();
|
|
|
|
_duringPress = false;
|
|
|
|
} else {
|
|
|
|
ButtonWidget::handleMouseUp(x, y, button, clickCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DropdownButtonWidget::reflowLayout() {
|
|
|
|
ButtonWidget::reflowLayout();
|
|
|
|
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
2019-12-28 09:43:58 +00:00
|
|
|
void DropdownButtonWidget::getMinSize(int &minWidth, int &minHeight) {
|
|
|
|
ButtonWidget::getMinSize(minWidth, minHeight);
|
|
|
|
|
|
|
|
if (minWidth >= 0) {
|
|
|
|
minWidth += _dropdownWidth * 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-10 16:07:51 +00:00
|
|
|
void DropdownButtonWidget::appendEntry(const Common::U32String &label, uint32 cmd) {
|
2019-11-13 20:09:21 +00:00
|
|
|
Entry e;
|
|
|
|
e.label = label;
|
|
|
|
e.cmd = cmd;
|
|
|
|
_entries.push_back(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DropdownButtonWidget::clearEntries() {
|
|
|
|
_entries.clear();
|
|
|
|
}
|
|
|
|
|
2020-05-18 18:16:20 +00:00
|
|
|
void DropdownButtonWidget::drawWidget() {
|
2020-05-20 20:59:59 +00:00
|
|
|
if (_entries.empty()) {
|
2019-11-13 20:09:21 +00:00
|
|
|
// Degrade to a regular button
|
2022-05-15 10:16:29 +00:00
|
|
|
g_gui.theme()->drawButton(Common::Rect(_x, _y, _x + _w, _y + _h), getLabel(), _state);
|
2019-11-13 20:09:21 +00:00
|
|
|
} else {
|
2022-05-15 10:16:29 +00:00
|
|
|
g_gui.theme()->drawDropDownButton(Common::Rect(_x, _y, _x + _w, _y + _h), _dropdownWidth, getLabel(),
|
2020-05-17 21:26:10 +00:00
|
|
|
_state, _inButton, _inDropdown, (g_gui.useRTL() && _useRTL));
|
2019-11-13 20:09:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
2002-07-07 23:37:47 +00:00
|
|
|
|
2022-02-22 17:00:19 +00:00
|
|
|
const Graphics::ManagedSurface *scaleGfx(const Graphics::ManagedSurface *gfx, int w, int h, bool filtering) {
|
2021-04-10 17:33:50 +00:00
|
|
|
int nw = w, nh = h;
|
|
|
|
|
2021-03-29 21:38:14 +00:00
|
|
|
// Maintain aspect ratio
|
|
|
|
float xRatio = 1.0f * w / gfx->w;
|
|
|
|
float yRatio = 1.0f * h / gfx->h;
|
|
|
|
|
|
|
|
if (xRatio < yRatio)
|
2021-04-10 17:33:50 +00:00
|
|
|
nh = gfx->h * xRatio;
|
2021-03-29 21:38:14 +00:00
|
|
|
else
|
2021-04-10 17:33:50 +00:00
|
|
|
nw = gfx->w * yRatio;
|
|
|
|
|
2021-08-14 15:10:19 +00:00
|
|
|
if (nw == gfx->w && nh == gfx->h)
|
2021-04-10 17:33:50 +00:00
|
|
|
return gfx;
|
|
|
|
|
|
|
|
w = nw;
|
|
|
|
h = nh;
|
2021-03-29 21:38:14 +00:00
|
|
|
|
2022-08-25 15:47:44 +00:00
|
|
|
return new Graphics::ManagedSurface(gfx->rawSurface().scale(w, h, filtering));
|
2020-11-03 22:18:56 +00:00
|
|
|
}
|
|
|
|
|
2020-07-01 20:08:10 +00:00
|
|
|
PicButtonWidget::PicButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey)
|
2020-11-15 18:15:58 +00:00
|
|
|
: ButtonWidget(boss, x, y, w, h, Common::U32String(), tooltip, cmd, hotkey),
|
2018-04-19 17:13:12 +00:00
|
|
|
_alpha(255), _transparency(false), _showButton(true) {
|
2011-01-03 12:23:50 +00:00
|
|
|
|
|
|
|
setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
|
|
|
|
_type = kButtonWidget;
|
|
|
|
}
|
|
|
|
|
2020-07-01 20:08:10 +00:00
|
|
|
PicButtonWidget::PicButtonWidget(GuiObject *boss, const Common::String &name, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey)
|
2020-11-15 18:15:58 +00:00
|
|
|
: ButtonWidget(boss, name, Common::U32String(), tooltip, cmd, hotkey),
|
2018-04-19 17:13:12 +00:00
|
|
|
_alpha(255), _transparency(false), _showButton(true) {
|
2011-01-03 12:23:50 +00:00
|
|
|
setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
|
|
|
|
_type = kButtonWidget;
|
|
|
|
}
|
|
|
|
|
2011-01-20 22:32:30 +00:00
|
|
|
PicButtonWidget::~PicButtonWidget() {
|
2014-05-02 15:09:30 +00:00
|
|
|
for (int i = 0; i < kPicButtonStateMax + 1; i++)
|
|
|
|
_gfx[i].free();
|
2011-01-20 22:32:30 +00:00
|
|
|
}
|
|
|
|
|
2021-04-08 13:08:57 +00:00
|
|
|
void PicButtonWidget::setGfx(const Graphics::ManagedSurface *gfx, int statenum, bool scale) {
|
2014-05-02 15:09:30 +00:00
|
|
|
_gfx[statenum].free();
|
2011-01-03 12:23:50 +00:00
|
|
|
|
2013-08-03 00:36:28 +00:00
|
|
|
if (!gfx || !gfx->getPixels())
|
2011-01-03 12:23:50 +00:00
|
|
|
return;
|
|
|
|
|
2012-06-13 02:44:39 +00:00
|
|
|
if (gfx->format.bytesPerPixel == 1) {
|
|
|
|
warning("PicButtonWidget::setGfx got paletted surface passed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-21 07:48:19 +00:00
|
|
|
if (!isVisible() || !_boss->isVisible())
|
|
|
|
return;
|
|
|
|
|
2021-03-26 00:41:53 +00:00
|
|
|
float sf = g_gui.getScaleFactor();
|
|
|
|
if (scale && sf != 1.0) {
|
2021-04-08 13:08:57 +00:00
|
|
|
Graphics::Surface *tmp2 = gfx->rawSurface().scale(gfx->w * sf, gfx->h * sf, false);
|
2021-03-26 00:41:53 +00:00
|
|
|
_gfx[statenum].copyFrom(*tmp2);
|
|
|
|
tmp2->free();
|
|
|
|
delete tmp2;
|
|
|
|
} else {
|
|
|
|
_gfx[statenum].copyFrom(*gfx);
|
|
|
|
}
|
2011-01-03 12:23:50 +00:00
|
|
|
}
|
|
|
|
|
2021-04-08 13:08:57 +00:00
|
|
|
void PicButtonWidget::setGfx(const Graphics::Surface *gfx, int statenum, bool scale) {
|
2021-05-12 07:41:53 +00:00
|
|
|
const Graphics::ManagedSurface *tmpGfx = new Graphics::ManagedSurface(gfx);
|
|
|
|
setGfx(tmpGfx, statenum, scale);
|
|
|
|
delete tmpGfx;
|
2021-04-08 13:08:57 +00:00
|
|
|
}
|
|
|
|
|
2021-04-05 23:51:53 +00:00
|
|
|
void PicButtonWidget::setGfxFromTheme(const char *name, int statenum, bool scale) {
|
2021-04-08 23:06:00 +00:00
|
|
|
const Graphics::ManagedSurface *gfx = g_gui.theme()->getImageSurface(name);
|
2021-04-05 23:51:53 +00:00
|
|
|
|
2021-04-08 23:06:00 +00:00
|
|
|
setGfx(gfx, statenum, scale);
|
2021-04-05 23:51:53 +00:00
|
|
|
|
2021-04-08 23:06:00 +00:00
|
|
|
return;
|
2021-04-05 23:51:53 +00:00
|
|
|
}
|
|
|
|
|
2014-05-02 15:09:30 +00:00
|
|
|
void PicButtonWidget::setGfx(int w, int h, int r, int g, int b, int statenum) {
|
2021-06-21 07:48:19 +00:00
|
|
|
_gfx[statenum].free();
|
|
|
|
|
|
|
|
if (!isVisible() || !_boss->isVisible())
|
2021-06-22 06:34:53 +00:00
|
|
|
return;
|
2021-06-21 07:48:19 +00:00
|
|
|
|
2012-06-29 14:15:46 +00:00
|
|
|
if (w == -1)
|
|
|
|
w = _w;
|
|
|
|
if (h == -1)
|
|
|
|
h = _h;
|
|
|
|
|
|
|
|
const Graphics::PixelFormat &requiredFormat = g_gui.theme()->getPixelFormat();
|
|
|
|
|
2014-05-02 15:09:30 +00:00
|
|
|
_gfx[statenum].create(w, h, requiredFormat);
|
|
|
|
_gfx[statenum].fillRect(Common::Rect(0, 0, w, h), _gfx[statenum].format.RGBToColor(r, g, b));
|
2012-06-29 14:15:46 +00:00
|
|
|
}
|
|
|
|
|
2011-01-03 12:23:50 +00:00
|
|
|
void PicButtonWidget::drawWidget() {
|
2014-04-27 22:05:04 +00:00
|
|
|
if (_showButton)
|
2020-11-15 18:15:58 +00:00
|
|
|
g_gui.theme()->drawButton(Common::Rect(_x, _y, _x + _w, _y + _h), Common::U32String(), _state, getFlags());
|
2011-01-03 12:23:50 +00:00
|
|
|
|
2021-04-05 23:51:53 +00:00
|
|
|
Graphics::ManagedSurface *gfx;
|
2014-05-02 15:09:30 +00:00
|
|
|
|
2018-04-19 17:13:12 +00:00
|
|
|
if (_state == ThemeEngine::kStateHighlight)
|
|
|
|
gfx = &_gfx[kPicButtonHighlight];
|
|
|
|
else if (_state == ThemeEngine::kStateDisabled)
|
|
|
|
gfx = &_gfx[kPicButtonStateDisabled];
|
|
|
|
else if (_state == ThemeEngine::kStatePressed)
|
|
|
|
gfx = &_gfx[kPicButtonStatePressed];
|
|
|
|
else
|
|
|
|
gfx = &_gfx[kPicButtonStateEnabled];
|
2014-05-02 15:09:30 +00:00
|
|
|
|
2018-04-19 17:13:12 +00:00
|
|
|
if (!gfx->getPixels())
|
|
|
|
gfx = &_gfx[kPicButtonStateEnabled];
|
2014-05-02 15:09:30 +00:00
|
|
|
|
2018-04-19 17:13:12 +00:00
|
|
|
if (gfx->getPixels()) {
|
|
|
|
const int x = _x + (_w - gfx->w) / 2;
|
|
|
|
const int y = _y + (_h - gfx->h) / 2;
|
2020-05-20 20:59:59 +00:00
|
|
|
|
2019-08-27 06:07:14 +00:00
|
|
|
g_gui.theme()->drawSurface(Common::Point(x, y), *gfx, _transparency);
|
2011-01-03 12:23:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2020-07-01 20:08:10 +00:00
|
|
|
CheckboxWidget::CheckboxWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &label, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey)
|
2022-05-24 21:45:45 +00:00
|
|
|
: ButtonWidget(boss, x, y, w, h, label, tooltip, cmd, hotkey), _state(false), _overrideText(false) {
|
2007-11-04 03:38:30 +00:00
|
|
|
setFlags(WIDGET_ENABLED);
|
2002-07-08 11:55:55 +00:00
|
|
|
_type = kCheckboxWidget;
|
2021-09-30 14:13:26 +00:00
|
|
|
_spacing = g_gui.xmlEval()->getVar("Globals.Checkbox.Spacing", 15);
|
2002-07-07 23:37:47 +00:00
|
|
|
}
|
|
|
|
|
2020-07-01 20:08:10 +00:00
|
|
|
CheckboxWidget::CheckboxWidget(GuiObject *boss, const Common::String &name, const Common::U32String &label, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey)
|
2022-05-24 21:45:45 +00:00
|
|
|
: ButtonWidget(boss, name, label, tooltip, cmd, hotkey), _state(false), _overrideText(false) {
|
2007-11-04 03:38:30 +00:00
|
|
|
setFlags(WIDGET_ENABLED);
|
2006-03-08 01:42:02 +00:00
|
|
|
_type = kCheckboxWidget;
|
2021-09-30 14:13:26 +00:00
|
|
|
_spacing = g_gui.xmlEval()->getVar("Globals.Checkbox.Spacing", 15);
|
2006-03-08 01:42:02 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void CheckboxWidget::handleMouseUp(int x, int y, int button, int clickCount) {
|
2016-03-23 19:24:43 +00:00
|
|
|
if (isEnabled() && _duringPress && x >= 0 && x < _w && y >= 0 && y < _h) {
|
2002-10-19 01:22:41 +00:00
|
|
|
toggleState();
|
2002-07-07 23:37:47 +00:00
|
|
|
}
|
2022-03-28 09:14:28 +00:00
|
|
|
setUnpressedState();
|
2016-03-23 19:24:43 +00:00
|
|
|
_duringPress = false;
|
2002-07-07 23:37:47 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 23:33:40 +00:00
|
|
|
void CheckboxWidget::setState(bool state) {
|
|
|
|
if (_state != state) {
|
|
|
|
_state = state;
|
2007-11-04 03:38:30 +00:00
|
|
|
//_flags ^= WIDGET_INV_BORDER;
|
2018-01-06 13:40:02 +00:00
|
|
|
markAsDirty();
|
2003-11-03 23:33:40 +00:00
|
|
|
}
|
2003-11-07 16:01:51 +00:00
|
|
|
sendCommand(_cmd, _state);
|
2003-11-03 23:33:40 +00:00
|
|
|
}
|
2022-05-12 19:43:31 +00:00
|
|
|
|
2022-05-24 21:45:45 +00:00
|
|
|
void CheckboxWidget::setOverride(bool enable) {
|
|
|
|
_overrideText = enable;
|
2022-05-12 19:43:31 +00:00
|
|
|
}
|
2003-11-03 23:33:40 +00:00
|
|
|
|
2007-11-04 03:38:30 +00:00
|
|
|
void CheckboxWidget::drawWidget() {
|
2022-05-24 21:45:45 +00:00
|
|
|
g_gui.theme()->drawCheckbox(Common::Rect(_x, _y, _x + _w, _y + _h), _spacing, getLabel(), _state, Widget::_state, _overrideText, (g_gui.useRTL() && _useRTL));
|
2002-07-07 23:37:47 +00:00
|
|
|
}
|
2002-07-08 13:52:50 +00:00
|
|
|
|
2010-06-15 10:48:39 +00:00
|
|
|
#pragma mark -
|
|
|
|
RadiobuttonGroup::RadiobuttonGroup(GuiObject *boss, uint32 cmd) : CommandSender(boss) {
|
|
|
|
_value = -1;
|
|
|
|
_cmd = cmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadiobuttonGroup::setValue(int value) {
|
|
|
|
Common::Array<RadiobuttonWidget *>::iterator button = _buttons.begin();
|
|
|
|
while (button != _buttons.end()) {
|
|
|
|
(*button)->setState((*button)->getValue() == value, false);
|
|
|
|
|
|
|
|
button++;
|
|
|
|
}
|
|
|
|
|
|
|
|
_value = value;
|
|
|
|
|
|
|
|
sendCommand(_cmd, _value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadiobuttonGroup::setEnabled(bool ena) {
|
|
|
|
Common::Array<RadiobuttonWidget *>::iterator button = _buttons.begin();
|
|
|
|
while (button != _buttons.end()) {
|
|
|
|
(*button)->setEnabled(ena);
|
|
|
|
|
|
|
|
button++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2020-07-01 20:08:10 +00:00
|
|
|
RadiobuttonWidget::RadiobuttonWidget(GuiObject *boss, int x, int y, int w, int h, RadiobuttonGroup *group, int value, const Common::U32String &label, const Common::U32String &tooltip, uint8 hotkey)
|
2010-06-15 10:52:35 +00:00
|
|
|
: ButtonWidget(boss, x, y, w, h, label, tooltip, 0, hotkey), _state(false), _value(value), _group(group) {
|
2010-06-15 10:48:39 +00:00
|
|
|
setFlags(WIDGET_ENABLED);
|
|
|
|
_type = kRadiobuttonWidget;
|
|
|
|
_group->addButton(this);
|
2021-09-30 14:13:26 +00:00
|
|
|
_spacing = g_gui.xmlEval()->getVar("Globals.Radiobutton.Spacing", 15);
|
2010-06-15 10:48:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-01 20:08:10 +00:00
|
|
|
RadiobuttonWidget::RadiobuttonWidget(GuiObject *boss, const Common::String &name, RadiobuttonGroup *group, int value, const Common::U32String &label, const Common::U32String &tooltip, uint8 hotkey)
|
2010-06-15 10:52:35 +00:00
|
|
|
: ButtonWidget(boss, name, label, tooltip, 0, hotkey), _state(false), _value(value), _group(group) {
|
2010-06-15 10:48:39 +00:00
|
|
|
setFlags(WIDGET_ENABLED);
|
|
|
|
_type = kRadiobuttonWidget;
|
|
|
|
_group->addButton(this);
|
2021-09-30 14:13:26 +00:00
|
|
|
_spacing = g_gui.xmlEval()->getVar("Globals.Radiobutton.Spacing", 15);
|
2010-06-15 10:48:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RadiobuttonWidget::handleMouseUp(int x, int y, int button, int clickCount) {
|
2016-03-23 19:24:43 +00:00
|
|
|
if (isEnabled() && _duringPress && x >= 0 && x < _w && y >= 0 && y < _h) {
|
2010-06-15 10:48:39 +00:00
|
|
|
toggleState();
|
|
|
|
}
|
2022-03-28 09:14:28 +00:00
|
|
|
setUnpressedState();
|
2016-03-23 19:24:43 +00:00
|
|
|
_duringPress = false;
|
2010-06-15 10:48:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RadiobuttonWidget::setState(bool state, bool setGroup) {
|
|
|
|
if (setGroup) {
|
|
|
|
_group->setValue(_value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_state != state) {
|
|
|
|
_state = state;
|
|
|
|
//_flags ^= WIDGET_INV_BORDER;
|
2018-01-06 13:40:02 +00:00
|
|
|
markAsDirty();
|
2010-06-15 10:48:39 +00:00
|
|
|
}
|
|
|
|
sendCommand(_cmd, _state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadiobuttonWidget::drawWidget() {
|
2022-05-15 10:16:29 +00:00
|
|
|
g_gui.theme()->drawRadiobutton(Common::Rect(_x, _y, _x + _w, _y + _h), _spacing, getLabel(), _state, Widget::_state, (g_gui.useRTL() && _useRTL));
|
2010-06-15 10:48:39 +00:00
|
|
|
}
|
|
|
|
|
2002-07-08 13:52:50 +00:00
|
|
|
#pragma mark -
|
2002-07-08 22:11:47 +00:00
|
|
|
|
2020-07-01 20:08:10 +00:00
|
|
|
SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &tooltip, uint32 cmd)
|
2010-06-15 10:52:35 +00:00
|
|
|
: Widget(boss, x, y, w, h, tooltip), CommandSender(boss),
|
2016-06-01 09:18:17 +00:00
|
|
|
_cmd(cmd), _value(0), _oldValue(0), _valueMin(0), _valueMax(100), _isDragging(false), _labelWidth(0) {
|
2007-11-04 03:38:30 +00:00
|
|
|
setFlags(WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG);
|
2002-07-08 13:52:50 +00:00
|
|
|
_type = kSliderWidget;
|
|
|
|
}
|
|
|
|
|
2020-07-01 20:08:10 +00:00
|
|
|
SliderWidget::SliderWidget(GuiObject *boss, const Common::String &name, const Common::U32String &tooltip, uint32 cmd)
|
2010-06-15 10:52:35 +00:00
|
|
|
: Widget(boss, name, tooltip), CommandSender(boss),
|
2016-06-01 09:18:17 +00:00
|
|
|
_cmd(cmd), _value(0), _oldValue(0), _valueMin(0), _valueMax(100), _isDragging(false), _labelWidth(0) {
|
2007-11-04 03:38:30 +00:00
|
|
|
setFlags(WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG);
|
2006-03-08 01:42:02 +00:00
|
|
|
_type = kSliderWidget;
|
|
|
|
}
|
|
|
|
|
2002-12-12 23:21:29 +00:00
|
|
|
void SliderWidget::handleMouseMoved(int x, int y, int button) {
|
2020-05-27 13:27:40 +00:00
|
|
|
if (g_gui.useRTL() && _useRTL == false) {
|
|
|
|
x = _w - x; // If internal flipping is off, adjust the mouse to behave as if it were LTR.
|
|
|
|
}
|
2006-06-28 04:52:48 +00:00
|
|
|
if (isEnabled() && _isDragging) {
|
2005-05-18 10:24:02 +00:00
|
|
|
int newValue = posToValue(x);
|
2002-07-26 23:29:43 +00:00
|
|
|
if (newValue < _valueMin)
|
|
|
|
newValue = _valueMin;
|
|
|
|
else if (newValue > _valueMax)
|
|
|
|
newValue = _valueMax;
|
2002-07-16 12:01:03 +00:00
|
|
|
|
|
|
|
if (newValue != _value) {
|
2005-07-30 21:11:48 +00:00
|
|
|
_value = newValue;
|
2018-01-06 13:40:02 +00:00
|
|
|
markAsDirty();
|
2002-07-27 00:05:46 +00:00
|
|
|
sendCommand(_cmd, _value); // FIXME - hack to allow for "live update" in sound dialog
|
2002-07-10 22:49:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-27 14:16:14 +00:00
|
|
|
void SliderWidget::handleMouseDown(int x, int y, int button, int clickCount) {
|
2002-10-01 23:11:19 +00:00
|
|
|
if (isEnabled()) {
|
2002-12-12 23:21:29 +00:00
|
|
|
_isDragging = true;
|
|
|
|
handleMouseMoved(x, y, button);
|
2002-07-27 00:05:46 +00:00
|
|
|
}
|
2002-07-13 18:32:09 +00:00
|
|
|
}
|
|
|
|
|
2002-07-27 14:16:14 +00:00
|
|
|
void SliderWidget::handleMouseUp(int x, int y, int button, int clickCount) {
|
2002-10-01 23:11:19 +00:00
|
|
|
if (isEnabled() && _isDragging) {
|
2002-07-27 00:05:46 +00:00
|
|
|
sendCommand(_cmd, _value);
|
2002-07-26 00:41:07 +00:00
|
|
|
}
|
2002-07-16 12:01:03 +00:00
|
|
|
_isDragging = false;
|
2002-07-13 18:32:09 +00:00
|
|
|
}
|
2002-07-26 23:29:43 +00:00
|
|
|
|
2008-12-23 23:36:38 +00:00
|
|
|
void SliderWidget::handleMouseWheel(int x, int y, int direction) {
|
|
|
|
if (isEnabled() && !_isDragging) {
|
2012-12-27 09:13:48 +00:00
|
|
|
// Increment or decrement by one
|
|
|
|
int newValue = _value - direction;
|
2008-12-23 23:36:38 +00:00
|
|
|
|
|
|
|
if (newValue < _valueMin)
|
|
|
|
newValue = _valueMin;
|
|
|
|
else if (newValue > _valueMax)
|
|
|
|
newValue = _valueMax;
|
|
|
|
|
|
|
|
if (newValue != _value) {
|
|
|
|
_value = newValue;
|
2018-01-06 13:40:02 +00:00
|
|
|
markAsDirty();
|
2008-12-23 23:36:38 +00:00
|
|
|
sendCommand(_cmd, _value); // FIXME - hack to allow for "live update" in sound dialog
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-04 03:38:30 +00:00
|
|
|
void SliderWidget::drawWidget() {
|
2020-05-13 22:41:39 +00:00
|
|
|
Common::Rect r1(_x, _y, _x + _w, _y + _h);
|
2020-05-21 20:30:17 +00:00
|
|
|
g_gui.theme()->drawSlider(r1, valueToBarWidth(_value), _state, (g_gui.useRTL() && _useRTL));
|
2008-12-24 01:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SliderWidget::valueToBarWidth(int value) {
|
2016-12-01 18:48:06 +00:00
|
|
|
value = CLIP(value, _valueMin, _valueMax);
|
2008-12-24 01:11:58 +00:00
|
|
|
return (_w * (value - _valueMin) / (_valueMax - _valueMin));
|
2002-07-26 23:29:43 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
int SliderWidget::valueToPos(int value) {
|
2016-12-01 18:48:06 +00:00
|
|
|
value = CLIP(value, _valueMin, _valueMax);
|
2008-12-23 23:36:38 +00:00
|
|
|
return ((_w - 1) * (value - _valueMin + 1) / (_valueMax - _valueMin));
|
2002-07-26 23:29:43 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
int SliderWidget::posToValue(int pos) {
|
2008-12-23 23:36:38 +00:00
|
|
|
return (pos) * (_valueMax - _valueMin) / (_w - 1) + _valueMin;
|
2002-07-26 23:29:43 +00:00
|
|
|
}
|
2003-11-10 23:40:48 +00:00
|
|
|
|
2005-05-08 22:38:29 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
GUI: U32: Downscale changes of U32, fix review issues
This commit addresses a range of changes, within scummvm subproject.
- Audio files, like mididrv, remove U32String based name and identifier, because ASCII only.
- mididrv.cpp had some wrong format for warning messages, fix those
- Message dialogs were modified to use default arguments more often, but reverting back to the orignal to minimize changes.
- SetTooltip has a fake constructor that takes in a string, and use it.
- U32Format had some break statements missing, add those.
- RemapWidget: Use fake constructor for setLabel and setTooltip, to make minimal changes
- SDL: setting text in clipboard no longer uses SDL_iconv_string
- TTS: Override base class "say" with strings, so tts->say can be used with normal strings too.
- About dialog: fix incorrect code for u32string variables
- Fix some extra brackets
- Some buttons were incorrectly removed from using translated labels, revert those
- Message Dialog: Pass default and alt buttons as const references
- Saveload Dialog: Use translations in missing places, use const-references. Also, use translations in a correct manner.
- Use const references for tooltip in GraphicsWidget, EditTextWidget, error.cpp
- DomainEditTextWidget: Use U32String for text
2020-07-20 12:36:37 +00:00
|
|
|
GraphicsWidget::GraphicsWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &tooltip)
|
2014-08-03 23:12:49 +00:00
|
|
|
: Widget(boss, x, y, w, h, tooltip), _gfx(), _alpha(255), _transparency(false) {
|
2007-11-04 03:38:30 +00:00
|
|
|
setFlags(WIDGET_ENABLED | WIDGET_CLEARBG);
|
2006-03-14 02:19:38 +00:00
|
|
|
_type = kGraphicsWidget;
|
|
|
|
}
|
|
|
|
|
GUI: U32: Downscale changes of U32, fix review issues
This commit addresses a range of changes, within scummvm subproject.
- Audio files, like mididrv, remove U32String based name and identifier, because ASCII only.
- mididrv.cpp had some wrong format for warning messages, fix those
- Message dialogs were modified to use default arguments more often, but reverting back to the orignal to minimize changes.
- SetTooltip has a fake constructor that takes in a string, and use it.
- U32Format had some break statements missing, add those.
- RemapWidget: Use fake constructor for setLabel and setTooltip, to make minimal changes
- SDL: setting text in clipboard no longer uses SDL_iconv_string
- TTS: Override base class "say" with strings, so tts->say can be used with normal strings too.
- About dialog: fix incorrect code for u32string variables
- Fix some extra brackets
- Some buttons were incorrectly removed from using translated labels, revert those
- Message Dialog: Pass default and alt buttons as const references
- Saveload Dialog: Use translations in missing places, use const-references. Also, use translations in a correct manner.
- Use const references for tooltip in GraphicsWidget, EditTextWidget, error.cpp
- DomainEditTextWidget: Use U32String for text
2020-07-20 12:36:37 +00:00
|
|
|
GraphicsWidget::GraphicsWidget(GuiObject *boss, const Common::String &name, const Common::U32String &tooltip)
|
2014-08-03 23:12:49 +00:00
|
|
|
: Widget(boss, name, tooltip), _gfx(), _alpha(255), _transparency(false) {
|
2007-11-04 03:38:30 +00:00
|
|
|
setFlags(WIDGET_ENABLED | WIDGET_CLEARBG);
|
2005-05-08 22:38:29 +00:00
|
|
|
_type = kGraphicsWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsWidget::~GraphicsWidget() {
|
2012-08-28 00:25:14 +00:00
|
|
|
_gfx.free();
|
2005-05-08 22:38:29 +00:00
|
|
|
}
|
|
|
|
|
2021-04-17 10:51:44 +00:00
|
|
|
void GraphicsWidget::setGfx(const Graphics::ManagedSurface *gfx, bool scale) {
|
2012-08-28 00:25:14 +00:00
|
|
|
_gfx.free();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2013-08-03 00:36:28 +00:00
|
|
|
if (!gfx || !gfx->getPixels())
|
2005-05-08 22:38:29 +00:00
|
|
|
return;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2012-06-13 02:44:39 +00:00
|
|
|
if (gfx->format.bytesPerPixel == 1) {
|
|
|
|
warning("GraphicsWidget::setGfx got paletted surface passed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-21 07:48:19 +00:00
|
|
|
if (!isVisible() || !_boss->isVisible())
|
2021-06-20 10:12:46 +00:00
|
|
|
return;
|
|
|
|
|
2021-04-17 10:51:44 +00:00
|
|
|
float sf = g_gui.getScaleFactor();
|
2021-04-17 16:44:47 +00:00
|
|
|
if (scale && sf != 1.0) {
|
2021-06-04 10:17:25 +00:00
|
|
|
_w = gfx->w * sf;
|
|
|
|
_h = gfx->h * sf;
|
2021-04-18 00:42:31 +00:00
|
|
|
} else {
|
2021-06-04 10:17:25 +00:00
|
|
|
_w = gfx->w;
|
|
|
|
_h = gfx->h;
|
2021-04-17 16:44:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((_w != gfx->w || _h != gfx->h) && _w && _h) {
|
2021-06-04 10:17:25 +00:00
|
|
|
Graphics::Surface *tmp2 = gfx->rawSurface().scale(_w, _h, false);
|
|
|
|
_gfx.copyFrom(*tmp2);
|
2021-04-17 10:51:44 +00:00
|
|
|
tmp2->free();
|
|
|
|
delete tmp2;
|
2020-11-03 00:33:37 +00:00
|
|
|
} else {
|
|
|
|
_gfx.copyFrom(*gfx);
|
|
|
|
}
|
2005-05-08 22:38:29 +00:00
|
|
|
}
|
|
|
|
|
2021-04-17 10:51:44 +00:00
|
|
|
void GraphicsWidget::setGfx(const Graphics::Surface *gfx, bool scale) {
|
2021-05-12 07:41:53 +00:00
|
|
|
const Graphics::ManagedSurface *tmpGfx = new Graphics::ManagedSurface(gfx);
|
|
|
|
setGfx(tmpGfx, scale);
|
|
|
|
delete tmpGfx;
|
2021-04-08 13:08:57 +00:00
|
|
|
}
|
|
|
|
|
2006-05-29 14:38:56 +00:00
|
|
|
void GraphicsWidget::setGfx(int w, int h, int r, int g, int b) {
|
2021-06-21 07:48:19 +00:00
|
|
|
_gfx.free();
|
|
|
|
|
|
|
|
if (!isVisible() || !_boss->isVisible())
|
2021-06-22 06:34:53 +00:00
|
|
|
return;
|
2021-06-21 07:48:19 +00:00
|
|
|
|
2006-05-29 14:38:56 +00:00
|
|
|
if (w == -1)
|
|
|
|
w = _w;
|
|
|
|
if (h == -1)
|
|
|
|
h = _h;
|
|
|
|
|
2012-06-13 02:44:39 +00:00
|
|
|
const Graphics::PixelFormat &requiredFormat = g_gui.theme()->getPixelFormat();
|
2011-04-17 14:34:58 +00:00
|
|
|
|
2012-08-28 00:25:14 +00:00
|
|
|
_gfx.create(w, h, requiredFormat);
|
|
|
|
_gfx.fillRect(Common::Rect(0, 0, w, h), _gfx.format.RGBToColor(r, g, b));
|
2006-05-29 14:38:56 +00:00
|
|
|
}
|
|
|
|
|
2021-04-04 21:57:30 +00:00
|
|
|
void GraphicsWidget::setGfxFromTheme(const char *name) {
|
2021-04-08 23:06:00 +00:00
|
|
|
const Graphics::ManagedSurface *gfx = g_gui.theme()->getImageSurface(name);
|
2021-04-04 21:57:30 +00:00
|
|
|
|
2021-04-18 00:42:31 +00:00
|
|
|
setGfx(gfx, false);
|
2021-04-04 21:57:30 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:38:30 +00:00
|
|
|
void GraphicsWidget::drawWidget() {
|
2013-08-03 00:36:28 +00:00
|
|
|
if (_gfx.getPixels()) {
|
2012-08-28 00:25:14 +00:00
|
|
|
const int x = _x + (_w - _gfx.w) / 2;
|
|
|
|
const int y = _y + (_h - _gfx.h) / 2;
|
2020-05-20 20:59:59 +00:00
|
|
|
|
2019-08-27 06:07:14 +00:00
|
|
|
g_gui.theme()->drawSurface(Common::Point(x, y), _gfx, _transparency);
|
2010-07-04 01:11:18 +00:00
|
|
|
}
|
2005-05-08 22:38:29 +00:00
|
|
|
}
|
|
|
|
|
2006-05-27 05:46:04 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2019-12-28 09:43:58 +00:00
|
|
|
ContainerWidget::ContainerWidget(GuiObject *boss, int x, int y, int w, int h) :
|
|
|
|
Widget(boss, x, y, w, h),
|
|
|
|
_backgroundType(ThemeEngine::kWidgetBackgroundBorder) {
|
2007-11-04 03:38:30 +00:00
|
|
|
setFlags(WIDGET_ENABLED | WIDGET_CLEARBG);
|
2006-05-27 05:46:04 +00:00
|
|
|
_type = kContainerWidget;
|
|
|
|
}
|
|
|
|
|
2019-12-28 09:43:58 +00:00
|
|
|
ContainerWidget::ContainerWidget(GuiObject *boss, const Common::String &name) :
|
|
|
|
Widget(boss, name),
|
|
|
|
_backgroundType(ThemeEngine::kWidgetBackgroundBorder) {
|
2007-11-04 03:38:30 +00:00
|
|
|
setFlags(WIDGET_ENABLED | WIDGET_CLEARBG);
|
2006-05-27 05:46:04 +00:00
|
|
|
_type = kContainerWidget;
|
|
|
|
}
|
|
|
|
|
2012-07-08 23:49:58 +00:00
|
|
|
ContainerWidget::~ContainerWidget() {
|
|
|
|
// We also remove the widget from the boss to avoid segfaults, when the
|
|
|
|
// deleted widget is an active widget in the boss.
|
|
|
|
for (Widget *w = _firstWidget; w; w = w->next()) {
|
|
|
|
_boss->removeWidget(w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-06 20:50:16 +00:00
|
|
|
bool ContainerWidget::containsWidget(Widget *w) const {
|
|
|
|
return containsWidgetInChain(_firstWidget, w);
|
|
|
|
}
|
|
|
|
|
2012-07-08 23:49:58 +00:00
|
|
|
Widget *ContainerWidget::findWidget(int x, int y) {
|
2018-07-23 22:34:01 +00:00
|
|
|
Widget *w = findWidgetInChain(_firstWidget, x, y);
|
|
|
|
if (w)
|
|
|
|
return w;
|
|
|
|
return this;
|
2012-07-08 23:49:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContainerWidget::removeWidget(Widget *widget) {
|
|
|
|
// We also remove the widget from the boss to avoid a reference to a
|
|
|
|
// widget not in the widget chain anymore.
|
|
|
|
_boss->removeWidget(widget);
|
|
|
|
|
|
|
|
Widget::removeWidget(widget);
|
|
|
|
}
|
|
|
|
|
2019-12-28 09:43:58 +00:00
|
|
|
void ContainerWidget::setBackgroundType(ThemeEngine::WidgetBackground backgroundType) {
|
|
|
|
_backgroundType = backgroundType;
|
|
|
|
}
|
|
|
|
|
2007-11-04 03:38:30 +00:00
|
|
|
void ContainerWidget::drawWidget() {
|
2019-12-28 09:43:58 +00:00
|
|
|
g_gui.theme()->drawWidgetBackground(Common::Rect(_x, _y, _x + _w, _y + _h), _backgroundType);
|
2006-05-27 05:46:04 +00:00
|
|
|
}
|
|
|
|
|
2021-05-29 14:10:00 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2020-03-22 14:19:56 +00:00
|
|
|
OptionsContainerWidget::OptionsContainerWidget(GuiObject *boss, const Common::String &name, const Common::String &dialogLayout,
|
2021-04-15 19:20:04 +00:00
|
|
|
bool scrollable, const Common::String &domain) :
|
2020-03-22 14:19:56 +00:00
|
|
|
Widget(boss, name),
|
|
|
|
_domain(domain),
|
|
|
|
_dialogLayout(dialogLayout),
|
|
|
|
_parentDialog(nullptr),
|
|
|
|
_scrollContainer(nullptr) {
|
|
|
|
|
|
|
|
if (scrollable) {
|
2021-02-20 11:17:11 +00:00
|
|
|
_scrollContainer = new ScrollContainerWidget(this, name, _dialogLayout, kReflowCmd);
|
2020-03-22 14:19:56 +00:00
|
|
|
_scrollContainer->setTarget(this);
|
|
|
|
_scrollContainer->setBackgroundType(GUI::ThemeEngine::kWidgetBackgroundNo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionsContainerWidget::~OptionsContainerWidget() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionsContainerWidget::reflowLayout() {
|
|
|
|
Widget::reflowLayout();
|
|
|
|
|
|
|
|
if (!_dialogLayout.empty()) {
|
2021-04-08 14:04:33 +00:00
|
|
|
// Since different engines have different number of options,
|
|
|
|
// we have to create it every time.
|
|
|
|
defineLayout(*g_gui.xmlEval(), _dialogLayout, _name);
|
2020-03-22 14:19:56 +00:00
|
|
|
|
2021-02-20 11:17:11 +00:00
|
|
|
if (!_scrollContainer) {
|
|
|
|
g_gui.xmlEval()->reflowDialogLayout(_dialogLayout, _firstWidget);
|
|
|
|
}
|
2020-03-22 14:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_scrollContainer) {
|
2021-03-30 22:37:31 +00:00
|
|
|
_scrollContainer->resize(_x, _y, _w, _h, false);
|
2020-03-22 14:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget *w = _firstWidget;
|
2021-12-07 13:29:53 +00:00
|
|
|
int16 minY = getAbsY();
|
2021-12-07 19:13:44 +00:00
|
|
|
int maxY = minY + _h;
|
2020-03-22 14:19:56 +00:00
|
|
|
while (w) {
|
|
|
|
w->reflowLayout();
|
2021-12-07 13:29:53 +00:00
|
|
|
minY = MIN(minY, w->getAbsY());
|
|
|
|
maxY = MAX(maxY, w->getAbsY() + w->getHeight());
|
2020-03-22 14:19:56 +00:00
|
|
|
w = w->next();
|
|
|
|
}
|
2021-12-07 13:29:53 +00:00
|
|
|
_h = maxY - minY;
|
2020-03-22 14:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OptionsContainerWidget::containsWidget(Widget *widget) const {
|
|
|
|
return containsWidgetInChain(_firstWidget, widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget *OptionsContainerWidget::findWidget(int x, int y) {
|
|
|
|
// Iterate over all child widgets and find the one which was clicked
|
|
|
|
return Widget::findWidgetInChain(_firstWidget, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionsContainerWidget::removeWidget(Widget *widget) {
|
|
|
|
_boss->removeWidget(widget);
|
|
|
|
Widget::removeWidget(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
GuiObject *OptionsContainerWidget::widgetsBoss() {
|
|
|
|
if (_scrollContainer) {
|
|
|
|
return _scrollContainer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
} // End of namespace GUI
|