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
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
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"
|
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"
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
2010-06-15 10:52:35 +00:00
|
|
|
Widget::Widget(GuiObject *boss, int x, int y, int w, int h, const char *tooltip)
|
|
|
|
: GuiObject(x, y, w, h), _type(0), _boss(boss), _tooltip(tooltip),
|
2008-11-10 11:24:55 +00:00
|
|
|
_id(0), _flags(0), _hasFocus(false), _state(ThemeEngine::kStateEnabled) {
|
2006-03-07 05:39:52 +00:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2010-06-15 10:52:35 +00:00
|
|
|
Widget::Widget(GuiObject *boss, const Common::String &name, const char *tooltip)
|
|
|
|
: GuiObject(name), _type(0), _boss(boss), _tooltip(tooltip),
|
2008-11-10 11:24:55 +00:00
|
|
|
_id(0), _flags(0), _hasFocus(false), _state(ThemeEngine::kStateDisabled) {
|
2006-03-07 05:39:52 +00:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::init() {
|
2002-07-05 16:56:53 +00:00
|
|
|
// Insert into the widget list of the boss
|
|
|
|
_next = _boss->_firstWidget;
|
|
|
|
_boss->_firstWidget = this;
|
|
|
|
}
|
|
|
|
|
2016-07-02 08:35:37 +00:00
|
|
|
Common::Rect Widget::getBossClipRect() const {
|
|
|
|
int bx = _boss->getAbsX();
|
|
|
|
int by = _boss->getAbsY();
|
|
|
|
Common::Rect result = Common::Rect(bx, by, bx + _boss->getWidth(), by + _boss->getHeight());
|
|
|
|
bool needsClipping = false;
|
|
|
|
|
|
|
|
//check whether clipping area is inside the screen
|
|
|
|
if (result.left < 0 && (needsClipping = true))
|
|
|
|
warning("Widget <%s> has clipping area x < 0 (%d)", _name.c_str(), result.left);
|
|
|
|
if (result.left >= g_gui.getWidth() && (needsClipping = true))
|
|
|
|
warning("Widget <%s> has clipping area x > %d (%d)", _name.c_str(), g_gui.getWidth(), result.left);
|
|
|
|
if (result.right > g_gui.getWidth() && (needsClipping = true))
|
|
|
|
warning("Widget <%s> has clipping area x + w > %d (%d)", _name.c_str(), g_gui.getWidth(), result.right);
|
|
|
|
if (result.top < 0 && (needsClipping = true))
|
|
|
|
warning("Widget <%s> has clipping area y < 0 (%d)", _name.c_str(), result.top);
|
|
|
|
if (result.top >= g_gui.getHeight() && (needsClipping = true))
|
|
|
|
warning("Widget <%s> has clipping area y > %d (%d)", _name.c_str(), g_gui.getHeight(), result.top);
|
|
|
|
if (result.bottom > g_gui.getHeight() && (needsClipping = true))
|
|
|
|
warning("Widget <%s> has clipping area y + h > %d (%d)", _name.c_str(), g_gui.getHeight(), result.bottom);
|
|
|
|
|
|
|
|
if (needsClipping)
|
|
|
|
result.clip(g_gui.getWidth(), g_gui.getHeight());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-11-04 03:38:30 +00:00
|
|
|
Widget::~Widget() {
|
|
|
|
delete _next;
|
|
|
|
_next = 0;
|
|
|
|
}
|
|
|
|
|
2006-04-19 01:05:28 +00:00
|
|
|
void Widget::resize(int x, int y, int w, int h) {
|
|
|
|
_x = x;
|
|
|
|
_y = y;
|
|
|
|
_w = w;
|
|
|
|
_h = h;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void Widget::draw() {
|
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
|
|
|
|
2003-11-02 22:31:20 +00:00
|
|
|
int oldX = _x, oldY = _y;
|
2002-07-05 16:56:53 +00:00
|
|
|
|
|
|
|
// Account for our relative position in the dialog
|
2003-11-02 22:31:20 +00:00
|
|
|
_x = getAbsX();
|
|
|
|
_y = getAbsY();
|
2002-07-07 13:14:34 +00:00
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
// Draw border
|
|
|
|
if (_flags & WIDGET_BORDER) {
|
2016-07-01 08:25:05 +00:00
|
|
|
g_gui.theme()->drawWidgetBackgroundClip(Common::Rect(_x, _y, _x+_w, _y+_h), getBossClipRect(), 0, ThemeEngine::kWidgetBackgroundBorder);
|
2002-07-05 16:56:53 +00:00
|
|
|
_x += 4;
|
|
|
|
_y += 4;
|
2002-07-15 12:59:56 +00:00
|
|
|
_w -= 8;
|
2003-11-01 22:21:18 +00:00
|
|
|
_h -= 8;
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
// Now perform the actual widget draw
|
2007-11-04 03:38:30 +00:00
|
|
|
drawWidget();
|
2002-07-07 13:14:34 +00:00
|
|
|
|
2002-07-08 00:10:11 +00:00
|
|
|
// Restore x/y
|
2002-07-05 16:56:53 +00:00
|
|
|
if (_flags & WIDGET_BORDER) {
|
|
|
|
_x -= 4;
|
|
|
|
_y -= 4;
|
2002-07-15 12:59:56 +00:00
|
|
|
_w += 8;
|
2003-11-01 22:21:18 +00:00
|
|
|
_h += 8;
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2003-11-02 22:31:20 +00:00
|
|
|
_x = oldX;
|
|
|
|
_y = oldY;
|
|
|
|
|
|
|
|
// Draw all children
|
|
|
|
Widget *w = _firstWidget;
|
|
|
|
while (w) {
|
|
|
|
w->draw();
|
|
|
|
w = w->_next;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2007-11-04 03:38:30 +00:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
_boss->draw();
|
|
|
|
}
|
2008-12-27 14:36:28 +00:00
|
|
|
}
|
|
|
|
|
2007-10-28 12:02:09 +00:00
|
|
|
bool Widget::isEnabled() const {
|
2008-08-07 10:53:33 +00:00
|
|
|
if (g_gui.xmlEval()->getVar("Dialog." + _name + ".Enabled", 1) == 0) {
|
2007-10-28 12:02:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
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 {
|
2008-08-07 10:53:33 +00:00
|
|
|
if (g_gui.xmlEval()->getVar("Dialog." + _name + ".Visible", 1) == 0)
|
2006-03-07 13:41:36 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return !(_flags & WIDGET_INVISIBLE);
|
|
|
|
}
|
|
|
|
|
2010-06-15 10:47:31 +00:00
|
|
|
uint8 Widget::parseHotkey(const Common::String &label) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state == 3)
|
|
|
|
return hotkey;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::String Widget::cleanupHotkey(const Common::String &label) {
|
|
|
|
Common::String res;
|
|
|
|
|
2011-02-07 23:01:06 +00:00
|
|
|
for (uint i = 0; i < label.size(); i++)
|
2010-06-15 10:47:31 +00:00
|
|
|
if (label[i] != '~')
|
|
|
|
res = res + label[i];
|
2010-07-21 18:17:51 +00:00
|
|
|
|
2010-06-15 10:47:31 +00:00
|
|
|
return res;
|
2010-07-21 18:17:51 +00:00
|
|
|
}
|
2010-06-15 10:47:31 +00:00
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2016-03-30 09:09:32 +00:00
|
|
|
StaticTextWidget::StaticTextWidget(GuiObject *boss, int x, int y, int w, int h, const Common::String &text, Graphics::TextAlign align, const char *tooltip, ThemeEngine::FontStyle font)
|
2010-06-15 10:52:35 +00:00
|
|
|
: Widget(boss, x, y, w, h, tooltip), _align(align) {
|
2007-11-04 03:38:30 +00:00
|
|
|
setFlags(WIDGET_ENABLED);
|
2002-07-08 11:55:55 +00:00
|
|
|
_type = kStaticTextWidget;
|
2005-04-16 17:53:18 +00:00
|
|
|
_label = text;
|
2016-03-30 09:09:32 +00:00
|
|
|
_font = font;
|
2002-07-10 22:49:41 +00:00
|
|
|
}
|
|
|
|
|
2016-03-30 09:09:32 +00:00
|
|
|
StaticTextWidget::StaticTextWidget(GuiObject *boss, const Common::String &name, const Common::String &text, const char *tooltip, ThemeEngine::FontStyle font)
|
2010-06-15 10:52:35 +00:00
|
|
|
: Widget(boss, name, tooltip) {
|
2007-11-04 03:38:30 +00:00
|
|
|
setFlags(WIDGET_ENABLED);
|
2006-03-07 05:39:52 +00:00
|
|
|
_type = kStaticTextWidget;
|
|
|
|
_label = text;
|
2006-03-24 01:24:26 +00:00
|
|
|
|
2009-06-06 17:52:44 +00:00
|
|
|
_align = g_gui.xmlEval()->getWidgetTextHAlign(name);
|
2016-03-30 09:09:32 +00:00
|
|
|
_font = font;
|
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
|
|
|
}
|
|
|
|
|
2007-02-03 21:32:18 +00:00
|
|
|
void StaticTextWidget::setLabel(const Common::String &label) {
|
2012-01-29 20:17:01 +00:00
|
|
|
if (_label != label) {
|
|
|
|
_label = label;
|
|
|
|
|
|
|
|
// when changing the label, add the CLEARBG flag
|
|
|
|
// so the widget is completely redrawn, otherwise
|
|
|
|
// the new text is drawn on top of the old one.
|
|
|
|
setFlags(WIDGET_CLEARBG);
|
|
|
|
draw();
|
|
|
|
clearFlags(WIDGET_CLEARBG);
|
|
|
|
}
|
2005-04-16 17:53:18 +00:00
|
|
|
}
|
|
|
|
|
2008-11-12 14:30:16 +00:00
|
|
|
void StaticTextWidget::setAlign(Graphics::TextAlign align) {
|
2016-03-25 01:34:35 +00:00
|
|
|
if (_align != align){
|
|
|
|
_align = align;
|
|
|
|
|
|
|
|
// same as setLabel() actually, the text
|
|
|
|
// would be redrawn on top of the old one so
|
|
|
|
// we add the CLEARBG flag
|
|
|
|
setFlags(WIDGET_CLEARBG);
|
|
|
|
draw();
|
|
|
|
clearFlags(WIDGET_CLEARBG);
|
|
|
|
}
|
2016-06-01 09:18:17 +00:00
|
|
|
|
2005-04-16 17:53:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-04 03:38:30 +00:00
|
|
|
void StaticTextWidget::drawWidget() {
|
2016-06-20 15:10:37 +00:00
|
|
|
g_gui.theme()->drawTextClip(
|
2016-06-22 09:02:46 +00:00
|
|
|
Common::Rect(_x, _y, _x+_w, _y+_h), getBossClipRect(),
|
2016-06-20 15:10:37 +00:00
|
|
|
_label, _state, _align, ThemeEngine::kTextInversionNone, 0, true, _font
|
|
|
|
);
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2010-06-15 10:52:35 +00:00
|
|
|
ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Common::String &label, const char *tooltip, uint32 cmd, uint8 hotkey)
|
|
|
|
: StaticTextWidget(boss, x, y, w, h, cleanupHotkey(label), Graphics::kTextAlignCenter, tooltip), CommandSender(boss),
|
2016-03-23 19:24:43 +00:00
|
|
|
_cmd(cmd), _hotkey(hotkey), _lastTime(0), _duringPress(false) {
|
2010-06-15 10:47:31 +00:00
|
|
|
|
|
|
|
if (hotkey == 0)
|
|
|
|
_hotkey = parseHotkey(label);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-06-15 10:52:35 +00:00
|
|
|
ButtonWidget::ButtonWidget(GuiObject *boss, const Common::String &name, const Common::String &label, const char *tooltip, uint32 cmd, uint8 hotkey)
|
2010-07-21 18:17:51 +00:00
|
|
|
: StaticTextWidget(boss, name, cleanupHotkey(label), tooltip), CommandSender(boss),
|
2016-03-23 19:24:43 +00:00
|
|
|
_cmd(cmd), _hotkey(hotkey), _lastTime(0), _duringPress(false) {
|
2010-06-15 10:47:31 +00:00
|
|
|
if (hotkey == 0)
|
|
|
|
_hotkey = parseHotkey(label);
|
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;
|
|
|
|
}
|
|
|
|
|
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() {
|
2016-06-21 09:15:15 +00:00
|
|
|
g_gui.theme()->drawButtonClip(
|
2016-06-22 09:02:46 +00:00
|
|
|
Common::Rect(_x, _y, _x + _w, _y + _h), getBossClipRect(),
|
2016-06-21 09:15:15 +00:00
|
|
|
_label, _state, getFlags()
|
|
|
|
);
|
2002-10-19 01:22:41 +00:00
|
|
|
}
|
|
|
|
|
2011-08-06 09:12:34 +00:00
|
|
|
void ButtonWidget::setLabel(const Common::String &label) {
|
|
|
|
StaticTextWidget::setLabel(cleanupHotkey(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())
|
|
|
|
button = new PicButtonWidget(boss, name, _("Clear value"), cmd);
|
|
|
|
else
|
|
|
|
button = new PicButtonWidget(boss, x, y, w, h, _("Clear value"), cmd);
|
2011-12-13 02:33:28 +00:00
|
|
|
((PicButtonWidget *)button)->useThemeTransparency(true);
|
|
|
|
((PicButtonWidget *)button)->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageEraser));
|
|
|
|
} else
|
|
|
|
#endif
|
2011-12-13 03:26:00 +00:00
|
|
|
if (!name.empty())
|
|
|
|
button = new ButtonWidget(boss, name, "C", _("Clear value"), cmd);
|
|
|
|
else
|
|
|
|
button = new ButtonWidget(boss, x, y, w, h, "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);
|
|
|
|
draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ButtonWidget::setPressedState() {
|
|
|
|
setFlags(WIDGET_PRESSED);
|
2016-04-13 10:08:36 +00:00
|
|
|
clearFlags(WIDGET_HILITED);
|
2012-05-03 16:32:08 +00:00
|
|
|
draw();
|
|
|
|
}
|
|
|
|
|
2016-04-13 12:02:33 +00:00
|
|
|
void ButtonWidget::setUnpressedState() {
|
2012-05-03 16:32:08 +00:00
|
|
|
clearFlags(WIDGET_PRESSED);
|
|
|
|
draw();
|
|
|
|
}
|
|
|
|
|
2002-07-07 23:37:47 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2011-01-03 12:23:50 +00:00
|
|
|
PicButtonWidget::PicButtonWidget(GuiObject *boss, int x, int y, int w, int h, const char *tooltip, uint32 cmd, uint8 hotkey)
|
2011-10-24 17:34:51 +00:00
|
|
|
: ButtonWidget(boss, x, y, w, h, "", tooltip, cmd, hotkey),
|
2014-05-02 15:09:30 +00:00
|
|
|
_alpha(256), _transparency(false), _showButton(true) {
|
2011-01-03 12:23:50 +00:00
|
|
|
|
|
|
|
setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
|
|
|
|
_type = kButtonWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
PicButtonWidget::PicButtonWidget(GuiObject *boss, const Common::String &name, const char *tooltip, uint32 cmd, uint8 hotkey)
|
2011-10-24 17:34:51 +00:00
|
|
|
: ButtonWidget(boss, name, "", tooltip, cmd, hotkey),
|
2014-05-02 15:09:30 +00:00
|
|
|
_alpha(256), _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
|
|
|
}
|
|
|
|
|
2014-05-02 15:09:30 +00:00
|
|
|
void PicButtonWidget::setGfx(const Graphics::Surface *gfx, int statenum) {
|
|
|
|
_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-03 12:23:50 +00:00
|
|
|
if (gfx->w > _w || gfx->h > _h) {
|
|
|
|
warning("PicButtonWidget has size %dx%d, but a surface with %dx%d is to be set", _w, _h, gfx->w, gfx->h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-02 15:09:30 +00:00
|
|
|
_gfx[statenum].copyFrom(*gfx);
|
2011-01-03 12:23:50 +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) {
|
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].free();
|
|
|
|
_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)
|
|
|
|
g_gui.theme()->drawButtonClip(Common::Rect(_x, _y, _x + _w, _y + _h), getBossClipRect(), "", _state, getFlags());
|
2011-01-03 12:23:50 +00:00
|
|
|
|
2014-05-02 15:09:30 +00:00
|
|
|
Graphics::Surface *gfx;
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
if (!gfx)
|
|
|
|
gfx = &_gfx[kPicButtonStateEnabled];
|
|
|
|
|
|
|
|
if (gfx->getPixels()) {
|
2012-06-13 02:44:39 +00:00
|
|
|
// Check whether the set up surface needs to be converted to the GUI
|
|
|
|
// color format.
|
|
|
|
const Graphics::PixelFormat &requiredFormat = g_gui.theme()->getPixelFormat();
|
2014-05-02 15:09:30 +00:00
|
|
|
if (gfx->format != requiredFormat) {
|
|
|
|
gfx->convertToInPlace(requiredFormat);
|
2012-06-13 02:44:39 +00:00
|
|
|
}
|
|
|
|
|
2014-05-02 15:09:30 +00:00
|
|
|
const int x = _x + (_w - gfx->w) / 2;
|
|
|
|
const int y = _y + (_h - gfx->h) / 2;
|
2011-01-03 12:23:50 +00:00
|
|
|
|
2014-05-02 15:09:30 +00:00
|
|
|
g_gui.theme()->drawSurfaceClip(Common::Rect(x, y, x + gfx->w, y + gfx->h), getBossClipRect(), *gfx, _state, _alpha, _transparency);
|
2011-01-03 12:23:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2010-06-15 10:52:35 +00:00
|
|
|
CheckboxWidget::CheckboxWidget(GuiObject *boss, int x, int y, int w, int h, const Common::String &label, const char *tooltip, uint32 cmd, uint8 hotkey)
|
|
|
|
: ButtonWidget(boss, x, y, w, h, label, tooltip, cmd, hotkey), _state(false) {
|
2007-11-04 03:38:30 +00:00
|
|
|
setFlags(WIDGET_ENABLED);
|
2002-07-08 11:55:55 +00:00
|
|
|
_type = kCheckboxWidget;
|
2002-07-07 23:37:47 +00:00
|
|
|
}
|
|
|
|
|
2010-06-15 10:52:35 +00:00
|
|
|
CheckboxWidget::CheckboxWidget(GuiObject *boss, const Common::String &name, const Common::String &label, const char *tooltip, uint32 cmd, uint8 hotkey)
|
|
|
|
: ButtonWidget(boss, name, label, tooltip, cmd, hotkey), _state(false) {
|
2007-11-04 03:38:30 +00:00
|
|
|
setFlags(WIDGET_ENABLED);
|
2006-03-08 01:42:02 +00:00
|
|
|
_type = kCheckboxWidget;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
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;
|
2003-11-03 23:33:40 +00:00
|
|
|
draw();
|
|
|
|
}
|
2003-11-07 16:01:51 +00:00
|
|
|
sendCommand(_cmd, _state);
|
2003-11-03 23:33:40 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:38:30 +00:00
|
|
|
void CheckboxWidget::drawWidget() {
|
2016-07-01 08:25:05 +00:00
|
|
|
g_gui.theme()->drawCheckboxClip(Common::Rect(_x, _y, _x+_w, _y+_h), getBossClipRect(), _label, _state, Widget::_state);
|
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 -
|
|
|
|
|
2010-06-15 10:52:35 +00:00
|
|
|
RadiobuttonWidget::RadiobuttonWidget(GuiObject *boss, int x, int y, int w, int h, RadiobuttonGroup *group, int value, const Common::String &label, const char *tooltip, uint8 hotkey)
|
|
|
|
: 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);
|
|
|
|
}
|
|
|
|
|
2010-06-15 10:52:35 +00:00
|
|
|
RadiobuttonWidget::RadiobuttonWidget(GuiObject *boss, const Common::String &name, RadiobuttonGroup *group, int value, const Common::String &label, const char *tooltip, uint8 hotkey)
|
|
|
|
: 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
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;
|
|
|
|
draw();
|
|
|
|
}
|
|
|
|
sendCommand(_cmd, _state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RadiobuttonWidget::drawWidget() {
|
2016-07-01 08:25:05 +00:00
|
|
|
g_gui.theme()->drawRadiobuttonClip(Common::Rect(_x, _y, _x+_w, _y+_h), getBossClipRect(), _label, _state, Widget::_state);
|
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
|
|
|
|
2010-06-15 10:52:35 +00:00
|
|
|
SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, const char *tooltip, uint32 cmd)
|
|
|
|
: 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;
|
|
|
|
}
|
|
|
|
|
2010-06-15 10:52:35 +00:00
|
|
|
SliderWidget::SliderWidget(GuiObject *boss, const Common::String &name, const char *tooltip, uint32 cmd)
|
|
|
|
: 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) {
|
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;
|
2002-07-10 22:49:41 +00:00
|
|
|
draw();
|
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;
|
|
|
|
draw();
|
|
|
|
sendCommand(_cmd, _value); // FIXME - hack to allow for "live update" in sound dialog
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-04 03:38:30 +00:00
|
|
|
void SliderWidget::drawWidget() {
|
2016-07-01 08:25:05 +00:00
|
|
|
g_gui.theme()->drawSliderClip(Common::Rect(_x, _y, _x + _w, _y + _h), getBossClipRect(), valueToBarWidth(_value), _state);
|
2008-12-24 01:11:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SliderWidget::valueToBarWidth(int value) {
|
|
|
|
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) {
|
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 -
|
|
|
|
|
2010-06-15 10:52:35 +00:00
|
|
|
GraphicsWidget::GraphicsWidget(GuiObject *boss, int x, int y, int w, int h, const char *tooltip)
|
2012-08-28 00:25:14 +00:00
|
|
|
: Widget(boss, x, y, w, h, tooltip), _gfx(), _alpha(256), _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;
|
|
|
|
}
|
|
|
|
|
2010-06-15 10:52:35 +00:00
|
|
|
GraphicsWidget::GraphicsWidget(GuiObject *boss, const Common::String &name, const char *tooltip)
|
2012-08-28 00:25:14 +00:00
|
|
|
: Widget(boss, name, tooltip), _gfx(), _alpha(256), _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
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsWidget::setGfx(const Graphics::Surface *gfx) {
|
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;
|
|
|
|
}
|
|
|
|
|
2010-07-04 01:18:49 +00:00
|
|
|
if (gfx->w > _w || gfx->h > _h) {
|
|
|
|
warning("GraphicsWidget has size %dx%d, but a surface with %dx%d is to be set", _w, _h, gfx->w, gfx->h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-28 00:25:14 +00:00
|
|
|
_gfx.copyFrom(*gfx);
|
2005-05-08 22:38:29 +00:00
|
|
|
}
|
|
|
|
|
2014-05-02 23:50:47 +00:00
|
|
|
void GraphicsWidget::setAGfx(const Graphics::TransparentSurface *gfx) {
|
|
|
|
_agfx.free();
|
|
|
|
|
|
|
|
if (!gfx || !gfx->getPixels())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (gfx->format.bytesPerPixel == 1) {
|
|
|
|
warning("GraphicsWidget::setGfx got paletted surface passed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gfx->w > _w || gfx->h > _h) {
|
|
|
|
warning("GraphicsWidget has size %dx%d, but a surface with %dx%d is to be set", _w, _h, gfx->w, gfx->h);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_agfx.copyFrom(*gfx);
|
|
|
|
}
|
|
|
|
|
2006-05-29 14:38:56 +00:00
|
|
|
void GraphicsWidget::setGfx(int w, int h, int r, int g, int b) {
|
|
|
|
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.free();
|
|
|
|
_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
|
|
|
}
|
|
|
|
|
2007-11-04 03:38:30 +00:00
|
|
|
void GraphicsWidget::drawWidget() {
|
2013-08-03 00:36:28 +00:00
|
|
|
if (_gfx.getPixels()) {
|
2012-06-13 02:44:39 +00:00
|
|
|
// Check whether the set up surface needs to be converted to the GUI
|
|
|
|
// color format.
|
|
|
|
const Graphics::PixelFormat &requiredFormat = g_gui.theme()->getPixelFormat();
|
2012-08-28 00:25:14 +00:00
|
|
|
if (_gfx.format != requiredFormat) {
|
|
|
|
_gfx.convertToInPlace(requiredFormat);
|
2012-06-13 02:44:39 +00:00
|
|
|
}
|
|
|
|
|
2012-08-28 00:25:14 +00:00
|
|
|
const int x = _x + (_w - _gfx.w) / 2;
|
|
|
|
const int y = _y + (_h - _gfx.h) / 2;
|
2010-07-04 01:11:18 +00:00
|
|
|
|
2016-07-01 07:04:25 +00:00
|
|
|
g_gui.theme()->drawSurfaceClip(Common::Rect(x, y, x + _gfx.w, y + _gfx.h), getBossClipRect(), _gfx, _state, _alpha, _transparency);
|
2014-05-02 23:50:47 +00:00
|
|
|
} else if (_agfx.getPixels()) {
|
|
|
|
// Check whether the set up surface needs to be converted to the GUI
|
|
|
|
// color format.
|
|
|
|
const Graphics::PixelFormat &requiredFormat = g_gui.theme()->getPixelFormat();
|
|
|
|
if (_agfx.format != requiredFormat) {
|
|
|
|
_agfx.convertToInPlace(requiredFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
const int x = _x + (_w - _agfx.w) / 2;
|
|
|
|
const int y = _y + (_h - _agfx.h) / 2;
|
|
|
|
|
|
|
|
g_gui.theme()->drawASurface(Common::Rect(x, y, x + _agfx.w, y + _agfx.h), _agfx, _state, _alpha, _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 -
|
|
|
|
|
|
|
|
ContainerWidget::ContainerWidget(GuiObject *boss, int x, int y, int w, int h) : Widget(boss, x, y, w, h) {
|
2007-11-04 03:38:30 +00:00
|
|
|
setFlags(WIDGET_ENABLED | WIDGET_CLEARBG);
|
2006-05-27 05:46:04 +00:00
|
|
|
_type = kContainerWidget;
|
|
|
|
}
|
|
|
|
|
2007-02-03 21:32:18 +00:00
|
|
|
ContainerWidget::ContainerWidget(GuiObject *boss, const Common::String &name) : Widget(boss, name) {
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget *ContainerWidget::findWidget(int x, int y) {
|
|
|
|
return findWidgetInChain(_firstWidget, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-11-04 03:38:30 +00:00
|
|
|
void ContainerWidget::drawWidget() {
|
2016-07-01 08:25:05 +00:00
|
|
|
g_gui.theme()->drawWidgetBackgroundClip(Common::Rect(_x, _y, _x + _w, _y + _h), getBossClipRect(), 0, ThemeEngine::kWidgetBackgroundBorder);
|
2006-05-27 05:46:04 +00:00
|
|
|
}
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
} // End of namespace GUI
|