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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sun Jan 18 15:48:00 CET 2009


Revision: 35898
          http://scummvm.svn.sourceforge.net/scummvm/?rev=35898&view=rev
Author:   fingolfin
Date:     2009-01-18 14:48:00 +0000 (Sun, 18 Jan 2009)

Log Message:
-----------
GUI: Some cleanup and renaming; moved some parsing code from ThemeEngine to ThemeParser

Modified Paths:
--------------
    scummvm/trunk/gui/ThemeEngine.cpp
    scummvm/trunk/gui/ThemeEngine.h
    scummvm/trunk/gui/ThemeParser.cpp

Modified: scummvm/trunk/gui/ThemeEngine.cpp
===================================================================
--- scummvm/trunk/gui/ThemeEngine.cpp	2009-01-18 14:46:53 UTC (rev 35897)
+++ scummvm/trunk/gui/ThemeEngine.cpp	2009-01-18 14:48:00 UTC (rev 35898)
@@ -62,7 +62,7 @@
 	/** List of all the steps needed to draw this widget */
 	Common::List<Graphics::DrawStep> _steps;
 
-	int _textDataId;
+	TextData _textDataId;
 	Graphics::TextAlign _textAlignH;
 	GUI::ThemeEngine::TextAlignVertical _textAlignV;
 
@@ -72,6 +72,16 @@
 	uint16 _backgroundOffset;
 
 	bool _buffer;
+
+
+	/**
+	 *	Calculates the background threshold offset of a given DrawData item.
+	 *	After fully loading all DrawSteps of a DrawData item, this function must be
+	 *	called in order to calculate if such draw steps would be drawn outside of
+	 *	the actual widget drawing zone (e.g. shadows). If this is the case, a constant
+	 *	value will be added when restoring the background of the widget.
+	 */
+	void calcBackgroundOffset();
 };
 
 class ThemeItem {
@@ -191,22 +201,7 @@
 	{kDDSeparator,					"separator",	true,	kDDNone},
 };
 
-struct TextDataInfo {
-	TextData id;
-	const char *name;
-};
 
-static const TextDataInfo kTextDataDefaults[] = {
-	{kTextDataDefault,		"text_default"},
-	{kTextDataHover,		"text_hover"},
-	{kTextDataDisabled,		"text_disabled"},
-	{kTextDataInverted,		"text_inverted"},
-	{kTextDataButton,		"text_button"},
-	{kTextDataButtonHover,	"text_button_hover"},
-	{kTextDataNormalFont,	"text_normal"}
-};
-
-
 /**********************************************************
  *	ThemeItem functions for drawing queues.
  *********************************************************/
@@ -486,10 +481,10 @@
 	_vectorRenderer->setSurface(&_screen);
 }
 
-void ThemeEngine::calcBackgroundOffset(DrawData type) {
+void WidgetDrawData::calcBackgroundOffset() {
 	uint maxShadow = 0;
-	for (Common::List<Graphics::DrawStep>::const_iterator step = _widgets[type]->_steps.begin();
-		step != _widgets[type]->_steps.end(); ++step) {
+	for (Common::List<Graphics::DrawStep>::const_iterator step = _steps.begin();
+		step != _steps.end(); ++step) {
 		if ((step->autoWidth || step->autoHeight) && step->shadow > maxShadow)
 			maxShadow = step->shadow;
 
@@ -497,7 +492,7 @@
 			maxShadow = step->bevel;
 	}
 
-	_widgets[type]->_backgroundOffset = maxShadow;
+	_backgroundOffset = maxShadow;
 }
 
 void ThemeEngine::restoreBackground(Common::Rect r) {
@@ -511,15 +506,14 @@
  *	Theme elements management
  *********************************************************/
 void ThemeEngine::addDrawStep(const Common::String &drawDataId, const Graphics::DrawStep &step) {
-	DrawData id = getDrawDataId(drawDataId);
+	DrawData id = parseDrawDataId(drawDataId);
 
 	assert(_widgets[id] != 0);
 	_widgets[id]->_steps.push_back(step);
 }
 
-bool ThemeEngine::addTextData(const Common::String &drawDataId, const Common::String &textDataId, Graphics::TextAlign alignH, TextAlignVertical alignV) {
-	DrawData id = getDrawDataId(drawDataId);
-	TextData textId = getTextDataId(textDataId);
+bool ThemeEngine::addTextData(const Common::String &drawDataId, TextData textId, Graphics::TextAlign alignH, TextAlignVertical alignV) {
+	DrawData id = parseDrawDataId(drawDataId);
 
 	if (id == -1 || textId == -1 || !_widgets[id])
 		return false;
@@ -531,9 +525,7 @@
 	return true;
 }
 
-bool ThemeEngine::addFont(const Common::String &fontId, const Common::String &file, int r, int g, int b) {
-	TextData textId = getTextDataId(fontId);
-
+bool ThemeEngine::addFont(TextData textId, const Common::String &file, int r, int g, int b) {
 	if (textId == -1)
 		return false;
 
@@ -551,7 +543,7 @@
 			_texts[textId]->_fontPtr = loadFont(file);
 
 			if (!_texts[textId]->_fontPtr)
-				error("Couldn't load %s font '%s'", fontId.c_str(), file.c_str());
+				error("Couldn't load font '%s'", file.c_str());
 
 			FontMan.assignFontToName(file, _texts[textId]->_fontPtr);
 		}
@@ -587,17 +579,17 @@
 }
 
 bool ThemeEngine::addDrawData(const Common::String &data, bool cached) {
-	DrawData data_id = getDrawDataId(data);
+	DrawData id = parseDrawDataId(data);
 
-	if (data_id == -1)
+	if (id == -1)
 		return false;
 
-	if (_widgets[data_id] != 0)
-		delete _widgets[data_id];
+	if (_widgets[id] != 0)
+		delete _widgets[id];
 
-	_widgets[data_id] = new WidgetDrawData;
-	_widgets[data_id]->_buffer = kDrawDataDefaults[data_id].buffer;
-	_widgets[data_id]->_textDataId = -1;
+	_widgets[id] = new WidgetDrawData;
+	_widgets[id]->_buffer = kDrawDataDefaults[id].buffer;
+	_widgets[id]->_textDataId = kTextDataNone;
 
 	return true;
 }
@@ -625,7 +617,7 @@
 		if (_widgets[i] == 0) {
 			warning("Missing data asset: '%s'", kDrawDataDefaults[i].name);
 		} else {
-			calcBackgroundOffset((DrawData)i);
+			_widgets[i]->calcBackgroundOffset();
 		}
 	}
 }
@@ -1221,7 +1213,7 @@
 }
 
 
-DrawData ThemeEngine::getDrawDataId(const Common::String &name) const {
+DrawData ThemeEngine::parseDrawDataId(const Common::String &name) const {
 	for (int i = 0; i < kDrawDataMAX; ++i)
 		if (name.compareToIgnoreCase(kDrawDataDefaults[i].name) == 0)
 			return kDrawDataDefaults[i].id;
@@ -1229,14 +1221,6 @@
 	return kDDNone;
 }
 
-TextData ThemeEngine::getTextDataId(const Common::String &name) const {
-	for (int i = 0; i < kTextDataMAX; ++i)
-		if (name.compareToIgnoreCase(kTextDataDefaults[i].name) == 0)
-			return kTextDataDefaults[i].id;
-
-	return kTextDataNone;
-}
-
 /**********************************************************
  *	External data loading
  *********************************************************/

Modified: scummvm/trunk/gui/ThemeEngine.h
===================================================================
--- scummvm/trunk/gui/ThemeEngine.h	2009-01-18 14:46:53 UTC (rev 35897)
+++ scummvm/trunk/gui/ThemeEngine.h	2009-01-18 14:48:00 UTC (rev 35898)
@@ -100,6 +100,7 @@
 	kDDNone = -1
 };
 
+// FIXME: TextData is really a bad name, not conveying what this enum is about.
 enum TextData {
 	kTextDataNone = -1,
 	kTextDataDefault = 0,
@@ -334,10 +335,8 @@
 	 *	@param name The representing name, as found on Theme Description XML files.
 	 *	@see kDrawDataDefaults[]
 	 */
-	DrawData getDrawDataId(const Common::String &name) const;
+	DrawData parseDrawDataId(const Common::String &name) const;
 
-	TextData getTextDataId(const Common::String &name) const;
-
 	TextData getTextData(DrawData ddId) const;
 
 
@@ -372,7 +371,7 @@
 	 *	@param file Name of the font file.
 	 *	@param r, g, b Color of the font.
 	 */
-	bool addFont(const Common::String &fontName, const Common::String &file, int r, int g, int b);
+	bool addFont(TextData textId, const Common::String &file, int r, int g, int b);
 
 
 	/**
@@ -385,9 +384,9 @@
 
 	/**
 	 *	Adds a new TextStep from the ThemeParser. This will be deprecated/removed once the
-	 *	new Font API is in place.
+	 *	new Font API is in place. FIXME: Is that so ???
 	 */
-	bool addTextData(const Common::String &drawDataId, const Common::String &textDataId, Graphics::TextAlign alignH, TextAlignVertical alignV);
+	bool addTextData(const Common::String &drawDataId, TextData textId, Graphics::TextAlign alignH, TextAlignVertical alignV);
 
 protected:
 	/**
@@ -504,17 +503,6 @@
 	void renderDirtyScreen();
 
 	/**
-	 *	Calculates the background threshold offset of a given DrawData item.
-	 *	After fully loading all DrawSteps of a DrawData item, this function must be
-	 *	called in order to calculate if such draw steps would be drawn outside of
-	 *	the actual widget drawing zone (e.g. shadows). If this is the case, a constant
-	 *	value will be added when restoring the background of the widget.
-	 *
-	 *	@param type DrawData type of the widget.
-	 */
-	void calcBackgroundOffset(DrawData type);
-
-	/**
 	 *	Generates a DrawQueue item and enqueues it so it's drawn to the screen
 	 *	when the drawing queue is processed.
 	 *

Modified: scummvm/trunk/gui/ThemeParser.cpp
===================================================================
--- scummvm/trunk/gui/ThemeParser.cpp	2009-01-18 14:46:53 UTC (rev 35897)
+++ scummvm/trunk/gui/ThemeParser.cpp	2009-01-18 14:48:00 UTC (rev 35898)
@@ -38,6 +38,31 @@
 
 namespace GUI {
 
+struct TextDataInfo {
+	TextData id;
+	const char *name;
+};
+
+static const TextDataInfo kTextDataDefaults[] = {
+	{kTextDataDefault,		"text_default"},
+	{kTextDataHover,		"text_hover"},
+	{kTextDataDisabled,		"text_disabled"},
+	{kTextDataInverted,		"text_inverted"},
+	{kTextDataButton,		"text_button"},
+	{kTextDataButtonHover,	"text_button_hover"},
+	{kTextDataNormalFont,	"text_normal"}
+};
+
+
+static TextData parseTextDataId(const Common::String &name) {
+	for (int i = 0; i < kTextDataMAX; ++i)
+		if (name.compareToIgnoreCase(kTextDataDefaults[i].name) == 0)
+			return kTextDataDefaults[i].id;
+
+	return kTextDataNone;
+}
+
+
 ThemeParser::ThemeParser(ThemeEngine *parent) : XMLParser() {
 
 	_drawFunctions["circle"]  = &Graphics::VectorRenderer::drawCallback_CIRCLE;
@@ -134,7 +159,8 @@
 	else if (!parseIntegerKey(node->values["color"].c_str(), 3, &red, &green, &blue))
 		return parserError("Error parsing color value for font definition.");
 
-	if (!_theme->addFont(node->values["id"], node->values["file"], red, green, blue))
+	TextData textDataId = parseTextDataId(node->values["id"]);
+	if (!_theme->addFont(textDataId, node->values["file"], red, green, blue))
 		return parserError("Error loading Font in theme engine.");
 
 	return true;
@@ -186,7 +212,8 @@
 		alignH = Graphics::kTextAlignRight;
 	else if (node->values["horizontal_align"] == "center")
 		alignH = Graphics::kTextAlignCenter;
-	else return parserError("Invalid value for text alignment.");
+	else
+		return parserError("Invalid value for text alignment.");
 
 	if (node->values["vertical_align"] == "top")
 		alignV = GUI::ThemeEngine::kTextAlignVTop;
@@ -194,11 +221,15 @@
 		alignV = GUI::ThemeEngine::kTextAlignVCenter;
 	else if (node->values["vertical_align"] == "bottom")
 		alignV = GUI::ThemeEngine::kTextAlignVBottom;
-	else return parserError("Invalid value for text alignment.");
+	else
+		return parserError("Invalid value for text alignment.");
 
-	if (!_theme->addTextData(getParentNode(node)->values["id"], node->values["font"], alignH, alignV))
-		return parserError("Error adding Text Data for '%s'.", getParentNode(node)->values["id"].c_str());
+	Common::String id = getParentNode(node)->values["id"];
+	TextData textDataId = parseTextDataId(node->values["font"]);
 
+	if (!_theme->addTextData(id, textDataId, alignH, alignV))
+		return parserError("Error adding Text Data for '%s'.", id.c_str());
+
 	return true;
 }
 
@@ -506,6 +537,7 @@
 			return parserError("Error parsing Layout properties of '%s'.", var.c_str());
 
 	} else {
+		// FIXME: Shouldn't we distinguish the name/id and the label of a widget?
 		var = node->values["name"];
 		int width = -1;
 		int height = -1;


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