summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/widgets/scrollarea.cpp49
-rw-r--r--src/gui/widgets/scrollarea.h2
2 files changed, 17 insertions, 34 deletions
diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp
index 70f955684..e2421dc93 100644
--- a/src/gui/widgets/scrollarea.cpp
+++ b/src/gui/widgets/scrollarea.cpp
@@ -455,11 +455,9 @@ void ScrollArea::setOpaque(bool opaque)
setFrameSize(mOpaque ? 2 : 0);
}
-void ScrollArea::drawButton(Graphics *const graphics,
- const BUTTON_DIR dir)
+Image *ScrollArea::getImageByState(Rect &dim, const BUTTON_DIR dir)
{
int state = 0;
- Rect dim;
switch (dir)
{
@@ -483,48 +481,31 @@ void ScrollArea::drawButton(Graphics *const graphics,
default:
logger->log("ScrollArea::drawButton unknown dir: "
+ toString(static_cast<unsigned>(dir)));
- return;
+ return nullptr;
}
+ return buttons[dir][state];
+}
+
+void ScrollArea::drawButton(Graphics *const graphics,
+ const BUTTON_DIR dir)
+{
+ Rect dim;
+ const Image *const image = getImageByState(dim, dir);
- if (buttons[dir][state])
- graphics->drawImage(buttons[dir][state], dim.x, dim.y);
+ if (image)
+ graphics->drawImage(image, dim.x, dim.y);
}
void ScrollArea::calcButton(Graphics *const graphics,
const BUTTON_DIR dir)
{
- int state = 0;
Rect dim;
+ const Image *const image = getImageByState(dim, dir);
- switch (dir)
- {
- case UP:
- state = mUpButtonPressed ? 1 : 0;
- dim = getUpButtonDimension();
- break;
- case DOWN:
- state = mDownButtonPressed ? 1 : 0;
- dim = getDownButtonDimension();
- break;
- case LEFT:
- state = mLeftButtonPressed ? 1 : 0;
- dim = getLeftButtonDimension();
- break;
- case RIGHT:
- state = mRightButtonPressed ? 1 : 0;
- dim = getRightButtonDimension();
- break;
- case BUTTONS_DIR:
- default:
- logger->log("ScrollArea::drawButton unknown dir: "
- + toString(static_cast<unsigned>(dir)));
- return;
- }
-
- if (buttons[dir][state])
+ if (image)
{
static_cast<Graphics*>(graphics)->calcTileCollection(
- mVertexes, buttons[dir][state], dim.x, dim.y);
+ mVertexes, image, dim.x, dim.y);
}
}
diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h
index 4653359e8..6a91ac0f8 100644
--- a/src/gui/widgets/scrollarea.h
+++ b/src/gui/widgets/scrollarea.h
@@ -456,6 +456,8 @@ class ScrollArea final : public BasicContainer,
void calcVMarker(Graphics *const graphics);
void calcHMarker(Graphics *const graphics);
+ Image *getImageByState(Rect &dim, const BUTTON_DIR dir);
+
void updateCalcFlag(Graphics *const graphics);
static int instances;