summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-05-25 17:31:08 +0300
committerAndrei Karas <akaras@inbox.ru>2015-05-25 17:31:08 +0300
commit9a57dd887539cab680cbcc2c8e7a2f18d5aa3c04 (patch)
tree0681105383fa9929db00094e865caaf3f0af0d5e
parente3672baa9a0d62ffcc1cb693cbb94644755b6d58 (diff)
downloadmv-9a57dd887539cab680cbcc2c8e7a2f18d5aa3c04.tar.gz
mv-9a57dd887539cab680cbcc2c8e7a2f18d5aa3c04.tar.bz2
mv-9a57dd887539cab680cbcc2c8e7a2f18d5aa3c04.tar.xz
mv-9a57dd887539cab680cbcc2c8e7a2f18d5aa3c04.zip
Add safeDraw method into slider.
-rw-r--r--src/gui/widgets/slider.cpp192
-rw-r--r--src/gui/widgets/slider.h2
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.
*/