summaryrefslogtreecommitdiff
path: root/src/gui/listbox.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-02-26 21:29:49 +0100
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-02-26 21:29:49 +0100
commit3008805eea4b972265597ba196ab05ce64c69965 (patch)
treed3195600e956e496b6b21f200fc04e5b08cab368 /src/gui/listbox.cpp
parent3ad6ac47d4967870a54fddd66aa9996724115b94 (diff)
parent6b0cff837b7adae56dc90d12e9c0e256e6aab134 (diff)
downloadmana-3008805eea4b972265597ba196ab05ce64c69965.tar.gz
mana-3008805eea4b972265597ba196ab05ce64c69965.tar.bz2
mana-3008805eea4b972265597ba196ab05ce64c69965.tar.xz
mana-3008805eea4b972265597ba196ab05ce64c69965.zip
Merge branch 'aethyra/master'
Conflicts: data/graphics/images/login_wallpaper.png src/being.cpp src/beingmanager.cpp src/engine.cpp src/game.cpp src/gui/buysell.cpp src/gui/buysell.h src/gui/gui.h src/gui/npc_text.cpp src/gui/npc_text.h src/gui/npcintegerdialog.cpp src/gui/npclistdialog.cpp src/gui/npclistdialog.h src/gui/npcstringdialog.cpp src/gui/sell.cpp src/gui/shop.cpp src/gui/table.cpp src/net/beinghandler.cpp src/net/npchandler.cpp src/net/playerhandler.cpp src/npc.cpp src/npc.h src/shopitem.cpp src/shopitem.h src/utils/stringutils.cpp src/utils/stringutils.h src/utils/trim.h
Diffstat (limited to 'src/gui/listbox.cpp')
-rw-r--r--src/gui/listbox.cpp88
1 files changed, 87 insertions, 1 deletions
diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp
index 74d0b9ad..64c8be85 100644
--- a/src/gui/listbox.cpp
+++ b/src/gui/listbox.cpp
@@ -21,6 +21,7 @@
#include <guichan/font.hpp>
#include <guichan/graphics.hpp>
+#include <guichan/key.hpp>
#include <guichan/listmodel.hpp>
#include "color.h"
@@ -54,7 +55,7 @@ void ListBox::draw(gcn::Graphics *graphics)
const int fontHeight = getFont()->getHeight();
- // Draw rectangle below the selected list element
+ // Draw filled rectangle around the selected list element
if (mSelected >= 0)
graphics->fillRectangle(gcn::Rectangle(0, fontHeight * mSelected,
getWidth(), fontHeight));
@@ -68,6 +69,91 @@ void ListBox::draw(gcn::Graphics *graphics)
}
}
+void ListBox::setSelected(int selected)
+{
+ if (!mListModel)
+ {
+ mSelected = -1;
+ }
+ else
+ {
+ if (selected < 0 && !mWrappingEnabled)
+ {
+ mSelected = -1;
+ }
+ else if (selected >= mListModel->getNumberOfElements() &&
+ mWrappingEnabled)
+ {
+ mSelected = 0;
+ }
+ else if ((selected >= mListModel->getNumberOfElements() &&
+ !mWrappingEnabled) || (selected < 0 && mWrappingEnabled))
+ {
+ mSelected = mListModel->getNumberOfElements() - 1;
+ }
+ else
+ {
+ mSelected = selected;
+ }
+ }
+ gcn::ListBox::setSelected(mSelected);
+}
+
+// -- KeyListener notifications
+void ListBox::keyPressed(gcn::KeyEvent& keyEvent)
+{
+ gcn::Key key = keyEvent.getKey();
+
+ if (key.getValue() == gcn::Key::ENTER || key.getValue() == gcn::Key::SPACE)
+ {
+ distributeActionEvent();
+ keyEvent.consume();
+ }
+ else if (key.getValue() == gcn::Key::UP)
+ {
+ setSelected(mSelected - 1);
+ keyEvent.consume();
+ }
+ else if (key.getValue() == gcn::Key::DOWN)
+ {
+ setSelected(mSelected + 1);
+ keyEvent.consume();
+ }
+ else if (key.getValue() == gcn::Key::HOME)
+ {
+ setSelected(0);
+ keyEvent.consume();
+ }
+ else if (key.getValue() == gcn::Key::END)
+ {
+ setSelected(getListModel()->getNumberOfElements() - 1);
+ keyEvent.consume();
+ }
+}
+
+void ListBox::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent)
+{
+ if (isFocused())
+ {
+ if (getSelected() > 0 || (getSelected() == 0 && mWrappingEnabled))
+ {
+ setSelected(getSelected() - 1);
+ }
+
+ mouseEvent.consume();
+ }
+}
+
+void ListBox::mouseWheelMovedDown(gcn::MouseEvent& mouseEvent)
+{
+ if (isFocused())
+ {
+ setSelected(getSelected() + 1);
+
+ mouseEvent.consume();
+ }
+}
+
void ListBox::mouseDragged(gcn::MouseEvent &event)
{
// Pretend mouse is pressed continuously while dragged. Causes list