More widgets.

svn-id: r33071
This commit is contained in:
Vicent Marti 2008-07-15 10:50:31 +00:00
parent d3d34ef295
commit b44b37d4ca
6 changed files with 98 additions and 23 deletions

View file

@ -489,6 +489,8 @@ public:
*/ */
virtual void blitSurface(Graphics::Surface *source, const Common::Rect &r) = 0; 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 drawString(const Graphics::Font *font, const Common::String &text, const Common::Rect &area, GUI::Theme::TextAlign alignH, GUI::Theme::TextAlignVertical alignV) = 0;
protected: protected:
@ -651,6 +653,10 @@ public:
} }
} }
virtual uint32 buildColor(uint8 r, uint8 g, uint8 b) {
return RGBToColor<PixelFormat>(r, g, b);
}
protected: protected:
/** /**

View file

@ -41,7 +41,10 @@ bool ThemeRenderer::loadDefaultXML() {
"<palette>" "<palette>"
"<color name = 'red' rgb = '255, 0, 0' />" "<color name = 'red' rgb = '255, 0, 0' />"
"<color name = 'green' rgb = '0, 255, 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>" "</palette>"
"<default fill = 'gradient' fg_color = '255, 255, 255' />" "<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' />" "<drawstep func = 'square' fill = 'foreground' height = '3' ypos = 'center' fg_color = '0, 0, 0' />"
"</drawdata>" "</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>" "<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 = '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' />" "<drawstep func = 'triangle' fg_color = '0, 0, 0' fill = 'foreground' width = '12' height = '12' xpos = '-16' ypos = 'center' orientation = 'bottom' />"

View file

@ -173,30 +173,32 @@ bool ThemeParser::parserCallback_text() {
step.alignVertical = GUI::Theme::kTextAlignVBottom; step.alignVertical = GUI::Theme::kTextAlignVBottom;
else return parserError("Invalid value for text alignment."); else return parserError("Invalid value for text alignment.");
if (tNode->values.contains("color")) { Common::String paletteColor = "text_default";
int red, green, blue; int red, green, blue;
if (parseIntegerKey(tNode->values["color"].c_str(), 3, &red, &green, &blue) == false || if (tNode->name.contains("hover"))
red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255) paletteColor = "text_hover";
if (tNode->name.contains("disabled"))
paletteColor = "text_disabled";
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"); return parserError("Error when parsing color value for text definition");
} 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.r = red;
step.color.g = green; step.color.g = green;
step.color.b = blue; step.color.b = blue;
step.color.set = true; 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); _theme->addTextStep(parentNode->values["id"], step);
return true; return true;

View file

@ -317,6 +317,17 @@ class ThemeParser : public XMLParser {
public: public:
ThemeParser(GUI::ThemeRenderer *parent); 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: protected:
ThemeRenderer *_theme; ThemeRenderer *_theme;
bool keyCallback(Common::String keyName); bool keyCallback(Common::String keyName);

View file

@ -69,7 +69,8 @@ const char *ThemeRenderer::kDrawDataStrings[] = {
"popup_hover", "popup_hover",
"caret", "caret",
"separator" "separator",
"default_text"
}; };
ThemeRenderer::ThemeRenderer(Common::String themeName, GraphicsMode mode) : ThemeRenderer::ThemeRenderer(Common::String themeName, GraphicsMode mode) :
@ -235,6 +236,19 @@ bool ThemeRenderer::loadTheme(Common::String themeName) {
} }
} }
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; _themeOk = true;
return true; return true;
} }
@ -361,6 +375,9 @@ void ThemeRenderer::drawScrollbar(const Common::Rect &r, int sliderY, int slider
if (!ready()) if (!ready())
return; return;
drawDD(kDDScrollbarBase, r);
debugWidgetPosition("SCB", r); debugWidgetPosition("SCB", r);
} }
@ -443,6 +460,15 @@ void ThemeRenderer::drawTab(const Common::Rect &r, int tabHeight, int tabWidth,
debugWidgetPosition("Tab widget", r); 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) { 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); // _font->drawString(_screen, name, r.left, r.top, r.width(), 0xFFFF, Graphics::kTextAlignRight, 0, true);
// _screen->hLine(r.left, r.top, r.right, 0xFFFF); // _screen->hLine(r.left, r.top, r.right, 0xFFFF);

View file

@ -112,9 +112,18 @@ public:
kDDCaret, kDDCaret,
kDDSeparator, kDDSeparator,
kDDDefaultText,
kDrawDataMAX kDrawDataMAX
}; };
enum TextColor {
kTextColorDefault,
kTextColorHover,
kTextColorDisabled,
kTextColorInverted,
kTextColorMAX
};
ThemeRenderer(Common::String themeName, GraphicsMode mode); ThemeRenderer(Common::String themeName, GraphicsMode mode);
~ThemeRenderer() { ~ThemeRenderer() {
@ -160,7 +169,7 @@ public:
void drawLineSeparator(const Common::Rect &r, WidgetStateInfo state = kStateEnabled); void drawLineSeparator(const Common::Rect &r, WidgetStateInfo state = kStateEnabled);
void drawDialogBackground(const Common::Rect &r, uint16 hints, WidgetStateInfo state); 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) {} 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) { bool addDirtyRect(Common::Rect r, bool backup = false, bool special = false) {
@ -255,6 +264,19 @@ protected:
return 3; return 3;
} }
uint32 getTextColor(WidgetStateInfo state) {
switch (state) {
case kStateDisabled:
return _textColors[kTextColorDisabled];
case kStateHighlight:
return _textColors[kTextColorHover];
default:
return _textColors[kTextColorDefault];
}
}
OSystem *_system; OSystem *_system;
Graphics::VectorRenderer *_vectorRenderer; Graphics::VectorRenderer *_vectorRenderer;
GUI::ThemeParser *_parser; GUI::ThemeParser *_parser;
@ -266,6 +288,7 @@ protected:
Common::String _fontName; Common::String _fontName;
const Graphics::Font *_font; const Graphics::Font *_font;
uint32 _textColors[kTextColorMAX];
WidgetDrawData *_widgets[kDrawDataMAX]; WidgetDrawData *_widgets[kDrawDataMAX];
Common::Array<Common::Rect> _dirtyScreen; Common::Array<Common::Rect> _dirtyScreen;