introduced common base class GuiObject for Dialog/Widget -> step towards making it possible to nest widgets (needed for TabWidget)
svn-id: r11052
This commit is contained in:
parent
70a1d43815
commit
e9ae86bb76
17 changed files with 125 additions and 75 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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);
|
||||
/*
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
14
gui/dialog.h
14
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,8 +55,6 @@ public:
|
|||
virtual int runModal();
|
||||
|
||||
bool isVisible() const { return _visible; }
|
||||
int16 getX() const { return _x; }
|
||||
int16 getY() const { return _y; }
|
||||
|
||||
void releaseFocus();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
75
gui/object.h
Normal file
75
gui/object.h
Normal file
|
@ -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
|
|
@ -28,6 +28,8 @@
|
|||
class BrowserDialog;
|
||||
class GameDetector;
|
||||
class PopUpWidget;
|
||||
class SliderWidget;
|
||||
class StaticTextWidget;
|
||||
|
||||
class GlobalOptionsDialog : public Dialog {
|
||||
typedef Common::String String;
|
||||
|
|
|
@ -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;
|
||||
|
|
51
gui/widget.h
51
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; }
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "common/str.h"
|
||||
#include "gui/about.h"
|
||||
#include "gui/dialog.h"
|
||||
#include "gui/widget.h"
|
||||
|
||||
#ifndef DISABLE_HELP
|
||||
#include "scumm/help.h"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue