diff options
| -rw-r--r-- | graphics/VectorRenderer.h | 6 | ||||
| -rw-r--r-- | gui/ThemeDefaultXML.cpp | 11 | ||||
| -rw-r--r-- | gui/ThemeParser.cpp | 38 | ||||
| -rw-r--r-- | gui/ThemeParser.h | 11 | ||||
| -rw-r--r-- | gui/ThemeRenderer.cpp | 30 | ||||
| -rw-r--r-- | gui/ThemeRenderer.h | 25 | 
6 files changed, 98 insertions, 23 deletions
| diff --git a/graphics/VectorRenderer.h b/graphics/VectorRenderer.h index 3af682953d..f1009ea2de 100644 --- a/graphics/VectorRenderer.h +++ b/graphics/VectorRenderer.h @@ -489,6 +489,8 @@ public:  	 */  	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;  protected: @@ -650,6 +652,10 @@ public:  			src_ptr += src_pitch;  		}  	} +	 +	virtual uint32 buildColor(uint8 r, uint8 g, uint8 b) { +		return RGBToColor<PixelFormat>(r, g, b); +	}  protected: diff --git a/gui/ThemeDefaultXML.cpp b/gui/ThemeDefaultXML.cpp index ace3debfc2..db01adb7c3 100644 --- a/gui/ThemeDefaultXML.cpp +++ b/gui/ThemeDefaultXML.cpp @@ -12,7 +12,7 @@   * 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. + * 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 @@ -41,7 +41,10 @@ bool ThemeRenderer::loadDefaultXML() {  	"<palette>"  		"<color name = 'red' rgb = '255, 0, 0' />"  		"<color name = 'green' rgb = '0, 255, 0' />" -		"<color name = 'blue' rgb = '0, 0, 255' />" +		"<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>"  	"<default fill = 'gradient' fg_color = '255, 255, 255' />" @@ -54,6 +57,10 @@ bool ThemeRenderer::loadDefaultXML() {  		"<drawstep func = 'square' fill = 'foreground' height = '3' ypos = 'center' fg_color = '0, 0, 0' />"  	"</drawdata>" +	"<drawdata id = 'scrollbar_base' cache = false>" +		"<drawstep func = 'roundedsq' stroke = 1 radius = 4 fill = 'none' fg_color = '255, 255, 255' />" +	"</drawdata>" +	  	"<drawdata id = 'popup_idle' 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 = 3 />"  		"<drawstep func = 'triangle' fg_color = '0, 0, 0' fill = 'foreground' width = '12' height = '12' xpos = '-16' ypos = 'center' orientation = 'bottom' />" diff --git a/gui/ThemeParser.cpp b/gui/ThemeParser.cpp index 398eab010a..fda291fb04 100644 --- a/gui/ThemeParser.cpp +++ b/gui/ThemeParser.cpp @@ -173,30 +173,32 @@ bool ThemeParser::parserCallback_text() {  		step.alignVertical = GUI::Theme::kTextAlignVBottom;  	else return parserError("Invalid value for text alignment."); +	Common::String paletteColor = "text_default"; +	int red, green, blue; +	 +	if (tNode->name.contains("hover")) +		paletteColor = "text_hover"; +	 +	if (tNode->name.contains("disabled")) +		paletteColor = "text_disabled"; +	  	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"); +		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");		 -		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 if (_palette.contains(paletteColor)) { +		getPaletteColor(paletteColor, red, green, blue);  	} 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;  	_theme->addTextStep(parentNode->values["id"], step);  	return true; diff --git a/gui/ThemeParser.h b/gui/ThemeParser.h index 778158bff0..1e365a9433 100644 --- a/gui/ThemeParser.h +++ b/gui/ThemeParser.h @@ -316,6 +316,17 @@ class ThemeParser : public XMLParser {  public:  	ThemeParser(GUI::ThemeRenderer *parent); +	 +	bool getPaletteColor(const Common::String &name, int &r, int &g, int &b) { +		if (!_palette.contains(name)) +			return false; +			 +		r = _palette[name].r; +		g = _palette[name].g; +		b = _palette[name].b; +		 +		return true; +	}  protected:  	ThemeRenderer *_theme; diff --git a/gui/ThemeRenderer.cpp b/gui/ThemeRenderer.cpp index 15d8b7d67b..0b3fbe1064 100644 --- a/gui/ThemeRenderer.cpp +++ b/gui/ThemeRenderer.cpp @@ -69,7 +69,8 @@ const char *ThemeRenderer::kDrawDataStrings[] = {  	"popup_hover",  	"caret", -	"separator" +	"separator", +	"default_text"  };  ThemeRenderer::ThemeRenderer(Common::String themeName, GraphicsMode mode) :  @@ -234,7 +235,20 @@ bool ThemeRenderer::loadTheme(Common::String themeName) {  			// draw the cached widget to the cache surface  		}  	} +	 +	int r, g, b; +	 +#define __LOAD_COLOR(id, name) { \ +	if (parser()->getPaletteColor(name, r, g, b))\ +		_textColors[id] = _vectorRenderer->buildColor(r, g, b); \ +} +	 +	__LOAD_COLOR(kTextColorDefault, "text_default"); +	__LOAD_COLOR(kTextColorHover, "text_hover"); +	__LOAD_COLOR(kTextColorDisabled, "text_disabled"); +#undef __LOAD_COLOR +	  	_themeOk = true;  	return true;  } @@ -360,6 +374,9 @@ void ThemeRenderer::drawSlider(const Common::Rect &r, int width, WidgetStateInfo  void ThemeRenderer::drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState sb_state, WidgetStateInfo state) {  	if (!ready())  		return; +		 +	drawDD(kDDScrollbarBase, r); +	  	debugWidgetPosition("SCB", r);  } @@ -399,7 +416,7 @@ void ThemeRenderer::drawPopUpWidget(const Common::Rect &r, const Common::String  	if (!sel.empty()) {  		Common::Rect text(r.left, r.top, r.right - 16, r.bottom);  		drawDDText(dd, text, sel); -	}	 +	}  	debugWidgetPosition("Popup Widget", r);  } @@ -443,6 +460,15 @@ void ThemeRenderer::drawTab(const Common::Rect &r, int tabHeight, int tabWidth,  	debugWidgetPosition("Tab widget", r);  } +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; + +	getFont(font)->drawString(_screen, str, r.left, r.top, r.width(), getTextColor(state), convertAligment(align), deltax, useEllipsis); +	addDirtyRect(r); +} + +  void ThemeRenderer::debugWidgetPosition(const char *name, const Common::Rect &r) {  	// _font->drawString(_screen, name, r.left, r.top, r.width(), 0xFFFF, Graphics::kTextAlignRight, 0, true);  	// _screen->hLine(r.left, r.top, r.right, 0xFFFF); diff --git a/gui/ThemeRenderer.h b/gui/ThemeRenderer.h index a9c597f60f..ba6cf633b0 100644 --- a/gui/ThemeRenderer.h +++ b/gui/ThemeRenderer.h @@ -112,8 +112,17 @@ public:  		kDDCaret,  		kDDSeparator, +		kDDDefaultText,  		kDrawDataMAX  	}; +	 +	enum TextColor { +		kTextColorDefault, +		kTextColorHover, +		kTextColorDisabled, +		kTextColorInverted, +		kTextColorMAX +	};  	ThemeRenderer(Common::String themeName, GraphicsMode mode); @@ -160,7 +169,7 @@ public:  	void drawLineSeparator(const Common::Rect &r, WidgetStateInfo state = kStateEnabled);  	void drawDialogBackground(const Common::Rect &r, uint16 hints, WidgetStateInfo state); -	void drawText(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, TextAlign align, bool inverted, int deltax, bool useEllipsis, FontStyle font) {} +	void drawText(const Common::Rect &r, const Common::String &str, WidgetStateInfo state, TextAlign align, bool inverted, int deltax, bool useEllipsis, FontStyle font);  	void drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, WidgetStateInfo state) {}  	bool addDirtyRect(Common::Rect r, bool backup = false, bool special = false) { @@ -254,6 +263,19 @@ protected:  	int getTabPadding() const {  		return 3;  	} +	 +	uint32 getTextColor(WidgetStateInfo state) { +		switch (state) { +			case kStateDisabled: +				return _textColors[kTextColorDisabled]; +			 +			case kStateHighlight: +				return _textColors[kTextColorHover]; +			 +			default: +				return _textColors[kTextColorDefault]; +		} +	}  	OSystem *_system;  	Graphics::VectorRenderer *_vectorRenderer; @@ -266,6 +288,7 @@ protected:  	Common::String _fontName;  	const Graphics::Font *_font; +	uint32 _textColors[kTextColorMAX];  	WidgetDrawData *_widgets[kDrawDataMAX];  	Common::Array<Common::Rect> _dirtyScreen; | 
