From 5459411ec64d09895f6a5a2944cf4215a3ea1c1a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 10 Mar 2014 18:31:37 +0300 Subject: Remove duplicate code from scrollarea. --- src/gui/widgets/scrollarea.cpp | 49 +++++++++++++----------------------------- src/gui/widgets/scrollarea.h | 2 ++ 2 files changed, 17 insertions(+), 34 deletions(-) (limited to 'src') 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(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(dir))); - return; - } - - if (buttons[dir][state]) + if (image) { static_cast(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; -- cgit v1.2.3-60-g2f50