summaryrefslogtreecommitdiff
path: root/src/gui/setup_keyboard.cpp
diff options
context:
space:
mode:
authorJoshua Langley <joshlangley[at]optusnet.com.au>2007-07-25 13:06:47 +0000
committerJoshua Langley <joshlangley[at]optusnet.com.au>2007-07-25 13:06:47 +0000
commitfbb717acfc2bd1f2a3cedf8465c817e8a5abec57 (patch)
treeb197517690f9afa24bbbb4bf0a5dff8bd7b5b67e /src/gui/setup_keyboard.cpp
parent8e3fad97a5df4bfc706b0246794b00428bd207e0 (diff)
downloadmana-client-fbb717acfc2bd1f2a3cedf8465c817e8a5abec57.tar.gz
mana-client-fbb717acfc2bd1f2a3cedf8465c817e8a5abec57.tar.bz2
mana-client-fbb717acfc2bd1f2a3cedf8465c817e8a5abec57.tar.xz
mana-client-fbb717acfc2bd1f2a3cedf8465c817e8a5abec57.zip
keyboard config - keyboard setup gui re-designed, fixed errors in keyboard config.
m_id:16
Diffstat (limited to 'src/gui/setup_keyboard.cpp')
-rw-r--r--src/gui/setup_keyboard.cpp123
1 files changed, 75 insertions, 48 deletions
diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp
index 6a89ce8f..2929cab6 100644
--- a/src/gui/setup_keyboard.cpp
+++ b/src/gui/setup_keyboard.cpp
@@ -24,9 +24,12 @@
#include "setup_keyboard.h"
#include <guichan/widgets/label.hpp>
+#include <guichan/listmodel.hpp>
#include "button.h"
+#include "listbox.h"
#include "ok_dialog.h"
+#include "scrollarea.h"
#include "../configuration.h"
#include "../keyboardconfig.h"
@@ -35,38 +38,71 @@
#include <SDL_keyboard.h>
-Setup_Keyboard::Setup_Keyboard()
+/**
+ * The list model for key function list.
+ *
+ * \ingroup Interface
+ */
+class KeyListModel : public gcn::ListModel
{
- setOpaque(false);
+ public:
+ /**
+ * Returns the number of elements in container.
+ */
+ int getNumberOfElements() { return keyboard.KEY_TOTAL; }
+
+ /**
+ * Returns element from container.
+ */
+ std::string getElementAt(int i) { return mKeyFunctions[i]; }
+
+ /**
+ * Sets element from container.
+ */
+ void setElementAt(int i, std::string caption)
+ {
+ mKeyFunctions[i] = caption;
+ }
+
+ private:
+ std::string mKeyFunctions[keyboard.KEY_TOTAL];
+};
+Setup_Keyboard::Setup_Keyboard():
+ mKeyListModel(new KeyListModel()),
+ mKeyList(new ListBox(mKeyListModel))
+{
keyboard.setSetupKeyboard(this);
+ setOpaque(false);
- mKeyLabel = new gcn::Label[keyboard.KEY_TOTAL];
- mKeyButton = new Button[keyboard.KEY_TOTAL];
+ refreshKeys();
+
+ mKeyList->setDimension(gcn::Rectangle(0, 0, 180, 140));
+ mKeyList->addActionListener(this);
+ mKeyList->setSelected(-1);
+
+ ScrollArea *scrollArea = new ScrollArea(mKeyList);
+ scrollArea->setDimension(gcn::Rectangle(10, 10, 180, 140));
+ add(scrollArea);
+
+ mAssignKeyButton = new Button("Assign", "assign", this);
+ mAssignKeyButton->setPosition(145, 155);
+ mAssignKeyButton->addActionListener(this);
+ mAssignKeyButton->setEnabled(false);
+ add(mAssignKeyButton);
- for (int i = 0; i < keyboard.KEY_TOTAL; i++)
- {
- refreshAssignedKey(i);
- mKeyLabel[i].setPosition(10, 10+(i*20));
- add(&mKeyLabel[i]);
-
- mKeyButton[i].setCaption("Set");
- mKeyButton[i].adjustSize();
- mKeyButton[i].addActionListener(this);
- mKeyButton[i].setActionEventId("sk"+toString(i));
- mKeyButton[i].setPosition(150,5+(i*20));
- add(&mKeyButton[i]);
- }
mMakeDefaultButton = new Button("Default", "makeDefault", this);
- mMakeDefaultButton->setPosition(200, 5);
+ mMakeDefaultButton->setPosition(10, 155);
mMakeDefaultButton->addActionListener(this);
add(mMakeDefaultButton);
}
Setup_Keyboard::~Setup_Keyboard()
{
- delete [] mKeyLabel;
- delete [] mKeyButton;
+ delete mKeyList;
+ delete mKeyListModel;
+
+ delete mAssignKeyButton;
delete mMakeDefaultButton;
}
@@ -75,9 +111,7 @@ void Setup_Keyboard::apply()
if (keyboard.hasConflicts())
{
new OkDialog("Key Conflict(s) Detected.",
- "One or more key conflicts has been detected. "
- "Resolve them immediately, "
- "or gameplay might result in unpredictable behaviour");
+ "Resolve them, or gameplay may result in strange behaviour.");
}
keyboard.setEnabled(true);
keyboard.store();
@@ -92,50 +126,43 @@ void Setup_Keyboard::cancel()
void Setup_Keyboard::action(const gcn::ActionEvent &event)
{
- if (event.getId() == "makeDefault")
+ if (event.getSource() == mKeyList)
{
- keyboard.makeDefault();
- refreshKeys();
- return;
+ mAssignKeyButton->setEnabled(true);
}
- for (int i = 0; i < keyboard.KEY_TOTAL; i++)
+ else if (event.getId() == "assign")
{
- if (event.getId() == "sk"+toString(i))
- {
- keyboard.setEnabled(false);
- keyboard.setNewKeyIndex(i);
- enableSetButtons(false);
- mKeyLabel[i].setCaption(keyboard.getKeyCaption(i) + ": ?");
- }
+ int i(mKeyList->getSelected());
+ mAssignKeyButton->setEnabled(false);
+ keyboard.setEnabled(false);
+ keyboard.setNewKeyIndex(i);
+ mKeyListModel->setElementAt(i, keyboard.getKeyCaption(i) + ": ?");
}
-}
-
-void Setup_Keyboard::enableSetButtons(bool bValue)
-{
- for (int i = 0; i < keyboard.KEY_TOTAL; i++)
+ else if (event.getId() == "makeDefault")
{
- mKeyButton[i].setEnabled(bValue);
+ keyboard.makeDefault();
+ refreshKeys();
}
}
-void Setup_Keyboard::refreshAssignedKey(const int index)
+void Setup_Keyboard::refreshAssignedKey(int index)
{
+ std::string caption;
char *temp = SDL_GetKeyName(
(SDLKey) keyboard.getKeyValue(index));
- mKeyLabel[index].setCaption(
- keyboard.getKeyCaption(index) + ": " + toString(temp));
- mKeyLabel[index].adjustSize();
+ caption = keyboard.getKeyCaption(index) + ": " + toString(temp);
+ mKeyListModel->setElementAt(index, caption);
}
-void Setup_Keyboard::newKeyCallback(const int index)
+void Setup_Keyboard::newKeyCallback(int index)
{
refreshAssignedKey(index);
- enableSetButtons(true);
+ mAssignKeyButton->setEnabled(true);
}
void Setup_Keyboard::refreshKeys()
{
- for (int i = 0; i < keyboard.KEY_TOTAL; i++)
+ for(int i = 0; i < keyboard.KEY_TOTAL; i++)
{
refreshAssignedKey(i);
}