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. --- src/gui/widgets/button.cpp | 62 ++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 40 deletions(-) (limited to 'src/gui/widgets') 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