More work on customizable GUI.

o Implemented special alias 'prev'
o Added new calling scheme to several widgets
o Partially converted launcher dialog to new scheme
o Converted couple widgets of chooser dialog

svn-id: r21118
This commit is contained in:
Eugene Sandulenko 2006-03-07 05:39:52 +00:00
parent 02bdcc45c9
commit 018c93b14a
16 changed files with 133 additions and 35 deletions

View file

@ -30,7 +30,17 @@ namespace GUI {
ListWidget::ListWidget(GuiObject *boss, int x, int y, int w, int h, WidgetSize ws) ListWidget::ListWidget(GuiObject *boss, int x, int y, int w, int h, WidgetSize ws)
: EditableWidget(boss, x, y, w, h, ws), CommandSender(boss) { : EditableWidget(boss, x, y, w, h, ws), CommandSender(boss) {
init(boss, w, ws);
}
ListWidget::ListWidget(GuiObject *boss, String name, WidgetSize ws)
: EditableWidget(boss, name, ws), CommandSender(boss) {
int w = g_gui.evaluator()->getVar(name + ".w");
init(boss, w, ws);
}
void ListWidget::init(GuiObject *boss, int w, WidgetSize ws) {
if (ws == kBigWidgetSize) { if (ws == kBigWidgetSize) {
_w = w - kBigScrollBarWidth; _w = w - kBigScrollBarWidth;
} else { } else {

View file

@ -63,8 +63,11 @@ protected:
public: public:
ListWidget(GuiObject *boss, int x, int y, int w, int h, WidgetSize ws = kDefaultWidgetSize); ListWidget(GuiObject *boss, int x, int y, int w, int h, WidgetSize ws = kDefaultWidgetSize);
ListWidget(GuiObject *boss, String name, WidgetSize ws = kDefaultWidgetSize);
virtual ~ListWidget(); virtual ~ListWidget();
void init(GuiObject *boss, int w, WidgetSize ws);
void setList(const StringList& list); void setList(const StringList& list);
const StringList& getList() const { return _list; } const StringList& getList() const { return _list; }
int getSelected() const { return _selectedItem; } int getSelected() const { return _selectedItem; }

View file

@ -62,14 +62,14 @@ ChooserDialog::ChooserDialog(const String &title, const String &buttonLabel, int
int yoffset = 6; int yoffset = 6;
// Headline // Headline
new StaticTextWidget(this, 10, 6, _w - 2 * 10, kLineHeight, title, kTextAlignCenter, ws); new StaticTextWidget(this, "chooser_headline", title, kTextAlignCenter, ws);
yoffset += kLineHeight + 2; yoffset += kLineHeight + 2;
// Add choice list // Add choice list
// HACK: Subtracting -12 from the height makes the list look good when // HACK: Subtracting -12 from the height makes the list look good when
// it's used to list savegames in the 320x200 version of the GUI. // it's used to list savegames in the 320x200 version of the GUI.
_list = new ListWidget(this, 10, yoffset, _w - 2 * 10, _h - yoffset - buttonHeight - 12, ws); _list = new ListWidget(this, "chooser_list", ws);
_list->setNumberingMode(kListNumberingOff); _list->setNumberingMode(kListNumberingOff);
// Buttons // Buttons

View file

@ -27,6 +27,15 @@ namespace GUI {
EditableWidget::EditableWidget(GuiObject *boss, int x, int y, int w, int h, WidgetSize ws) EditableWidget::EditableWidget(GuiObject *boss, int x, int y, int w, int h, WidgetSize ws)
: Widget(boss, x, y, w, h) { : Widget(boss, x, y, w, h) {
init();
}
EditableWidget::EditableWidget(GuiObject *boss, String name, WidgetSize ws)
: Widget(boss, name) {
init();
}
void EditableWidget::init() {
_caretVisible = false; _caretVisible = false;
_caretTime = 0; _caretTime = 0;
_caretPos = 0; // FIXME _caretPos = 0; // FIXME

View file

@ -48,8 +48,11 @@ protected:
public: public:
EditableWidget(GuiObject *boss, int x, int y, int w, int h, WidgetSize ws = kNormalWidgetSize); EditableWidget(GuiObject *boss, int x, int y, int w, int h, WidgetSize ws = kNormalWidgetSize);
EditableWidget(GuiObject *boss, String name, WidgetSize ws = kNormalWidgetSize);
virtual ~EditableWidget(); virtual ~EditableWidget();
void init();
virtual void setEditString(const String &str); virtual void setEditString(const String &str);
virtual const String &getEditString() const { return _editString; } virtual const String &getEditString() const { return _editString; }

View file

@ -127,7 +127,7 @@ void Eval::primitive(int *result) {
switch (_tokenType) { switch (_tokenType) {
case tVariable: case tVariable:
*result = lookupVar(_token); *result = getVar(_token);
if (*result == EVAL_UNDEF_VAR) if (*result == EVAL_UNDEF_VAR)
exprError(eUndefVar); exprError(eUndefVar);
getToken(); getToken();
@ -249,7 +249,7 @@ int Eval::getBuiltinVar(const char *s) {
return EVAL_UNDEF_VAR; return EVAL_UNDEF_VAR;
} }
int Eval::lookupVar(const char *s, bool includeAliases) { int Eval::getVar(const char *s, bool includeAliases) {
int i; int i;
int val; int val;

View file

@ -67,7 +67,7 @@ public:
void setVariable(const String name, int val) { _vars[name] = val; } void setVariable(const String name, int val) { _vars[name] = val; }
void setAlias(const String name, const String val) { _aliases[name] = val; } void setAlias(const String name, const String val) { _aliases[name] = val; }
int lookupVar(String s) { return lookupVar(s.c_str()); }; int getVar(String s) { return getVar(s.c_str()); };
void reset(); void reset();
@ -84,7 +84,7 @@ private:
void arith(char op, int *r, int *h); void arith(char op, int *r, int *h);
void unary(char op, int *r); void unary(char op, int *r);
void exprError(int error); void exprError(int error);
int lookupVar(const char *s, bool includeAliases = true); int getVar(const char *s, bool includeAliases = true);
int getBuiltinVar(const char *s); int getBuiltinVar(const char *s);
char _input[256]; char _input[256];

View file

@ -515,33 +515,27 @@ LauncherDialog::LauncherDialog(GameDetector &detector)
} }
// Show ScummVM version // Show ScummVM version
new StaticTextWidget(this, hBorder, 8, _w - 2*hBorder, kLineHeight, gScummVMFullVersion, kTextAlignCenter, ws); new StaticTextWidget(this, "launcher_version", gScummVMFullVersion, kTextAlignCenter, ws);
// Add some buttons at the bottom // Add some buttons at the bottom
// TODO: Rearrange them a bit? In particular, we could put a slightly smaller space // TODO: Rearrange them a bit? In particular, we could put a slightly smaller space
// between About and Options, and in exchange remove those a bit from Quit and Start. // between About and Options, and in exchange remove those a bit from Quit and Start.
top = _h - 8 - buttonHeight; new ButtonWidget(this, "launcher_quit_button", "Quit", kQuitCmd, 'Q', ws);
BEGIN_BUTTONS(4, 8, top) new ButtonWidget(this, "launcher_about_button", "About", kAboutCmd, 'B', ws);
ADD("Quit", kQuitCmd, 'Q'); new ButtonWidget(this, "launcher_options_button", "Options", kOptionsCmd, 'O', ws);
ADD("About", kAboutCmd, 'B'); _startButton =
ADD("Options", kOptionsCmd, 'O'); new ButtonWidget(this, "launcher_start_button", "Start", kStartCmd, 'S', ws);
_startButton =
ADD("Start", kStartCmd, 'S');
END_BUTTONS
// Above the lowest button rows: two more buttons (directly below the list box) // Above the lowest button rows: two more buttons (directly below the list box)
top -= 2 * buttonHeight; new ButtonWidget(this, "launcher_addGame_button", "Add Game...", kAddGameCmd, 'A', ws);
BEGIN_BUTTONS(3, 10, top) _editButton =
ADD("Add Game...", kAddGameCmd, 'A'); new ButtonWidget(this, "launcher_editGame_button", "Edit Game...", kEditGameCmd, 'E', ws);
_editButton = _removeButton =
ADD("Edit Game...", kEditGameCmd, 'E'); new ButtonWidget(this, "launcher_removeGame_button", "Remove Game", kRemoveGameCmd, 'R', ws);
_removeButton =
ADD("Remove Game", kRemoveGameCmd, 'R');
END_BUTTONS
// Add list with game titles // Add list with game titles
_list = new ListWidget(this, hBorder, kLineHeight + 16, _w - 2 * hBorder, top - kLineHeight - 20, ws); _list = new ListWidget(this, "launcher_list", ws);
_list->setEditable(false); _list->setEditable(false);
_list->setNumberingMode(kListNumberingOff); _list->setNumberingMode(kListNumberingOff);

View file

@ -56,6 +56,15 @@ enum {
#define USE_AUTO_SCALING false #define USE_AUTO_SCALING false
#endif #endif
// HACK. FIXME. This doesn't belong here. But otherwise it creates compulation problems
GuiObject::GuiObject(Common::String name) : _firstWidget(0) {
_x = g_gui.evaluator()->getVar(name + ".x");
_y = g_gui.evaluator()->getVar(name + ".y");
_w = g_gui.evaluator()->getVar(name + ".w");
_h = g_gui.evaluator()->getVar(name + ".h");
}
// Constructor // Constructor
NewGui::NewGui() : _needRedraw(false), NewGui::NewGui() : _needRedraw(false),
_stateIsSaved(false), _cursorAnimateCounter(0), _cursorAnimateTimer(0) { _stateIsSaved(false), _cursorAnimateCounter(0), _cursorAnimateTimer(0) {

View file

@ -34,6 +34,7 @@ class OSystem;
namespace GUI { namespace GUI {
class Dialog; class Dialog;
class Eval;
#define g_gui (GUI::NewGui::instance()) #define g_gui (GUI::NewGui::instance())
@ -70,6 +71,7 @@ public:
bool isActive() const { return ! _dialogStack.empty(); } bool isActive() const { return ! _dialogStack.empty(); }
Theme *theme() { return _theme; } Theme *theme() { return _theme; }
Eval *evaluator() { return _theme->_evaluator; }
const Graphics::Font &getFont() const { return *(_theme->getFont()); } const Graphics::Font &getFont() const { return *(_theme->getFont()); }
int getFontHeight() const { return _theme->getFontHeight(); } int getFontHeight() const { return _theme->getFontHeight(); }

View file

@ -64,6 +64,7 @@ protected:
public: public:
GuiObject(int x, int y, int w, int h) : _x(x), _y(y), _w(w), _h(h), _firstWidget(0) { } GuiObject(int x, int y, int w, int h) : _x(x), _y(y), _w(w), _h(h), _firstWidget(0) { }
GuiObject(Common::String name);
virtual int16 getAbsX() const { return _x; } virtual int16 getAbsX() const { return _x; }
virtual int16 getAbsY() const { return _y; } virtual int16 getAbsY() const { return _y; }

View file

@ -31,6 +31,24 @@ def_buttonHeight=kBigButtonHeight\n\
def_kLineHeight=16\n\ def_kLineHeight=16\n\
chooser_headline=10 6 (w - 2 * 16) (kLineHeight)\n\ chooser_headline=10 6 (w - 2 * 16) (kLineHeight)\n\
chooser_list=10 (6 + kLineHeight + 2) (w - 2 * 16) (h - self.y - buttonHeight - 12)\n\ chooser_list=10 (6 + kLineHeight + 2) (w - 2 * 16) (h - self.y - buttonHeight - 12)\n\
hBorder=10\n\
launcher_version=hBorder 8 (w - 2 * hBorder) kLineHeight\n\
top=(h - 8 - buttonHeight)\n\
numButtons=4\n\
space=8\n\
buttonWidth=((w - 2 * hBorder - space * (numButtons - 1)) / numButtons)\n\
launcher_quit_button=hBorder top buttonWidth buttonHeight\n\
launcher_about_button=(prev.x2 + space) top buttonWidth buttonHeight\n\
launcher_options_button=(prev.x2 + space) top buttonWidth buttonHeight\n\
launcher_start_button=(prev.x2 + space) top buttonWidth buttonHeight\n\
top=(top - buttonHeight * 2)\n\
numButtons=3\n\
space=10\n\
buttonWidth=((w - 2 * hBorder - space * (numButtons - 1)) / numButtons)\n\
launcher_addGame_button=hBorder top buttonWidth buttonHeight\n\
launcher_editGame_button=(prev.x2 + space) top buttonWidth buttonHeight\n\
launcher_removeGame_button=(prev.x2 + space) top buttonWidth buttonHeight\n\
launcher_list=hBorder (kLineHeight + 16) (w - 2 * hBorder) (top - kLineHeight - 20)\n\
"; ";
using Common::String; using Common::String;
@ -85,12 +103,14 @@ void Theme::processSingleLine(const String &section, const String name, const St
_evaluator->setVariable(name + "." + postfixes[npostfix], value); _evaluator->setVariable(name + "." + postfixes[npostfix], value);
// If we have all 4 parameters, set .x2 and .y2 // If we have all 4 parameters, set .x2 and .y2
if (npostfix == 4) { if (npostfix == 3) {
_evaluator->setVariable(name + ".x2", _evaluator->lookupVar(name + ".x") + _evaluator->setVariable(name + ".x2", _evaluator->getVar(name + ".x") +
_evaluator->lookupVar(name + ".w")); _evaluator->getVar(name + ".w"));
_evaluator->setVariable(name + ".y2", _evaluator->lookupVar(name + ".y") + _evaluator->setVariable(name + ".y2", _evaluator->getVar(name + ".y") +
_evaluator->lookupVar(name + ".h")); _evaluator->getVar(name + ".h"));
} }
setSpecialAlias("prev", name);
} }
@ -102,7 +122,7 @@ void Theme::processResSection(Common::ConfigFile &config, String name, bool skip
Common::ConfigFile::SectionKeyList::const_iterator iterk; Common::ConfigFile::SectionKeyList::const_iterator iterk;
for (iterk = keys.begin(); iterk != keys.end(); ++iterk) { for (iterk = keys.begin(); iterk != keys.end(); ++iterk) {
if (iterk->key == "set_parent") { if (iterk->key == "set_parent") {
setParent(iterk->value); setSpecialAlias("parent", iterk->value);
continue; continue;
} }
if (iterk->key.hasPrefix("set_")) { if (iterk->key.hasPrefix("set_")) {
@ -126,14 +146,14 @@ void Theme::processResSection(Common::ConfigFile &config, String name, bool skip
} }
} }
void Theme::setParent(const String &name) { void Theme::setSpecialAlias(const String alias, const String &name) {
const char *postfixes[] = {"x", "y", "w", "h", "x2", "y2"}; const char *postfixes[] = {"x", "y", "w", "h", "x2", "y2"};
int i; int i;
for (i = 0; i < ARRAYSIZE(postfixes); i++) { for (i = 0; i < ARRAYSIZE(postfixes); i++) {
String from, to; String from, to;
from = String("parent.") + postfixes[i]; from = alias + "." + postfixes[i];
to = name + "." + postfixes[i]; to = name + "." + postfixes[i];
_evaluator->setAlias(from, to); _evaluator->setAlias(from, to);

View file

@ -171,18 +171,18 @@ public:
void processResSection(Common::ConfigFile &config, String name, bool skipDefs = false); void processResSection(Common::ConfigFile &config, String name, bool skipDefs = false);
void processSingleLine(const String &section, const String name, const String str); void processSingleLine(const String &section, const String name, const String str);
void setParent(const String &name); void setSpecialAlias(const String alias, const String &name);
bool isThemeLoadingRequired(); bool isThemeLoadingRequired();
void loadTheme(Common::ConfigFile &config, bool reset = true); void loadTheme(Common::ConfigFile &config, bool reset = true);
Eval *_evaluator;
protected: protected:
Common::Rect _drawArea; Common::Rect _drawArea;
Common::ConfigFile _configFile; Common::ConfigFile _configFile;
Common::ConfigFile _defaultConfig; Common::ConfigFile _defaultConfig;
Eval *_evaluator;
private: private:
static const char *_defaultConfigINI; static const char *_defaultConfigINI;
int _loadedThemeX, _loadedThemeY; int _loadedThemeX, _loadedThemeY;

View file

@ -133,3 +133,21 @@ def_buttonHeight=kBigButtonHeight
def_kLineHeight=16 def_kLineHeight=16
chooser_headline=10 6 (w - 2 * 16) (kLineHeight) chooser_headline=10 6 (w - 2 * 16) (kLineHeight)
chooser_list=10 (6 + kLineHeight + 2) (w - 2 * 16) (h - self.y - buttonHeight - 12) chooser_list=10 (6 + kLineHeight + 2) (w - 2 * 16) (h - self.y - buttonHeight - 12)
hBorder=10
launcher_version=hBorder 8 (w - 2 * hBorder) kLineHeight
top=(h - 8 - buttonHeight)
numButtons=4
space=8
buttonWidth=((w - 2 * hBorder - space * (numButtons - 1)) / numButtons)
launcher_quit_button=hBorder top buttonWidth buttonHeight
launcher_about_button=(prev.x2 + space) top buttonWidth buttonHeight
launcher_options_button=(prev.x2 + space) top buttonWidth buttonHeight
launcher_start_button=(prev.x2 + space) top buttonWidth buttonHeight
top=(top - buttonHeight * 2)
numButtons=3
space=10
buttonWidth=((w - 2 * hBorder - space * (numButtons - 1)) / numButtons)
launcher_addGame_button=hBorder top buttonWidth buttonHeight
launcher_editGame_button=(prev.x2 + space) top buttonWidth buttonHeight
launcher_removeGame_button=(prev.x2 + space) top buttonWidth buttonHeight
launcher_list=hBorder (kLineHeight + 16) (w - 2 * hBorder) (top - kLineHeight - 20)

View file

@ -31,6 +31,16 @@ namespace GUI {
Widget::Widget(GuiObject *boss, int x, int y, int w, int h) Widget::Widget(GuiObject *boss, int x, int y, int w, int h)
: GuiObject(x, y, w, h), _type(0), _boss(boss), : GuiObject(x, y, w, h), _type(0), _boss(boss),
_id(0), _flags(0), _hints(THEME_HINT_FIRST_DRAW), _hasFocus(false) { _id(0), _flags(0), _hints(THEME_HINT_FIRST_DRAW), _hasFocus(false) {
init();
}
Widget::Widget(GuiObject *boss, String name)
: GuiObject(name), _type(0), _boss(boss),
_id(0), _flags(0), _hints(THEME_HINT_FIRST_DRAW), _hasFocus(false) {
init();
}
void Widget::init() {
// Insert into the widget list of the boss // Insert into the widget list of the boss
_next = _boss->_firstWidget; _next = _boss->_firstWidget;
_boss->_firstWidget = this; _boss->_firstWidget = this;
@ -112,6 +122,13 @@ StaticTextWidget::StaticTextWidget(GuiObject *boss, int x, int y, int w, int h,
_label = text; _label = text;
} }
StaticTextWidget::StaticTextWidget(GuiObject *boss, String name, const String &text, TextAlignment align, WidgetSize ws)
: Widget(boss, name), _align(align), _ws(ws) {
_flags = WIDGET_ENABLED;
_type = kStaticTextWidget;
_label = text;
}
void StaticTextWidget::setValue(int value) { void StaticTextWidget::setValue(int value) {
char buf[256]; char buf[256];
sprintf(buf, "%d", value); sprintf(buf, "%d", value);
@ -149,6 +166,13 @@ ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const St
_type = kButtonWidget; _type = kButtonWidget;
} }
ButtonWidget::ButtonWidget(GuiObject *boss, String name, const String &label, uint32 cmd, uint8 hotkey, WidgetSize ws)
: StaticTextWidget(boss, name, label, kTextAlignCenter, ws), CommandSender(boss),
_cmd(cmd), _hotkey(hotkey) {
_flags = WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG;
_type = kButtonWidget;
}
void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount) { void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount) {
if (isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h) if (isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h)
sendCommand(_cmd, 0); sendCommand(_cmd, 0);

View file

@ -101,8 +101,11 @@ public:
public: public:
Widget(GuiObject *boss, int x, int y, int w, int h); Widget(GuiObject *boss, int x, int y, int w, int h);
Widget(GuiObject *boss, Common::String name);
virtual ~Widget(); virtual ~Widget();
void init();
virtual int16 getAbsX() const { return _x + _boss->getChildX(); } virtual int16 getAbsX() const { return _x + _boss->getChildX(); }
virtual int16 getAbsY() const { return _y + _boss->getChildY(); } virtual int16 getAbsY() const { return _y + _boss->getChildY(); }
@ -161,6 +164,7 @@ protected:
const WidgetSize _ws; const WidgetSize _ws;
public: public:
StaticTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text, TextAlignment align, WidgetSize ws = kDefaultWidgetSize); StaticTextWidget(GuiObject *boss, int x, int y, int w, int h, const String &text, TextAlignment align, WidgetSize ws = kDefaultWidgetSize);
StaticTextWidget(GuiObject *boss, String name, const String &text, TextAlignment align, WidgetSize ws = kDefaultWidgetSize);
void setValue(int value); void setValue(int value);
void setLabel(const String &label); void setLabel(const String &label);
const String &getLabel() const { return _label; } const String &getLabel() const { return _label; }
@ -179,6 +183,7 @@ protected:
uint8 _hotkey; uint8 _hotkey;
public: public:
ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint32 cmd = 0, uint8 hotkey = 0, WidgetSize ws = kDefaultWidgetSize); ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint32 cmd = 0, uint8 hotkey = 0, WidgetSize ws = kDefaultWidgetSize);
ButtonWidget(GuiObject *boss, String name, const String &label, uint32 cmd = 0, uint8 hotkey = 0, WidgetSize ws = kDefaultWidgetSize);
void setCmd(uint32 cmd) { _cmd = cmd; } void setCmd(uint32 cmd) { _cmd = cmd; }
uint32 getCmd() const { return _cmd; } uint32 getCmd() const { return _cmd; }