summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-05-31 22:10:04 +0300
committerAndrei Karas <akaras@inbox.ru>2013-05-31 22:10:04 +0300
commitce59f2855e3d52615b133478a101c016b0122ba8 (patch)
tree5a3159efb2c9df48c79288418bbb535ab6a6c6f2 /src
parent639d8883192accdc502ec11ea2bfee474320c06e (diff)
downloadmv-ce59f2855e3d52615b133478a101c016b0122ba8.tar.gz
mv-ce59f2855e3d52615b133478a101c016b0122ba8.tar.bz2
mv-ce59f2855e3d52615b133478a101c016b0122ba8.tar.xz
mv-ce59f2855e3d52615b133478a101c016b0122ba8.zip
improve dropdown.
Diffstat (limited to 'src')
-rw-r--r--src/gui/widgets/dropdown.cpp59
-rw-r--r--src/gui/widgets/dropdown.h21
2 files changed, 39 insertions, 41 deletions
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
index 6645d92bc..4ebbcc001 100644
--- a/src/gui/widgets/dropdown.cpp
+++ b/src/gui/widgets/dropdown.cpp
@@ -70,7 +70,6 @@ DropDown::DropDown(const Widget2 *const widget,
gcn::FocusListener(),
gcn::SelectionListener(),
Widget2(widget),
- mExtended(extended),
mPopup(new PopupList(this, listModel, extended, modal)),
mShadowColor(getThemeColor(Theme::DROPDOWN_SHADOW)),
mHighlightColor(getThemeColor(Theme::HIGHLIGHT)),
@@ -78,11 +77,12 @@ DropDown::DropDown(const Widget2 *const widget,
mImagePadding(2),
mSpacing(0),
mForegroundColor2(getThemeColor(Theme::DROPDOWN_OUTLINE)),
+ mFoldedUpHeight(0),
+ mSelectionListeners(),
+ mExtended(extended),
mDroppedDown(false),
mPushed(false),
- mFoldedUpHeight(0),
- mIsDragged(false),
- mSelectionListeners()
+ mIsDragged(false)
{
mFrameSize = 2;
@@ -94,7 +94,7 @@ DropDown::DropDown(const Widget2 *const widget,
// Load the background skin
for (int i = 0; i < 2; i ++)
{
- Skin *skin = Theme::instance()->load(
+ Skin *const skin = Theme::instance()->load(
dropdownFiles[i], "dropdown.xml");
if (skin)
{
@@ -228,7 +228,7 @@ void DropDown::draw(gcn::Graphics* graphics)
if (mDroppedDown)
h = mFoldedUpHeight;
else
- h = getHeight();
+ h = mDimension.height;
updateAlpha();
@@ -257,7 +257,7 @@ void DropDown::draw(gcn::Graphics* graphics)
else
{
static_cast<Graphics*>(graphics)->drawImage(
- image, mImagePadding, (getHeight()
+ image, mImagePadding, (mDimension.height
- image->getHeight()) / 2 + mPadding);
font->drawString(graphics, model->getElementAt(sel),
image->getWidth() + mImagePadding + mSpacing, mPadding);
@@ -274,7 +274,7 @@ void DropDown::draw(gcn::Graphics* graphics)
{
graphics->setColor(mHighlightColor);
graphics->drawRectangle(gcn::Rectangle(mPadding, mPadding,
- getWidth() - h - pad, h - pad));
+ mDimension.width - h - pad, h - pad));
}
drawButton(graphics);
@@ -283,10 +283,11 @@ void DropDown::draw(gcn::Graphics* graphics)
{
// Draw two lines separating the ListBox with selected
// element view.
+ const int w = mDimension.width;
graphics->setColor(mHighlightColor);
- graphics->drawLine(0, h, getWidth(), h);
+ graphics->drawLine(0, h, w, h);
graphics->setColor(mShadowColor);
- graphics->drawLine(0, h + 1, getWidth(), h + 1);
+ graphics->drawLine(0, h + 1, w, h + 1);
}
BLOCK_END("DropDown::draw")
}
@@ -294,23 +295,22 @@ void DropDown::draw(gcn::Graphics* graphics)
void DropDown::drawFrame(gcn::Graphics *graphics)
{
BLOCK_START("DropDown::drawFrame")
- const int bs = getFrameSize();
- const int w = getWidth() + bs * 2;
- const int h = getHeight() + bs * 2;
-
- static_cast<Graphics*>(graphics)->drawImageRect(0, 0, w, h, skinRect);
+ const int bs2 = getFrameSize();
+ const gcn::Rectangle &rect = mDimension;
+ static_cast<Graphics*>(graphics)->drawImageRect(
+ 0, 0, rect.width + bs2, rect.height + bs2, skinRect);
BLOCK_END("DropDown::drawFrame")
}
void DropDown::drawButton(gcn::Graphics *graphics)
{
- const int height = mDroppedDown ? mFoldedUpHeight : getHeight();
+ const int height = mDroppedDown ? mFoldedUpHeight : mDimension.height;
Image *image = buttons[mDroppedDown][mPushed];
if (image)
{
static_cast<Graphics*>(graphics)->drawImage(image,
- getWidth() - image->getWidth() - mImagePadding,
+ mDimension.width - image->getWidth() - mImagePadding,
(height - image->getHeight()) / 2);
}
}
@@ -321,7 +321,6 @@ void DropDown::keyPressed(gcn::KeyEvent& keyEvent)
return;
const int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId();
-
switch (actionId)
{
case Input::KEY_GUI_SELECT:
@@ -384,18 +383,18 @@ void DropDown::mouseReleased(gcn::MouseEvent &mouseEvent)
if (mIsDragged)
mPushed = false;
+ const int button = mouseEvent.getButton();
+ const int x = mouseEvent.getX();
+ const int y = mouseEvent.getY();
// Released outside of widget. Can happen when we have modal
// input focus.
- if ((0 > mouseEvent.getY()
- || mouseEvent.getY() >= getHeight()
- || mouseEvent.getX() < 0
- || mouseEvent.getX() >= getWidth())
- && mouseEvent.getButton() == gcn::MouseEvent::LEFT)
+ if ((0 > y || y >= mDimension.height || x < 0 || x >= mDimension.width)
+ && button == gcn::MouseEvent::LEFT)
{
if (mIsDragged)
foldUp();
}
- else if (mouseEvent.getButton() == gcn::MouseEvent::LEFT)
+ else if (button == gcn::MouseEvent::LEFT)
{
mPushed = false;
}
@@ -421,7 +420,7 @@ void DropDown::mouseWheelMovedDown(gcn::MouseEvent& mouseEvent)
mouseEvent.consume();
}
-void DropDown::setSelectedString(std::string str)
+void DropDown::setSelectedString(const std::string &str)
{
gcn::ListModel *const listModel = mPopup->getListModel();
if (!listModel)
@@ -459,8 +458,6 @@ void DropDown::dropDown()
mFoldedUpHeight = getHeight();
adjustHeight();
-// if (getParent())
-// getParent()->moveToTop(this);
int x = 0;
int y = 0;
getAbsolutePosition(x, y);
@@ -469,8 +466,8 @@ void DropDown::dropDown()
const int pad2 = pad * 2;
// here width should be adjusted on some other parameters
- mPopup->setWidth(getWidth() - pad2 + 8);
- mPopup->show(x - mPadding - frame - 1, y + getHeight());
+ mPopup->setWidth(mDimension.width - pad2 + 8);
+ mPopup->show(x - mPadding - frame - 1, y + mDimension.height);
mPopup->requestMoveToTop();
mPopup->requestFocus();
}
@@ -496,7 +493,7 @@ void DropDown::setSelected(int selected)
mPopup->setSelected(selected);
}
-void DropDown::setListModel(gcn::ListModel *listModel)
+void DropDown::setListModel(gcn::ListModel *const listModel)
{
mPopup->setListModel(listModel);
@@ -523,7 +520,7 @@ gcn::Rectangle DropDown::getChildrenArea()
{
// Calculate the children area (with the one pixel border in mind)
return gcn::Rectangle(1, mFoldedUpHeight + 1,
- getWidth() - 2, getHeight() - mFoldedUpHeight - 2);
+ mDimension.width - 2, mDimension.height - mFoldedUpHeight - 2);
}
return gcn::Rectangle();
diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h
index 4c6120dfa..da0251260 100644
--- a/src/gui/widgets/dropdown.h
+++ b/src/gui/widgets/dropdown.h
@@ -104,11 +104,11 @@ class DropDown final : public gcn::ActionListener,
void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent) override;
- void setSelectedString(std::string str);
+ void setSelectedString(const std::string &str);
std::string getSelectedString() const A_WARN_UNUSED;
- void valueChanged(const gcn::SelectionEvent& event);
+ void valueChanged(const gcn::SelectionEvent& event) override;
void updateSelection();
@@ -124,7 +124,7 @@ class DropDown final : public gcn::ActionListener,
void setSelected(int selected);
- void setListModel(gcn::ListModel *listModel);
+ void setListModel(gcn::ListModel *const listModel);
gcn::ListModel *getListModel();
@@ -132,9 +132,9 @@ class DropDown final : public gcn::ActionListener,
void removeSelectionListener(SelectionListener* selectionListener);
- gcn::Rectangle getChildrenArea();
+ gcn::Rectangle getChildrenArea() override;
- void action(const gcn::ActionEvent &actionEvent);
+ void action(const gcn::ActionEvent &actionEvent) override;
void distributeValueChangedEvent();
@@ -146,7 +146,6 @@ class DropDown final : public gcn::ActionListener,
*/
void drawButton(gcn::Graphics *graphics);
- bool mExtended;
PopupList *mPopup;
gcn::Color mShadowColor;
gcn::Color mHighlightColor;
@@ -154,15 +153,17 @@ class DropDown final : public gcn::ActionListener,
int mImagePadding;
int mSpacing;
gcn::Color mForegroundColor2;
-
- bool mDroppedDown;
- bool mPushed;
int mFoldedUpHeight;
- bool mIsDragged;
+
typedef std::list<SelectionListener*> SelectionListenerList;
SelectionListenerList mSelectionListeners;
typedef SelectionListenerList::iterator SelectionListenerIterator;
+ bool mExtended;
+ bool mDroppedDown;
+ bool mPushed;
+ bool mIsDragged;
+
// Add own Images.
static int instances;
static Image *buttons[2][2];