summaryrefslogtreecommitdiff
path: root/src/gui/widgets/listbox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets/listbox.cpp')
-rw-r--r--src/gui/widgets/listbox.cpp29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp
index ef591023..a3dafe72 100644
--- a/src/gui/widgets/listbox.cpp
+++ b/src/gui/widgets/listbox.cpp
@@ -25,7 +25,8 @@
#include "gui/palette.h"
#include "gui/sdlinput.h"
-#include "gui/theme.h"
+
+#include "resources/theme.h"
#include <guichan/font.hpp>
#include <guichan/graphics.hpp>
@@ -45,8 +46,8 @@ ListBox::~ListBox()
void ListBox::updateAlpha()
{
- float alpha = std::max(config.getValue("guialpha", 0.8),
- (double) Theme::instance()->getMinimumOpacity());
+ float alpha = std::max(config.getFloatValue("guialpha"),
+ Theme::instance()->getMinimumOpacity());
if (mAlpha != alpha)
mAlpha = alpha;
@@ -117,14 +118,31 @@ void ListBox::keyPressed(gcn::KeyEvent& keyEvent)
}
}
-// Don't do anything on scrollwheel. ScrollArea will deal with that.
+void ListBox::mousePressed(gcn::MouseEvent &mouseEvent)
+{
+ if (mouseEvent.getButton() != gcn::MouseEvent::LEFT)
+ return;
+
+ int y = std::max(0, mouseEvent.getY());
+ if (y / (int)getRowHeight() < getListModel()->getNumberOfElements())
+ {
+ setSelected(y / getRowHeight());
+ distributeActionEvent();
+ }
+ else
+ {
+ setSelected(-1);
+ }
+}
void ListBox::mouseWheelMovedUp(gcn::MouseEvent &mouseEvent)
{
+ // Don't do anything on scrollwheel. ScrollArea will deal with that.
}
void ListBox::mouseWheelMovedDown(gcn::MouseEvent &mouseEvent)
{
+ // Don't do anything on scrollwheel. ScrollArea will deal with that.
}
void ListBox::mouseDragged(gcn::MouseEvent &event)
@@ -134,5 +152,6 @@ void ListBox::mouseDragged(gcn::MouseEvent &event)
// Make list selection update on drag, but guard against negative y
int y = std::max(0, event.getY());
- setSelected(y / getRowHeight());
+ if (y / (int)getRowHeight() < getListModel()->getNumberOfElements())
+ setSelected(y / getRowHeight());
}