diff options
Diffstat (limited to 'src/gui/widgets/slider.cpp')
-rw-r--r-- | src/gui/widgets/slider.cpp | 85 |
1 files changed, 74 insertions, 11 deletions
diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index 7cd0e54a..6ce5f849 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -29,17 +29,21 @@ 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; float Slider::mAlpha = 1.0; int Slider::mInstances = 0; Slider::Slider(double scaleEnd): - gcn::Slider(scaleEnd) + gcn::Slider(scaleEnd), + mHasMouse(false) { init(); } Slider::Slider(double scaleStart, double scaleEnd): - gcn::Slider(scaleStart, scaleEnd) + gcn::Slider(scaleStart, scaleEnd), + mHasMouse(false) { init(); } @@ -58,6 +62,14 @@ Slider::~Slider() delete vMid; delete vEnd; delete vGrip; + delete hStartHi; + delete hMidHi; + delete hEndHi; + delete hGripHi; + delete vStartHi; + delete vMidHi; + delete vEndHi; + delete vGripHi; } } @@ -71,6 +83,7 @@ void Slider::init() { ResourceManager *resman = ResourceManager::getInstance(); Image *slider = resman->getImage("graphics/gui/slider.png"); + Image *sliderHi = resman->getImage("graphics/gui/slider_hilight.png"); x = 0; y = 0; w = 15; h = 6; @@ -78,10 +91,14 @@ void Slider::init() 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); + 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); x = 6; y = 8; w = 9; h = 10; hGrip = slider->getSubImage(x, y, w, h); + hGripHi = sliderHi->getSubImage(x, y, w, h); x = 0; y = 6; w = 6; h = 21; @@ -89,22 +106,35 @@ void Slider::init() 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); + 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); x = 6; y = 8; w = 9; h = 10; vGrip = slider->getSubImage(x, y, w, h); + vGripHi = sliderHi->getSubImage(x, y, w, h); slider->decRef(); + sliderHi->decRef(); hStart->setAlpha(mAlpha); hMid->setAlpha(mAlpha); hEnd->setAlpha(mAlpha); hGrip->setAlpha(mAlpha); + hStartHi->setAlpha(mAlpha); + hMidHi->setAlpha(mAlpha); + hEndHi->setAlpha(mAlpha); + hGripHi->setAlpha(mAlpha); vStart->setAlpha(mAlpha); vMid->setAlpha(mAlpha); vEnd->setAlpha(mAlpha); vGrip->setAlpha(mAlpha); + vStartHi->setAlpha(mAlpha); + vMidHi->setAlpha(mAlpha); + vEndHi->setAlpha(mAlpha); + vGripHi->setAlpha(mAlpha); } mInstances++; @@ -117,7 +147,7 @@ void Slider::draw(gcn::Graphics *graphics) int w = getWidth(); int h = getHeight(); int x = 0; - int y = (h - hStart->getHeight()) / 2; + int y = mHasMouse?(h - hStartHi->getHeight()) / 2:(h - hStart->getHeight()) / 2; if (config.getValue("guialpha", 0.8) != mAlpha) { @@ -126,23 +156,45 @@ void Slider::draw(gcn::Graphics *graphics) hMid->setAlpha(mAlpha); hEnd->setAlpha(mAlpha); hGrip->setAlpha(mAlpha); + hStartHi->setAlpha(mAlpha); + hMidHi->setAlpha(mAlpha); + hEndHi->setAlpha(mAlpha); + hGripHi->setAlpha(mAlpha); vStart->setAlpha(mAlpha); vMid->setAlpha(mAlpha); vEnd->setAlpha(mAlpha); vGrip->setAlpha(mAlpha); + vStartHi->setAlpha(mAlpha); + vMidHi->setAlpha(mAlpha); + vEndHi->setAlpha(mAlpha); + vGripHi->setAlpha(mAlpha); } + if (!mHasMouse) + { + static_cast<Graphics*>(graphics)->drawImage(hStart, x, y); - static_cast<Graphics*>(graphics)->drawImage(hStart, x, y); + w -= hStart->getWidth() + hEnd->getWidth(); + x += hStart->getWidth(); - w -= hStart->getWidth() + hEnd->getWidth(); - x += hStart->getWidth(); + static_cast<Graphics*>(graphics)-> + drawImagePattern(hMid, x, y, w, hMid->getHeight()); - static_cast<Graphics*>(graphics)-> - drawImagePattern(hMid, x, y, w, hMid->getHeight()); + x += w; + static_cast<Graphics*>(graphics)->drawImage(hEnd, x, y); + } else + { + static_cast<Graphics*>(graphics)->drawImage(hStartHi, x, y); - x += w; - static_cast<Graphics*>(graphics)->drawImage(hEnd, x, y); + w -= hStartHi->getWidth() + hEndHi->getWidth(); + x += hStartHi->getWidth(); + + static_cast<Graphics*>(graphics)-> + drawImagePattern(hMidHi, x, y, w, hMidHi->getHeight()); + + x += w; + static_cast<Graphics*>(graphics)->drawImage(hEndHi, x, y); + } drawMarker(graphics); } @@ -150,5 +202,16 @@ void Slider::draw(gcn::Graphics *graphics) void Slider::drawMarker(gcn::Graphics *graphics) { static_cast<Graphics*>(graphics)-> - drawImage(hGrip, getMarkerPosition(), (getHeight() - hGrip->getHeight()) / 2); + drawImage(mHasMouse?hGripHi:hGrip, getMarkerPosition(), + (getHeight() - (mHasMouse?hGripHi:hGrip)->getHeight()) / 2); } + +void Slider::mouseEntered(gcn::MouseEvent& event) +{ + mHasMouse = true; +} + +void Slider::mouseExited(gcn::MouseEvent& event) +{ + mHasMouse = false; +}
\ No newline at end of file |