summaryrefslogtreecommitdiff
path: root/src/gui/widgets/listbox.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-10-05 13:18:04 +0300
committerAndrei Karas <akaras@inbox.ru>2013-10-05 13:18:04 +0300
commit53f2f59ade349bd404672ee3a5a06f1289afa190 (patch)
treeca595c457181a742bbebd3f890480341c949399b /src/gui/widgets/listbox.cpp
parent01660865a49250c6ed77159cb3d8b38e7ea37b95 (diff)
downloadmanaverse-53f2f59ade349bd404672ee3a5a06f1289afa190.tar.gz
manaverse-53f2f59ade349bd404672ee3a5a06f1289afa190.tar.bz2
manaverse-53f2f59ade349bd404672ee3a5a06f1289afa190.tar.xz
manaverse-53f2f59ade349bd404672ee3a5a06f1289afa190.zip
Allow scroll listboxes and popup list by holding and moving mouse.
Diffstat (limited to 'src/gui/widgets/listbox.cpp')
-rw-r--r--src/gui/widgets/listbox.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp
index 8d945180a..a31947e39 100644
--- a/src/gui/widgets/listbox.cpp
+++ b/src/gui/widgets/listbox.cpp
@@ -48,6 +48,7 @@ ListBox::ListBox(const Widget2 *const widget,
mForegroundSelectedColor2(getThemeColor(Theme::LISTBOX_SELECTED_OUTLINE)),
mOldSelected(-1),
mPadding(0),
+ mPressedIndex(-2),
mSkin(nullptr),
mDistributeMousePressed(true),
mCenterText(false)
@@ -204,8 +205,16 @@ void ListBox::mouseWheelMovedDown(gcn::MouseEvent &mouseEvent A_UNUSED)
{
}
+void ListBox::mousePressed(gcn::MouseEvent &event)
+{
+ mPressedIndex = getSelectionByMouse(event.getY());
+}
+
void ListBox::mouseReleased(gcn::MouseEvent &event)
{
+ if (mPressedIndex != getSelectionByMouse(event.getY()))
+ return;
+
if (mDistributeMousePressed)
{
mouseReleased1(event);
@@ -233,6 +242,7 @@ void ListBox::mouseReleased(gcn::MouseEvent &event)
break;
}
}
+ mPressedIndex = -2;
}
void ListBox::mouseReleased1(gcn::MouseEvent &mouseEvent)
@@ -281,5 +291,7 @@ void ListBox::logic()
int ListBox::getSelectionByMouse(const int y) const
{
+ if (y < mPadding)
+ return -1;
return (y - mPadding) / getRowHeight();
}