diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-07-08 20:03:16 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-07-13 01:02:40 +0300 |
commit | 36b586e32474e0d21de2383aa106869cfef89902 (patch) | |
tree | 6db1072a500cc63124c3a9a0712eada375605527 /src/gui | |
parent | 960820b57ecf45a4bf5e337bf36adbe02e668fbf (diff) | |
download | mv-36b586e32474e0d21de2383aa106869cfef89902.tar.gz mv-36b586e32474e0d21de2383aa106869cfef89902.tar.bz2 mv-36b586e32474e0d21de2383aa106869cfef89902.tar.xz mv-36b586e32474e0d21de2383aa106869cfef89902.zip |
Change scrollarea theming.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/theme.cpp | 26 | ||||
-rw-r--r-- | src/gui/theme.h | 3 | ||||
-rw-r--r-- | src/gui/widgets/button.cpp | 22 | ||||
-rw-r--r-- | src/gui/widgets/scrollarea.cpp | 135 | ||||
-rw-r--r-- | src/gui/widgets/scrollarea.h | 3 |
5 files changed, 61 insertions, 128 deletions
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 779d98768..9bf5adcf6 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -410,6 +410,14 @@ Skin *Theme::readSkin(const std::string &filename) loadSkinImage(7, "bottom-edge") else loadSkinImage(8, "bottom-right-corner") + else + loadSkinImage(0, "up") + else + loadSkinImage(1, "down") + else + loadSkinImage(2, "left") + else + loadSkinImage(3, "right") } else if (xmlNameEqual(partNode, "option")) { @@ -818,3 +826,21 @@ void Theme::loadColors(std::string file) } } } + +void Theme::loadRect(ImageRect &image, std::string name, int start, int end) +{ + Skin *skin = load(name); + if (skin) + { + const ImageRect &rect = skin->getBorder(); + for (int f = start; f <= end; f ++) + { + if (rect.grid[f]) + { + rect.grid[f]->incRef(); + image.grid[f] = rect.grid[f]; + } + } + unload(skin); + } +} diff --git a/src/gui/theme.h b/src/gui/theme.h index 8c5675454..144cfd274 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -269,6 +269,9 @@ class Theme : public Palette, public ConfigListener void optionChanged(const std::string &); + void loadRect(ImageRect &image, std::string name, + int start = 0, int end = 8); + private: Theme(); ~Theme(); diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 990faaaeb..ba789f2c5 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -173,30 +173,10 @@ void Button::init() if (mInstances == 0) { - // Load the skin - Image *btn[BUTTON_COUNT]; - if (Theme::instance()) { for (int mode = 0; mode < BUTTON_COUNT; mode ++) - { - Skin *skin = Theme::instance()->load(data[mode]); - if (skin) - { - 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); - } - } + Theme::instance()->loadRect(button[mode], data[mode]); } updateAlpha(); diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 021bd3d15..4e15bc167 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -43,6 +43,12 @@ ImageRect ScrollArea::vMarker; ImageRect ScrollArea::vMarkerHi; Image *ScrollArea::buttons[4][2]; +static std::string const buttonFiles[2] = +{ + "scrollbuttons.xml", + "scrollbuttons_pressed.xml" +}; + ScrollArea::ScrollArea(): gcn::ScrollArea(), mX(0), @@ -87,29 +93,6 @@ ScrollArea::~ScrollArea() instances--; - if (instances == 0) - { - for_each(background.grid, background.grid + 9, dtor<Image*>()); - for_each(vMarker.grid, vMarker.grid + 9, dtor<Image*>()); - for_each(vMarkerHi.grid, vMarkerHi.grid + 9, dtor<Image*>()); - - if (buttons[UP][0]) - buttons[UP][0]->decRef(); - if (buttons[UP][1]) - buttons[UP][1]->decRef(); - if (buttons[DOWN][0]) - buttons[DOWN][0]->decRef(); - if (buttons[DOWN][1]) - buttons[DOWN][1]->decRef(); - if (buttons[LEFT][0]) - buttons[LEFT][0]->decRef(); - if (buttons[LEFT][1]) - buttons[LEFT][1]->decRef(); - if (buttons[RIGHT][0]) - buttons[RIGHT][0]->decRef(); - if (buttons[RIGHT][1]) - buttons[RIGHT][1]->decRef(); - } delete mVertexes; mVertexes = nullptr; } @@ -126,99 +109,39 @@ void ScrollArea::init() if (instances == 0) { - // Load the background skin - Image *textbox = Theme::getImageFromTheme("deepbox.png"); - const int bggridx[4] = {0, 3, 28, 31}; - const int bggridy[4] = {0, 3, 28, 31}; - int a = 0, x, y; - - for (y = 0; y < 3; y++) + for (int f = 0; f < 9; f ++) { - for (x = 0; x < 3; x++) - { - if (textbox) - { - background.grid[a] = textbox->getSubImage( - bggridx[x], bggridy[y], - bggridx[x + 1] - bggridx[x] + 1, - bggridy[y + 1] - bggridy[y] + 1); - background.grid[a]->setAlpha( - Client::getGuiAlpha()); - } - else - { - background.grid[a] = nullptr; - } - a++; - } + background.grid[f] = nullptr; + vMarker.grid[f] = nullptr; + vMarkerHi.grid[f] = nullptr; } - if (textbox) - textbox->decRef(); - - // Load vertical scrollbar skin - Image *vscroll = Theme::getImageFromTheme("vscroll_grey.png"); - Image *vscrollHi = Theme::getImageFromTheme("vscroll_highlight.png"); - - int vsgridx[4] = {0, 4, 7, 11}; - int vsgridy[4] = {0, 4, 15, 19}; - a = 0; + if (Theme::instance()) + { + Theme::instance()->loadRect(background, "scroll_background.xml"); + Theme::instance()->loadRect(vMarker, "scroll.xml"); + Theme::instance()->loadRect(vMarkerHi, "scroll_highlighted.xml"); + } - for (y = 0; y < 3; y++) + for (int i = 0; i < 2; i ++) { - for (x = 0; x < 3; x++) + Skin *skin = Theme::instance()->load(buttonFiles[i]); + if (skin) { - if (vscroll) - { - vMarker.grid[a] = vscroll->getSubImage( - vsgridx[x], vsgridy[y], - vsgridx[x + 1] - vsgridx[x], - vsgridy[y + 1] - vsgridy[y]); - vMarker.grid[a]->setAlpha( - Client::getGuiAlpha()); - } - else - { - vMarker.grid[a] = nullptr; - } - if (vscrollHi) - { - vMarkerHi.grid[a] = vscrollHi->getSubImage( - vsgridx[x], vsgridy[y], - vsgridx[x + 1] - vsgridx[x], - vsgridy[y + 1] - vsgridy[y]); - vMarkerHi.grid[a]->setAlpha( - Client::getGuiAlpha()); - } - else + const ImageRect &rect = skin->getBorder(); + for (int f = UP; f < BUTTONS_DIR; f ++) { - vMarkerHi.grid[a] = nullptr; + rect.grid[f]->incRef(); + buttons[f][i] = rect.grid[f]; } - a++; } + else + { + for (int f = UP; f < BUTTONS_DIR; f ++) + buttons[f][i] = nullptr; + } + Theme::instance()->unload(skin); } - - if (vscroll) - vscroll->decRef(); - if (vscrollHi) - vscrollHi->decRef(); - - buttons[UP][0] = - Theme::getImageFromTheme("vscroll_up_default.png"); - buttons[DOWN][0] = - Theme::getImageFromTheme("vscroll_down_default.png"); - buttons[LEFT][0] = - Theme::getImageFromTheme("hscroll_left_default.png"); - buttons[RIGHT][0] = - Theme::getImageFromTheme("hscroll_right_default.png"); - buttons[UP][1] = - Theme::getImageFromTheme("vscroll_up_pressed.png"); - buttons[DOWN][1] = - Theme::getImageFromTheme("vscroll_down_pressed.png"); - buttons[LEFT][1] = - Theme::getImageFromTheme("hscroll_left_pressed.png"); - buttons[RIGHT][1] = - Theme::getImageFromTheme("hscroll_right_pressed.png"); } instances++; diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h index 582033071..53a79d20f 100644 --- a/src/gui/widgets/scrollarea.h +++ b/src/gui/widgets/scrollarea.h @@ -121,7 +121,8 @@ class ScrollArea : public gcn::ScrollArea, public gcn::WidgetListener UP = 0, DOWN, LEFT, - RIGHT + RIGHT, + BUTTONS_DIR }; /** |