diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-11-03 19:30:43 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-11-03 19:30:43 +0300 |
commit | 9c3ba8303da72248d978696fc9363a2b47528b29 (patch) | |
tree | 354473f72b40e8db53c007cf9f9b92cdb2072068 | |
parent | fea0de5f467181252909f7c2456362a9c9401b0d (diff) | |
download | manaplus-9c3ba8303da72248d978696fc9363a2b47528b29.tar.gz manaplus-9c3ba8303da72248d978696fc9363a2b47528b29.tar.bz2 manaplus-9c3ba8303da72248d978696fc9363a2b47528b29.tar.xz manaplus-9c3ba8303da72248d978696fc9363a2b47528b29.zip |
add batch draw to slider.
-rw-r--r-- | src/gui/widgets/slider.cpp | 234 | ||||
-rw-r--r-- | src/gui/widgets/slider.h | 19 | ||||
-rw-r--r-- | src/guichan/include/guichan/widgets/slider.hpp | 15 | ||||
-rw-r--r-- | src/guichan/widgets/slider.cpp | 61 |
4 files changed, 196 insertions, 133 deletions
diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index a500a8014..27b5fa43a 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -23,6 +23,7 @@ #include "gui/widgets/slider.h" #include "client.h" +#include "graphicsvertexes.h" #include "input/keydata.h" #include "input/keyevent.h" @@ -44,7 +45,9 @@ static std::string const data[2] = Slider::Slider(const double scaleEnd) : gcn::Slider(scaleEnd), Widget2(), - mHasMouse(false) + mVertexes(new ImageCollection), + mHasMouse(false), + mRedraw(true) { init(); } @@ -52,7 +55,9 @@ Slider::Slider(const double scaleEnd) : Slider::Slider(const double scaleStart, const double scaleEnd) : gcn::Slider(scaleStart, scaleEnd), Widget2(), - mHasMouse(false) + mVertexes(new ImageCollection), + mHasMouse(false), + mRedraw(true) { init(); } @@ -62,6 +67,8 @@ Slider::~Slider() if (gui) gui->removeDragged(this); + delete mVertexes; + mVertexes = nullptr; mInstances--; if (mInstances == 0 && Theme::instance()) { @@ -127,79 +134,196 @@ void Slider::draw(gcn::Graphics *graphics) int x = 0; const int y = mHasMouse ? (h - buttons[1].grid[HSTART]->getHeight()) / 2 : (h - buttons[0].grid[HSTART]->getHeight()) / 2; + Graphics *const g = static_cast<Graphics*>(graphics); updateAlpha(); - if (!mHasMouse) + if (openGLMode != RENDER_SAFE_OPENGL) { - static_cast<Graphics*>(graphics)->drawImage( - buttons[0].grid[HSTART], x, y); - - const int width = buttons[0].grid[HSTART]->getWidth(); - w -= width + buttons[0].grid[HEND]->getWidth(); - x += width; - - if (buttons[0].grid[HMID]) + if (mRedraw || g->getRedraw()) { - const Image *const hMid = buttons[0].grid[HMID]; - static_cast<Graphics*>(graphics)-> - drawImagePattern(hMid, x, y, w, hMid->getHeight()); + mRedraw = false; + mVertexes->clear(); + if (!mHasMouse) + { + g->calcTile(mVertexes, buttons[0].grid[HSTART], x, y); + + const int width = buttons[0].grid[HSTART]->getWidth(); + w -= width + buttons[0].grid[HEND]->getWidth(); + x += width; + + if (buttons[0].grid[HMID]) + { + const Image *const hMid = buttons[0].grid[HMID]; + g->calcImagePattern(mVertexes, hMid, x, y, + w, hMid->getHeight()); + } + + x += w; + g->calcTile(mVertexes, buttons[0].grid[HEND], x, y); + + const Image *const img = buttons[0].grid[HGRIP]; + if (img) + { + g->calcTile(mVertexes, img, getMarkerPosition(), + (mDimension.height - img->getHeight()) / 2); + } + } + else + { + g->calcTile(mVertexes, buttons[1].grid[HSTART], x, y); + + const int width = buttons[1].grid[HSTART]->getWidth(); + w -= width; + if (buttons[1].grid[HEND]) + w -= buttons[1].grid[HEND]->getWidth(); + x += width; + + if (buttons[1].grid[HMID]) + { + const Image *const hMid = buttons[1].grid[HMID]; + g->calcImagePattern(mVertexes, hMid, x, y, + w, hMid->getHeight()); + } + + x += w; + if (buttons[1].grid[HEND]) + g->calcTile(mVertexes, buttons[1].grid[HEND], x, y); + + const Image *const img = buttons[1].grid[HGRIP]; + if (img) + { + g->calcTile(mVertexes, img, getMarkerPosition(), + (mDimension.height - img->getHeight()) / 2); + } + } } - - x += w; - static_cast<Graphics*>(graphics)->drawImage( - buttons[0].grid[HEND], x, y); + g->drawTile(mVertexes); } else { - static_cast<Graphics*>(graphics)->drawImage( - buttons[1].grid[HSTART], x, y); + if (!mHasMouse) + { + g->drawImage(buttons[0].grid[HSTART], x, y); + const int width = buttons[0].grid[HSTART]->getWidth(); + w -= width + buttons[0].grid[HEND]->getWidth(); + x += width; - const int width = buttons[1].grid[HSTART]->getWidth(); - w -= width; - if (buttons[1].grid[HEND]) - w -= buttons[1].grid[HEND]->getWidth(); - x += width; + if (buttons[0].grid[HMID]) + { + const Image *const hMid = buttons[0].grid[HMID]; + g->drawImagePattern(hMid, x, y, w, hMid->getHeight()); + } - if (buttons[1].grid[HMID]) - { - const Image *const hMid = buttons[1].grid[HMID]; - static_cast<Graphics*>(graphics)->drawImagePattern( - hMid, x, y, w, - hMid->getHeight()); - } + x += w; + g->drawImage(buttons[0].grid[HEND], x, y); - x += w; - if (buttons[1].grid[HEND]) + const Image *const img = buttons[0].grid[HGRIP]; + if (img) + { + g->drawImage(img, getMarkerPosition(), + (mDimension.height - img->getHeight()) / 2); + } + } + else { - static_cast<Graphics*>(graphics)->drawImage( - buttons[1].grid[HEND], x, y); + g->drawImage(buttons[1].grid[HSTART], x, y); + + const int width = buttons[1].grid[HSTART]->getWidth(); + w -= width; + if (buttons[1].grid[HEND]) + w -= buttons[1].grid[HEND]->getWidth(); + x += width; + + if (buttons[1].grid[HMID]) + { + const Image *const hMid = buttons[1].grid[HMID]; + g->drawImagePattern(hMid, x, y, w, hMid->getHeight()); + } + + x += w; + if (buttons[1].grid[HEND]) + g->drawImage(buttons[1].grid[HEND], x, y); + + const Image *const img = buttons[1].grid[HGRIP]; + if (img) + { + g->drawImage(img, getMarkerPosition(), + (mDimension.height - img->getHeight()) / 2); + } } } - drawMarker(graphics); BLOCK_END("Slider::draw") } -void Slider::drawMarker(gcn::Graphics *const graphics) const -{ - const Image *const img = (mHasMouse ? buttons[1].grid[HGRIP] - : buttons[0].grid[HGRIP]); - if (!img) - return; - - static_cast<Graphics*>(graphics)->drawImage(img, getMarkerPosition(), - (mDimension.height - img->getHeight()) / 2); -} - void Slider::mouseEntered(gcn::MouseEvent& event A_UNUSED) { mHasMouse = true; + mRedraw = true; } void Slider::mouseExited(gcn::MouseEvent& event A_UNUSED) { mHasMouse = false; + mRedraw = true; +} + +void Slider::mousePressed(gcn::MouseEvent &mouseEvent) +{ + if (mouseEvent.getButton() == gcn::MouseEvent::LEFT + && mouseEvent.getX() >= 0 + && mouseEvent.getX() <= getWidth() + && mouseEvent.getY() >= 0 + && mouseEvent.getY() <= getHeight()) + { + if (getOrientation() == HORIZONTAL) + { + setValue2(markerPositionToValue( + mouseEvent.getX() - getMarkerLength() / 2)); + } + else + { + setValue2(markerPositionToValue(getHeight() + - mouseEvent.getY() - getMarkerLength() / 2)); + } + + distributeActionEvent(); + } +} + +void Slider::mouseDragged(gcn::MouseEvent &mouseEvent) +{ + if (getOrientation() == HORIZONTAL) + { + setValue2(markerPositionToValue(mouseEvent.getX() + - getMarkerLength() / 2)); + } + else + { + setValue2(markerPositionToValue(getHeight() + - mouseEvent.getY() - getMarkerLength() / 2)); + } + + distributeActionEvent(); + + mouseEvent.consume(); +} + +void Slider::mouseWheelMovedUp(gcn::MouseEvent &mouseEvent) +{ + setValue2(getValue() + getStepLength()); + distributeActionEvent(); + + mouseEvent.consume(); +} + +void Slider::mouseWheelMovedDown(gcn::MouseEvent &mouseEvent) +{ + setValue2(getValue() - getStepLength()); + distributeActionEvent(); + + mouseEvent.consume(); } void Slider::keyPressed(gcn::KeyEvent& keyEvent) @@ -210,13 +334,13 @@ void Slider::keyPressed(gcn::KeyEvent& keyEvent) { if (action == Input::KEY_GUI_RIGHT) { - setValue(getValue() + getStepLength()); + setValue2(getValue() + getStepLength()); distributeActionEvent(); keyEvent.consume(); } else if (action == Input::KEY_GUI_LEFT) { - setValue(getValue() - getStepLength()); + setValue2(getValue() - getStepLength()); distributeActionEvent(); keyEvent.consume(); } @@ -225,15 +349,21 @@ void Slider::keyPressed(gcn::KeyEvent& keyEvent) { if (action == Input::KEY_GUI_UP) { - setValue(getValue() + getStepLength()); + setValue2(getValue() + getStepLength()); distributeActionEvent(); keyEvent.consume(); } else if (action == Input::KEY_GUI_DOWN) { - setValue(getValue() - getStepLength()); + setValue2(getValue() - getStepLength()); distributeActionEvent(); keyEvent.consume(); } } } + +void Slider::setValue2(const double value) +{ + setValue(value); + mRedraw = true; +} diff --git a/src/gui/widgets/slider.h b/src/gui/widgets/slider.h index e54c9e374..79ef2b961 100644 --- a/src/gui/widgets/slider.h +++ b/src/gui/widgets/slider.h @@ -29,6 +29,8 @@ #include "localconsts.h" +class ImageCollection; + /** * Slider widget. Same as the Guichan slider but with custom look. * @@ -66,11 +68,6 @@ class Slider final : public gcn::Slider, void draw(gcn::Graphics *graphics) override final; /** - * Draws the marker. - */ - void drawMarker(gcn::Graphics *const graphics) const; - - /** * Called when the mouse enteres the widget area. */ void mouseEntered(gcn::MouseEvent& event) override final; @@ -80,8 +77,18 @@ class Slider final : public gcn::Slider, */ void mouseExited(gcn::MouseEvent& event) override final; + void mousePressed(gcn::MouseEvent &mouseEvent) override final; + + void mouseDragged(gcn::MouseEvent &mouseEvent) override final; + + void mouseWheelMovedUp(gcn::MouseEvent &mouseEvent) override final; + + void mouseWheelMovedDown(gcn::MouseEvent &mouseEvent) override final; + void keyPressed(gcn::KeyEvent& keyEvent) override final; + void setValue2(const double value); + enum SLIDER_ENUM { HSTART = 0, @@ -104,7 +111,9 @@ class Slider final : public gcn::Slider, static ImageRect buttons[2]; static float mAlpha; static int mInstances; + ImageCollection *mVertexes; bool mHasMouse; + bool mRedraw; }; #endif // GUI_WIDGETS_SLIDER_H diff --git a/src/guichan/include/guichan/widgets/slider.hpp b/src/guichan/include/guichan/widgets/slider.hpp index c4229a514..c925df45f 100644 --- a/src/guichan/include/guichan/widgets/slider.hpp +++ b/src/guichan/include/guichan/widgets/slider.hpp @@ -207,21 +207,6 @@ namespace gcn */ double getStepLength() const; - // Inherited from MouseListener. - - virtual void mousePressed(MouseEvent& mouseEvent) override; - - virtual void mouseDragged(MouseEvent& mouseEvent) override; - - virtual void mouseWheelMovedUp(MouseEvent& mouseEvent) override; - - virtual void mouseWheelMovedDown(MouseEvent& mouseEvent) override; - - - // Inherited from KeyListener - - virtual void keyPressed(KeyEvent& keyEvent) override; - protected: /** * Converts a marker position to a value in the scale. diff --git a/src/guichan/widgets/slider.cpp b/src/guichan/widgets/slider.cpp index 322f2ef76..9a328f2cc 100644 --- a/src/guichan/widgets/slider.cpp +++ b/src/guichan/widgets/slider.cpp @@ -120,47 +120,6 @@ namespace gcn mScaleEnd = scaleEnd; } - void Slider::mousePressed(MouseEvent& mouseEvent) - { - if (mouseEvent.getButton() == gcn::MouseEvent::LEFT - && mouseEvent.getX() >= 0 - && mouseEvent.getX() <= getWidth() - && mouseEvent.getY() >= 0 - && mouseEvent.getY() <= getHeight()) - { - if (getOrientation() == HORIZONTAL) - { - setValue(markerPositionToValue( - mouseEvent.getX() - getMarkerLength() / 2)); - } - else - { - setValue(markerPositionToValue(getHeight() - - mouseEvent.getY() - getMarkerLength() / 2)); - } - - distributeActionEvent(); - } - } - - void Slider::mouseDragged(MouseEvent& mouseEvent) - { - if (getOrientation() == HORIZONTAL) - { - setValue(markerPositionToValue(mouseEvent.getX() - - getMarkerLength() / 2)); - } - else - { - setValue(markerPositionToValue(getHeight() - - mouseEvent.getY() - getMarkerLength() / 2)); - } - - distributeActionEvent(); - - mouseEvent.consume(); - } - void Slider::setValue(double value) { if (value > getScaleEnd()) @@ -193,10 +152,6 @@ namespace gcn mMarkerLength = length; } - void Slider::keyPressed(KeyEvent& keyEvent A_UNUSED) - { - } - void Slider::setOrientation(Slider::Orientation orientation) { mOrientation = orientation; @@ -254,20 +209,4 @@ namespace gcn { return valueToMarkerPosition(getValue()); } - - void Slider::mouseWheelMovedUp(MouseEvent& mouseEvent) - { - setValue(getValue() + getStepLength()); - distributeActionEvent(); - - mouseEvent.consume(); - } - - void Slider::mouseWheelMovedDown(MouseEvent& mouseEvent) - { - setValue(getValue() - getStepLength()); - distributeActionEvent(); - - mouseEvent.consume(); - } } // namespace gcn |