diff options
author | Eugene Sandulenko | 2006-03-07 05:39:52 +0000 |
---|---|---|
committer | Eugene Sandulenko | 2006-03-07 05:39:52 +0000 |
commit | 018c93b14a9f2b3eda3bdfafcf9b90ee9ac0f8f2 (patch) | |
tree | ce773d203cb6e24aa2a3f206a7eaf2547bef5762 /gui | |
parent | 02bdcc45c9aaca4ab98b27eccd21ae00731aa2f8 (diff) | |
download | scummvm-rg350-018c93b14a9f2b3eda3bdfafcf9b90ee9ac0f8f2.tar.gz scummvm-rg350-018c93b14a9f2b3eda3bdfafcf9b90ee9ac0f8f2.tar.bz2 scummvm-rg350-018c93b14a9f2b3eda3bdfafcf9b90ee9ac0f8f2.zip |
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
Diffstat (limited to 'gui')
-rw-r--r-- | gui/ListWidget.cpp | 10 | ||||
-rw-r--r-- | gui/ListWidget.h | 3 | ||||
-rw-r--r-- | gui/chooser.cpp | 4 | ||||
-rw-r--r-- | gui/editable.cpp | 9 | ||||
-rw-r--r-- | gui/editable.h | 3 | ||||
-rw-r--r-- | gui/eval.cpp | 4 | ||||
-rw-r--r-- | gui/eval.h | 4 | ||||
-rw-r--r-- | gui/launcher.cpp | 30 | ||||
-rw-r--r-- | gui/newgui.cpp | 9 | ||||
-rw-r--r-- | gui/newgui.h | 2 | ||||
-rw-r--r-- | gui/object.h | 1 | ||||
-rw-r--r-- | gui/theme-config.cpp | 36 | ||||
-rw-r--r-- | gui/theme.h | 6 | ||||
-rw-r--r-- | gui/themes/default-theme.ini | 18 | ||||
-rw-r--r-- | gui/widget.cpp | 24 | ||||
-rw-r--r-- | gui/widget.h | 5 |
16 files changed, 133 insertions, 35 deletions
diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp index c1aa044af8..963b37b944 100644 --- a/gui/ListWidget.cpp +++ b/gui/ListWidget.cpp @@ -30,7 +30,17 @@ namespace GUI { ListWidget::ListWidget(GuiObject *boss, int x, int y, int w, int h, WidgetSize ws) : 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) { _w = w - kBigScrollBarWidth; } else { diff --git a/gui/ListWidget.h b/gui/ListWidget.h index e76907297d..2ee8ed8c37 100644 --- a/gui/ListWidget.h +++ b/gui/ListWidget.h @@ -63,8 +63,11 @@ protected: public: ListWidget(GuiObject *boss, int x, int y, int w, int h, WidgetSize ws = kDefaultWidgetSize); + ListWidget(GuiObject *boss, String name, WidgetSize ws = kDefaultWidgetSize); virtual ~ListWidget(); + void init(GuiObject *boss, int w, WidgetSize ws); + void setList(const StringList& list); const StringList& getList() const { return _list; } int getSelected() const { return _selectedItem; } diff --git a/gui/chooser.cpp b/gui/chooser.cpp index 1901da1609..b373078a11 100644 --- a/gui/chooser.cpp +++ b/gui/chooser.cpp @@ -62,14 +62,14 @@ ChooserDialog::ChooserDialog(const String &title, const String &buttonLabel, int int yoffset = 6; // Headline - new StaticTextWidget(this, 10, 6, _w - 2 * 10, kLineHeight, title, kTextAlignCenter, ws); + new StaticTextWidget(this, "chooser_headline", title, kTextAlignCenter, ws); yoffset += kLineHeight + 2; // Add choice list // 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. - _list = new ListWidget(this, 10, yoffset, _w - 2 * 10, _h - yoffset - buttonHeight - 12, ws); + _list = new ListWidget(this, "chooser_list", ws); _list->setNumberingMode(kListNumberingOff); // Buttons diff --git a/gui/editable.cpp b/gui/editable.cpp index 679e1dad58..d44b43131d 100644 --- a/gui/editable.cpp +++ b/gui/editable.cpp @@ -27,6 +27,15 @@ namespace GUI { EditableWidget::EditableWidget(GuiObject *boss, int x, int y, int w, int h, WidgetSize ws) : Widget(boss, x, y, w, h) { + init(); +} + +EditableWidget::EditableWidget(GuiObject *boss, String name, WidgetSize ws) + : Widget(boss, name) { + init(); +} + +void EditableWidget::init() { _caretVisible = false; _caretTime = 0; _caretPos = 0; // FIXME diff --git a/gui/editable.h b/gui/editable.h index c93783f4f7..8d13a691d4 100644 --- a/gui/editable.h +++ b/gui/editable.h @@ -48,8 +48,11 @@ protected: public: EditableWidget(GuiObject *boss, int x, int y, int w, int h, WidgetSize ws = kNormalWidgetSize); + EditableWidget(GuiObject *boss, String name, WidgetSize ws = kNormalWidgetSize); virtual ~EditableWidget(); + void init(); + virtual void setEditString(const String &str); virtual const String &getEditString() const { return _editString; } diff --git a/gui/eval.cpp b/gui/eval.cpp index 6828823e68..5b86a6d8d5 100644 --- a/gui/eval.cpp +++ b/gui/eval.cpp @@ -127,7 +127,7 @@ void Eval::primitive(int *result) { switch (_tokenType) { case tVariable: - *result = lookupVar(_token); + *result = getVar(_token); if (*result == EVAL_UNDEF_VAR) exprError(eUndefVar); getToken(); @@ -249,7 +249,7 @@ int Eval::getBuiltinVar(const char *s) { return EVAL_UNDEF_VAR; } -int Eval::lookupVar(const char *s, bool includeAliases) { +int Eval::getVar(const char *s, bool includeAliases) { int i; int val; diff --git a/gui/eval.h b/gui/eval.h index 18d2c48394..297f455b54 100644 --- a/gui/eval.h +++ b/gui/eval.h @@ -67,7 +67,7 @@ public: void setVariable(const String name, int val) { _vars[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(); @@ -84,7 +84,7 @@ private: void arith(char op, int *r, int *h); void unary(char op, int *r); 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); char _input[256]; diff --git a/gui/launcher.cpp b/gui/launcher.cpp index 9357d52b0b..187b171e18 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -515,33 +515,27 @@ LauncherDialog::LauncherDialog(GameDetector &detector) } // 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 // 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. - top = _h - 8 - buttonHeight; - BEGIN_BUTTONS(4, 8, top) - ADD("Quit", kQuitCmd, 'Q'); - ADD("About", kAboutCmd, 'B'); - ADD("Options", kOptionsCmd, 'O'); - _startButton = - ADD("Start", kStartCmd, 'S'); - END_BUTTONS + new ButtonWidget(this, "launcher_quit_button", "Quit", kQuitCmd, 'Q', ws); + new ButtonWidget(this, "launcher_about_button", "About", kAboutCmd, 'B', ws); + new ButtonWidget(this, "launcher_options_button", "Options", kOptionsCmd, 'O', ws); + _startButton = + new ButtonWidget(this, "launcher_start_button", "Start", kStartCmd, 'S', ws); // Above the lowest button rows: two more buttons (directly below the list box) - top -= 2 * buttonHeight; - BEGIN_BUTTONS(3, 10, top) - ADD("Add Game...", kAddGameCmd, 'A'); - _editButton = - ADD("Edit Game...", kEditGameCmd, 'E'); - _removeButton = - ADD("Remove Game", kRemoveGameCmd, 'R'); - END_BUTTONS + new ButtonWidget(this, "launcher_addGame_button", "Add Game...", kAddGameCmd, 'A', ws); + _editButton = + new ButtonWidget(this, "launcher_editGame_button", "Edit Game...", kEditGameCmd, 'E', ws); + _removeButton = + new ButtonWidget(this, "launcher_removeGame_button", "Remove Game", kRemoveGameCmd, 'R', ws); // 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->setNumberingMode(kListNumberingOff); diff --git a/gui/newgui.cpp b/gui/newgui.cpp index 61bed6817e..3c76febfae 100644 --- a/gui/newgui.cpp +++ b/gui/newgui.cpp @@ -56,6 +56,15 @@ enum { #define USE_AUTO_SCALING false #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 NewGui::NewGui() : _needRedraw(false), _stateIsSaved(false), _cursorAnimateCounter(0), _cursorAnimateTimer(0) { diff --git a/gui/newgui.h b/gui/newgui.h index 688b067fc6..4eb3e9d10c 100644 --- a/gui/newgui.h +++ b/gui/newgui.h @@ -34,6 +34,7 @@ class OSystem; namespace GUI { class Dialog; +class Eval; #define g_gui (GUI::NewGui::instance()) @@ -70,6 +71,7 @@ public: bool isActive() const { return ! _dialogStack.empty(); } Theme *theme() { return _theme; } + Eval *evaluator() { return _theme->_evaluator; } const Graphics::Font &getFont() const { return *(_theme->getFont()); } int getFontHeight() const { return _theme->getFontHeight(); } diff --git a/gui/object.h b/gui/object.h index c4fe7a6003..c9fe097a06 100644 --- a/gui/object.h +++ b/gui/object.h @@ -64,6 +64,7 @@ protected: public: 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 getAbsY() const { return _y; } diff --git a/gui/theme-config.cpp b/gui/theme-config.cpp index feb2ec6f43..c482969c60 100644 --- a/gui/theme-config.cpp +++ b/gui/theme-config.cpp @@ -31,6 +31,24 @@ def_buttonHeight=kBigButtonHeight\n\ def_kLineHeight=16\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\ +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; @@ -85,12 +103,14 @@ void Theme::processSingleLine(const String §ion, const String name, const St _evaluator->setVariable(name + "." + postfixes[npostfix], value); // If we have all 4 parameters, set .x2 and .y2 - if (npostfix == 4) { - _evaluator->setVariable(name + ".x2", _evaluator->lookupVar(name + ".x") + - _evaluator->lookupVar(name + ".w")); - _evaluator->setVariable(name + ".y2", _evaluator->lookupVar(name + ".y") + - _evaluator->lookupVar(name + ".h")); + if (npostfix == 3) { + _evaluator->setVariable(name + ".x2", _evaluator->getVar(name + ".x") + + _evaluator->getVar(name + ".w")); + _evaluator->setVariable(name + ".y2", _evaluator->getVar(name + ".y") + + _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; for (iterk = keys.begin(); iterk != keys.end(); ++iterk) { if (iterk->key == "set_parent") { - setParent(iterk->value); + setSpecialAlias("parent", iterk->value); continue; } 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"}; int i; for (i = 0; i < ARRAYSIZE(postfixes); i++) { String from, to; - from = String("parent.") + postfixes[i]; + from = alias + "." + postfixes[i]; to = name + "." + postfixes[i]; _evaluator->setAlias(from, to); diff --git a/gui/theme.h b/gui/theme.h index 9befabdb87..45216cc83b 100644 --- a/gui/theme.h +++ b/gui/theme.h @@ -171,18 +171,18 @@ public: void processResSection(Common::ConfigFile &config, String name, bool skipDefs = false); void processSingleLine(const String §ion, const String name, const String str); - void setParent(const String &name); + void setSpecialAlias(const String alias, const String &name); bool isThemeLoadingRequired(); void loadTheme(Common::ConfigFile &config, bool reset = true); + Eval *_evaluator; + protected: Common::Rect _drawArea; Common::ConfigFile _configFile; Common::ConfigFile _defaultConfig; - Eval *_evaluator; - private: static const char *_defaultConfigINI; int _loadedThemeX, _loadedThemeY; diff --git a/gui/themes/default-theme.ini b/gui/themes/default-theme.ini index 71f9d59891..ef467846cc 100644 --- a/gui/themes/default-theme.ini +++ b/gui/themes/default-theme.ini @@ -133,3 +133,21 @@ def_buttonHeight=kBigButtonHeight def_kLineHeight=16 chooser_headline=10 6 (w - 2 * 16) (kLineHeight) 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) diff --git a/gui/widget.cpp b/gui/widget.cpp index 6b65904ebf..0bf3c07fc7 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -31,6 +31,16 @@ namespace GUI { 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), _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 _next = _boss->_firstWidget; _boss->_firstWidget = this; @@ -112,6 +122,13 @@ StaticTextWidget::StaticTextWidget(GuiObject *boss, int x, int y, int w, int h, _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) { char buf[256]; sprintf(buf, "%d", value); @@ -149,6 +166,13 @@ ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const St _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) { if (isEnabled() && x >= 0 && x < _w && y >= 0 && y < _h) sendCommand(_cmd, 0); diff --git a/gui/widget.h b/gui/widget.h index fc01e3d56a..dbc87e4127 100644 --- a/gui/widget.h +++ b/gui/widget.h @@ -101,8 +101,11 @@ public: public: Widget(GuiObject *boss, int x, int y, int w, int h); + Widget(GuiObject *boss, Common::String name); virtual ~Widget(); + void init(); + virtual int16 getAbsX() const { return _x + _boss->getChildX(); } virtual int16 getAbsY() const { return _y + _boss->getChildY(); } @@ -161,6 +164,7 @@ protected: const WidgetSize _ws; public: 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 setLabel(const String &label); const String &getLabel() const { return _label; } @@ -179,6 +183,7 @@ protected: uint8 _hotkey; 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, String name, const String &label, uint32 cmd = 0, uint8 hotkey = 0, WidgetSize ws = kDefaultWidgetSize); void setCmd(uint32 cmd) { _cmd = cmd; } uint32 getCmd() const { return _cmd; } |