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

Tanoku at users.sourceforge.net Tanoku at users.sourceforge.net
Thu Jul 10 17:50:44 CEST 2008


Revision: 32991
          http://scummvm.svn.sourceforge.net/scummvm/?rev=32991&view=rev
Author:   Tanoku
Date:     2008-07-10 08:50:44 -0700 (Thu, 10 Jul 2008)

Log Message:
-----------
Added support for Text Steps in the Vector Renderer.

Modified Paths:
--------------
    scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.cpp
    scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.h
    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

Modified: scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.cpp	2008-07-10 12:14:00 UTC (rev 32990)
+++ scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.cpp	2008-07-10 15:50:44 UTC (rev 32991)
@@ -71,6 +71,14 @@
 	(this->*(step.drawingCall))(area, step);	
 }
 
+void VectorRenderer::textStep(const Common::String &text, const Common::Rect &area, const TextStep &step) {
+	if (step.color.set)
+		setFgColor(step.color.r, step.color.g, step.color.b);
+		
+	assert(step.font);
+	drawString(step.font, text.c_str(), area, step.align);
+}
+
 /********************************************************************
  * MISCELANEOUS functions
  ********************************************************************/
@@ -176,6 +184,12 @@
 /********************************************************************
  * Primitive shapes drawing - Public API calls - VectorRendererSpec
  ********************************************************************/
+template <typename PixelType, typename PixelFormat>
+void VectorRendererSpec<PixelType, PixelFormat>::
+drawString(Graphics::Font *font, const Common::String &text, const Common::Rect &area, GUI::Theme::TextAlign align) {
+	font->drawString(_activeSurface, text, area.left, area.top, area.width(), _fgColor, (Graphics::TextAlignment)align, 0, false);
+}
+
 /** LINES **/
 template<typename PixelType, typename PixelFormat>
 void VectorRendererSpec<PixelType, PixelFormat>::

Modified: scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.h
===================================================================
--- scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.h	2008-07-10 12:14:00 UTC (rev 32990)
+++ scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.h	2008-07-10 15:50:44 UTC (rev 32991)
@@ -47,6 +47,8 @@
 	color; /** text color */
 
 	GUI::Theme::TextAlign align;
+	char *text;
+	Graphics::Font *font;
 };
 
 struct DrawStep {
@@ -426,6 +428,7 @@
 	 * @param step Pointer to a DrawStep struct.
 	 */
 	virtual void drawStep(const Common::Rect &area, const DrawStep &step);
+	virtual void textStep(const Common::String &text, const Common::Rect &area, const TextStep &step);
 
 	/**
 	 * Copies the current surface to the system overlay 
@@ -442,6 +445,8 @@
 	 * @param r Position in the active drawing surface to do the blitting.
 	 */
 	virtual void blitSurface(Graphics::Surface *source, const Common::Rect &r) = 0;
+	
+	virtual void drawString(Graphics::Font *font, const Common::String &text, const Common::Rect &area, GUI::Theme::TextAlign align) = 0;
 
 protected:
 	Surface *_activeSurface; /** Pointer to the surface currently being drawn */
@@ -507,6 +512,8 @@
 	void drawBeveledSquare(int x, int y, int w, int h, int bevel) {
 		drawBevelSquareAlg(x, y, w, h, bevel, _fgColor, _bgColor);
 	}
+	
+	void drawString(Graphics::Font *font, const Common::String &text, const Common::Rect &area, GUI::Theme::TextAlign align);
 
 	/**
 	 * @see VectorRenderer::setFgColor()

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeDefaultXML.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeDefaultXML.cpp	2008-07-10 12:14:00 UTC (rev 32990)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeDefaultXML.cpp	2008-07-10 15:50:44 UTC (rev 32991)
@@ -51,14 +51,17 @@
 	"</drawdata>"
 
 	"<drawdata id = 'button_idle' cache = false>"
+		"<text align = 'center' color = '255, 0, 0' />"
 		"<drawstep func = 'roundedsq' radius = '8' stroke = 0 fill = 'gradient' gradient_start = '206, 121, 99' gradient_end = '173, 40, 8' size = 'auto' shadow = 3 />"
 	"</drawdata>"
 
 	"<drawdata id = 'button_hover' cache = false>"
+		"<text align = 'center' color = '255, 0, 0' />"
 		"<drawstep func = 'roundedsq' radius = '8' fill = 'gradient' gradient_start = '206, 121, 99' gradient_end = '173, 40, 8' size = 'auto' shadow = 3 />"
 	"</drawdata>"
 
 	"<drawdata id = 'checkbox_disabled' cache = false>"
+		"<text align = 'center' color = '255, 0, 0' />"
 		"<drawstep func = 'square' fill = 'gradient' gradient_start = '206, 121, 99' gradient_end = '173, 40, 8' size = 'auto' shadow = 0 />"
 	"</drawdata>"
 

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp	2008-07-10 12:14:00 UTC (rev 32990)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp	2008-07-10 15:50:44 UTC (rev 32991)
@@ -48,7 +48,8 @@
 	_callbacks["render_info"] = &ThemeParser::parserCallback_renderInfo;
 	_callbacks["layout_info"] = &ThemeParser::parserCallback_layoutInfo;
 	_callbacks["default"] = &ThemeParser::parserCallback_defaultSet;
-
+	_callbacks["text"] = &ThemeParser::parserCallback_text;
+	
 	_drawFunctions["circle"]  = &Graphics::VectorRenderer::drawCallback_CIRCLE;
 	_drawFunctions["square"]  = &Graphics::VectorRenderer::drawCallback_SQUARE;
 	_drawFunctions["roundedsq"]  = &Graphics::VectorRenderer::drawCallback_ROUNDSQ;
@@ -136,6 +137,56 @@
 	return parseDrawStep(defNode, step, false);
 }
 
+bool ThemeParser::parserCallback_text() {
+	ParserNode *tNode = getActiveNode();
+	ParserNode *parentNode = getParentNode(tNode);
+	
+	if (parentNode == 0 || parentNode->name != "drawdata")
+		return parserError("Text Steps must be contained inside <drawdata> keys.");
+		
+	Graphics::TextStep step;
+	
+	if (tNode->values.contains("align") == false)
+		return parserError("Text inside widgets requires an alignement key.");
+		
+	if (tNode->values["align"] == "left")
+		step.align = GUI::Theme::kTextAlignLeft;
+	else if (tNode->values["align"] == "right")
+		step.align = GUI::Theme::kTextAlignRight;
+	else if (tNode->values["align"] == "center")
+		step.align = GUI::Theme::kTextAlignCenter;
+	else return parserError("Invalid value for text alignment.");
+	
+	
+	if (tNode->values.contains("color")) {
+		int red, green, blue;
+
+		if (parseIntegerKey(tNode->values["color"].c_str(), 3, &red, &green, &blue) == false ||
+			red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255)
+			return parserError("Error when parsing color value for text definition");
+			
+		step.color.r = red;
+		step.color.g = green;
+		step.color.b = blue;
+		step.color.set = true;
+	} else if (_defaultStepLocal && _defaultStepLocal->fgColor.set) {
+		step.color.r = _defaultStepLocal->fgColor.r;
+		step.color.g = _defaultStepLocal->fgColor.g;
+		step.color.b = _defaultStepLocal->fgColor.b;
+		step.color.set = true;
+	} 	else if (_defaultStepGlobal && _defaultStepGlobal->fgColor.set) {
+		step.color.r = _defaultStepGlobal->fgColor.r;
+		step.color.g = _defaultStepGlobal->fgColor.g;
+		step.color.b = _defaultStepGlobal->fgColor.b;
+		step.color.set = true;
+	} else {
+		return parserError("Cannot assign color for text drawing.");
+	}
+
+	_theme->addTextStep(parentNode->values["id"], step);
+	return true;
+}
+
 bool ThemeParser::parserCallback_renderInfo() {
 	ParserNode *infoNode = getActiveNode();
 

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeParser.h
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeParser.h	2008-07-10 12:14:00 UTC (rev 32990)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeParser.h	2008-07-10 15:50:44 UTC (rev 32991)
@@ -328,6 +328,7 @@
 	bool parserCallback_renderInfo();
 	bool parserCallback_layoutInfo();
 	bool parserCallback_defaultSet();
+	bool parserCallback_text();
 
 	void cleanup();
 

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp	2008-07-10 12:14:00 UTC (rev 32990)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp	2008-07-10 15:50:44 UTC (rev 32991)
@@ -180,6 +180,19 @@
 	_widgets[id]->_steps.push_back(step);
 }
 
+bool ThemeRenderer::addTextStep(Common::String &drawDataId, Graphics::TextStep step) {
+	DrawData id = getDrawDataId(drawDataId);
+	
+	assert(_widgets[id] != 0);
+	if (_widgets[id]->_hasText == true)
+		return false;
+		
+	_widgets[id]->_textStep = step;
+	_widgets[id]->_hasText = true;
+
+	return true;
+}
+
 bool ThemeRenderer::addDrawData(DrawData data_id, bool cached) {
 	assert(data_id >= 0 && data_id < kDrawDataMAX);
 
@@ -189,6 +202,7 @@
 	_widgets[data_id] = new WidgetDrawData;
 	_widgets[data_id]->_cached = cached;
 	_widgets[data_id]->_surfaceCache = 0;
+	_widgets[data_id]->_hasText = false;
 
 	return true;
 }
@@ -252,9 +266,12 @@
 }
 
 void ThemeRenderer::drawDD(DrawData type, const Common::Rect &r) {
+	if (_widgets[type] == 0)
+		return;
+		
 	if (isWidgetCached(type, r)) {
 		drawCached(type, r);
-	} else if (_widgets[type] != 0) {
+	} else {
 		for (Common::List<Graphics::DrawStep>::const_iterator step = _widgets[type]->_steps.begin(); 
 			 step != _widgets[type]->_steps.end(); ++step)
 			_vectorRenderer->drawStep(r, *step);
@@ -264,15 +281,20 @@
 void ThemeRenderer::drawButton(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, uint16 hints) {
 	if (!ready())
 		return;
+		
+	DrawData dd;
 
 	if (state == kStateEnabled)
-		drawDD(kDDButtonIdle, r);
+		dd = kDDButtonIdle;
 	else if (state == kStateHighlight)
-		drawDD(kDDButtonHover, r);
+		dd = kDDButtonHover;
 	else if (state == kStateDisabled)
-		drawDD(kDDButtonDisabled, r);
+		dd = kDDButtonDisabled;
 
-	// TODO: Add text drawing.
+	drawDD(dd, r);
+	if (hasWidgetText(dd))
+		_vectorRenderer->textStep(str, r, _widgets[dd]->_textStep);
+		
 
 	addDirtyRect(r);
 	debugWidgetPosition(r);

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.h
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.h	2008-07-10 12:14:00 UTC (rev 32990)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.h	2008-07-10 15:50:44 UTC (rev 32991)
@@ -43,6 +43,8 @@
 
 struct WidgetDrawData {
 	Common::List<Graphics::DrawStep> _steps;
+	Graphics::TextStep _textStep;
+	bool _hasText;
 
 	bool _cached;
 	Graphics::Surface *_surfaceCache;
@@ -175,6 +177,7 @@
 
 	void addDrawStep(Common::String &drawDataId, Graphics::DrawStep step);
 	bool addDrawData(DrawData data_id, bool cached);
+	bool addTextStep(Common::String &drawDataId, Graphics::TextStep step);
 
 	ThemeParser *parser() {
 		return _parser;
@@ -227,6 +230,10 @@
 
 	void redrawDialogStack();
 
+	bool hasWidgetText(DrawData type) {
+		return (_widgets[type] != 0 && _widgets[type]->_hasText);
+	}
+	
 	bool isWidgetCached(DrawData type, const Common::Rect &r);
 	void drawCached(DrawData type, const Common::Rect &r);
 


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