[Scummvm-cvs-logs] SF.net SVN: scummvm: [21118] scummvm/trunk/gui

sev at users.sourceforge.net sev at users.sourceforge.net
Mon Mar 6 21:41:07 CET 2006


Revision: 21118
Author:   sev
Date:     2006-03-06 21:39:52 -0800 (Mon, 06 Mar 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=21118&view=rev

Log Message:
-----------
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

Modified Paths:
--------------
    scummvm/trunk/gui/ListWidget.cpp
    scummvm/trunk/gui/ListWidget.h
    scummvm/trunk/gui/chooser.cpp
    scummvm/trunk/gui/editable.cpp
    scummvm/trunk/gui/editable.h
    scummvm/trunk/gui/eval.cpp
    scummvm/trunk/gui/eval.h
    scummvm/trunk/gui/launcher.cpp
    scummvm/trunk/gui/newgui.cpp
    scummvm/trunk/gui/newgui.h
    scummvm/trunk/gui/object.h
    scummvm/trunk/gui/theme-config.cpp
    scummvm/trunk/gui/theme.h
    scummvm/trunk/gui/themes/default-theme.ini
    scummvm/trunk/gui/widget.cpp
    scummvm/trunk/gui/widget.h
Modified: scummvm/trunk/gui/ListWidget.cpp
===================================================================
--- scummvm/trunk/gui/ListWidget.cpp	2006-03-07 04:34:09 UTC (rev 21117)
+++ scummvm/trunk/gui/ListWidget.cpp	2006-03-07 05:39:52 UTC (rev 21118)
@@ -30,7 +30,17 @@
 
 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 {

Modified: scummvm/trunk/gui/ListWidget.h
===================================================================
--- scummvm/trunk/gui/ListWidget.h	2006-03-07 04:34:09 UTC (rev 21117)
+++ scummvm/trunk/gui/ListWidget.h	2006-03-07 05:39:52 UTC (rev 21118)
@@ -63,8 +63,11 @@
 
 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; }

Modified: scummvm/trunk/gui/chooser.cpp
===================================================================
--- scummvm/trunk/gui/chooser.cpp	2006-03-07 04:34:09 UTC (rev 21117)
+++ scummvm/trunk/gui/chooser.cpp	2006-03-07 05:39:52 UTC (rev 21118)
@@ -62,14 +62,14 @@
 	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

Modified: scummvm/trunk/gui/editable.cpp
===================================================================
--- scummvm/trunk/gui/editable.cpp	2006-03-07 04:34:09 UTC (rev 21117)
+++ scummvm/trunk/gui/editable.cpp	2006-03-07 05:39:52 UTC (rev 21118)
@@ -27,6 +27,15 @@
 
 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

Modified: scummvm/trunk/gui/editable.h
===================================================================
--- scummvm/trunk/gui/editable.h	2006-03-07 04:34:09 UTC (rev 21117)
+++ scummvm/trunk/gui/editable.h	2006-03-07 05:39:52 UTC (rev 21118)
@@ -48,8 +48,11 @@
 
 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; }
 

Modified: scummvm/trunk/gui/eval.cpp
===================================================================
--- scummvm/trunk/gui/eval.cpp	2006-03-07 04:34:09 UTC (rev 21117)
+++ scummvm/trunk/gui/eval.cpp	2006-03-07 05:39:52 UTC (rev 21118)
@@ -127,7 +127,7 @@
 
 	switch (_tokenType) {
 	case tVariable:
-		*result = lookupVar(_token);
+		*result = getVar(_token);
 		if (*result == EVAL_UNDEF_VAR)
 			exprError(eUndefVar);
 		getToken();
@@ -249,7 +249,7 @@
 	return EVAL_UNDEF_VAR;
 }
 
-int Eval::lookupVar(const char *s, bool includeAliases) {
+int Eval::getVar(const char *s, bool includeAliases) {
 	int i;
 	int val;
 

Modified: scummvm/trunk/gui/eval.h
===================================================================
--- scummvm/trunk/gui/eval.h	2006-03-07 04:34:09 UTC (rev 21117)
+++ scummvm/trunk/gui/eval.h	2006-03-07 05:39:52 UTC (rev 21118)
@@ -67,7 +67,7 @@
 	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 @@
 	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];

Modified: scummvm/trunk/gui/launcher.cpp
===================================================================
--- scummvm/trunk/gui/launcher.cpp	2006-03-07 04:34:09 UTC (rev 21117)
+++ scummvm/trunk/gui/launcher.cpp	2006-03-07 05:39:52 UTC (rev 21118)
@@ -515,33 +515,27 @@
 	}
 
 	// 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);
 

Modified: scummvm/trunk/gui/newgui.cpp
===================================================================
--- scummvm/trunk/gui/newgui.cpp	2006-03-07 04:34:09 UTC (rev 21117)
+++ scummvm/trunk/gui/newgui.cpp	2006-03-07 05:39:52 UTC (rev 21118)
@@ -56,6 +56,15 @@
 #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) {

Modified: scummvm/trunk/gui/newgui.h
===================================================================
--- scummvm/trunk/gui/newgui.h	2006-03-07 04:34:09 UTC (rev 21117)
+++ scummvm/trunk/gui/newgui.h	2006-03-07 05:39:52 UTC (rev 21118)
@@ -34,6 +34,7 @@
 namespace GUI {
 
 class Dialog;
+class Eval;
 
 #define g_gui	(GUI::NewGui::instance())
 
@@ -70,6 +71,7 @@
 	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(); }

Modified: scummvm/trunk/gui/object.h
===================================================================
--- scummvm/trunk/gui/object.h	2006-03-07 04:34:09 UTC (rev 21117)
+++ scummvm/trunk/gui/object.h	2006-03-07 05:39:52 UTC (rev 21118)
@@ -64,6 +64,7 @@
 
 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; }

Modified: scummvm/trunk/gui/theme-config.cpp
===================================================================
--- scummvm/trunk/gui/theme-config.cpp	2006-03-07 04:34:09 UTC (rev 21117)
+++ scummvm/trunk/gui/theme-config.cpp	2006-03-07 05:39:52 UTC (rev 21118)
@@ -31,6 +31,24 @@
 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 @@
 		_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 @@
 	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::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);

Modified: scummvm/trunk/gui/theme.h
===================================================================
--- scummvm/trunk/gui/theme.h	2006-03-07 04:34:09 UTC (rev 21117)
+++ scummvm/trunk/gui/theme.h	2006-03-07 05:39:52 UTC (rev 21118)
@@ -171,18 +171,18 @@
 
 	void processResSection(Common::ConfigFile &config, String name, bool skipDefs = false);
 	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();
 	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;

Modified: scummvm/trunk/gui/themes/default-theme.ini
===================================================================
--- scummvm/trunk/gui/themes/default-theme.ini	2006-03-07 04:34:09 UTC (rev 21117)
+++ scummvm/trunk/gui/themes/default-theme.ini	2006-03-07 05:39:52 UTC (rev 21118)
@@ -133,3 +133,21 @@
 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)

Modified: scummvm/trunk/gui/widget.cpp
===================================================================
--- scummvm/trunk/gui/widget.cpp	2006-03-07 04:34:09 UTC (rev 21117)
+++ scummvm/trunk/gui/widget.cpp	2006-03-07 05:39:52 UTC (rev 21118)
@@ -31,6 +31,16 @@
 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 @@
 	_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 @@
 	_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);

Modified: scummvm/trunk/gui/widget.h
===================================================================
--- scummvm/trunk/gui/widget.h	2006-03-07 04:34:09 UTC (rev 21117)
+++ scummvm/trunk/gui/widget.h	2006-03-07 05:39:52 UTC (rev 21118)
@@ -101,8 +101,11 @@
 
 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 @@
 	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 @@
 	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; }


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Scummvm-git-logs mailing list