summaryrefslogtreecommitdiff
path: root/src/gui/widgets
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
parent01660865a49250c6ed77159cb3d8b38e7ea37b95 (diff)
downloadmv-53f2f59ade349bd404672ee3a5a06f1289afa190.tar.gz
mv-53f2f59ade349bd404672ee3a5a06f1289afa190.tar.bz2
mv-53f2f59ade349bd404672ee3a5a06f1289afa190.tar.xz
mv-53f2f59ade349bd404672ee3a5a06f1289afa190.zip
Allow scroll listboxes and popup list by holding and moving mouse.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/listbox.cpp12
-rw-r--r--src/gui/widgets/listbox.h6
-rw-r--r--src/gui/widgets/popuplist.cpp15
-rw-r--r--src/gui/widgets/popuplist.h3
4 files changed, 36 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();
}
diff --git a/src/gui/widgets/listbox.h b/src/gui/widgets/listbox.h
index 4397a201e..27e24a030 100644
--- a/src/gui/widgets/listbox.h
+++ b/src/gui/widgets/listbox.h
@@ -73,6 +73,8 @@ class ListBox : public gcn::ListBox,
void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent) override;
+ void mousePressed(gcn::MouseEvent &event) override;
+
void mouseReleased(gcn::MouseEvent &event) override;
void mouseReleased1(gcn::MouseEvent &event);
@@ -93,12 +95,16 @@ class ListBox : public gcn::ListBox,
void setCenter(const bool b)
{ mCenterText = b; }
+ int getPressedIndex()
+ { return mPressedIndex; }
+
protected:
gcn::Color mHighlightColor;
gcn::Color mForegroundSelectedColor;
gcn::Color mForegroundSelectedColor2;
int mOldSelected;
int mPadding;
+ int mPressedIndex;
Skin *mSkin;
static float mAlpha;
bool mDistributeMousePressed;
diff --git a/src/gui/widgets/popuplist.cpp b/src/gui/widgets/popuplist.cpp
index 2d32a5490..5fd38a785 100644
--- a/src/gui/widgets/popuplist.cpp
+++ b/src/gui/widgets/popuplist.cpp
@@ -39,6 +39,7 @@ PopupList::PopupList(DropDown *const widget,
new ListBox(widget, listModel, "popuplistbox.xml")),
mScrollArea(new ScrollArea(mListBox, false)),
mDropDown(widget),
+ mPressedIndex(-2),
mModal(modal)
{
setFocusable(true);
@@ -122,8 +123,22 @@ void PopupList::adjustSize()
mListBox->setWidth(width);
}
+void PopupList::mousePressed(gcn::MouseEvent& mouseEvent)
+{
+ mPressedIndex = mListBox->getSelectionByMouse(
+ mouseEvent.getY() + mPadding);
+}
+
void PopupList::mouseReleased(gcn::MouseEvent& mouseEvent)
{
+ if (mPressedIndex != mListBox->getSelectionByMouse(
+ mouseEvent.getY() + mPadding))
+ {
+ mPressedIndex = -2;
+ return;
+ }
+
+ mPressedIndex = -2;
if (mouseEvent.getSource() == mScrollArea)
return;
if (mDropDown)
diff --git a/src/gui/widgets/popuplist.h b/src/gui/widgets/popuplist.h
index ad2ad0d03..b4575d51e 100644
--- a/src/gui/widgets/popuplist.h
+++ b/src/gui/widgets/popuplist.h
@@ -63,6 +63,8 @@ class PopupList final : public Popup,
void focusLost(const gcn::Event& event A_UNUSED) override;
+ void mousePressed(gcn::MouseEvent& mouseEvent) override;
+
void mouseReleased(gcn::MouseEvent& mouseEvent) override;
private:
@@ -70,6 +72,7 @@ class PopupList final : public Popup,
ListBox *mListBox;
ScrollArea *mScrollArea;
DropDown *mDropDown;
+ int mPressedIndex;
bool mModal;
};