From 7da95c7f4da447876458a0b1a17736b9a2865844 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 18 May 2014 19:47:28 +0300 Subject: Move inputaction into separate file. --- src/gui/widgets/button.cpp | 5 ++-- src/gui/widgets/checkbox.cpp | 3 +- src/gui/widgets/desktop.cpp | 2 +- src/gui/widgets/dropdown.cpp | 13 +++++---- src/gui/widgets/emoteshortcutcontainer.cpp | 2 +- src/gui/widgets/guitable.cpp | 15 +++++----- src/gui/widgets/inttextfield.cpp | 4 ++- src/gui/widgets/itemshortcutcontainer.cpp | 2 +- src/gui/widgets/listbox.cpp | 11 +++---- src/gui/widgets/radiobutton.cpp | 3 +- src/gui/widgets/slider.cpp | 9 +++--- src/gui/widgets/tabbedarea.cpp | 5 ++-- src/gui/widgets/tabs/setup_input.cpp | 24 ++++++++-------- src/gui/widgets/textbox.cpp | 25 ++++++++-------- src/gui/widgets/textfield.cpp | 46 +++++++++++++++--------------- 15 files changed, 90 insertions(+), 79 deletions(-) (limited to 'src/gui/widgets') diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 3b3c97911..661dfc66d 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -70,6 +70,7 @@ #include "events/keyevent.h" +#include "input/inputaction.h" #include "input/keydata.h" #include "resources/image.h" @@ -674,7 +675,7 @@ void Button::keyPressed(KeyEvent& event) { const int action = event.getActionId(); - if (action == Input::KEY_GUI_SELECT) + if (action == InputAction::GUI_SELECT) { mKeyPressed = true; event.consume(); @@ -685,7 +686,7 @@ void Button::keyReleased(KeyEvent& event) { const int action = event.getActionId(); - if (action == Input::KEY_GUI_SELECT && mKeyPressed) + if (action == InputAction::GUI_SELECT && mKeyPressed) { mKeyPressed = false; if (mStick) diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp index b9d74e067..48f603532 100644 --- a/src/gui/widgets/checkbox.cpp +++ b/src/gui/widgets/checkbox.cpp @@ -67,6 +67,7 @@ #include "client.h" +#include "input/inputaction.h" #include "input/keydata.h" #include "resources/image.h" @@ -241,7 +242,7 @@ void CheckBox::keyPressed(KeyEvent& event) { const int action = event.getActionId(); - if (action == Input::KEY_GUI_SELECT) + if (action == InputAction::GUI_SELECT) { toggleSelected(); event.consume(); diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp index a1158a59b..0a0b98b4c 100644 --- a/src/gui/widgets/desktop.cpp +++ b/src/gui/widgets/desktop.cpp @@ -209,5 +209,5 @@ void Desktop::setBestFittingWallpaper() void Desktop::handleLink(const std::string &link, MouseEvent *event A_UNUSED) { if (link == "copyright") - inputManager.executeAction(Input::KEY_WINDOW_ABOUT); + inputManager.executeAction(InputAction::WINDOW_ABOUT); } diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 65a5b10c9..71e546faa 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -26,6 +26,7 @@ #include "events/keyevent.h" +#include "input/inputaction.h" #include "input/keydata.h" #include "gui/gui.h" @@ -317,24 +318,24 @@ void DropDown::keyPressed(KeyEvent& event) const int actionId = event.getActionId(); switch (actionId) { - case Input::KEY_GUI_SELECT: - case Input::KEY_GUI_SELECT2: + case InputAction::GUI_SELECT: + case InputAction::GUI_SELECT2: dropDown(); break; - case Input::KEY_GUI_UP: + case InputAction::GUI_UP: setSelected(getSelected() - 1); break; - case Input::KEY_GUI_DOWN: + case InputAction::GUI_DOWN: setSelected(getSelected() + 1); break; - case Input::KEY_GUI_HOME: + case InputAction::GUI_HOME: setSelected(0); break; - case Input::KEY_GUI_END: + case InputAction::GUI_END: if (mPopup->getListModel()) { setSelected(mPopup->getListModel()-> diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp index 9d9aa8d92..79a4021a4 100644 --- a/src/gui/widgets/emoteshortcutcontainer.cpp +++ b/src/gui/widgets/emoteshortcutcontainer.cpp @@ -125,7 +125,7 @@ void EmoteShortcutContainer::draw(Graphics *graphics) // Draw emote keyboard shortcut. const std::string key = inputManager.getKeyValueString( - Input::KEY_EMOTE_1 + i); + InputAction::EMOTE_1 + i); font->drawString(graphics, key, emoteX + 2, emoteY + 2); } diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp index 9aa17c512..ba2c36713 100644 --- a/src/gui/widgets/guitable.cpp +++ b/src/gui/widgets/guitable.cpp @@ -28,6 +28,7 @@ #include "events/keyevent.h" +#include "input/inputaction.h" #include "input/keydata.h" #include "listeners/guitableactionlistener.h" @@ -370,38 +371,38 @@ void GuiTable::keyPressed(KeyEvent& event) { const int action = event.getActionId(); - if (action == Input::KEY_GUI_SELECT) + if (action == InputAction::GUI_SELECT) { distributeActionEvent(); event.consume(); } - else if (action == Input::KEY_GUI_UP) + else if (action == InputAction::GUI_UP) { setSelectedRow(mSelectedRow - 1); event.consume(); } - else if (action == Input::KEY_GUI_DOWN) + else if (action == InputAction::GUI_DOWN) { setSelectedRow(mSelectedRow + 1); event.consume(); } - else if (action == Input::KEY_GUI_LEFT) + else if (action == InputAction::GUI_LEFT) { setSelectedColumn(mSelectedColumn - 1); event.consume(); } - else if (action == Input::KEY_GUI_RIGHT) + else if (action == InputAction::GUI_RIGHT) { setSelectedColumn(mSelectedColumn + 1); event.consume(); } - else if (action == Input::KEY_GUI_HOME) + else if (action == InputAction::GUI_HOME) { setSelectedRow(0); setSelectedColumn(0); event.consume(); } - else if (action == Input::KEY_GUI_END && mModel) + else if (action == InputAction::GUI_END && mModel) { setSelectedRow(mModel->getRows() - 1); setSelectedColumn(mModel->getColumns() - 1); diff --git a/src/gui/widgets/inttextfield.cpp b/src/gui/widgets/inttextfield.cpp index 160cfe5de..fcec92a39 100644 --- a/src/gui/widgets/inttextfield.cpp +++ b/src/gui/widgets/inttextfield.cpp @@ -28,6 +28,7 @@ #include "events/keyevent.h" +#include "input/inputaction.h" #include "input/keydata.h" #include "utils/stringutils.h" @@ -57,7 +58,8 @@ void IntTextField::keyPressed(KeyEvent &event) { const int action = event.getActionId(); - if (action == Input::KEY_GUI_DELETE || action == Input::KEY_GUI_BACKSPACE) + if (action == InputAction::GUI_DELETE + || action == InputAction::GUI_BACKSPACE) { setText(std::string()); if (mSendAlwaysEvents) diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp index a993afcd0..4cf0e76f7 100644 --- a/src/gui/widgets/itemshortcutcontainer.cpp +++ b/src/gui/widgets/itemshortcutcontainer.cpp @@ -149,7 +149,7 @@ void ItemShortcutContainer::draw(Graphics *graphics) // Draw item keyboard shortcut. const std::string key = inputManager.getKeyValueString( - Input::KEY_SHORTCUT_1 + i); + InputAction::SHORTCUT_1 + i); graphics->setColorAll(mForegroundColor, mForegroundColor); font->drawString(graphics, key, itemX + 2, itemY + 2); diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index ceb3c1669..ab5e8dccb 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -67,6 +67,7 @@ #include "client.h" +#include "input/inputaction.h" #include "input/keydata.h" #include "listeners/selectionlistener.h" @@ -230,12 +231,12 @@ void ListBox::draw(Graphics *graphics) void ListBox::keyPressed(KeyEvent &event) { const int action = event.getActionId(); - if (action == Input::KEY_GUI_SELECT) + if (action == InputAction::GUI_SELECT) { distributeActionEvent(); event.consume(); } - else if (action == Input::KEY_GUI_UP) + else if (action == InputAction::GUI_UP) { if (mSelected > 0) setSelected(mSelected - 1); @@ -243,7 +244,7 @@ void ListBox::keyPressed(KeyEvent &event) setSelected(getListModel()->getNumberOfElements() - 1); event.consume(); } - else if (action == Input::KEY_GUI_DOWN) + else if (action == InputAction::GUI_DOWN) { const int num = getListModel()->getNumberOfElements() - 1; if (mSelected < num) @@ -252,12 +253,12 @@ void ListBox::keyPressed(KeyEvent &event) setSelected(0); event.consume(); } - else if (action == Input::KEY_GUI_HOME) + else if (action == InputAction::GUI_HOME) { setSelected(0); event.consume(); } - else if (action == Input::KEY_GUI_END && getListModel()) + else if (action == InputAction::GUI_END && getListModel()) { setSelected(getListModel()->getNumberOfElements() - 1); event.consume(); diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp index ad1b5d902..87621e945 100644 --- a/src/gui/widgets/radiobutton.cpp +++ b/src/gui/widgets/radiobutton.cpp @@ -67,6 +67,7 @@ #include "client.h" +#include "input/inputaction.h" #include "input/keydata.h" #include "resources/image.h" @@ -240,7 +241,7 @@ void RadioButton::mouseExited(MouseEvent& event A_UNUSED) void RadioButton::keyPressed(KeyEvent& event) { const int action = event.getActionId(); - if (action == Input::KEY_GUI_SELECT) + if (action == InputAction::GUI_SELECT) { setSelected(true); distributeActionEvent(); diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index 77ae38931..848027c94 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -70,6 +70,7 @@ #include "events/keyevent.h" +#include "input/inputaction.h" #include "input/keydata.h" #include "gui/gui.h" @@ -409,13 +410,13 @@ void Slider::keyPressed(KeyEvent& event) if (mOrientation == HORIZONTAL) { - if (action == Input::KEY_GUI_RIGHT) + if (action == InputAction::GUI_RIGHT) { setValue(mValue + mStepLength); distributeActionEvent(); event.consume(); } - else if (action == Input::KEY_GUI_LEFT) + else if (action == InputAction::GUI_LEFT) { setValue(mValue - mStepLength); distributeActionEvent(); @@ -424,13 +425,13 @@ void Slider::keyPressed(KeyEvent& event) } else { - if (action == Input::KEY_GUI_UP) + if (action == InputAction::GUI_UP) { setValue(mValue + mStepLength); distributeActionEvent(); event.consume(); } - else if (action == Input::KEY_GUI_DOWN) + else if (action == InputAction::GUI_DOWN) { setValue(mValue - mStepLength); distributeActionEvent(); diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index f99f6ccc8..81cf34dd2 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -67,6 +67,7 @@ #include "events/keyevent.h" +#include "input/inputaction.h" #include "input/keydata.h" #include "gui/gui.h" @@ -728,7 +729,7 @@ void TabbedArea::keyPressed(KeyEvent& event) const int actionId = event.getActionId(); - if (actionId == Input::KEY_GUI_LEFT) + if (actionId == InputAction::GUI_LEFT) { int index = getSelectedTabIndex(); index--; @@ -740,7 +741,7 @@ void TabbedArea::keyPressed(KeyEvent& event) event.consume(); } - else if (actionId == Input::KEY_GUI_RIGHT) + else if (actionId == InputAction::GUI_RIGHT) { int index = getSelectedTabIndex(); index++; diff --git a/src/gui/widgets/tabs/setup_input.cpp b/src/gui/widgets/tabs/setup_input.cpp index 4fae66b47..97aa7421f 100644 --- a/src/gui/widgets/tabs/setup_input.cpp +++ b/src/gui/widgets/tabs/setup_input.cpp @@ -177,7 +177,7 @@ void Setup_Input::action(const ActionEvent &event) if (i >= 0 && i < mActionDataSize[selectedData]) { if (setupActionData[selectedData][i].actionId - == static_cast(Input::KEY_NO_VALUE)) + == static_cast(InputAction::NO_VALUE)) { mAssignKeyButton->setEnabled(false); mUnassignKeyButton->setEnabled(false); @@ -215,7 +215,7 @@ void Setup_Input::action(const ActionEvent &event) inputManager.setNewKeyIndex(ik); refreshAssignedKey(mKeyList->getSelected()); inputManager.unassignKey(); - inputManager.setNewKeyIndex(static_cast(Input::KEY_NO_VALUE)); + inputManager.setNewKeyIndex(static_cast(InputAction::NO_VALUE)); } mAssignKeyButton->setEnabled(true); } @@ -260,7 +260,7 @@ void Setup_Input::refreshAssignedKey(const int index) { const int selectedData = mKeyListModel->getSelectedData(); const SetupActionData &key = setupActionData[selectedData][index]; - if (key.actionId == static_cast(Input::KEY_NO_VALUE)) + if (key.actionId == static_cast(InputAction::NO_VALUE)) { const std::string str(" \342\200\225\342\200\225\342\200\225" "\342\200\225\342\200\225 "); @@ -328,7 +328,7 @@ void Setup_Input::keyUnresolved() if (mKeySetting) { newKeyCallback(inputManager.getNewKeyIndex()); - inputManager.setNewKeyIndex(static_cast(Input::KEY_NO_VALUE)); + inputManager.setNewKeyIndex(static_cast(InputAction::NO_VALUE)); } } @@ -355,17 +355,17 @@ void Setup_Input::fixTranslation(SetupActionData *const actionDatas, void Setup_Input::fixTranslations() { - fixTranslation(setupActionData1, static_cast(Input::KEY_SHORTCUT_1), - static_cast(Input::KEY_SHORTCUT_20), "Item Shortcut %d"); + fixTranslation(setupActionData1, static_cast(InputAction::SHORTCUT_1), + static_cast(InputAction::SHORTCUT_20), "Item Shortcut %d"); - fixTranslation(setupActionData3, static_cast(Input::KEY_EMOTE_1), - static_cast(Input::KEY_EMOTE_48), "Emote Shortcut %d"); + fixTranslation(setupActionData3, static_cast(InputAction::EMOTE_1), + static_cast(InputAction::EMOTE_48), "Emote Shortcut %d"); - fixTranslation(setupActionData4, static_cast(Input::KEY_OUTFIT_1), - static_cast(Input::KEY_OUTFIT_48), "Outfit Shortcut %d"); + fixTranslation(setupActionData4, static_cast(InputAction::OUTFIT_1), + static_cast(InputAction::OUTFIT_48), "Outfit Shortcut %d"); fixTranslation(setupActionData7, static_cast( - Input::KEY_MOVE_TO_POINT_1), - static_cast(Input::KEY_MOVE_TO_POINT_48), + InputAction::MOVE_TO_POINT_1), + static_cast(InputAction::MOVE_TO_POINT_48), "Move to point Shortcut %d"); } diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp index 917c613c5..23fa63a07 100644 --- a/src/gui/widgets/textbox.cpp +++ b/src/gui/widgets/textbox.cpp @@ -65,6 +65,7 @@ #include "gui/widgets/textbox.h" +#include "input/inputaction.h" #include "input/keydata.h" #include "gui/gui.h" @@ -256,7 +257,7 @@ void TextBox::keyPressed(KeyEvent& event) switch (action) { - case Input::KEY_GUI_LEFT: + case InputAction::GUI_LEFT: { --mCaretColumn; if (mCaretColumn < 0) @@ -277,7 +278,7 @@ void TextBox::keyPressed(KeyEvent& event) break; } - case Input::KEY_GUI_RIGHT: + case InputAction::GUI_RIGHT: { ++mCaretColumn; if (mCaretColumn > static_cast(mTextRows[mCaretRow].size())) @@ -302,28 +303,28 @@ void TextBox::keyPressed(KeyEvent& event) break; } - case Input::KEY_GUI_DOWN: + case InputAction::GUI_DOWN: { setCaretRow(mCaretRow + 1); break; } - case Input::KEY_GUI_UP: + case InputAction::GUI_UP: { setCaretRow(mCaretRow - 1); break; } - case Input::KEY_GUI_HOME: + case InputAction::GUI_HOME: { mCaretColumn = 0; break; } - case Input::KEY_GUI_END: + case InputAction::GUI_END: { mCaretColumn = static_cast(mTextRows[mCaretRow].size()); break; } - case Input::KEY_GUI_SELECT2: + case InputAction::GUI_SELECT2: { if (mEditable) { @@ -337,7 +338,7 @@ void TextBox::keyPressed(KeyEvent& event) break; } - case Input::KEY_GUI_BACKSPACE: + case InputAction::GUI_BACKSPACE: { if (mCaretColumn != 0 && mEditable) { @@ -355,7 +356,7 @@ void TextBox::keyPressed(KeyEvent& event) break; } - case Input::KEY_GUI_DELETE: + case InputAction::GUI_DELETE: { if (mCaretColumn < static_cast( mTextRows[mCaretRow].size()) && mEditable) @@ -373,7 +374,7 @@ void TextBox::keyPressed(KeyEvent& event) break; } - case Input::KEY_GUI_PAGE_UP: + case InputAction::GUI_PAGE_UP: { Widget *const par = getParent(); @@ -389,7 +390,7 @@ void TextBox::keyPressed(KeyEvent& event) break; } - case Input::KEY_GUI_PAGE_DOWN: + case InputAction::GUI_PAGE_DOWN: { Widget *const par = getParent(); @@ -406,7 +407,7 @@ void TextBox::keyPressed(KeyEvent& event) break; } - case Input::KEY_GUI_TAB: + case InputAction::GUI_TAB: { if (mEditable) { diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 7aec5e4fc..14faad2f0 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -327,7 +327,7 @@ void TextField::keyPressed(KeyEvent &event) const int action = event.getActionId(); if (!inputManager.isActionActive(static_cast( - Input::KEY_GUI_CTRL))) + InputAction::GUI_CTRL))) { if (!handleNormalKeys(action, consumed)) { @@ -353,7 +353,7 @@ bool TextField::handleNormalKeys(const int action, bool &consumed) { switch (action) { - case Input::KEY_GUI_LEFT: + case InputAction::GUI_LEFT: { consumed = true; while (mCaretPosition > 0) @@ -365,7 +365,7 @@ bool TextField::handleNormalKeys(const int action, bool &consumed) break; } - case Input::KEY_GUI_RIGHT: + case InputAction::GUI_RIGHT: { consumed = true; const unsigned sz = static_cast(mText.size()); @@ -381,7 +381,7 @@ bool TextField::handleNormalKeys(const int action, bool &consumed) break; } - case Input::KEY_GUI_DELETE: + case InputAction::GUI_DELETE: { consumed = true; unsigned sz = static_cast(mText.size()); @@ -398,28 +398,28 @@ bool TextField::handleNormalKeys(const int action, bool &consumed) break; } - case Input::KEY_GUI_BACKSPACE: + case InputAction::GUI_BACKSPACE: consumed = true; deleteCharLeft(mText, &mCaretPosition); break; - case Input::KEY_GUI_SELECT2: + case InputAction::GUI_SELECT2: distributeActionEvent(); consumed = true; fixScroll(); return false; - case Input::KEY_GUI_HOME: + case InputAction::GUI_HOME: mCaretPosition = 0; consumed = true; break; - case Input::KEY_GUI_END: + case InputAction::GUI_END: mCaretPosition = static_cast(mText.size()); consumed = true; break; - case Input::KEY_GUI_TAB: + case InputAction::GUI_TAB: if (mLoseFocusOnTab) return false; consumed = true; @@ -435,19 +435,19 @@ void TextField::handleCtrlKeys(const int action, bool &consumed) { switch (action) { - case Input::KEY_GUI_LEFT: + case InputAction::GUI_LEFT: { moveCaretWordBack(); consumed = true; break; } - case Input::KEY_GUI_RIGHT: + case InputAction::GUI_RIGHT: { moveCaretWordForward(); consumed = true; break; } - case Input::KEY_GUI_B: + case InputAction::GUI_B: { if (mAllowSpecialActions) { @@ -456,49 +456,49 @@ void TextField::handleCtrlKeys(const int action, bool &consumed) } break; } - case Input::KEY_GUI_F: + case InputAction::GUI_F: { moveCaretForward(); consumed = true; break; } - case Input::KEY_GUI_D: + case InputAction::GUI_D: { caretDelete(); consumed = true; break; } - case Input::KEY_GUI_E: + case InputAction::GUI_E: { mCaretPosition = static_cast(mText.size()); consumed = true; break; } - case Input::KEY_GUI_H: + case InputAction::GUI_H: { deleteCharLeft(mText, &mCaretPosition); consumed = true; break; } - case Input::KEY_GUI_K: + case InputAction::GUI_K: { mText = mText.substr(0, mCaretPosition); consumed = true; break; } - case Input::KEY_GUI_U: + case InputAction::GUI_U: { caretDeleteToStart(); consumed = true; break; } - case Input::KEY_GUI_C: + case InputAction::GUI_C: { handleCopy(); consumed = true; break; } - case Input::KEY_GUI_V: + case InputAction::GUI_V: { #ifdef USE_SDL2 handlePaste(); @@ -512,7 +512,7 @@ void TextField::handleCtrlKeys(const int action, bool &consumed) consumed = true; break; } - case Input::KEY_GUI_W: + case InputAction::GUI_W: { caretDeleteWord(); consumed = true; @@ -699,7 +699,7 @@ void TextField::mousePressed(MouseEvent &event) { #ifdef ANDROID if (!client->isKeyboardVisible()) - inputManager.executeAction(Input::KEY_SHOW_KEYBOARD); + inputManager.executeAction(InputAction::SHOW_KEYBOARD); #endif event.consume(); if (event.getButton() == MouseButton::RIGHT) @@ -736,7 +736,7 @@ void TextField::focusGained(const Event &event A_UNUSED) { #ifdef ANDROID if (!client->isKeyboardVisible()) - inputManager.executeAction(Input::KEY_SHOW_KEYBOARD); + inputManager.executeAction(InputAction::SHOW_KEYBOARD); #endif } -- cgit v1.2.3-70-g09d2