[Scummvm-cvs-logs] SF.net SVN: scummvm:[33475] scummvm/branches/gsoc2008-gui

Tanoku at users.sourceforge.net Tanoku at users.sourceforge.net
Thu Jul 31 19:23:39 CEST 2008


Revision: 33475
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33475&view=rev
Author:   Tanoku
Date:     2008-07-31 17:23:38 +0000 (Thu, 31 Jul 2008)

Log Message:
-----------
GUI Layout parsing. Work in progress.

Modified Paths:
--------------
    scummvm/branches/gsoc2008-gui/common/xmlparser.cpp
    scummvm/branches/gsoc2008-gui/gui/ThemeDefaultXML.cpp
    scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp
    scummvm/branches/gsoc2008-gui/gui/ThemeParser.h
    scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp
    scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.h

Added Paths:
-----------
    scummvm/branches/gsoc2008-gui/gui/ThemeEval.h

Property Changed:
----------------
    scummvm/branches/gsoc2008-gui/


Property changes on: scummvm/branches/gsoc2008-gui
___________________________________________________________________
Modified: svnmerge-integrated
   - /scummvm/trunk:1-32700
   + /scummvm/trunk:1-33460

Modified: scummvm/branches/gsoc2008-gui/common/xmlparser.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/common/xmlparser.cpp	2008-07-31 15:15:42 UTC (rev 33474)
+++ scummvm/branches/gsoc2008-gui/common/xmlparser.cpp	2008-07-31 17:23:38 UTC (rev 33475)
@@ -41,25 +41,34 @@
 	int lineCount = 1;
 	int lineStart = 0;
 
-	do {
-		if (_text[pos] == '\n' || _text[pos] == '\r') {
-			lineCount++;
-			
-			if (lineStart == 0)
-				lineStart = MAX(pos + 1, _pos - 60);
-		}
-	} while (pos-- > 0);
+	if (_fileName == "Memory Stream") {
+		lineStart = MAX(0, _pos - 35);
+		lineCount = 0;
+	} else {
+		do {
+			if (_text[pos] == '\n' || _text[pos] == '\r') {
+				lineCount++;
+		
+				if (lineStart == 0)
+					lineStart = MAX(pos + 1, _pos - 60);
+			}
+		} while (pos-- > 0);
+	}
 
 	char lineStr[70];
 	_text.stream()->seek(lineStart, SEEK_SET);
 	_text.stream()->readLine(lineStr, 70);
+	
+	for (int i = 0; i < 70; ++i)
+		if (lineStr[i] == '\n')
+			lineStr[i] = ' ';
 
-	printf("  File <%s>, line %d:\n", _fileName.c_str(), lineCount);
+	printf("\n  File <%s>, line %d:\n", _fileName.c_str(), lineCount);
 
 	bool startFull = lineStr[0] == '<';
 	bool endFull = lineStr[strlen(lineStr) - 1] == '>';
 
-	printf("%s%s%s\n", startFull ? "" : "...", endFull ? "" : "...", lineStr);
+	printf("%s%s%s\n", startFull ? "" : "...", lineStr, endFull ? "" : "...");
 
 	int cursor = MIN(_pos - lineStart, 70);
 
@@ -77,7 +86,7 @@
 	vprintf(errorString, args);
 	va_end(args);
 
-	printf("\n");
+	printf("\n\n");
 
 	return false;
 }
@@ -123,9 +132,8 @@
 		return false;
 	}
 	
-	if (closed) {
+	if (closed)
 		delete _activeKey.pop();
-	}
 
 	return true;
 }

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeDefaultXML.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeDefaultXML.cpp	2008-07-31 15:15:42 UTC (rev 33474)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeDefaultXML.cpp	2008-07-31 17:23:38 UTC (rev 33475)
@@ -154,16 +154,29 @@
 "</render_info>"
 
 "<layout_info>"
-	"<definitions>"
-		"<def widgetSize = '30' />"
-		"<def buttonWidth = '120' buttonHeight = '25' />"
-		"<def sliderWidth = '' sliderHeight = '' />"
-		"<def lineHeight = 16 fontHeight = 14 />"
-		"<def />"
-	"</definitions>"
-	"<widgets>"
-		"<widget id = 'scrollbar' />"
-	"</widgets>"
+	"<globals>"
+		"<def var = 'Widget.Size' value = '30' />"
+		"<def var = 'Line.Height' value = '16' />"
+		"<def var = 'Font.Height' value = '16' />"
+		
+		"<widget name = 'Inset' pos = '23, 94' size = '666, 666' />"
+		"<widget name = 'Button' size = '120, 25' />"
+		"<widget name = 'Slider' size = '666, 666' />"
+		
+		"<widget name = 'ListWidget' padding = '7, 5, 5, 5' />"
+		"<widget name = 'PopUpWidget' padding = '7, 5, 0, 0' />"
+		"<widget name = 'EditTextWidget' padding = '7, 5, 0, 0' />"
+		"<widget name = 'Console' padding = '7, 5, 5, 5' />"
+		
+		"<widget name = 'TabWidget'>"
+			"<child name = 'Tab' size = '75, 27' />"
+			"<child name = 'NavButton' size = '15, 18' padding = '0, 3, 4, 0' />"
+		"</widget>"
+	"</globals>"
+	
+	"<dialog name = 'GlobalOptions'>"
+		"<widget name = 'scrollbar' />"
+	"</dialog>"
 "</layout_info>";
 
 	if (!parser()->loadBuffer((const byte*)defaultXML, strlen(defaultXML), false))

Added: scummvm/branches/gsoc2008-gui/gui/ThemeEval.h
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeEval.h	                        (rev 0)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeEval.h	2008-07-31 17:23:38 UTC (rev 33475)
@@ -0,0 +1,81 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef GUI_THEME_EVAL
+#define GUI_THEME_EVAL
+
+#include "common/util.h"
+#include "common/system.h"
+#include "common/events.h"
+#include "common/hashmap.h"
+#include "common/hash-str.h"
+#include "common/xmlparser.h"
+
+#include "gui/ThemeRenderer.h"
+#include "gui/ThemeParser.h"
+#include "gui/ThemeEval.h"
+
+namespace GUI {
+	
+class ThemeEval {
+
+	typedef Common::HashMap<Common::String, int> VariablesMap;
+	
+public:
+	ThemeEval() {}
+	~ThemeEval() {}
+	
+	int getVar(const Common::String &s) {
+		if (!_vars.contains(s)) {
+			warning("Missing variable: '%s'", s.c_str());
+			return -1;
+		} 
+		
+		return _vars[s];
+	}
+	
+	int getVar(const Common::String &s, int def) {
+		return (_vars.contains(s)) ? _vars[s] : def;
+	}
+	
+	void setVar(const String &name, int val) { _vars[name] = val; }
+	
+	void debugPrint() {
+		printf("Debug variable list:\n");
+		
+		VariablesMap::const_iterator i;
+		for (i = _vars.begin(); i != _vars.end(); ++i) {
+			printf("  '%s' = %d\n", i->_key.c_str(), i->_value);
+		}
+	}
+	
+private:
+	VariablesMap _vars;
+};
+
+
+}
+
+#endif


Property changes on: scummvm/branches/gsoc2008-gui/gui/ThemeEval.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp	2008-07-31 15:15:42 UTC (rev 33474)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp	2008-07-31 17:23:38 UTC (rev 33475)
@@ -433,5 +433,55 @@
 	return true;
 }
 
+bool ThemeParser::parserCallback_def(ParserNode *node) {
+	Common::String var = "Globals." + node->values["var"];
+	int value;
+	
+	if (!parseIntegerKey(node->values["value"].c_str(), 1, &value))
+		return parserError("Invalid definition for '%s'.", var.c_str());
+		
+	_theme->themeEval()->setVar(var, value);
+	return true;	
 }
 
+bool ThemeParser::parserCallback_widget(ParserNode *node) {
+	Common::String var;
+	int width, height, x, y, paddingL, paddingR, paddingT, paddingB;
+	
+	if (getParentNode(node)->name == "globals")
+		var = "Globals." + node->values["name"] + ".";
+	else if (getParentNode(node)->name == "dialog")
+		var = "Dialog." + getParentNode(node)->values["name"] + "." + node->values["name"] + ".";
+	else 
+		assert(!"Corruption in XML parser.");
+	
+	if (node->values.contains("size")) {
+		if (!parseIntegerKey(node->values["size"].c_str(), 2, &width, &height))
+			return parserError("Invalid definition for '%sSize'.", var.c_str());
+		
+		_theme->themeEval()->setVar(var + "Width", width);
+		_theme->themeEval()->setVar(var + "Height", height);
+	}
+	
+	if (node->values.contains("pos")) {
+		if (!parseIntegerKey(node->values["pos"].c_str(), 2, &x, &y))
+			return parserError("Invalid definition for '%sPosition'.", var.c_str());
+		
+		_theme->themeEval()->setVar(var + "X", x);
+		_theme->themeEval()->setVar(var + "Y", y);
+	}
+	
+	if (node->values.contains("padding")) {
+		if (!parseIntegerKey(node->values["padding"].c_str(), 4, &paddingL, &paddingR, &paddingT, &paddingB))
+			return parserError("Invalid definition for '%sPadding'.", var.c_str());
+		
+		_theme->themeEval()->setVar(var + "Padding.Left", paddingL);
+		_theme->themeEval()->setVar(var + "Padding.Right", paddingR);
+		_theme->themeEval()->setVar(var + "Padding.Top", paddingT);
+		_theme->themeEval()->setVar(var + "Padding.Bottom", paddingB);
+	}
+	
+	return true;
+}
+
+}
\ No newline at end of file

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeParser.h
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeParser.h	2008-07-31 15:15:42 UTC (rev 33474)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeParser.h	2008-07-31 17:23:38 UTC (rev 33475)
@@ -406,21 +406,63 @@
 		KEY_END() // render_info end
 
 		XML_KEY(layout_info)
-		KEY_END()
+			XML_KEY(globals)
+				XML_PROP(resolution, false)
+				XML_KEY(def)
+					XML_PROP(var, true)
+					XML_PROP(value, true)
+				KEY_END()
+				
+				XML_KEY(widget)
+					XML_PROP(name, true)
+					XML_PROP(size, false)
+					XML_PROP(pos, false)
+					XML_PROP(padding, false)
+					
+					XML_KEY(child)
+						XML_PROP(name, true)
+						XML_PROP(size, false)
+						XML_PROP(padding, false)
+					KEY_END()
+				KEY_END()
+			KEY_END()
+			
+			XML_KEY(dialog)
+				XML_PROP(name, true)
+				XML_PROP(size, false)
+				XML_PROP(pos, false)
+				XML_PROP(resolution, false)
+				
+				XML_KEY(widget)
+					XML_PROP(name, true)
+					XML_PROP(size, false)
+					XML_PROP(pos, false)
+					XML_PROP(padding, false)
+				KEY_END()
+			KEY_END()
+		KEY_END() 
 		
 	} PARSER_END();
 	
+	/** Render info callbacks */
+	bool parserCallback_render_info(ParserNode *node);
 	bool parserCallback_defaults(ParserNode *node);
 	bool parserCallback_font(ParserNode *node);
 	bool parserCallback_fonts(ParserNode *node);
 	bool parserCallback_text(ParserNode *node);
-	bool parserCallback_render_info(ParserNode *node);
-	bool parserCallback_layout_info(ParserNode *node);
 	bool parserCallback_palette(ParserNode *node);
 	bool parserCallback_color(ParserNode *node);
 	bool parserCallback_drawstep(ParserNode *node);
 	bool parserCallback_drawdata(ParserNode *node);
 	
+	/** Layout info callbacks */
+	bool parserCallback_layout_info(ParserNode *node);
+	bool parserCallback_globals(ParserNode *node) { return true; }
+	bool parserCallback_def(ParserNode *node);
+	bool parserCallback_widget(ParserNode *node);
+	bool parserCallback_dialog(ParserNode *node) { return true; }
+	bool parserCallback_child(ParserNode *node) { return true; }
+	
 	void cleanup();
 
 	Graphics::DrawStep *newDrawStep();

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp	2008-07-31 15:15:42 UTC (rev 33474)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp	2008-07-31 17:23:38 UTC (rev 33475)
@@ -33,6 +33,7 @@
 #include "gui/launcher.h"
 
 #include "gui/ThemeRenderer.h"
+#include "gui/ThemeEval.h"
 #include "graphics/VectorRenderer.h"
 
 namespace GUI {
@@ -92,6 +93,7 @@
 	_themeOk(false), _enabled(false), _buffering(false) {
 	_system = g_system;
 	_parser = new ThemeParser(this);
+	_themeEval = new GUI::ThemeEval();
 
 	for (int i = 0; i < kDrawDataMAX; ++i) {
 		_widgets[i] = 0;
@@ -284,6 +286,9 @@
 		}
 	}
 	
+	// Debug print all the parsed variables. remove
+	_themeEval->debugPrint();
+	
 	_themeOk = true;
 	return true;
 }

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.h
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.h	2008-07-31 15:15:42 UTC (rev 33474)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.h	2008-07-31 17:23:38 UTC (rev 33475)
@@ -35,6 +35,7 @@
 
 #include "gui/dialog.h"
 #include "gui/ThemeParser.h"
+#include "gui/ThemeEval.h"
 #include "graphics/VectorRenderer.h"
 
 namespace GUI {
@@ -208,6 +209,8 @@
 		unloadTheme();
 		delete _parser;
 	}
+	
+	GUI::ThemeEval *themeEval() { return _themeEval; }
 
 	/**
 	 *	VIRTUAL METHODS
@@ -585,6 +588,9 @@
 	
 	/** XML Parser, does the Theme parsing instead of the default parser */
 	GUI::ThemeParser *_parser;
+	
+	/** Theme evaluator (changed from GUI::Eval to add functionality) */
+	GUI::ThemeEval *_themeEval;
 
 	/** Main screen surface. This is blitted straight into the overlay. */
 	Graphics::Surface *_screen;


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