2002-07-05 16:56:53 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2005-01-01 16:09:25 +00:00
|
|
|
* Copyright (C) 2002-2005 The ScummVM project
|
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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*/
|
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.h"
|
2003-11-02 18:57:20 +00:00
|
|
|
#include "common/util.h"
|
2005-05-11 19:30:30 +00:00
|
|
|
#include "graphics/fontman.h"
|
2003-11-02 18:57:20 +00:00
|
|
|
#include "gui/widget.h"
|
|
|
|
#include "gui/dialog.h"
|
|
|
|
#include "gui/newgui.h"
|
2002-07-05 16:56:53 +00:00
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
2003-11-02 14:50:53 +00:00
|
|
|
Widget::Widget(GuiObject *boss, int x, int y, int w, int h)
|
|
|
|
: GuiObject(x, y, w, h), _type(0), _boss(boss),
|
2003-03-06 19:52:54 +00:00
|
|
|
_id(0), _flags(0), _hasFocus(false) {
|
2002-07-05 16:56:53 +00:00
|
|
|
// Insert into the widget list of the boss
|
|
|
|
_next = _boss->_firstWidget;
|
|
|
|
_boss->_firstWidget = this;
|
|
|
|
}
|
|
|
|
|
2003-11-07 14:50:32 +00:00
|
|
|
Widget::~Widget() {
|
|
|
|
delete _next;
|
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void Widget::draw() {
|
2003-11-02 02:18:16 +00:00
|
|
|
NewGui *gui = &g_gui;
|
2003-03-06 19:52:54 +00:00
|
|
|
|
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-10 16:49:45 +00:00
|
|
|
// Clear background (unless alpha blending is enabled)
|
2002-07-12 16:24:11 +00:00
|
|
|
if (_flags & WIDGET_CLEARBG)
|
2002-07-10 22:49:41 +00:00
|
|
|
gui->fillRect(_x, _y, _w, _h, gui->_bgcolor);
|
2002-07-07 13:14:34 +00:00
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
// Draw border
|
|
|
|
if (_flags & WIDGET_BORDER) {
|
2004-02-28 12:58:13 +00:00
|
|
|
OverlayColor colorA = gui->_color;
|
|
|
|
OverlayColor colorB = gui->_shadowcolor;
|
2003-11-02 18:57:20 +00:00
|
|
|
if ((_flags & WIDGET_INV_BORDER) == WIDGET_INV_BORDER)
|
|
|
|
SWAP(colorA, colorB);
|
|
|
|
gui->box(_x, _y, _w, _h, colorA, colorB);
|
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
|
2002-09-21 Matt Hargett <matt@use.net>
* scumm.dsp, scummvm.dsp, simon.dsp: Turn on warning as errors. Generate
PDBs on all builds.
* gameDetector.cpp, newgui.cpp, widget.cpp, actor.cpp,
dialogs.cpp, resource.cpp, saveload.cpp, scumm_renderer.cpp:
Fix warnings where possible. One pragma added to eliminate
warning of unknown pragmas.
* string.cpp: If unknown escape sequence, print warning.
svn-id: r4998
2002-09-22 03:53:53 +00:00
|
|
|
drawWidget((_flags & WIDGET_HILITED) ? true : false);
|
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
|
|
|
|
2002-09-19 16:06:51 +00:00
|
|
|
// Flag the draw area as dirty
|
|
|
|
gui->addDirtyRect(_x, _y, _w, _h);
|
|
|
|
|
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)
|
|
|
|
if (x >= w->_x && x < w->_x + w->_w && y >= w->_y && y < w->_y + w->_h)
|
|
|
|
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
|
|
|
|
2002-07-05 16:56:53 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2005-05-11 19:30:30 +00:00
|
|
|
StaticTextWidget::StaticTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text, TextAlignment align, WidgetSize ws)
|
|
|
|
: Widget(boss, x, y, w, h), _align(align), _ws(ws) {
|
2003-11-07 15:05:14 +00:00
|
|
|
_flags = WIDGET_ENABLED;
|
2002-07-08 11:55:55 +00:00
|
|
|
_type = kStaticTextWidget;
|
2005-04-16 17:53:18 +00:00
|
|
|
_label = text;
|
2002-07-10 22:49:41 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void StaticTextWidget::setValue(int value) {
|
2002-08-31 13:42:07 +00:00
|
|
|
char buf[256];
|
|
|
|
sprintf(buf, "%d", value);
|
|
|
|
_label = buf;
|
2002-07-27 00:05:46 +00:00
|
|
|
}
|
|
|
|
|
2005-04-16 17:53:18 +00:00
|
|
|
void StaticTextWidget::setLabel(const String &label) {
|
|
|
|
_label = label;
|
|
|
|
// TODO: We should automatically redraw when the label is changed.
|
|
|
|
// The following doesn't quite work when we are using tabs, plus it
|
|
|
|
// is rather clumsy to force a full redraw for a single static text.
|
|
|
|
// However, as long as we do blending, it might be the only way.
|
|
|
|
//_boss->draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void StaticTextWidget::setAlign(TextAlignment align) {
|
|
|
|
_align = align;
|
|
|
|
// TODO: We should automatically redraw when the alignment is changed.
|
|
|
|
// See setLabel() for more insights.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void StaticTextWidget::drawWidget(bool hilite) {
|
2003-11-02 02:18:16 +00:00
|
|
|
NewGui *gui = &g_gui;
|
2005-06-03 11:15:03 +00:00
|
|
|
gui->drawString(_label, _x, _y, _w, isEnabled() ? gui->_textcolor : gui->_color, _align);
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2005-05-11 19:30:30 +00:00
|
|
|
ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey, WidgetSize ws)
|
|
|
|
: StaticTextWidget(boss, x, y, w, h, label, kTextAlignCenter, ws), CommandSender(boss),
|
2003-03-06 19:52:54 +00:00
|
|
|
_cmd(cmd), _hotkey(hotkey) {
|
2002-10-19 01:22:41 +00:00
|
|
|
_flags = WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG;
|
2002-07-08 11:55:55 +00:00
|
|
|
_type = kButtonWidget;
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount) {
|
2002-10-01 23:11:19 +00:00
|
|
|
if (isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h)
|
2002-07-12 16:24:11 +00:00
|
|
|
sendCommand(_cmd, 0);
|
|
|
|
}
|
2002-07-07 23:37:47 +00:00
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void ButtonWidget::drawWidget(bool hilite) {
|
2003-11-02 02:18:16 +00:00
|
|
|
NewGui *gui = &g_gui;
|
2005-06-03 11:15:03 +00:00
|
|
|
const int off = (_h - g_gui.getFontHeight()) / 2;
|
|
|
|
gui->drawString(_label, _x, _y + off, _w,
|
2003-11-08 23:22:16 +00:00
|
|
|
!isEnabled() ? gui->_color :
|
|
|
|
hilite ? gui->_textcolorhi : gui->_textcolor, _align);
|
2002-10-19 01:22:41 +00:00
|
|
|
}
|
|
|
|
|
2002-07-07 23:37:47 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2005-05-11 19:30:30 +00:00
|
|
|
CheckboxWidget::CheckboxWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey, WidgetSize ws)
|
2005-05-18 10:30:52 +00:00
|
|
|
: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey, ws), _state(false) {
|
2002-07-07 23:37:47 +00:00
|
|
|
_flags = WIDGET_ENABLED;
|
2002-07-08 11:55:55 +00:00
|
|
|
_type = kCheckboxWidget;
|
2002-07-07 23:37:47 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void CheckboxWidget::handleMouseUp(int x, int y, int button, int clickCount) {
|
2002-10-19 01:22:41 +00:00
|
|
|
if (isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h) {
|
|
|
|
toggleState();
|
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;
|
|
|
|
_flags ^= WIDGET_INV_BORDER;
|
|
|
|
draw();
|
|
|
|
}
|
2003-11-07 16:01:51 +00:00
|
|
|
sendCommand(_cmd, _state);
|
2003-11-03 23:33:40 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void CheckboxWidget::drawWidget(bool hilite) {
|
2003-11-02 02:18:16 +00:00
|
|
|
NewGui *gui = &g_gui;
|
2005-06-03 11:15:03 +00:00
|
|
|
int fontHeight = gui->getFontHeight();
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-07-07 23:37:47 +00:00
|
|
|
// Draw the box
|
2005-05-18 07:23:21 +00:00
|
|
|
gui->box(_x, _y, fontHeight + 4, fontHeight + 4, gui->_color, gui->_shadowcolor);
|
|
|
|
gui->fillRect(_x + 2, _y + 2, fontHeight, fontHeight, gui->_bgcolor);
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-07-07 23:37:47 +00:00
|
|
|
// If checked, draw cross inside the box
|
2005-05-18 07:23:21 +00:00
|
|
|
if (_state) {
|
|
|
|
Graphics::Surface &surf = gui->getScreen();
|
|
|
|
Common::Point p0, p1, p2, p3;
|
|
|
|
OverlayColor color = isEnabled() ? gui->_textcolor : gui->_color;
|
|
|
|
|
|
|
|
p0 = Common::Point(_x + 4, _y + 4);
|
|
|
|
p1 = Common::Point(_x + fontHeight - 1, _y + 4);
|
|
|
|
p2 = Common::Point(_x + 4, _y + fontHeight - 1);
|
|
|
|
p3 = Common::Point(_x + fontHeight - 1, _y + fontHeight - 1);
|
|
|
|
|
|
|
|
if (_ws == kBigWidgetSize) {
|
|
|
|
surf.drawLine(p0.x + 1, p0.y, p3.x, p3.y - 1, color);
|
|
|
|
surf.drawLine(p0.x, p0.y + 1, p3.x - 1, p3.y, color);
|
|
|
|
surf.drawLine(p0.x + 1, p0.y + 1, p3.x - 1, p3.y - 1, color);
|
|
|
|
surf.drawLine(p2.x + 1, p2.y - 1, p1.x - 1, p1.y + 1, color);
|
|
|
|
surf.drawLine(p2.x + 1, p2.y, p1.x, p1.y + 1, color);
|
|
|
|
surf.drawLine(p2.x, p2.y - 1, p1.x - 1, p1.y, color);
|
|
|
|
} else {
|
|
|
|
surf.drawLine(p0.x, p0.y, p3.x, p3.y, color);
|
|
|
|
surf.drawLine(p2.x, p2.y, p1.x, p1.y, color);
|
|
|
|
}
|
|
|
|
}
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-07-07 23:37:47 +00:00
|
|
|
// Finally draw the label
|
2005-06-03 11:15:03 +00:00
|
|
|
gui->drawString(_label, _x + fontHeight + 10, _y + 3, _w, isEnabled() ? gui->_textcolor : gui->_color);
|
2002-07-07 23:37:47 +00:00
|
|
|
}
|
2002-07-08 13:52:50 +00:00
|
|
|
|
|
|
|
#pragma mark -
|
2002-07-08 22:11:47 +00:00
|
|
|
|
2005-05-18 10:24:02 +00:00
|
|
|
SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, uint32 cmd)
|
|
|
|
: Widget(boss, x, y, w, h), CommandSender(boss),
|
2005-05-18 15:58:39 +00:00
|
|
|
_cmd(cmd), _value(0), _oldValue(0), _valueMin(0), _valueMax(100), _isDragging(false) {
|
2002-07-10 16:49:45 +00:00
|
|
|
_flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG;
|
2002-07-08 13:52:50 +00:00
|
|
|
_type = kSliderWidget;
|
|
|
|
}
|
|
|
|
|
2002-12-12 23:21:29 +00:00
|
|
|
void SliderWidget::handleMouseMoved(int x, int y, int button) {
|
2005-05-18 10:24:02 +00:00
|
|
|
if (isEnabled() && _isDragging && x >= 0) {
|
|
|
|
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
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void SliderWidget::drawWidget(bool hilite) {
|
2003-11-02 02:18:16 +00:00
|
|
|
NewGui *gui = &g_gui;
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-07-26 23:29:43 +00:00
|
|
|
// Draw the box
|
2005-05-18 10:24:02 +00:00
|
|
|
gui->box(_x, _y, _w, _h, gui->_color, gui->_shadowcolor);
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-07-26 23:29:43 +00:00
|
|
|
// Draw the 'bar'
|
2005-05-18 10:24:02 +00:00
|
|
|
gui->fillRect(_x + 2, _y + 2, valueToPos(_value), _h - 4,
|
2003-11-08 23:22:16 +00:00
|
|
|
!isEnabled() ? gui->_color :
|
|
|
|
hilite ? gui->_textcolorhi : gui->_textcolor);
|
2002-07-26 23:29:43 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
int SliderWidget::valueToPos(int value) {
|
2005-05-18 10:24:02 +00:00
|
|
|
return ((_w - 4) * (value - _valueMin) / (_valueMax - _valueMin));
|
2002-07-26 23:29:43 +00:00
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
int SliderWidget::posToValue(int pos) {
|
2005-05-18 10:24:02 +00:00
|
|
|
return (pos) * (_valueMax - _valueMin) / (_w - 4) + _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 -
|
|
|
|
|
|
|
|
GraphicsWidget::GraphicsWidget(GuiObject *boss, int x, int y, int w, int h)
|
|
|
|
: Widget(boss, x, y, w, h), _gfx() {
|
2005-07-30 21:11:48 +00:00
|
|
|
_flags = WIDGET_ENABLED | WIDGET_CLEARBG;
|
2005-05-08 22:38:29 +00:00
|
|
|
_type = kGraphicsWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsWidget::~GraphicsWidget() {
|
|
|
|
_gfx.free();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsWidget::setGfx(const Graphics::Surface *gfx) {
|
|
|
|
_gfx.free();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-08 23:39:37 +00:00
|
|
|
if (!gfx || !gfx->pixels)
|
2005-05-08 22:38:29 +00:00
|
|
|
return;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-08 22:38:29 +00:00
|
|
|
// TODO: add conversion to OverlayColor
|
|
|
|
_gfx.create(gfx->w, gfx->h, gfx->bytesPerPixel);
|
|
|
|
memcpy(_gfx.pixels, gfx->pixels, gfx->h * gfx->pitch);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsWidget::drawWidget(bool hilite) {
|
|
|
|
if (sizeof(OverlayColor) != _gfx.bytesPerPixel || !_gfx.pixels) {
|
|
|
|
// FIXME: It doesn't really make sense to render this text here, since
|
|
|
|
// this widget might be used for other things than rendering savegame
|
|
|
|
// graphics/previews...
|
|
|
|
g_gui.drawString("No preview", _x, _y + _h / 2 - g_gui.getFontHeight() / 2, _w, g_gui._textcolor, Graphics::kTextAlignCenter);
|
2005-05-08 23:39:37 +00:00
|
|
|
} else
|
|
|
|
g_gui.drawSurface(_gfx, _x, _y);
|
2005-05-08 22:38:29 +00:00
|
|
|
}
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
} // End of namespace GUI
|