diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-07-09 20:43:13 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-07-13 01:02:41 +0300 |
commit | 47e405bb722a222ae7e536bbada2c44d8ea0cd73 (patch) | |
tree | 65230239ca4f797aafb9dfb60af98b7129c87667 | |
parent | 25ebec2265b2b995bb85ce74f25db8137ea9db87 (diff) | |
download | plus-47e405bb722a222ae7e536bbada2c44d8ea0cd73.tar.gz plus-47e405bb722a222ae7e536bbada2c44d8ea0cd73.tar.bz2 plus-47e405bb722a222ae7e536bbada2c44d8ea0cd73.tar.xz plus-47e405bb722a222ae7e536bbada2c44d8ea0cd73.zip |
Change slider theming.
-rw-r--r-- | data/graphics/gui/CMakeLists.txt | 4 | ||||
-rw-r--r-- | data/graphics/gui/Makefile.am | 4 | ||||
-rw-r--r-- | data/graphics/gui/slider.png | bin | 485 -> 0 bytes | |||
-rw-r--r-- | data/graphics/gui/slider.xml | 13 | ||||
-rw-r--r-- | data/graphics/gui/slider_highlighted.xml | 13 | ||||
-rw-r--r-- | data/graphics/gui/slider_hilight.png | bin | 444 -> 0 bytes | |||
-rw-r--r-- | data/graphics/gui/window.png | bin | 12406 -> 13236 bytes | |||
-rw-r--r-- | src/gui/theme.cpp | 16 | ||||
-rw-r--r-- | src/gui/widgets/slider.cpp | 225 | ||||
-rw-r--r-- | src/gui/widgets/slider.h | 23 |
10 files changed, 118 insertions, 180 deletions
diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index b03b856c7..af8e0b2b2 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -30,8 +30,8 @@ SET (FILES scrollbuttons.xml scrollbuttons_pressed.xml selection.png - slider.png - slider_hilight.png + slider.xml + slider_highlighted.xml speechbubble.xml sticky_button.png tab.xml diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am index b8591a783..75ea12a3a 100644 --- a/data/graphics/gui/Makefile.am +++ b/data/graphics/gui/Makefile.am @@ -33,8 +33,8 @@ gui_DATA = \ scrollbuttons.xml \ scrollbuttons_pressed.xml\ selection.png \ - slider.png \ - slider_hilight.png \ + slider.xml \ + slider_highlighted.xml \ speechbubble.xml \ sticky_button.png \ tab.xml \ diff --git a/data/graphics/gui/slider.png b/data/graphics/gui/slider.png Binary files differdeleted file mode 100644 index 465ad0e88..000000000 --- a/data/graphics/gui/slider.png +++ /dev/null diff --git a/data/graphics/gui/slider.xml b/data/graphics/gui/slider.xml new file mode 100644 index 000000000..163e3258d --- /dev/null +++ b/data/graphics/gui/slider.xml @@ -0,0 +1,13 @@ +<skinset name="Default" image="window.png"> + <widget type="Window" xpos="98" ypos="0"> + <part type="hstart" xpos="0" ypos="0" width="4" height="6" /> + <part type="hmiddle" xpos="4" ypos="0" width="7" height="6" /> + <part type="hend" xpos="11" ypos="0" width="4" height="6" /> + <part type="hgrip" xpos="6" ypos="7" width="9" height="10" /> + + <part type="vstart" xpos="0" ypos="6" width="6" height="4" /> + <part type="vmiddle" xpos="0" ypos="10" width="6" height="8" /> + <part type="vend" xpos="0" ypos="18" width="6" height="9" /> + <part type="vgrip" xpos="6" ypos="7" width="9" height="10" /> + </widget> +</skinset> diff --git a/data/graphics/gui/slider_highlighted.xml b/data/graphics/gui/slider_highlighted.xml new file mode 100644 index 000000000..af5f4a0e6 --- /dev/null +++ b/data/graphics/gui/slider_highlighted.xml @@ -0,0 +1,13 @@ +<skinset name="Default" image="window.png"> + <widget type="Window" xpos="98" ypos="50"> + <part type="hstart" xpos="0" ypos="0" width="4" height="6" /> + <part type="hmiddle" xpos="4" ypos="0" width="7" height="6" /> + <part type="hend" xpos="11" ypos="0" width="4" height="6" /> + <part type="hgrip" xpos="6" ypos="7" width="9" height="10" /> + + <part type="vstart" xpos="0" ypos="6" width="6" height="4" /> + <part type="vmiddle" xpos="0" ypos="10" width="6" height="8" /> + <part type="vend" xpos="0" ypos="18" width="6" height="9" /> + <part type="vgrip" xpos="6" ypos="7" width="9" height="10" /> + </widget> +</skinset> diff --git a/data/graphics/gui/slider_hilight.png b/data/graphics/gui/slider_hilight.png Binary files differdeleted file mode 100644 index 37c780cd1..000000000 --- a/data/graphics/gui/slider_hilight.png +++ /dev/null diff --git a/data/graphics/gui/window.png b/data/graphics/gui/window.png Binary files differindex 37395d0a2..2e3454976 100644 --- a/data/graphics/gui/window.png +++ b/data/graphics/gui/window.png diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 9bf5adcf6..727777286 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -411,13 +411,21 @@ Skin *Theme::readSkin(const std::string &filename) else loadSkinImage(8, "bottom-right-corner") else - loadSkinImage(0, "up") + loadSkinImage2(0, "up", "hstart") else - loadSkinImage(1, "down") + loadSkinImage2(1, "down", "hmiddle") else - loadSkinImage(2, "left") + loadSkinImage2(2, "left", "hend") else - loadSkinImage(3, "right") + loadSkinImage2(3, "right", "hgrip") + else + loadSkinImage(4, "vstart") + else + loadSkinImage(5, "vmiddle") + else + loadSkinImage(6, "vend") + else + loadSkinImage(7, "vgrip") } else if (xmlNameEqual(partNode, "option")) { diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index 69df4c289..595b2f85d 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -34,13 +34,16 @@ #include "debug.h" -Image *Slider::hStart, *Slider::hMid, *Slider::hEnd, *Slider::hGrip; -Image *Slider::vStart, *Slider::vMid, *Slider::vEnd, *Slider::vGrip; -Image *Slider::hStartHi, *Slider::hMidHi, *Slider::hEndHi, *Slider::hGripHi; -Image *Slider::vStartHi, *Slider::vMidHi, *Slider::vEndHi, *Slider::vGripHi; +ImageRect Slider::buttons[2]; float Slider::mAlpha = 1.0; int Slider::mInstances = 0; +static std::string const data[2] = +{ + "slider.xml", + "slider_highlighted.xml" +}; + Slider::Slider(double scaleEnd): gcn::Slider(scaleEnd), mHasMouse(false) @@ -58,26 +61,6 @@ Slider::Slider(double scaleStart, double scaleEnd): Slider::~Slider() { mInstances--; - - if (mInstances == 0) - { - delete hStart; - delete hMid; - delete hEnd; - delete hGrip; - delete vStart; - delete vMid; - delete vEnd; - delete vGrip; - delete hStartHi; - delete hMidHi; - delete hEndHi; - delete hGripHi; - delete vStartHi; - delete vMidHi; - delete vEndHi; - delete vGripHi; - } } void Slider::init() @@ -87,100 +70,18 @@ void Slider::init() // Load resources if (mInstances == 0) { - int x, y, w, h, o1, o2; - - Image *slider = Theme::getImageFromTheme("slider.png"); - Image *sliderHi = Theme::getImageFromTheme("slider_hilight.png"); - - x = 0; y = 0; - w = 15; h = 6; - o1 = 4; o2 = 11; - if (slider) - { - hStart = slider->getSubImage(x, y, o1 - x, h); - hMid = slider->getSubImage(o1, y, o2 - o1, h); - hEnd = slider->getSubImage(o2, y, w - o2 + x, h); - } - else - { - hStart = nullptr; - hMid = nullptr; - hEnd = nullptr; - } - if (sliderHi) - { - hStartHi = sliderHi->getSubImage(x, y, o1 - x, h); - hMidHi = sliderHi->getSubImage(o1, y, o2 - o1, h); - hEndHi = sliderHi->getSubImage(o2, y, w - o2 + x, h); - } - else - { - hStartHi = nullptr; - hMidHi = nullptr; - hEndHi = nullptr; - } - - x = 6; y = 8; - w = 9; h = 10; - if (slider) - hGrip = slider->getSubImage(x, y, w, h); - else - hGrip = nullptr; - if (sliderHi) - hGripHi = sliderHi->getSubImage(x, y, w, h); - else - hGripHi = nullptr; - - x = 0; y = 6; - w = 6; h = 21; - o1 = 10; o2 = 18; - if (slider) - { - vStart = slider->getSubImage(x, y, w, o1 - y); - vMid = slider->getSubImage(x, o1, w, o2 - o1); - vEnd = slider->getSubImage(x, o2, w, h - o2 + y); - } - else - { - vStart = nullptr; - vMid = nullptr; - vEnd = nullptr; - } - if (sliderHi) - { - vStartHi = sliderHi->getSubImage(x, y, w, o1 - y); - vMidHi = sliderHi->getSubImage(x, o1, w, o2 - o1); - vEndHi = sliderHi->getSubImage(x, o2, w, h - o2 + y); - } - else + if (Theme::instance()) { - vStartHi = nullptr; - vMidHi = nullptr; - vEndHi = nullptr; + for (int mode = 0; mode < 2; mode ++) + Theme::instance()->loadRect(buttons[mode], data[mode], 0, 8); } - - x = 6; y = 8; - w = 9; h = 10; - if (slider) - vGrip = slider->getSubImage(x, y, w, h); - else - vGrip = nullptr; - - if (sliderHi) - vGripHi = sliderHi->getSubImage(x, y, w, h); - else - vGripHi = nullptr; - - if (slider) - slider->decRef(); - if (sliderHi) - sliderHi->decRef(); + updateAlpha(); } mInstances++; - if (hGrip) - setMarkerLength(hGrip->getWidth()); + if (buttons[0].grid[HGRIP]) + setMarkerLength(buttons[0].grid[HGRIP]->getWidth()); } void Slider::updateAlpha() @@ -191,90 +92,77 @@ void Slider::updateAlpha() if (alpha != mAlpha) { mAlpha = alpha; - if (hStart) - hStart->setAlpha(mAlpha); - if (hMid) - hMid->setAlpha(mAlpha); - if (hEnd) - hEnd->setAlpha(mAlpha); - if (hGrip) - hGrip->setAlpha(mAlpha); - if (hStartHi) - hStartHi->setAlpha(mAlpha); - if (hMidHi) - hMidHi->setAlpha(mAlpha); - if (hEndHi) - hEndHi->setAlpha(mAlpha); - if (hGripHi) - hGripHi->setAlpha(mAlpha); - - if (vStart) - vStart->setAlpha(mAlpha); - if (vMid) - vMid->setAlpha(mAlpha); - if (vEnd) - vEnd->setAlpha(mAlpha); - if (vGrip) - vGrip->setAlpha(mAlpha); - if (vStartHi) - vStartHi->setAlpha(mAlpha); - if (vMidHi) - vMidHi->setAlpha(mAlpha); - if (vEndHi) - vEndHi->setAlpha(mAlpha); - if (vGripHi) - vGripHi->setAlpha(mAlpha); + for (int f = 0; f < 2; f ++) + { + for (int d = 0; d < SLIDER_MAX; d ++) + { + if (buttons[f].grid[d]) + buttons[f].grid[d]->setAlpha(mAlpha); + } + } } - } void Slider::draw(gcn::Graphics *graphics) { - if (!hStart || !hStartHi || !hEnd) + if (!buttons[0].grid[HSTART] || !buttons[1].grid[HSTART] + || !buttons[0].grid[HEND]) + { return; + } int w = getWidth(); int h = getHeight(); int x = 0; - int y = mHasMouse ? (h - hStartHi->getHeight()) / 2 : - (h - hStart->getHeight()) / 2; + int y = mHasMouse ? (h - buttons[1].grid[HSTART]->getHeight()) / 2 : + (h - buttons[0].grid[HSTART]->getHeight()) / 2; updateAlpha(); if (!mHasMouse) { - static_cast<Graphics*>(graphics)->drawImage(hStart, x, y); + static_cast<Graphics*>(graphics)->drawImage( + buttons[0].grid[HSTART], x, y); - w -= hStart->getWidth() + hEnd->getWidth(); - x += hStart->getWidth(); + const int width = buttons[0].grid[HSTART]->getWidth(); + w -= width + buttons[0].grid[HEND]->getWidth(); + x += width; - if (hMid) + if (buttons[0].grid[HMID]) { + const Image *hMid = buttons[0].grid[HMID]; static_cast<Graphics*>(graphics)-> drawImagePattern(hMid, x, y, w, hMid->getHeight()); } x += w; - static_cast<Graphics*>(graphics)->drawImage(hEnd, x, y); + static_cast<Graphics*>(graphics)->drawImage(buttons[0].grid[HEND], x, y); } else { - static_cast<Graphics*>(graphics)->drawImage(hStartHi, x, y); + static_cast<Graphics*>(graphics)->drawImage( + buttons[1].grid[HSTART], x, y); - w -= hStartHi->getWidth(); - if (hEndHi) - w -= hEndHi->getWidth(); - x += hStartHi->getWidth(); + const int width = buttons[1].grid[HSTART]->getWidth(); + w -= width; + if (buttons[1].grid[HEND]) + w -= buttons[1].grid[HEND]->getWidth(); + x += width; - if (hMidHi) + if (buttons[1].grid[HMID]) { - static_cast<Graphics*>(graphics)-> - drawImagePattern(hMidHi, x, y, w, hMidHi->getHeight()); + const Image *hMid = buttons[1].grid[HMID]; + static_cast<Graphics*>(graphics)->drawImagePattern( + hMid, x, y, w, + hMid->getHeight()); } x += w; - if (hEndHi) - static_cast<Graphics*>(graphics)->drawImage(hEndHi, x, y); + if (buttons[1].grid[HEND]) + { + static_cast<Graphics*>(graphics)->drawImage( + buttons[1].grid[HEND], x, y); + } } drawMarker(graphics); @@ -282,12 +170,13 @@ void Slider::draw(gcn::Graphics *graphics) void Slider::drawMarker(gcn::Graphics *graphics) { - if (!(mHasMouse?hGripHi:hGrip)) + const Image *img = (mHasMouse ? buttons[1].grid[HGRIP] + : buttons[0].grid[HGRIP]); + if (!img) return; - static_cast<Graphics*>(graphics)-> - drawImage(mHasMouse?hGripHi:hGrip, getMarkerPosition(), - (getHeight() - (mHasMouse?hGripHi:hGrip)->getHeight()) / 2); + static_cast<Graphics*>(graphics)->drawImage(img, getMarkerPosition(), + (getHeight() - img->getHeight()) / 2); } void Slider::mouseEntered(gcn::MouseEvent& event A_UNUSED) diff --git a/src/gui/widgets/slider.h b/src/gui/widgets/slider.h index 00aefcb1a..94eef42a0 100644 --- a/src/gui/widgets/slider.h +++ b/src/gui/widgets/slider.h @@ -26,6 +26,7 @@ #include <guichan/widgets/slider.hpp> class Image; +class ImageRect; /** * Slider widget. Same as the Guichan slider but with custom look. @@ -77,16 +78,30 @@ class Slider : public gcn::Slider void keyPressed(gcn::KeyEvent& keyEvent); + enum SLIDER_ENUM + { + HSTART, + HMID, + HEND, + HGRIP, + VSTART, + VMID, + VEND, + VGRIP, + SLIDER_MAX + }; + private: /** * Used to initialize instances. */ void init(); - static Image *hStart, *hMid, *hEnd, *hGrip; - static Image *vStart, *vMid, *vEnd, *vGrip; - static Image *hStartHi, *hMidHi, *hEndHi, *hGripHi; - static Image *vStartHi, *vMidHi, *vEndHi, *vGripHi; + static ImageRect buttons[2]; + //*hStart, *hMid, *hEnd, *hGrip; +// static Image *vStart, *vMid, *vEnd, *vGrip; +// static Image *hStartHi, *hMidHi, *hEndHi, *hGripHi; +// static Image *vStartHi, *vMidHi, *vEndHi, *vGripHi; bool mHasMouse; static float mAlpha; static int mInstances; |