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

Tanoku at users.sourceforge.net Tanoku at users.sourceforge.net
Wed Jul 23 18:38:39 CEST 2008


Revision: 33247
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33247&view=rev
Author:   Tanoku
Date:     2008-07-23 16:38:39 +0000 (Wed, 23 Jul 2008)

Log Message:
-----------
Font rendering overhaul. Work in progress.

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/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-23 16:33:53 UTC (rev 33246)
+++ scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.cpp	2008-07-23 16:38:39 UTC (rev 33247)
@@ -75,15 +75,6 @@
 	(this->*(step.drawingCall))(area, step);
 }
 
-void VectorRenderer::textStep(const Common::String &text, const Common::Rect &area, const TextStep &step, GUI::Theme::TextAlign alignH) {
-	if (step.color.set)
-		setFgColor(step.color.r, step.color.g, step.color.b);
-		
-	drawString(step.font, text.c_str(), area, 
-		!step.hasAlign ? alignH : step.alignHorizontal, 
-		!step.hasAlign ? GUI::Theme::kTextAlignVTop : step.alignVertical);
-}
-
 int VectorRenderer::stepGetRadius(const DrawStep &step, const Common::Rect &area) {
 	int radius = 0;
 

Modified: scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.h
===================================================================
--- scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.h	2008-07-23 16:33:53 UTC (rev 33246)
+++ scummvm/branches/gsoc2008-gui/graphics/VectorRenderer.h	2008-07-23 16:38:39 UTC (rev 33247)
@@ -39,20 +39,6 @@
 class VectorRenderer;
 struct DrawStep;
 
-struct TextStep {
-	struct { 
-		uint8 r, g, b;
-		bool set;
-	}
-	color; /** text color */
-
-	GUI::Theme::TextAlign alignHorizontal;
-	GUI::Theme::TextAlignVertical alignVertical;
-	bool hasAlign;
-	char *text;
-	const Graphics::Font *font;
-};
-
 struct DrawStep {
 	struct { 
 		uint8 r, g, b;
@@ -404,7 +390,6 @@
 	 * @param step Pointer to a DrawStep struct.
 	 */
 	virtual void drawStep(const Common::Rect &area, const DrawStep &step, uint32 extra = 0);
-	virtual void textStep(const Common::String &text, const Common::Rect &area, const TextStep &step, GUI::Theme::TextAlign alignH = GUI::Theme::kTextAlignLeft);
 
 	/**
 	 * Copies the current surface to the system overlay 
@@ -422,8 +407,6 @@
 	 */
 	virtual void blitSurface(Graphics::Surface *source, const Common::Rect &r) = 0;
 	
-	virtual uint32 buildColor(uint8 r, uint8 g, uint8 b) = 0;
-	
 	virtual void drawString(const Graphics::Font *font, const Common::String &text, const Common::Rect &area, GUI::Theme::TextAlign alignH, GUI::Theme::TextAlignVertical alignV) = 0;
 	
 	virtual void disableShadows() { _disableShadows = true; }
@@ -595,10 +578,6 @@
 			src_ptr += src_pitch;
 		}
 	}
-	
-	virtual uint32 buildColor(uint8 r, uint8 g, uint8 b) {
-		return RGBToColor<PixelFormat>(r, g, b);
-	}
 
 protected:
 

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeDefaultXML.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeDefaultXML.cpp	2008-07-23 16:33:53 UTC (rev 33246)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeDefaultXML.cpp	2008-07-23 16:38:39 UTC (rev 33247)
@@ -42,18 +42,20 @@
 		"<color name = 'red' rgb = '255, 0, 0' />"
 		"<color name = 'green' rgb = '0, 255, 0' />"
 		"<color name = 'blue' rgb = '0, 255, 255' />"
-		"<color name = 'text_default' rgb = '0, 0, 0' />"
-		"<color name = 'text_hover' rgb = '255, 255, 255' />"
-		"<color name = 'text_disabled' rgb = '128, 128, 128' />"
 	"</palette>"
 	
 	"<fonts>"
-		"<font id = 'default' type = 'default' color = 'text_default' />"
-		"<font id = 'hover' type = 'default' color = 'text_hover' />"
-		"<font id = 'disabled' type = 'default' color = 'text_disabled' />"
+		"<font id = 'text_default' type = 'default' color = '0, 0, 0' />"
+		"<font id = 'text_hover' type = 'default' color = '255, 255, 255' />"
+		"<font id = 'text_disabled' type = 'default' color = '128, 128, 128' />"
+		"<font id = 'text_inverted' type = 'default' color = '255, 0, 0' />"
 	"</fonts>"
 
 	"<defaults fill = 'gradient' fg_color = '255, 255, 255' />"
+	
+	"<drawdata id = 'text_selection' cache = false>"
+		"<drawstep func = 'square' fill = 'foreground' fg_color = '0, 255, 0' />"
+	"</drawdata>"
 
 	"<drawdata id = 'mainmenu_bg' cache = false>"
 		"<drawstep func = 'fill' fill = 'gradient' gradient_start = '214, 113, 8' gradient_end = '240, 200, 25' />"
@@ -68,12 +70,12 @@
 	"</drawdata>"
 	
 	"<drawdata id = 'tab_active' cache = false>"
-		"<text vertical_align = 'center' horizontal_align = 'center' color = '0, 0, 0' />"
+		"<text font = 'text_default' vertical_align = 'center' horizontal_align = 'center' />"
 		"<drawstep func = 'tab' radius = '4' stroke = '2' fill = 'gradient' gradient_end = '255, 231, 140' gradient_start = '255, 243, 206' shadow = 3 />"
 	"</drawdata>"
 	
 	"<drawdata id = 'tab_inactive' cache = false>"
-		"<text vertical_align = 'center' horizontal_align = 'center' color = '128, 128, 128' />"
+		"<text font = 'text_disabled' vertical_align = 'center' horizontal_align = 'center' />"
 		"<drawstep func = 'tab' radius = '4' stroke = '0' fill = 'foreground' fg_color = '206, 121, 99' shadow = 3 />"
 	"</drawdata>"
 	
@@ -95,7 +97,7 @@
 	"<drawdata id = 'popup_hover' cache = false>"
 		"<drawstep func = 'square' stroke = 0 fg_color = '0, 0, 0' fill = 'gradient' gradient_start = '214, 113, 8' gradient_end = '240, 200, 25' shadow = 0 />"
 		"<drawstep func = 'triangle' fg_color = '0, 0, 0' fill = 'foreground' width = '12' height = '12' xpos = '-16' ypos = 'center' orientation = 'bottom' />"
-		"<text vertical_align = 'center' horizontal_align = 'right' color = '255, 255, 255' />"
+		"<text font = 'text_hover' vertical_align = 'center' horizontal_align = 'right' />"
 	"</drawdata>"
 	
 	"<drawdata id = 'default_bg' cache = false>"
@@ -103,27 +105,27 @@
 	"</drawdata>"
 
 	"<drawdata id = 'button_idle' cache = false>"
-		"<text vertical_align = 'center' horizontal_align = 'center' color = '173, 40, 8' />"
+		"<text font = 'text_default' vertical_align = 'center' horizontal_align = 'center' />"
 		"<drawstep func = 'roundedsq' radius = '8' stroke = 0 fill = 'foreground' shadow = 3 />"
 	"</drawdata>"
 
 	"<drawdata id = 'button_hover' cache = false>"
-		"<text vertical_align = 'center' horizontal_align = 'center' color = '255, 255, 255' />"
+		"<text font = 'text_hover' vertical_align = 'center' horizontal_align = 'center' />"
 		"<drawstep func = 'roundedsq' radius = '8' stroke = '1' fill = 'gradient' gradient_start = '206, 121, 99' gradient_end = '173, 40, 8' shadow = 0 />"
 	"</drawdata>"
 	
 	"<drawdata id = 'button_disabled' cache = false>"
-		"<text vertical_align = 'center' horizontal_align = 'center' color = '128, 128, 128' />"
+		"<text font = 'text_disabled' vertical_align = 'center' horizontal_align = 'center' />"
 		"<drawstep func = 'roundedsq' radius = '8' stroke = 0 fill = 'foreground' fg_color = '200, 200, 200' shadow = 3 />"
 	"</drawdata>"
 
 	"<drawdata id = 'checkbox_disabled' cache = false>"
-		"<text vertical_align = 'top' horizontal_align = 'left' color = '0,0,0' />"
+		"<text font = 'text_disabled' vertical_align = 'top' horizontal_align = 'left' />"
 		"<drawstep func = 'square' fill = 'gradient' gradient_start = '206, 121, 99' gradient_end = '173, 40, 8' shadow = 0 />"
 	"</drawdata>"
 
 	"<drawdata id = 'checkbox_enabled' cache = false>"
-		"<text vertical_align = 'top' horizontal_align = 'left' color = '0,0,0' />"
+		"<text font = 'text_default' vertical_align = 'top' horizontal_align = 'left' />"
 		"<drawstep func = 'square' fill = 'gradient' gradient_start = '206, 121, 99' gradient_end = '173, 40, 8' shadow = 0 />"
 		"<drawstep func = 'circle' radius = 'auto' fill = 'foreground' />"
 	"</drawdata>"

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp	2008-07-23 16:33:53 UTC (rev 33246)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeParser.cpp	2008-07-23 16:38:39 UTC (rev 33247)
@@ -160,11 +160,7 @@
 	
 	if (!tNode->values.contains("type"))
 		return parserError("Font definitions need a valid typename.");
-		
-	// TODO: set typename on the drawstep.
 	
-	Graphics::TextStep step;
-	
 	if (tNode->values.contains("horizontal_align") || tNode->values.contains("vertical_align"))
 		return parserError("Font definitions cannot contain alignments.");
 		
@@ -181,13 +177,7 @@
 		return parserError("Cannot assign color in font definition.");
 	}
 	
-	step.color.r = red;
-	step.color.g = green;
-	step.color.b = blue;
-	step.color.set = true;
-	step.hasAlign = false;
-	
-	if (!_theme->addTextStep(tNode->values["id"], step))
+	if (!_theme->addFont(tNode->values["id"], red, green, blue))
 		return parserError("Error when loading Font in theme engine.");
 		
 	return true;
@@ -209,47 +199,29 @@
 	if (parentNode == 0 || parentNode->name != "drawdata")
 		return parserError("Text Steps must be contained inside <drawdata> keys.");
 		
-	Graphics::TextStep step;
+	GUI::Theme::TextAlign alignH;
+	GUI::Theme::TextAlignVertical alignV;
 	
 	if (tNode->values.contains("horizontal_align") == false || tNode->values.contains("vertical_align") == false)
 		return parserError("Text inside widgets requires proper alignment keys.");
 		
 	if (tNode->values["horizontal_align"] == "left")
-		step.alignHorizontal = GUI::Theme::kTextAlignLeft;
+		alignH = GUI::Theme::kTextAlignLeft;
 	else if (tNode->values["horizontal_align"] == "right")
-		step.alignHorizontal = GUI::Theme::kTextAlignRight;
+		alignH = GUI::Theme::kTextAlignRight;
 	else if (tNode->values["horizontal_align"] == "center")
-		step.alignHorizontal = GUI::Theme::kTextAlignCenter;
+		alignH = GUI::Theme::kTextAlignCenter;
 	else return parserError("Invalid value for text alignment.");
 	
 	if (tNode->values["vertical_align"] == "top")
-		step.alignVertical = GUI::Theme::kTextAlignVTop;
+		alignV = GUI::Theme::kTextAlignVTop;
 	else if (tNode->values["vertical_align"] == "center")
-		step.alignVertical = GUI::Theme::kTextAlignVCenter;
+		alignV = GUI::Theme::kTextAlignVCenter;
 	else if (tNode->values["vertical_align"] == "bottom")
-		step.alignVertical = GUI::Theme::kTextAlignVBottom;
+		alignV = GUI::Theme::kTextAlignVBottom;
 	else return parserError("Invalid value for text alignment.");
 	
-	int red, green, blue;
-	
-	if (tNode->values.contains("color")) {
-
-		if (_palette.contains(tNode->values["color"]))
-			getPaletteColor(tNode->values["color"], red, green, blue);
-		else if (!parseIntegerKey(tNode->values["color"].c_str(), 3, &red, &green, &blue))
-			return parserError("Error when parsing color value for text definition");
-			
-	} else {
-		return parserError("Cannot assign color for text drawing.");
-	}
-	
-	step.color.r = red;
-	step.color.g = green;
-	step.color.b = blue;
-	step.color.set = true;
-	step.hasAlign = true;
-	
-	return _theme->addTextStep(parentNode->values["id"], step);
+	return _theme->addTextData(parentNode->values["id"], tNode->values["font"], alignH, alignV);
 }
 
 bool ThemeParser::parserCallback_renderInfo() {

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp	2008-07-23 16:33:53 UTC (rev 33246)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.cpp	2008-07-23 16:38:39 UTC (rev 33247)
@@ -44,6 +44,7 @@
 	{kDDSpecialColorBackground, "special_bg", true, kDDNone},
 	{kDDPlainColorBackground, "plain_bg", true, kDDNone},
 	{kDDDefaultBackground, "default_bg", true, kDDNone},
+	{kDDTextSelectionBackground, "text_selection", false, kDDNone},
 
 	{kDDWidgetBackgroundDefault, "widget_default", true, kDDNone},
 	{kDDWidgetBackgroundSmall, "widget_small", true, kDDNone},
@@ -72,7 +73,14 @@
 	{kDDSeparator, "separator", true, kDDNone},
 };
 
+const ThemeRenderer::TextDataInfo ThemeRenderer::kTextDataDefaults[] = {
+	{kTextDataDefault, "text_default"},
+	{kTextDataHover, "text_hover"},
+	{kTextDataDisabled, "text_disabled"},
+	{kTextDataInverted, "text_inverted"}
+};
 
+
 ThemeRenderer::ThemeRenderer(Common::String themeName, GraphicsMode mode) : 
 	_vectorRenderer(0), _system(0), _graphicsMode(kGfxDisabled), 
 	_screen(0), _backBuffer(0), _bytesPerPixel(0), _initOk(false), 
@@ -83,6 +91,10 @@
 	for (int i = 0; i < kDrawDataMAX; ++i) {
 		_widgets[i] = 0;
 	}
+	
+	for (int i = 0; i < kTextDataMAX; ++i) {
+		_texts[i] = 0;
+	}
 
 	_graphicsMode = mode;
 	setGraphicsMode(_graphicsMode);
@@ -111,14 +123,6 @@
 		Theme::loadTheme(_configFile, false, true);
 	}
 
-	if (_fontName.empty()) {
-		if (_screen->w >= 400 && _screen->h >= 300) {
-			_font = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
-		} else {
-			_font = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont);
-		}
-	}
-
 	return true;
 }
 
@@ -195,29 +199,43 @@
 	_widgets[id]->_steps.push_back(step);
 }
 
-bool ThemeRenderer::addTextStep(const Common::String &drawDataId, Graphics::TextStep step) {
+bool ThemeRenderer::addTextData(const Common::String &drawDataId, const Common::String &textDataId, TextAlign alignH, TextAlignVertical alignV) {
 	DrawData id = getDrawDataId(drawDataId);
+	TextData textId = getTextDataId(textDataId);
 
-	step.font = 0;
+	if (id == -1 || textId == -1 || !_widgets[id])
+		return false;
 	
-	if (id != -1) {
-		assert(_widgets[id] != 0);
-		if (_widgets[id]->_hasText == true)
-			return false;
+	_widgets[id]->_textDataId = textId;
+	_widgets[id]->_textAlignH = alignH;
+	_widgets[id]->_textAlignV = alignV;	
 
-		_widgets[id]->_textStep = step;
-		_widgets[id]->_hasText = true;
+	return true;
+}
+
+bool ThemeRenderer::addFont(const Common::String &fontId, int r, int g, int b) {
+	TextData textId = getTextDataId(fontId);
+	
+	if (textId == -1)
+		return false;
+		
+	if (_texts[textId] != 0)
+		return false;
+		
+	_texts[textId] = new TextDrawData;
+	
+	// TODO: Allow the user to specify the font he wants, instead of choosing based on resolution
+	if (_screen->w >= 400 && _screen->h >= 300) {
+		_texts[textId]->_fontPtr = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
 	} else {
-		if (drawDataId == "default") {
-			_texts[kTextColorDefault] = step;
-		} else if (drawDataId == "hover") {
-			_texts[kTextColorHover] = step;
-		} else if (drawDataId == "disabled") {
-			_texts[kTextColorDisabled] = step;
-		} else return false;
+		_texts[textId]->_fontPtr = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont);
 	}
-
+	
+	_texts[textId]->_color.r = r;
+	_texts[textId]->_color.g = g;
+	_texts[textId]->_color.b = b;
 	return true;
+	
 }
 
 bool ThemeRenderer::addDrawData(const Common::String &data, bool cached) {
@@ -230,7 +248,7 @@
 	_widgets[data_id]->_cached = cached;
 	_widgets[data_id]->_buffer = kDrawDataDefaults[data_id].buffer;
 	_widgets[data_id]->_surfaceCache = 0;
-	_widgets[data_id]->_hasText = false;
+	_widgets[data_id]->_textDataId = -1;
 
 	return true;
 }
@@ -320,14 +338,19 @@
 	}
 }
 
-void ThemeRenderer::queueDDText(DrawData type, const Common::Rect &r, const Common::String &text, TextColor colorId, TextAlign align) {
+void ThemeRenderer::queueDDText(TextData type, const Common::Rect &r, const Common::String &text,
+	bool elipsis, TextAlign alignH, TextAlignVertical alignV) {
+		
+	if (_texts[type] == 0)
+		return;
+		
 	DrawQueueText q;
 	q.type = type;
 	q.area = r;
 	q.area.clip(_screen->w, _screen->h);
 	q.text = text;
-	q.colorId = colorId;
-	q.align = align;
+	q.alignH = alignH;
+	q.alignV = alignV;
 	
 	if (_buffering) {		
 		_textQueue.push_back(q);
@@ -359,19 +382,11 @@
 }
 
 void ThemeRenderer::drawDDText(const DrawQueueText &q) {	
-	if (q.type == kDDNone) {
+	if (q.type != kTextDataInverted)
 		restoreBackground(q.area);
-		if (_texts[q.colorId].font == 0)
-			_texts[q.colorId].font = _font;
-
-		_vectorRenderer->textStep(q.text, q.area, _texts[q.colorId], q.align);
-	} else {
-		if (_widgets[q.type]->_textStep.font == 0)
-			_widgets[q.type]->_textStep.font = _font;
-
-		_vectorRenderer->textStep(q.text, q.area, _widgets[q.type]->_textStep);
-	}
 	
+	_vectorRenderer->setFgColor(_texts[q.type]->_color.r, _texts[q.type]->_color.g, _texts[q.type]->_color.b);
+	_vectorRenderer->drawString(_texts[q.type]->_fontPtr, q.text, q.area, q.alignH, q.alignV);
 	addDirtyRect(q.area);
 }
 
@@ -405,7 +420,7 @@
 		dd = kDDButtonDisabled;
 
 	queueDD(dd, r);
-	queueDDText(dd, r, str);	
+	queueDDText(getTextData(dd), r, str, false, _widgets[dd]->_textAlignH, _widgets[dd]->_textAlignV);
 }
 
 void ThemeRenderer::drawLineSeparator(const Common::Rect &r, WidgetStateInfo state) {
@@ -420,17 +435,18 @@
 		return;
 
 	Common::Rect r2 = r;
+	DrawData dd = checked ? kDDCheckboxEnabled : kDDCheckboxDisabled;
 	const int checkBoxSize = MIN((int)r.height(), getFontHeight());
 
 	r2.bottom = r2.top + checkBoxSize;
 	r2.right = r2.left + checkBoxSize;
 
-	queueDD(checked ? kDDCheckboxEnabled : kDDCheckboxDisabled, r2);
+	queueDD(dd, r2);
 	
 	r2.left = r2.right + checkBoxSize;
 	r2.right = r.right;
 	
-	queueDDText(checked ? kDDCheckboxEnabled : kDDCheckboxDisabled, r2, str);
+	queueDDText(getTextData(dd), r2, str, false, _widgets[dd]->_textAlignH, _widgets[dd]->_textAlignV);
 }
 
 void ThemeRenderer::drawSlider(const Common::Rect &r, int width, WidgetStateInfo state) {
@@ -484,7 +500,7 @@
 	
 	if (!sel.empty()) {
 		Common::Rect text(r.left, r.top, r.right - 16, r.bottom);
-		queueDDText(dd, text, sel);
+		queueDDText(getTextData(dd), text, sel, false, _widgets[dd]->_textAlignH, _widgets[dd]->_textAlignV);
 	}
 }
 
@@ -530,7 +546,7 @@
 
 		Common::Rect tabRect(r.left + i * (tabWidth + tabOffset), r.top, r.left + i * (tabWidth + tabOffset) + tabWidth, r.top + tabHeight);
 		queueDD(kDDTabInactive, tabRect);
-		queueDDText(kDDTabInactive, tabRect, tabs[i]);
+		queueDDText(getTextData(kDDTabInactive), tabRect, tabs[i], false, _widgets[kDDTabInactive]->_textAlignH, _widgets[kDDTabInactive]->_textAlignV);
 	}
 	
 	if (active >= 0) {
@@ -538,15 +554,30 @@
 		const uint16 tabLeft = active * (tabWidth + tabOffset);
 		const uint16 tabRight =  MAX(r.right - tabRect.right, 0);
 		queueDD(kDDTabActive, tabRect, (tabLeft << 16) | (tabRight & 0xFFFF));
-		queueDDText(kDDTabActive, tabRect, tabs[active]);
+		queueDDText(getTextData(kDDTabActive), tabRect, tabs[active], false, _widgets[kDDTabActive]->_textAlignH, _widgets[kDDTabActive]->_textAlignV);
 	}
 }
 
 void ThemeRenderer::drawText(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, TextAlign align, bool inverted, int deltax, bool useEllipsis, FontStyle font) {
 	if (!_initOk)
 		return;
-	
-	queueDDText(kDDNone, r, str, getTextColor(state), align);
+		
+	if (inverted)
+		queueDD(kDDTextSelectionBackground, r);
+		
+	switch (state) {
+		case kStateDisabled:
+			queueDDText(inverted ? kTextDataInverted : kTextDataDisabled, r, str, useEllipsis);
+			break;
+			
+		case kStateHighlight:
+			queueDDText(inverted ? kTextDataInverted : kTextDataHover, r, str, useEllipsis);
+			break;
+		
+		case kStateEnabled:
+			queueDDText(inverted ? kTextDataInverted : kTextDataDefault, r, str, useEllipsis);
+			break;
+	}
 }
 
 void ThemeRenderer::debugWidgetPosition(const char *name, const Common::Rect &r) {

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.h
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.h	2008-07-23 16:33:53 UTC (rev 33246)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeRenderer.h	2008-07-23 16:38:39 UTC (rev 33247)
@@ -42,13 +42,21 @@
 struct WidgetDrawData;
 struct DrawDataInfo;
 
+struct TextDrawData {
+	const Graphics::Font *_fontPtr;
+	
+	struct { 
+		uint8 r, g, b;
+	} _color;
+};
+
 struct WidgetDrawData {
 	/** List of all the steps needed to draw this widget */
 	Common::List<Graphics::DrawStep> _steps;
 	
-	/** Single step that defines the text shown inside the widget */
-	Graphics::TextStep _textStep;
-	bool _hasText;
+	int _textDataId;
+	GUI::Theme::TextAlign _textAlignH;
+	GUI::Theme::TextAlignVertical _textAlignV;
 
 	/** Extra space that the widget occupies when it's drawn.
 	    E.g. when taking into account rounded corners, drop shadows, etc 
@@ -97,6 +105,7 @@
 		kDDSpecialColorBackground,
 		kDDPlainColorBackground,
 		kDDDefaultBackground,
+		kDDTextSelectionBackground,
 		
 		kDDWidgetBackgroundDefault,
 		kDDWidgetBackgroundSmall,
@@ -149,21 +158,28 @@
 		uint32 dynData;		/** Dynamic data which modifies the DrawData item (optional)*/
 	};
 	
-	enum TextColor {
-		kTextColorNone = -1,
-		kTextColorDefault,
-		kTextColorHover,
-		kTextColorDisabled,
-		kTextColorInverted,
-		kTextColorMAX
+	enum TextData {
+		kTextDataNone = -1,
+		kTextDataDefault = 0,
+		kTextDataHover,
+		kTextDataDisabled,
+		kTextDataInverted,
+		kTextDataMAX
 	};
 	
+	static const struct TextDataInfo {
+		TextData id;
+		const char *name;
+	} kTextDataDefaults[];
+	
 	struct DrawQueueText {
-		DrawData type;
+		TextData type;
 		Common::Rect area;
 		Common::String text;
-		TextColor colorId;
-		TextAlign align;
+		
+		GUI::Theme::TextAlign alignH;
+		GUI::Theme::TextAlignVertical alignV;
+		bool elipsis;
 	};
 	
 public:
@@ -312,7 +328,15 @@
 
 		return kDDNone;
 	}
+	
+	TextData getTextDataId(const Common::String &name) {
+		for (int i = 0; i < kTextDataMAX; ++i)
+			if (name.compareToIgnoreCase(kTextDataDefaults[i].name) == 0)
+				return kTextDataDefaults[i].id;
 
+		return kTextDataNone;
+	}
+
 	/**
 	 *	Interface for ThemeParser class: Parsed DrawSteps are added via this function.
 	 *	There is no return type because DrawSteps can always be added, unless something
@@ -334,12 +358,13 @@
 	 *	@param cached Whether this DD set will be cached beforehand.
 	 */ 
 	bool addDrawData(const Common::String &data, bool cached);
+	bool addFont(const Common::String &fontName, int r, int g, int b);
 	
 	/**
 	 *	Adds a new TextStep from the ThemeParser. This will be deprecated/removed once the 
 	 *	new Font API is in place.
 	 */
-	bool addTextStep(const Common::String &drawDataId, Graphics::TextStep step);
+	bool addTextData(const Common::String &drawDataId, const Common::String &textDataId, TextAlign alignH, TextAlignVertical alignV);
 
 	/** Interface to the new Theme XML parser */
 	ThemeParser *parser() {
@@ -414,6 +439,11 @@
 			delete _widgets[i];
 			_widgets[i] = 0;
 		}
+		
+		for (int i = 0; i < kTextDataMAX; ++i) {
+			delete _texts[i];
+			_texts[i] = 0;
+		}
 
 		_themeOk = false;
 	}
@@ -461,14 +491,9 @@
 			_screen = 0;
 		}
 	}
-
-	/**
-	 *	Checks if the given widget type has a Text drawing step associated to it.
-	 *
-	 *	@param type DrawData type of the widget.
-	 */
-	bool hasWidgetText(DrawData type) {
-		return (_widgets[type] != 0 && _widgets[type]->_hasText);
+	
+	TextData getTextData(DrawData ddId) {
+		return _widgets[ddId] ? (TextData)_widgets[ddId]->_textDataId : kTextDataNone;
 	}
 	
 	/**
@@ -523,8 +548,8 @@
 	 *	This function is called from all the Widget Drawing methods.
 	 */
 	inline void queueDD(DrawData type,  const Common::Rect &r, uint32 dynamic = 0);
-	inline void queueDDText(DrawData type, const Common::Rect &r, const Common::String &text, 
-							TextColor colorId = kTextColorNone, TextAlign align = kTextAlignLeft);
+	inline void queueDDText(TextData type, const Common::Rect &r, const Common::String &text,
+		bool elipsis, TextAlign alignH = kTextAlignLeft, TextAlignVertical alignV = kTextAlignVTop);
 	
 	/**
 	 *	DEBUG: Draws a white square around the given position and writes the given next to it.
@@ -547,22 +572,6 @@
 	 */
 	int getTabSpacing() const { return 0; }
 	int getTabPadding() const { return 3; }
-	
-	/**
-	 *	Translates a WidgetStateInfo of a Text widget to the actual font color value.
-	 */
-	TextColor getTextColor(WidgetStateInfo state) {
-		switch (state) {
-			case kStateDisabled:
-			return kTextColorDisabled;
-			
-			case kStateHighlight:
-			return kTextColorHover;
-			
-			default:
-			return kTextColorDefault;
-		}
-	}
 
 	OSystem *_system; /** Global system object. */
 	
@@ -597,7 +606,7 @@
 	WidgetDrawData *_widgets[kDrawDataMAX];
 	
 	/** Array of all the text fonts that can be drawn. */
-	Graphics::TextStep _texts[kTextColorMAX];
+	TextDrawData *_texts[kTextDataMAX];
 	
 	/** List of all the dirty screens that must be blitted to the overlay. */
 	Common::List<Common::Rect> _dirtyScreen;


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