From 960820b57ecf45a4bf5e337bf36adbe02e668fbf Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 8 Jul 2012 13:48:58 +0300 Subject: Improve theming. Add support for theming button. --- data/graphics/gui/CMakeLists.txt | 5 +-- data/graphics/gui/Makefile.am | 5 +-- data/graphics/gui/button.png | Bin 374 -> 0 bytes data/graphics/gui/button.xml | 18 +++++++++ data/graphics/gui/button_disabled.png | Bin 313 -> 0 bytes data/graphics/gui/button_disabled.xml | 18 +++++++++ data/graphics/gui/button_highlighted.xml | 18 +++++++++ data/graphics/gui/button_pressed.xml | 18 +++++++++ data/graphics/gui/buttonhi.png | Bin 374 -> 0 bytes data/graphics/gui/buttonpress.png | Bin 377 -> 0 bytes data/graphics/gui/window.png | Bin 3410 -> 4857 bytes src/gui/theme.cpp | 51 +++++++++++++++++-------- src/gui/widgets/button.cpp | 62 +++++++++++-------------------- 13 files changed, 132 insertions(+), 63 deletions(-) delete mode 100644 data/graphics/gui/button.png create mode 100644 data/graphics/gui/button.xml delete mode 100644 data/graphics/gui/button_disabled.png create mode 100644 data/graphics/gui/button_disabled.xml create mode 100644 data/graphics/gui/button_highlighted.xml create mode 100644 data/graphics/gui/button_pressed.xml delete mode 100644 data/graphics/gui/buttonhi.png delete mode 100644 data/graphics/gui/buttonpress.png diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index b262a5ac3..2fefbfe6c 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -1,10 +1,7 @@ SET (FILES bubble.png - button.png - button_disabled.png - buttonhi.png + button.xml buttonplay.png - buttonpress.png checkbox.png circle-gray.png circle-green.png diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am index 6f294fa45..0e3e13a1e 100644 --- a/data/graphics/gui/Makefile.am +++ b/data/graphics/gui/Makefile.am @@ -3,11 +3,8 @@ guidir = $(pkgdatadir)/data/graphics/gui gui_DATA = \ bubble.png \ - button.png \ - button_disabled.png \ - buttonhi.png \ + button.xml \ buttonplay.png \ - buttonpress.png \ checkbox.png \ circle-gray.png \ circle-green.png \ diff --git a/data/graphics/gui/button.png b/data/graphics/gui/button.png deleted file mode 100644 index 9ebbea639..000000000 Binary files a/data/graphics/gui/button.png and /dev/null differ diff --git a/data/graphics/gui/button.xml b/data/graphics/gui/button.xml new file mode 100644 index 000000000..899030820 --- /dev/null +++ b/data/graphics/gui/button.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/data/graphics/gui/button_disabled.png b/data/graphics/gui/button_disabled.png deleted file mode 100644 index 0ce3aa6ff..000000000 Binary files a/data/graphics/gui/button_disabled.png and /dev/null differ diff --git a/data/graphics/gui/button_disabled.xml b/data/graphics/gui/button_disabled.xml new file mode 100644 index 000000000..8194bf4d5 --- /dev/null +++ b/data/graphics/gui/button_disabled.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/data/graphics/gui/button_highlighted.xml b/data/graphics/gui/button_highlighted.xml new file mode 100644 index 000000000..356cee5ce --- /dev/null +++ b/data/graphics/gui/button_highlighted.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/data/graphics/gui/button_pressed.xml b/data/graphics/gui/button_pressed.xml new file mode 100644 index 000000000..bd9de9e28 --- /dev/null +++ b/data/graphics/gui/button_pressed.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/data/graphics/gui/buttonhi.png b/data/graphics/gui/buttonhi.png deleted file mode 100644 index c47726346..000000000 Binary files a/data/graphics/gui/buttonhi.png and /dev/null differ diff --git a/data/graphics/gui/buttonpress.png b/data/graphics/gui/buttonpress.png deleted file mode 100644 index e9cd17653..000000000 Binary files a/data/graphics/gui/buttonpress.png and /dev/null differ diff --git a/data/graphics/gui/window.png b/data/graphics/gui/window.png index f0ef1af4b..a0d5da63c 100644 Binary files a/data/graphics/gui/window.png and b/data/graphics/gui/window.png differ diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 704a1f939..779d98768 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -307,15 +307,33 @@ void Theme::optionChanged(const std::string &) updateAlpha(); } -#define loadSkinSubImage(object, name) \ +#define loadSkinImage(obj, name) \ if (partType == name) \ { \ if (dBorders) \ - object = dBorders->getSubImage(xPos, yPos, width, height); \ + { \ + border.grid[obj] = dBorders->getSubImage( \ + xPos, yPos, width, height); \ + } \ else \ - object = nullptr; \ + { \ + border.grid[obj] = nullptr; \ + } \ } +#define loadSkinImage2(obj, name1, name2) \ + if (partType == name1 || partType == name2) \ + { \ + if (dBorders) \ + { \ + border.grid[obj] = dBorders->getSubImage( \ + xPos, yPos, width, height); \ + } \ + else \ + { \ + border.grid[obj] = nullptr; \ + } \ + } Skin *Theme::readSkin(const std::string &filename) { @@ -360,35 +378,38 @@ Skin *Theme::readSkin(const std::string &filename) XML::getProperty(widgetNode, "type", "unknown"); if (widgetType == "Window") { + const int globalXPos = XML::getProperty(widgetNode, "xpos", 0); + const int globalYPos = XML::getProperty(widgetNode, "ypos", 0); for_each_xml_child_node(partNode, widgetNode) { if (xmlNameEqual(partNode, "part")) { const std::string partType = XML::getProperty(partNode, "type", "unknown"); - // TOP ROW - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); + const int xPos = XML::getProperty( + partNode, "xpos", 0) + globalXPos; + const int yPos = XML::getProperty( + partNode, "ypos", 0) + globalYPos; const int width = XML::getProperty(partNode, "width", 1); const int height = XML::getProperty(partNode, "height", 1); - loadSkinSubImage(border.grid[0], "top-left-corner") + loadSkinImage2(0, "top-left-corner", "standart") else - loadSkinSubImage(border.grid[1], "top-edge") + loadSkinImage2(1, "top-edge", "highlighted") else - loadSkinSubImage(border.grid[2], "top-right-corner") + loadSkinImage2(2, "top-right-corner", "pressed") else - loadSkinSubImage(border.grid[3], "left-edge") + loadSkinImage2(3, "left-edge", "disabled") else - loadSkinSubImage(border.grid[4], "bg-quad") + loadSkinImage(4, "bg-quad") else - loadSkinSubImage(border.grid[5], "right-edge") + loadSkinImage(5, "right-edge") else - loadSkinSubImage(border.grid[6], "bottom-left-corner") + loadSkinImage(6, "bottom-left-corner") else - loadSkinSubImage(border.grid[7], "bottom-edge") + loadSkinImage(7, "bottom-edge") else - loadSkinSubImage(border.grid[8], "bottom-right-corner") + loadSkinImage(8, "bottom-right-corner") } else if (xmlNameEqual(partNode, "option")) { diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 15af963b0..990faaaeb 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -55,19 +55,12 @@ enum BUTTON_COUNT // 4 - Must be last. }; -struct ButtonData +static std::string const data[BUTTON_COUNT] = { - char const *file; - int gridX; - int gridY; -}; - -static ButtonData const data[BUTTON_COUNT] = -{ - { "button.png", 0, 0 }, - { "buttonhi.png", 9, 4 }, - { "buttonpress.png", 16, 19 }, - { "button_disabled.png", 25, 23 } + "button.xml", + "button_highlighted.xml", + "button_pressed.xml", + "button_disabled.xml" }; ImageRect Button::button[BUTTON_COUNT]; @@ -183,29 +176,29 @@ void Button::init() // Load the skin Image *btn[BUTTON_COUNT]; - int a, x, y, mode; - - for (mode = 0; mode < BUTTON_COUNT; mode++) + if (Theme::instance()) { - btn[mode] = Theme::getImageFromTheme(data[mode].file); - if (!btn[mode]) - continue; - - a = 0; - for (y = 0; y < 3; y++) + for (int mode = 0; mode < BUTTON_COUNT; mode ++) { - for (x = 0; x < 3; x++) + Skin *skin = Theme::instance()->load(data[mode]); + if (skin) { - button[mode].grid[a] = btn[mode]->getSubImage( - data[x].gridX, data[y].gridY, - data[x + 1].gridX - data[x].gridX + 1, - data[y + 1].gridY - data[y].gridY + 1); - a++; + const ImageRect &rect = skin->getBorder(); + + for (int f = 0; f < 9; f ++) + { + if (rect.grid[f]) + { + rect.grid[f]->incRef(); + button[mode].grid[f] = rect.grid[f]; + } + } + + Theme::instance()->unload(skin); } } - if (btn[mode]) - btn[mode]->decRef(); } + updateAlpha(); } mEnabledColor = Theme::getThemeColor(Theme::BUTTON); @@ -220,17 +213,6 @@ Button::~Button() delete mVertexes; mVertexes = nullptr; - if (mInstances == 0) - { - for (int mode = 0; mode < BUTTON_COUNT; mode++) - { - if (button[mode].grid) - { - for_each(button[mode].grid, - button[mode].grid + 9, dtor()); - } - } - } if (mImageSet) { mImageSet->decRef(); -- cgit v1.2.3-60-g2f50