From 9a57dd887539cab680cbcc2c8e7a2f18d5aa3c04 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 25 May 2015 17:31:08 +0300 Subject: Add safeDraw method into slider. --- src/gui/widgets/slider.cpp | 192 ++++++++++++++++++++++++--------------------- src/gui/widgets/slider.h | 2 + 2 files changed, 106 insertions(+), 88 deletions(-) diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index e867c9528..8c17c03fa 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -207,90 +207,15 @@ void Slider::draw(Graphics *graphics) updateAlpha(); - if (isBatchDrawRenders(openGLMode)) - { - if (mRedraw || graphics->getRedraw()) - { - mRedraw = false; - mVertexes->clear(); - if (!mHasMouse) - { - graphics->calcTileCollection(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]; - graphics->calcPattern(mVertexes, - hMid, - x, y, - w, hMid->getHeight()); - } - - x += w; - graphics->calcTileCollection(mVertexes, - buttons[0].grid[HEND], - x, y); - - const Image *const img = buttons[0].grid[HGRIP]; - if (img) - { - graphics->calcTileCollection(mVertexes, - img, - getMarkerPosition(), - (mDimension.height - img->getHeight()) / 2); - } - } - else - { - graphics->calcTileCollection(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]; - graphics->calcPattern(mVertexes, - hMid, - x, y, - w, hMid->getHeight()); - } - - x += w; - if (buttons[1].grid[HEND]) - { - graphics->calcTileCollection(mVertexes, - buttons[1].grid[HEND], x, y); - } - - const Image *const img = buttons[1].grid[HGRIP]; - if (img) - { - graphics->calcTileCollection(mVertexes, - img, - getMarkerPosition(), - (mDimension.height - img->getHeight()) / 2); - } - } - graphics->finalize(mVertexes); - } - graphics->drawTileCollection(mVertexes); - } - else + if (mRedraw || graphics->getRedraw()) { + mRedraw = false; + mVertexes->clear(); if (!mHasMouse) { - graphics->drawImage(buttons[0].grid[HSTART], x, y); + graphics->calcTileCollection(mVertexes, + buttons[0].grid[HSTART], x, y); + const int width = buttons[0].grid[HSTART]->getWidth(); w -= width + buttons[0].grid[HEND]->getWidth(); x += width; @@ -298,22 +223,31 @@ void Slider::draw(Graphics *graphics) if (buttons[0].grid[HMID]) { const Image *const hMid = buttons[0].grid[HMID]; - graphics->drawPattern(hMid, x, y, w, hMid->getHeight()); + graphics->calcPattern(mVertexes, + hMid, + x, y, + w, hMid->getHeight()); } x += w; - graphics->drawImage(buttons[0].grid[HEND], x, y); + graphics->calcTileCollection(mVertexes, + buttons[0].grid[HEND], + x, y); const Image *const img = buttons[0].grid[HGRIP]; if (img) { - graphics->drawImage(img, getMarkerPosition(), + graphics->calcTileCollection(mVertexes, + img, + getMarkerPosition(), (mDimension.height - img->getHeight()) / 2); } } else { - graphics->drawImage(buttons[1].grid[HSTART], x, y); + graphics->calcTileCollection(mVertexes, + buttons[1].grid[HSTART], + x, y); const int width = buttons[1].grid[HSTART]->getWidth(); w -= width; @@ -324,20 +258,102 @@ void Slider::draw(Graphics *graphics) if (buttons[1].grid[HMID]) { const Image *const hMid = buttons[1].grid[HMID]; - graphics->drawPattern(hMid, x, y, w, hMid->getHeight()); + graphics->calcPattern(mVertexes, + hMid, + x, y, + w, hMid->getHeight()); } x += w; if (buttons[1].grid[HEND]) - graphics->drawImage(buttons[1].grid[HEND], x, y); + { + graphics->calcTileCollection(mVertexes, + buttons[1].grid[HEND], x, y); + } const Image *const img = buttons[1].grid[HGRIP]; if (img) { - graphics->drawImage(img, getMarkerPosition(), + graphics->calcTileCollection(mVertexes, + img, + getMarkerPosition(), (mDimension.height - img->getHeight()) / 2); } } + graphics->finalize(mVertexes); + } + graphics->drawTileCollection(mVertexes); + + BLOCK_END("Slider::draw") +} + +void Slider::safeDraw(Graphics *graphics) +{ + BLOCK_START("Slider::draw") + if (!buttons[0].grid[HSTART] || !buttons[1].grid[HSTART] + || !buttons[0].grid[HEND]) + { + BLOCK_END("Slider::draw") + return; + } + + int w = getWidth(); + const int h = getHeight(); + int x = 0; + const int y = mHasMouse ? (h - buttons[1].grid[HSTART]->getHeight()) / 2 : + (h - buttons[0].grid[HSTART]->getHeight()) / 2; + + updateAlpha(); + + if (!mHasMouse) + { + 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]) + { + const Image *const hMid = buttons[0].grid[HMID]; + graphics->drawPattern(hMid, x, y, w, hMid->getHeight()); + } + + x += w; + graphics->drawImage(buttons[0].grid[HEND], x, y); + + const Image *const img = buttons[0].grid[HGRIP]; + if (img) + { + graphics->drawImage(img, getMarkerPosition(), + (mDimension.height - img->getHeight()) / 2); + } + } + else + { + graphics->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]; + graphics->drawPattern(hMid, x, y, w, hMid->getHeight()); + } + + x += w; + if (buttons[1].grid[HEND]) + graphics->drawImage(buttons[1].grid[HEND], x, y); + + const Image *const img = buttons[1].grid[HGRIP]; + if (img) + { + graphics->drawImage(img, getMarkerPosition(), + (mDimension.height - img->getHeight()) / 2); + } } BLOCK_END("Slider::draw") diff --git a/src/gui/widgets/slider.h b/src/gui/widgets/slider.h index ec4144ff9..d31c9e9fc 100644 --- a/src/gui/widgets/slider.h +++ b/src/gui/widgets/slider.h @@ -127,6 +127,8 @@ class Slider final : public Widget, */ void draw(Graphics *graphics) override final; + void safeDraw(Graphics *graphics) override final; + /** * Called when the mouse enteres the widget area. */ -- cgit v1.2.3-60-g2f50