mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-02 23:26:44 +00:00
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:
parent
02bdcc45c9
commit
018c93b14a
@ -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 {
|
||||
|
@ -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; }
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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; }
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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];
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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(); }
|
||||
|
@ -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; }
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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; }
|
||||
|
Loading…
Reference in New Issue
Block a user