2002-07-05 16:56:53 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2003-03-06 21:46:56 +00:00
|
|
|
* Copyright (C) 2002-2003 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$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2003-11-02 18:57:20 +00:00
|
|
|
#include "common/util.h"
|
|
|
|
#include "gui/widget.h"
|
|
|
|
#include "gui/dialog.h"
|
|
|
|
#include "gui/newgui.h"
|
2002-07-05 16:56:53 +00:00
|
|
|
|
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-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) {
|
2003-11-02 18:57:20 +00:00
|
|
|
NewGuiColor colorA = gui->_color;
|
|
|
|
NewGuiColor colorB = gui->_shadowcolor;
|
|
|
|
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 -
|
|
|
|
|
2003-11-02 14:50:53 +00:00
|
|
|
StaticTextWidget::StaticTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text, int align)
|
2003-11-02 02:18:16 +00:00
|
|
|
: Widget(boss, x, y, w, h), _align(align) {
|
2002-07-08 11:55:55 +00:00
|
|
|
_type = kStaticTextWidget;
|
2002-07-12 16:24:11 +00:00
|
|
|
setLabel(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
|
|
|
}
|
|
|
|
|
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;
|
2003-11-07 14:58:12 +00:00
|
|
|
gui->drawString(_label, _x, _y, _w, isEnabled() ? gui->_textcolor : gui->_color, _align);
|
2002-07-05 16:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2003-11-02 14:50:53 +00:00
|
|
|
ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey)
|
2002-10-19 01:22:41 +00:00
|
|
|
: StaticTextWidget(boss, x, y, w, h, label, kTextAlignCenter), 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;
|
2002-11-21 15:20:52 +00:00
|
|
|
gui->drawString(_label, _x, _y, _w,
|
2003-11-03 23:33:40 +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 -
|
|
|
|
|
|
|
|
/* 8x8 checkbox bitmap */
|
|
|
|
static uint32 checked_img[8] = {
|
|
|
|
0x00000000,
|
|
|
|
0x01000010,
|
|
|
|
0x00100100,
|
|
|
|
0x00011000,
|
|
|
|
0x00011000,
|
|
|
|
0x00100100,
|
|
|
|
0x01000010,
|
|
|
|
0x00000000,
|
|
|
|
};
|
|
|
|
|
2003-11-02 14:50:53 +00:00
|
|
|
CheckboxWidget::CheckboxWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey)
|
2003-11-03 23:33:40 +00:00
|
|
|
: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey), _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-12 16:24:11 +00:00
|
|
|
sendCommand(_cmd, 0);
|
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-03-06 19:52:54 +00:00
|
|
|
void CheckboxWidget::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-07 23:37:47 +00:00
|
|
|
// Draw the box
|
2003-11-02 18:57:20 +00:00
|
|
|
gui->box(_x, _y, 14, 14, gui->_color, gui->_shadowcolor);
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-07-07 23:37:47 +00:00
|
|
|
// If checked, draw cross inside the box
|
|
|
|
if (_state)
|
2003-11-03 00:43:29 +00:00
|
|
|
gui->drawBitmap(checked_img, _x + 3, _y + 3, isEnabled() ? gui->_textcolor : gui->_color);
|
2002-07-07 23:37:47 +00:00
|
|
|
else
|
2002-07-10 22:49:41 +00:00
|
|
|
gui->fillRect(_x + 2, _y + 2, 10, 10, gui->_bgcolor);
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-07-07 23:37:47 +00:00
|
|
|
// Finally draw the label
|
2003-11-03 00:43:29 +00:00
|
|
|
gui->drawString(_label, _x + 20, _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
|
|
|
|
2003-11-03 01:00:26 +00:00
|
|
|
SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint labelWidth, uint32 cmd, uint8 hotkey)
|
2003-11-03 00:43:29 +00:00
|
|
|
: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey),
|
|
|
|
_value(0), _oldValue(0),_valueMin(0), _valueMax(100), _isDragging(false),
|
|
|
|
_labelWidth(labelWidth) {
|
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) {
|
|
|
|
// TODO: when the mouse is dragged outside the widget, the slider should
|
|
|
|
// snap back to the old value.
|
2003-11-03 01:00:26 +00:00
|
|
|
if (isEnabled() && _isDragging && x >= (int)_labelWidth) {
|
2003-11-03 00:43:29 +00:00
|
|
|
int newValue = posToValue(x - _labelWidth);
|
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) {
|
|
|
|
_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
|
|
|
|
2003-11-03 00:43:29 +00:00
|
|
|
// Draw the label, if any
|
|
|
|
if (_labelWidth > 0)
|
|
|
|
gui->drawString(_label, _x, _y + 2, _labelWidth, isEnabled() ? gui->_textcolor : gui->_color, kTextAlignRight);
|
|
|
|
|
2002-07-26 23:29:43 +00:00
|
|
|
// Draw the box
|
2003-11-03 00:43:29 +00:00
|
|
|
gui->box(_x + _labelWidth, _y, _w - _labelWidth, _h, gui->_color, gui->_shadowcolor);
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-07-26 23:29:43 +00:00
|
|
|
// Draw the 'bar'
|
2003-11-03 00:43:29 +00:00
|
|
|
gui->fillRect(_x + _labelWidth + 2, _y + 2, valueToPos(_value), _h - 4, 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) {
|
2003-11-03 00:43:29 +00:00
|
|
|
return ((_w - _labelWidth - 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) {
|
2003-11-03 00:43:29 +00:00
|
|
|
return (pos) * (_valueMax - _valueMin) / (_w - _labelWidth - 4) + _valueMin;
|
2002-07-26 23:29:43 +00:00
|
|
|
}
|