aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
Diffstat (limited to 'gui')
-rw-r--r--gui/EditTextWidget.cpp6
-rw-r--r--gui/EditTextWidget.h2
-rw-r--r--gui/ListWidget.cpp2
-rw-r--r--gui/ListWidget.h4
-rw-r--r--gui/PopUpWidget.cpp2
-rw-r--r--gui/PopUpWidget.h2
-rw-r--r--gui/ScrollBarWidget.cpp2
-rw-r--r--gui/ScrollBarWidget.h2
-rw-r--r--gui/about.cpp6
-rw-r--r--gui/dialog.cpp4
-rw-r--r--gui/dialog.h16
-rw-r--r--gui/message.cpp7
-rw-r--r--gui/object.h75
-rw-r--r--gui/options.h2
-rw-r--r--gui/widget.cpp16
-rw-r--r--gui/widget.h51
16 files changed, 124 insertions, 75 deletions
diff --git a/gui/EditTextWidget.cpp b/gui/EditTextWidget.cpp
index 9a72badb5b..ade3e0ec8d 100644
--- a/gui/EditTextWidget.cpp
+++ b/gui/EditTextWidget.cpp
@@ -23,7 +23,7 @@
#include "dialog.h"
#include "newgui.h"
-EditTextWidget::EditTextWidget(Dialog *boss, int x, int y, int w, int h, const String &text)
+EditTextWidget::EditTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text)
: StaticTextWidget(boss, x, y-1, w, h+2, text, kTextAlignLeft), _backupString(text) {
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE;
_type = kEditTextWidget;
@@ -83,7 +83,7 @@ bool EditTextWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
switch (keycode) {
case '\n': // enter/return
case '\r':
- _boss->releaseFocus();
+ releaseFocus();
dirty = true;
break;
case 27: // escape
@@ -92,7 +92,7 @@ bool EditTextWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
_labelOffset = (g_gui.getStringWidth(_label) - (_w-6));
if (_labelOffset < 0)
_labelOffset = 0;
- _boss->releaseFocus();
+ releaseFocus();
dirty = true;
break;
case 8: // backspace
diff --git a/gui/EditTextWidget.h b/gui/EditTextWidget.h
index a6fe8dbdce..e86b3f1c95 100644
--- a/gui/EditTextWidget.h
+++ b/gui/EditTextWidget.h
@@ -36,7 +36,7 @@ protected:
int _pos;
int _labelOffset;
public:
- EditTextWidget(Dialog *boss, int x, int y, int w, int h, const String &text);
+ EditTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text);
virtual void handleTickle();
virtual void handleMouseDown(int x, int y, int button, int clickCount);
diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp
index a205528cd4..2216b06a43 100644
--- a/gui/ListWidget.cpp
+++ b/gui/ListWidget.cpp
@@ -25,7 +25,7 @@
#include "newgui.h"
-ListWidget::ListWidget(Dialog *boss, int x, int y, int w, int h)
+ListWidget::ListWidget(GuiObject *boss, int x, int y, int w, int h)
: Widget(boss, x, y, w - kScrollBarWidth, h), CommandSender(boss) {
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE;
_type = kListWidget;
diff --git a/gui/ListWidget.h b/gui/ListWidget.h
index f61ff55259..cbff05faaa 100644
--- a/gui/ListWidget.h
+++ b/gui/ListWidget.h
@@ -41,7 +41,7 @@ enum {
};
/* ListWidget */
-class ListWidget : public Widget, public CommandReceiver, public CommandSender {
+class ListWidget : public Widget, public CommandSender {
typedef Common::StringList StringList;
typedef Common::String String;
protected:
@@ -58,7 +58,7 @@ protected:
bool _caretVisible;
uint32 _caretTime;
public:
- ListWidget(Dialog *boss, int x, int y, int w, int h);
+ ListWidget(GuiObject *boss, int x, int y, int w, int h);
virtual ~ListWidget();
void setList(const StringList& list);
diff --git a/gui/PopUpWidget.cpp b/gui/PopUpWidget.cpp
index 62735a17b5..c53598c772 100644
--- a/gui/PopUpWidget.cpp
+++ b/gui/PopUpWidget.cpp
@@ -271,7 +271,7 @@ void PopUpDialog::drawMenuEntry(int entry, bool hilite) {
// PopUpWidget
//
-PopUpWidget::PopUpWidget(Dialog *boss, int x, int y, int w, int h)
+PopUpWidget::PopUpWidget(GuiObject *boss, int x, int y, int w, int h)
: Widget(boss, x, y - 1, w, h + 2), CommandSender(boss) {
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS;
_type = 'POPU';
diff --git a/gui/PopUpWidget.h b/gui/PopUpWidget.h
index 0027fe0ea6..f5d7ad6da9 100644
--- a/gui/PopUpWidget.h
+++ b/gui/PopUpWidget.h
@@ -52,7 +52,7 @@ protected:
int _selectedItem;
public:
- PopUpWidget(Dialog *boss, int x, int y, int w, int h);
+ PopUpWidget(GuiObject *boss, int x, int y, int w, int h);
void handleMouseDown(int x, int y, int button, int clickCount);
/*
diff --git a/gui/ScrollBarWidget.cpp b/gui/ScrollBarWidget.cpp
index a77752b570..0b1945272c 100644
--- a/gui/ScrollBarWidget.cpp
+++ b/gui/ScrollBarWidget.cpp
@@ -60,7 +60,7 @@ static uint32 down_arrow[8] = {
0x00001000,
};
-ScrollBarWidget::ScrollBarWidget(Dialog *boss, int x, int y, int w, int h)
+ScrollBarWidget::ScrollBarWidget(GuiObject *boss, int x, int y, int w, int h)
: Widget (boss, x, y, w, h), CommandSender(boss) {
_flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG | WIDGET_WANT_TICKLE;
_type = kScrollBarWidget;
diff --git a/gui/ScrollBarWidget.h b/gui/ScrollBarWidget.h
index 8d8eeca036..5787da4229 100644
--- a/gui/ScrollBarWidget.h
+++ b/gui/ScrollBarWidget.h
@@ -57,7 +57,7 @@ public:
int _currentPos;
public:
- ScrollBarWidget(Dialog *boss, int x, int y, int w, int h);
+ ScrollBarWidget(GuiObject *boss, int x, int y, int w, int h);
void handleMouseDown(int x, int y, int button, int clickCount);
void handleMouseUp(int x, int y, int button, int clickCount);
diff --git a/gui/about.cpp b/gui/about.cpp
index 5ef2188c4c..15ca1f0ebc 100644
--- a/gui/about.cpp
+++ b/gui/about.cpp
@@ -19,10 +19,10 @@
*/
#include "stdafx.h"
-#include "about.h"
-#include "newgui.h"
#include "base/engine.h"
-#include "common/str.h"
+#include "gui/about.h"
+#include "gui/newgui.h"
+#include "gui/widget.h"
AboutDialog::AboutDialog()
: Dialog(10, 20, 300, 124) {
diff --git a/gui/dialog.cpp b/gui/dialog.cpp
index a0c3d41405..856e9a9960 100644
--- a/gui/dialog.cpp
+++ b/gui/dialog.cpp
@@ -27,10 +27,6 @@
/*
* TODO list
- * - If saving or loading fails (e.g. due to disk full/directory write protected),
- * display an error dialog?
- * - The user can edit the name of the autosave game. Of course this will not
- * do anything, but we should still prevent this.
* - add some sense of the window being "active" (i.e. in front) or not. If it
* was inactive and just became active, reset certain vars (like who is focused).
* Maybe we should just add lostFocus and receivedFocus methods to Dialog, just
diff --git a/gui/dialog.h b/gui/dialog.h
index f5a35b691a..81e519d3b3 100644
--- a/gui/dialog.h
+++ b/gui/dialog.h
@@ -22,7 +22,9 @@
#define DIALOG_H
#include "common/scummsys.h"
-#include "widget.h" // For CommandReceiver
+#include "common/str.h"
+
+#include "gui/object.h"
class NewGui;
class ButtonWidget;
@@ -33,13 +35,9 @@ enum {
kCloseCmd = 'clos'
};
-class Dialog : public CommandReceiver {
- friend class Widget;
+class Dialog : public GuiObject {
friend class NewGui;
protected:
- int16 _x, _y;
- uint16 _w, _h;
- Widget *_firstWidget;
Widget *_mouseWidget;
Widget *_focusedWidget;
bool _visible;
@@ -49,7 +47,7 @@ private:
public:
Dialog(int x, int y, int w, int h)
- : _x(x), _y(y), _w(w), _h(h), _firstWidget(0),
+ : GuiObject(x, y, w, h),
_mouseWidget(0), _focusedWidget(0), _visible(false) {
}
virtual ~Dialog();
@@ -57,10 +55,8 @@ public:
virtual int runModal();
bool isVisible() const { return _visible; }
- int16 getX() const { return _x; }
- int16 getY() const { return _y; }
- void releaseFocus();
+ void releaseFocus();
protected:
virtual void open();
diff --git a/gui/message.cpp b/gui/message.cpp
index f82f0086c9..4d60e876c0 100644
--- a/gui/message.cpp
+++ b/gui/message.cpp
@@ -19,16 +19,19 @@
*/
#include "stdafx.h"
-#include "gui/message.h"
-#include "gui/newgui.h"
#include "common/str.h"
#include "common/list.h"
+#include "gui/message.h"
+#include "gui/newgui.h"
+#include "gui/widget.h"
enum {
kOkCmd = 'OK ',
kCancelCmd = 'CNCL'
};
+// TODO: The default button should be visibly distinct from the alternate button
+
MessageDialog::MessageDialog(const String &message, const char *defaultButton, const char *altButton)
: Dialog(30, 20, 260, 124) {
// First, determine the size the dialog needs. For this we have to break
diff --git a/gui/object.h b/gui/object.h
new file mode 100644
index 0000000000..72401af0cf
--- /dev/null
+++ b/gui/object.h
@@ -0,0 +1,75 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2002-2003 The ScummVM project
+ *
+ * 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$
+ */
+
+#ifndef GUI_OBJECT_H
+#define GUI_OBJECT_H
+
+class CommandReceiver;
+class CommandSender;
+
+class CommandReceiver {
+ friend class CommandSender;
+protected:
+ virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {}
+};
+
+class CommandSender {
+ // TODO - allow for multiple targets, i.e. store targets in a list
+ // and add methods addTarget/removeTarget.
+protected:
+ CommandReceiver *_target;
+public:
+ CommandSender(CommandReceiver *target) : _target(target) {}
+
+ void setTarget(CommandReceiver *target) { _target = target; }
+ CommandReceiver *getTarget() const { return _target; }
+
+ virtual void sendCommand(uint32 cmd, uint32 data) {
+ if (_target && cmd)
+ _target->handleCommand(this, cmd, data);
+ }
+};
+
+class Widget;
+
+class GuiObject : public CommandReceiver {
+ friend class Widget;
+protected:
+ int16 _x, _y;
+ uint16 _w, _h;
+
+ Widget *_firstWidget;
+
+public:
+ GuiObject(int x, int y, int w, int h) : _x(x), _y(y), _w(w), _h(h), _firstWidget(0) { }
+
+ virtual bool isVisible() const = 0;
+
+ int16 getX() const { return _x; }
+ int16 getY() const { return _y; }
+ uint16 getW() const { return _w; }
+ uint16 getH() const { return _h; }
+
+protected:
+ virtual void releaseFocus() = 0;
+};
+
+
+#endif
diff --git a/gui/options.h b/gui/options.h
index e589563ab6..68c04e38a7 100644
--- a/gui/options.h
+++ b/gui/options.h
@@ -28,6 +28,8 @@
class BrowserDialog;
class GameDetector;
class PopUpWidget;
+class SliderWidget;
+class StaticTextWidget;
class GlobalOptionsDialog : public Dialog {
typedef Common::String String;
diff --git a/gui/widget.cpp b/gui/widget.cpp
index f20dbf4624..b0ab5889b0 100644
--- a/gui/widget.cpp
+++ b/gui/widget.cpp
@@ -23,8 +23,9 @@
#include "dialog.h"
#include "newgui.h"
-Widget::Widget(Dialog *boss, int x, int y, int w, int h)
- : _type(0), _boss(boss), _x(x), _y(y), _w(w), _h(h),
+
+Widget::Widget(GuiObject *boss, int x, int y, int w, int h)
+ : GuiObject(x, y, w, h), _type(0), _boss(boss),
_id(0), _flags(0), _hasFocus(false) {
// Insert into the widget list of the boss
_next = _boss->_firstWidget;
@@ -72,9 +73,10 @@ void Widget::draw() {
_y -= _boss->_y;
}
+
#pragma mark -
-StaticTextWidget::StaticTextWidget(Dialog *boss, int x, int y, int w, int h, const String &text, int align)
+StaticTextWidget::StaticTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text, int align)
: Widget(boss, x, y, w, h), _align(align) {
_type = kStaticTextWidget;
setLabel(text);
@@ -93,7 +95,7 @@ void StaticTextWidget::drawWidget(bool hilite) {
#pragma mark -
-ButtonWidget::ButtonWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey)
+ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey)
: StaticTextWidget(boss, x, y, w, h, label, kTextAlignCenter), CommandSender(boss),
_cmd(cmd), _hotkey(hotkey) {
_flags = WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG;
@@ -114,7 +116,7 @@ void ButtonWidget::drawWidget(bool hilite) {
#pragma mark -
-PushButtonWidget::PushButtonWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey)
+PushButtonWidget::PushButtonWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey)
: ButtonWidget(boss, x, y, w, h, label, cmd, hotkey), _state(false) {
_flags = WIDGET_ENABLED | WIDGET_BORDER | WIDGET_CLEARBG;
_type = kButtonWidget;
@@ -142,7 +144,7 @@ static uint32 checked_img[8] = {
0x00000000,
};
-CheckboxWidget::CheckboxWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey)
+CheckboxWidget::CheckboxWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint32 cmd, uint8 hotkey)
: PushButtonWidget(boss, x, y, w, h, label, cmd, hotkey) {
_flags = WIDGET_ENABLED;
_type = kCheckboxWidget;
@@ -173,7 +175,7 @@ void CheckboxWidget::drawWidget(bool hilite) {
#pragma mark -
-SliderWidget::SliderWidget(Dialog *boss, int x, int y, int w, int h, uint32 cmd, uint8 hotkey)
+SliderWidget::SliderWidget(GuiObject *boss, int x, int y, int w, int h, uint32 cmd, uint8 hotkey)
: ButtonWidget(boss, x, y, w, h, "", cmd, hotkey),
_value(0), _oldValue(0),_valueMin(0), _valueMax(100), _isDragging(false) {
_flags = WIDGET_ENABLED | WIDGET_TRACK_MOUSE | WIDGET_CLEARBG;
diff --git a/gui/widget.h b/gui/widget.h
index de650dcfa4..c4ce1b9abd 100644
--- a/gui/widget.h
+++ b/gui/widget.h
@@ -18,11 +18,12 @@
* $Header$
*/
-#ifndef WIDGET_H
-#define WIDGET_H
+#ifndef GUI_WIDGET_H
+#define GUI_WIDGET_H
#include "common/scummsys.h"
#include "common/str.h"
+#include "gui/object.h"
class Dialog;
@@ -59,47 +60,19 @@ enum {
};
-class CommandReceiver;
-class CommandSender;
-
-class CommandReceiver {
- friend class CommandSender;
-protected:
- virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) = 0;
-};
-
-class CommandSender {
- // TODO - allow for multiple targets, i.e. store targets in a list
- // and add methods addTarget/removeTarget.
-protected:
- CommandReceiver *_target;
-public:
- CommandSender(CommandReceiver *target) : _target(target) {}
-
- void setTarget(CommandReceiver *target) { _target = target; }
- CommandReceiver *getTarget() const { return _target; }
-
- virtual void sendCommand(uint32 cmd, uint32 data) {
- if (_target && cmd)
- _target->handleCommand(this, cmd, data);
- }
-};
-
/* Widget */
-class Widget {
+class Widget : public GuiObject {
friend class Dialog;
protected:
uint32 _type;
- Dialog *_boss;
+ GuiObject *_boss;
Widget *_next;
- int16 _x, _y;
- uint16 _w, _h;
uint16 _id;
uint16 _flags;
bool _hasFocus;
public:
- Widget(Dialog *boss, int x, int y, int w, int h);
+ Widget(GuiObject *boss, int x, int y, int w, int h);
virtual ~Widget() {}
virtual void handleMouseDown(int x, int y, int button, int clickCount) {}
@@ -131,6 +104,8 @@ protected:
virtual void lostFocusWidget() {}
virtual Widget *findWidget(int x, int y) { return this; }
+
+ void releaseFocus() { _boss->releaseFocus(); }
};
/* StaticTextWidget */
@@ -141,7 +116,7 @@ protected:
String _label;
int _align;
public:
- StaticTextWidget(Dialog *boss, int x, int y, int w, int h, const String &text, int align);
+ StaticTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text, int align);
void setValue(int value);
void setLabel(const String &label) { _label = label; }
const String &getLabel() const { return _label; }
@@ -159,7 +134,7 @@ protected:
uint32 _cmd;
uint8 _hotkey;
public:
- ButtonWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd = 0, uint8 hotkey = 0);
+ ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint32 cmd = 0, uint8 hotkey = 0);
void setCmd(uint32 cmd) { _cmd = cmd; }
uint32 getCmd() const { return _cmd; }
@@ -177,7 +152,7 @@ class PushButtonWidget : public ButtonWidget {
protected:
bool _state;
public:
- PushButtonWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd = 0, uint8 hotkey = 0);
+ PushButtonWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint32 cmd = 0, uint8 hotkey = 0);
void setState(bool state);
void toggleState() { setState(!_state); }
@@ -188,7 +163,7 @@ public:
class CheckboxWidget : public PushButtonWidget {
protected:
public:
- CheckboxWidget(Dialog *boss, int x, int y, int w, int h, const String &label, uint32 cmd = 0, uint8 hotkey = 0);
+ CheckboxWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint32 cmd = 0, uint8 hotkey = 0);
void handleMouseUp(int x, int y, int button, int clickCount);
virtual void handleMouseEntered(int button) {}
@@ -205,7 +180,7 @@ protected:
int _valueMin, _valueMax;
bool _isDragging;
public:
- SliderWidget(Dialog *boss, int x, int y, int w, int h, uint32 cmd = 0, uint8 hotkey = 0);
+ SliderWidget(GuiObject *boss, int x, int y, int w, int h, uint32 cmd = 0, uint8 hotkey = 0);
void setValue(int value) { _value = value; }
int getValue() const { return _value; }