summaryrefslogtreecommitdiff
path: root/src/gui/widgets/scrollarea.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-03-10 18:31:37 +0300
committerAndrei Karas <akaras@inbox.ru>2014-03-10 18:31:37 +0300
commit5459411ec64d09895f6a5a2944cf4215a3ea1c1a (patch)
treeaf09683b7f22dcd18da18cc7d58e5e051910181b /src/gui/widgets/scrollarea.cpp
parentb939ab9402d0f8bc4cac933b4ec118f0d9e901a9 (diff)
downloadplus-5459411ec64d09895f6a5a2944cf4215a3ea1c1a.tar.gz
plus-5459411ec64d09895f6a5a2944cf4215a3ea1c1a.tar.bz2
plus-5459411ec64d09895f6a5a2944cf4215a3ea1c1a.tar.xz
plus-5459411ec64d09895f6a5a2944cf4215a3ea1c1a.zip
Remove duplicate code from scrollarea.
Diffstat (limited to 'src/gui/widgets/scrollarea.cpp')
-rw-r--r--src/gui/widgets/scrollarea.cpp49
1 files changed, 15 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);
}
}