summaryrefslogtreecommitdiff
path: root/src/gui
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
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')
-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;