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

Tanoku at users.sourceforge.net Tanoku at users.sourceforge.net
Thu Jun 26 15:50:17 CEST 2008


Revision: 32800
          http://scummvm.svn.sourceforge.net/scummvm/?rev=32800&view=rev
Author:   Tanoku
Date:     2008-06-26 06:50:16 -0700 (Thu, 26 Jun 2008)

Log Message:
-----------
InterfaceManager now loads themes.

Modified Paths:
--------------
    scummvm/branches/gsoc2008-gui/base/main.cpp
    scummvm/branches/gsoc2008-gui/common/xmlparser.cpp
    scummvm/branches/gsoc2008-gui/common/xmlparser.h
    scummvm/branches/gsoc2008-gui/dists/msvc9/scummvm.vcproj
    scummvm/branches/gsoc2008-gui/gui/InterfaceManager.cpp
    scummvm/branches/gsoc2008-gui/gui/InterfaceManager.h
    scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp
    scummvm/branches/gsoc2008-gui/gui/ThemeParser.h
    scummvm/branches/gsoc2008-gui/gui/module.mk

Added Paths:
-----------
    scummvm/branches/gsoc2008-gui/gui/ThemeDefaultXML.cpp

Modified: scummvm/branches/gsoc2008-gui/base/main.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/base/main.cpp	2008-06-26 10:12:47 UTC (rev 32799)
+++ scummvm/branches/gsoc2008-gui/base/main.cpp	2008-06-26 13:50:16 UTC (rev 32800)
@@ -72,8 +72,6 @@
 
 #if 1
 
-	GUI::ThemeParser parser;
-	parser.debug_testEval();
 	g_InterfaceManager.runGUI();
 	return true;
 

Modified: scummvm/branches/gsoc2008-gui/common/xmlparser.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/common/xmlparser.cpp	2008-06-26 10:12:47 UTC (rev 32799)
+++ scummvm/branches/gsoc2008-gui/common/xmlparser.cpp	2008-06-26 13:50:16 UTC (rev 32800)
@@ -34,25 +34,6 @@
 
 using namespace Graphics;
 
-void XMLParser::debug_testEval() {
-	static const char *debugConfigText =
-		"<render_info>\n"
-		"<palette>\n"
-		"<color name = \"red\" rgb = \"255, 255, 255\"/>\n"
-		"</palette>\n"
-		"<drawdata id = \"mainmenu_bg\" cache = true>\n"
-		"<drawstep func = \"roundedsq\" radius = 23 fill = \"none\" color = \"0, 1, 2\" size = \"auto\" />\n"
-		"<drawstep func = \"roundedsq\" radius = 15 fill = \"none\" color = \"red\" size = \"auto\"/>\n"
-		"</drawdata>/* lol this is just a simple test*/\n"
-		"</render_info>";
-
-	loadBuffer(debugConfigText);
-	_fileName = "test_parse.xml";
-
-	parse();
-}
-
-
 bool XMLParser::parserError(const char *errorString, ...) {
 	_state = kParserError;
 

Modified: scummvm/branches/gsoc2008-gui/common/xmlparser.h
===================================================================
--- scummvm/branches/gsoc2008-gui/common/xmlparser.h	2008-06-26 10:12:47 UTC (rev 32799)
+++ scummvm/branches/gsoc2008-gui/common/xmlparser.h	2008-06-26 13:50:16 UTC (rev 32800)
@@ -120,23 +120,45 @@
 		int depth;
 	};
 
+	/**
+	 * Loads a file into the parser.
+	 * Used for the loading of Theme Description files
+	 * straight from the filesystem.
+	 *
+	 * @param filename Name of the file to load.
+	 */
 	virtual bool loadFile(Common::String filename) {
 		Common::File *f = new Common::File;
 
 		if (!f->open(filename, Common::File::kFileReadMode))
 			return false;
 
+		_fileName = filename;
 		_text.loadStream(f);
 		return true;
 	}
 
+	/**
+	 * Loads a memory buffer into the parser.
+	 * Used for loading the default theme fallback directly
+	 * from memory if no themes can be found.
+	 *
+	 * @param buffer Pointer to the buffer.
+	 * @param disposable Sets if the XMLParser owns the buffer,
+	 *                   i.e. if it can be freed safely after it's
+	 *                   no longer needed by the parser.
+	 */
 	virtual bool loadBuffer(const char *buffer, bool disposable = false) {
 		_text.loadStream(new MemoryReadStream((const byte*)buffer, strlen(buffer), disposable));
+		_fileName = "Memory Stream";
 		return true;
 	}
 
+	/**
+	 * The actual parsing function.
+	 * Parses the loaded data stream, returns true if successful.
+	 */
 	virtual bool parse();
-	void debug_testEval();
 
 	/**
 	 * Returns the active node being parsed (the one on top of

Modified: scummvm/branches/gsoc2008-gui/dists/msvc9/scummvm.vcproj
===================================================================
--- scummvm/branches/gsoc2008-gui/dists/msvc9/scummvm.vcproj	2008-06-26 10:12:47 UTC (rev 32799)
+++ scummvm/branches/gsoc2008-gui/dists/msvc9/scummvm.vcproj	2008-06-26 13:50:16 UTC (rev 32800)
@@ -1225,19 +1225,16 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\gui\ThemeDefaultXML.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\..\gui\ThemeModern.cpp"
 				>
 			</File>
 			<File
 				RelativePath="..\..\gui\ThemeParser.cpp"
 				>
-				<FileConfiguration
-					Name="Debug|Win32"
-					>
-					<Tool
-						Name="VCCLCompilerTool"
-					/>
-				</FileConfiguration>
 			</File>
 			<File
 				RelativePath="..\..\gui\ThemeParser.h"

Modified: scummvm/branches/gsoc2008-gui/gui/InterfaceManager.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/InterfaceManager.cpp	2008-06-26 10:12:47 UTC (rev 32799)
+++ scummvm/branches/gsoc2008-gui/gui/InterfaceManager.cpp	2008-06-26 13:50:16 UTC (rev 32800)
@@ -132,10 +132,12 @@
 	return true;
 }
 
-bool InterfaceManager::loadTheme(Common::String &themeName) {
+bool InterfaceManager::loadTheme(Common::String themeName) {
 	if (!loadThemeXML(themeName)) {
-		warning("Could not parse custom theme '%s'.", themeName.c_str());
-		return false;
+		warning("Could not parse custom theme '%s'.\nFalling back to default theme", themeName.c_str());
+		
+		if (!loadDefaultXML()) // if we can't load the embeded theme, this is a complete failure
+			error("Could not load default embeded theme.");
 	}
 
 	for (int i = 0; i < kDrawDataMAX; ++i) {
@@ -153,7 +155,7 @@
 	return true;
 }
 
-bool InterfaceManager::loadThemeXML(Common::String &themeName) {
+bool InterfaceManager::loadThemeXML(Common::String themeName) {
 	assert(_parser);
 
 	if (ConfMan.hasKey("themepath"))
@@ -254,57 +256,28 @@
 
 int InterfaceManager::runGUI() {
 	Common::EventManager *eventMan = _system->getEventManager();
+
+	loadTheme("modern_theme.xml");
+
 	_system->showOverlay();
 
-	Graphics::DrawStep *steps = new Graphics::DrawStep[5];
+	Graphics::DrawStep *steps = new Graphics::DrawStep[2];
 
 	steps[0].gradColor1.r = 214;
 	steps[0].gradColor1.g = 113;
 	steps[0].gradColor1.b = 8;
+	steps[0].gradColor1.set = true;
 	steps[0].gradColor2.r = 240;
 	steps[0].gradColor2.g = 200;
 	steps[0].gradColor2.b = 25;
+	steps[0].gradColor2.set = true;
 	steps[0].fillMode = VectorRenderer::kFillGradient;
 	steps[0].drawingCall = &VectorRenderer::drawCallback_FILLSURFACE;
 
-	steps[1].gradColor1.r = 206;
-	steps[1].gradColor1.g = 121;
-	steps[1].gradColor1.b = 99;
-	steps[1].gradColor2.r = 173;
-	steps[1].gradColor2.g = 40;
-	steps[1].gradColor2.b = 8;
-	steps[1].radius = 8; // radius
-	steps[1].fillArea = true;
-	steps[1].drawingCall = &VectorRenderer::drawCallback_ROUNDSQ;
-	steps[1].scale = (1 << 16);
-
-	steps[2].radius = 8; // radius
-	steps[2].fillArea = false;
-	steps[2].x.relative = true;
-	steps[2].x.pos = 32;
-	steps[2].y.relative = false;
-	steps[2].y.pos = 32;
-	steps[2].w = 128;
-	steps[2].h = 32;
-	steps[2].drawingCall = &VectorRenderer::drawCallback_ROUNDSQ;
-	steps[2].scale = (1 << 16);
-
-	steps[3].fgColor.r = 255;
-	steps[3].fgColor.g = 255;
-	steps[3].fgColor.b = 255;
-	steps[3].drawingCall = &VectorRenderer::drawCallback_VOID;
-
-	Common::Rect area = Common::Rect(32, 32, 256, 256);
-
 	bool running = true;
 	while (running) { // draw!!
 
 		_vectorRenderer->drawStep(Common::Rect(), steps[0]);
-		_vectorRenderer->drawStep(Common::Rect(), steps[3]);
-		_vectorRenderer->drawStep(area, steps[1]);
-		_vectorRenderer->drawStep(area, steps[2]);
-//		_vectorRenderer->drawStep(Common::Rect(32, 32, 256, 256), &steps[3]);
-
 		_vectorRenderer->copyFrame(_system);
 
 		Common::Event event;

Modified: scummvm/branches/gsoc2008-gui/gui/InterfaceManager.h
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/InterfaceManager.h	2008-06-26 10:12:47 UTC (rev 32799)
+++ scummvm/branches/gsoc2008-gui/gui/InterfaceManager.h	2008-06-26 13:50:16 UTC (rev 32800)
@@ -190,12 +190,13 @@
 		return _initOk && _themeOk;
 	}
 
-	bool loadTheme(Common::String &themeName);
+	bool loadTheme(Common::String themeName);
 
 protected:
 	template<typename PixelType> void screenInit();
 
-	bool loadThemeXML(Common::String &themeName);
+	bool loadThemeXML(Common::String themeName);
+	bool loadDefaultXML();
 
 	void freeRenderer() {
 		delete _vectorRenderer;
@@ -232,6 +233,8 @@
 	bool _initOk;
 	bool _themeOk;
 	bool _caching;
+
+	static const char *_defaultXML;
 };
 
 struct WidgetDrawData {

Added: scummvm/branches/gsoc2008-gui/gui/ThemeDefaultXML.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeDefaultXML.cpp	                        (rev 0)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeDefaultXML.cpp	2008-06-26 13:50:16 UTC (rev 32800)
@@ -0,0 +1,57 @@
+/* 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$
+ *
+ */
+
+#include "common/system.h"
+#include "gui/InterfaceManager.h"
+
+namespace GUI {
+
+bool InterfaceManager::loadDefaultXML() {
+	const char *defaultXML =
+/**
+ * Default theme description file. Work in progress.
+ * Newlines are not necessary, parser ignores them.
+ * You may use single quotes (') instead of scaped double quotes.
+ * Remember to indent properly the XML so it's easier to read and
+ * to maintain!
+ */
+"<render_info>"
+	"<palette>"
+		"<color name = 'red' rgb = '255, 0, 0' />"
+		"<color name = 'green' rgb = '0, 255, 0' />"
+		"<color name = 'blue' rgb = '0, 0, 255' />"
+	"</palette>"
+	"<drawdata id = 'mainmenu_bg' cache = false>"
+		"<drawstep func = 'roundedsq' radius = 8 fill = 'none' color = '0, 1, 2' size = 'auto' />"
+	"</drawdata>"
+"</render_info>";
+
+	if (!parser()->loadBuffer(defaultXML, true))
+		return false;
+
+	return parser()->parse();
+}
+
+}


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

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp	2008-06-26 10:12:47 UTC (rev 32799)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp	2008-06-26 13:50:16 UTC (rev 32800)
@@ -45,6 +45,7 @@
 	_callbacks["palette"] = &ThemeParser::parserCallback_palette;
 	_callbacks["color"] = &ThemeParser::parserCallback_color;
 	_callbacks["render_info"] = &ThemeParser::parserCallback_renderInfo;
+	_callbacks["layout_info"] = &ThemeParser::parserCallback_layoutInfo;
 
 	_drawFunctions["circle"]  = &Graphics::VectorRenderer::drawCallback_CIRCLE;
 	_drawFunctions["square"]  = &Graphics::VectorRenderer::drawCallback_SQUARE;
@@ -97,6 +98,17 @@
 	return true;
 }
 
+bool ThemeParser::parserCallback_layoutInfo() {
+	ParserNode *layoutNode = getActiveNode();
+
+	assert(layoutNode->name == "layout_info");
+
+	if (getParentNode(layoutNode) != 0)
+		return parserError("<layout_info> keys must be root elements.");
+
+	return true;
+}
+
 bool ThemeParser::parserCallback_palette() {
 	ParserNode *paletteNode = getActiveNode();
 

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeParser.h
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeParser.h	2008-06-26 10:12:47 UTC (rev 32799)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeParser.h	2008-06-26 13:50:16 UTC (rev 32800)
@@ -323,6 +323,8 @@
 	bool parserCallback_palette();
 	bool parserCallback_color();
 	bool parserCallback_renderInfo();
+	bool parserCallback_layoutInfo();
+		
 
 	bool validateKeyIntSigned(const char *key) {
 		if (!isdigit(*key) && *key != '+' && *key != '-')

Modified: scummvm/branches/gsoc2008-gui/gui/module.mk
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/module.mk	2008-06-26 10:12:47 UTC (rev 32799)
+++ scummvm/branches/gsoc2008-gui/gui/module.mk	2008-06-26 13:50:16 UTC (rev 32800)
@@ -25,6 +25,7 @@
 	widget.o \
 	theme.o \
 	ThemeClassic.o \
+	ThemeDefaultXML.o \
 	ThemeModern.o \
 	ThemeParser.o \
 	theme-config.o


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