diff options
author | Joshua Langley <joshlangley[at]optusnet.com.au> | 2007-07-25 13:06:47 +0000 |
---|---|---|
committer | Joshua Langley <joshlangley[at]optusnet.com.au> | 2007-07-25 13:06:47 +0000 |
commit | fbb717acfc2bd1f2a3cedf8465c817e8a5abec57 (patch) | |
tree | b197517690f9afa24bbbb4bf0a5dff8bd7b5b67e /src/gui | |
parent | 8e3fad97a5df4bfc706b0246794b00428bd207e0 (diff) | |
download | mana-fbb717acfc2bd1f2a3cedf8465c817e8a5abec57.tar.gz mana-fbb717acfc2bd1f2a3cedf8465c817e8a5abec57.tar.bz2 mana-fbb717acfc2bd1f2a3cedf8465c817e8a5abec57.tar.xz mana-fbb717acfc2bd1f2a3cedf8465c817e8a5abec57.zip |
keyboard config - keyboard setup gui re-designed, fixed errors in keyboard config.
m_id:16
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/setup.cpp | 4 | ||||
-rw-r--r-- | src/gui/setup_keyboard.cpp | 123 | ||||
-rw-r--r-- | src/gui/setup_keyboard.h | 15 |
3 files changed, 82 insertions, 60 deletions
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index b936f688..1c17c50e 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -44,7 +44,7 @@ Setup::Setup(): Window("Setup") { int width = 260; - int height = 305; + int height = 245; setContentSize(width, height); const char *buttonNames[] = { @@ -59,7 +59,7 @@ Setup::Setup(): } TabbedContainer *panel = new TabbedContainer(); - panel->setDimension(gcn::Rectangle(5, 5, 250, 265)); + panel->setDimension(gcn::Rectangle(5, 5, 250, 205)); panel->setOpaque(false); SetupTab *tab; 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); } diff --git a/src/gui/setup_keyboard.h b/src/gui/setup_keyboard.h index 4701487b..ccc2558f 100644 --- a/src/gui/setup_keyboard.h +++ b/src/gui/setup_keyboard.h @@ -52,19 +52,14 @@ class Setup_Keyboard : public SetupTab, public gcn::ActionListener void action(const gcn::ActionEvent &event); /** - * Easy way to disable/enable all the set buttons. - */ - void enableSetButtons(bool bValue); - - /** * Get an update on the assigned key. */ - void refreshAssignedKey(const int index); + void refreshAssignedKey(int index); /** * The callback function when a new key has been pressed. */ - void newKeyCallback(const int index); + void newKeyCallback(int index); /** * Shorthand method to update all the keys. @@ -72,10 +67,10 @@ class Setup_Keyboard : public SetupTab, public gcn::ActionListener void refreshKeys(); private: - gcn::Label *mKeyLabel; - - Button *mKeyButton; + class KeyListModel *mKeyListModel; + gcn::ListBox *mKeyList; + gcn::Button *mAssignKeyButton; gcn::Button *mMakeDefaultButton; }; |