diff options
Diffstat (limited to 'src/input')
-rw-r--r-- | src/input/inputevent.cpp | 29 | ||||
-rw-r--r-- | src/input/inputevent.h | 51 | ||||
-rw-r--r-- | src/input/inputmanager.cpp | 35 | ||||
-rw-r--r-- | src/input/inputmanager.h | 3 | ||||
-rw-r--r-- | src/input/joystick.h | 2 | ||||
-rw-r--r-- | src/input/key.cpp | 110 | ||||
-rw-r--r-- | src/input/key.h | 197 | ||||
-rw-r--r-- | src/input/keyboardconfig.h | 2 | ||||
-rw-r--r-- | src/input/keydata.h | 2 | ||||
-rw-r--r-- | src/input/keyevent.cpp | 47 | ||||
-rw-r--r-- | src/input/keyevent.h | 66 | ||||
-rw-r--r-- | src/input/keyinput.cpp | 38 | ||||
-rw-r--r-- | src/input/keyinput.h | 203 | ||||
-rw-r--r-- | src/input/mouseinput.h | 216 | ||||
-rw-r--r-- | src/input/multitouchmanager.cpp | 2 | ||||
-rw-r--r-- | src/input/multitouchmanager.h | 2 |
16 files changed, 734 insertions, 271 deletions
diff --git a/src/input/inputevent.cpp b/src/input/inputevent.cpp deleted file mode 100644 index b87e4fe0a..000000000 --- a/src/input/inputevent.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "input/inputevent.h" - -#include "debug.h" - -InputEvent::InputEvent(const int action0, const int mask0) : - action(action0), - mask(mask0) -{ -} diff --git a/src/input/inputevent.h b/src/input/inputevent.h deleted file mode 100644 index 61f80c8e2..000000000 --- a/src/input/inputevent.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef INPUT_INPUTEVENT_H -#define INPUT_INPUTEVENT_H - -#include <map> -#include <vector> - -#include "localconsts.h" - -typedef std::vector<int> KeysVector; -typedef KeysVector::iterator KeysVectorIter; -typedef KeysVector::const_iterator KeysVectorCIter; - -typedef std::map<int, KeysVector> KeyToActionMap; -typedef KeyToActionMap::iterator KeyToActionMapIter; - -typedef std::map<int, int> KeyToIdMap; -typedef KeyToIdMap::iterator KeyToIdMapIter; - -typedef std::map<int, int> KeyTimeMap; -typedef KeyTimeMap::iterator KeyTimeMapIter; - -struct InputEvent final -{ - InputEvent(const int action0, const int mask0); - - int action; - - int mask; -}; - -#endif // INPUT_INPUTEVENT_H diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp index cc37001cc..5d157f0fa 100644 --- a/src/input/inputmanager.cpp +++ b/src/input/inputmanager.cpp @@ -28,7 +28,6 @@ #include "input/keyboardconfig.h" #include "input/keyboarddata.h" #include "being/localplayer.h" -#include "being/playerinfo.h" #ifdef USE_SDL2 #include "input/multitouchmanager.h" #endif @@ -47,12 +46,10 @@ #include "gui/windows/setupwindow.h" #include "gui/windows/textdialog.h" #include "gui/windows/tradewindow.h" -#include "gui/windows/quitdialog.h" #include "utils/timer.h" -#include <guichan/exception.hpp> -#include <guichan/focushandler.hpp> +#include "gui/focushandler.h" #include <algorithm> @@ -60,6 +57,8 @@ InputManager inputManager; +class QuitDialog; + extern QuitDialog *quitDialog; static class KeyFunctor final @@ -549,18 +548,10 @@ bool InputManager::handleEvent(const SDL_Event &event) if (quitDialog || TextDialog::isActive() || NpcPostDialog::isActive()) { - try - { - if (guiInput) - guiInput->pushInput(event); - if (gui) - gui->handleInput(); - } - catch(const gcn::Exception &e) - { - const char *const err = e.getMessage().c_str(); - logger->log("Warning: guichan input exception: %s", err); - } + if (guiInput) + guiInput->pushInput(event); + if (gui) + gui->handleInput(); return true; } break; @@ -605,16 +596,8 @@ bool InputManager::handleEvent(const SDL_Event &event) break; } - try - { - if (guiInput) - guiInput->pushInput(event); - } - catch(const gcn::Exception &e) - { - const char *const err = e.getMessage().c_str(); - logger->log("Warning: guichan input exception: %s", err); - } + if (guiInput) + guiInput->pushInput(event); if (gui) { const bool res = gui->handleInput(); diff --git a/src/input/inputmanager.h b/src/input/inputmanager.h index 630b52948..fcd1252c0 100644 --- a/src/input/inputmanager.h +++ b/src/input/inputmanager.h @@ -21,7 +21,8 @@ #ifndef INPUT_INPUTMANAGER_H #define INPUT_INPUTMANAGER_H -#include "input/inputevent.h" +#include "events/inputevent.h" + #include "input/keydata.h" #include <string> diff --git a/src/input/joystick.h b/src/input/joystick.h index 06823ca27..8693d0d75 100644 --- a/src/input/joystick.h +++ b/src/input/joystick.h @@ -23,7 +23,7 @@ #ifndef INPUT_JOYSTICK_H #define INPUT_JOYSTICK_H -#include "input/inputevent.h" +#include "events/inputevent.h" #include <SDL_events.h> diff --git a/src/input/key.cpp b/src/input/key.cpp new file mode 100644 index 000000000..13d2a301d --- /dev/null +++ b/src/input/key.cpp @@ -0,0 +1,110 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * For comments regarding functions please see the header file. + */ + +#include "input/key.h" + +#include "debug.h" + +Key::Key(const int value) : + mValue(value) +{ +} + +bool Key::isCharacter() const +{ + return (mValue >= 32 && mValue <= 126) + || (mValue >= 162 && mValue <= 255) + || (mValue == 9); +} + +bool Key::isNumber() const +{ + return mValue >= 48 && mValue <= 57; +} + +bool Key::isLetter() const +{ + return (((mValue >= 65 && mValue <= 90) + || (mValue >= 97 && mValue <= 122) + || (mValue >= 192 && mValue <= 255)) + && (mValue != 215) && (mValue != 247)); +} + +int Key::getValue() const +{ + return mValue; +} + +bool Key::operator==(const Key& key) const +{ + return mValue == key.mValue; +} + +bool Key::operator!=(const Key& key) const +{ + return (mValue != key.mValue); +} diff --git a/src/input/key.h b/src/input/key.h new file mode 100644 index 000000000..97bc7113d --- /dev/null +++ b/src/input/key.h @@ -0,0 +1,197 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef INPUT_KEY_H +#define INPUT_KEY_H + +#include "localconsts.h" + +// windows.h defines DELETE which breaks this file as we have a constant named +// DELETE, hence we undefine DELETE if it is defined and hope people don't use +// that windows define with Guichan. +#if defined (_WIN32) && defined(DELETE) +#undef DELETE +#endif + +/** + * Represents a key or a character. + */ +class Key final +{ + public: + /** + * Constructor. + * + * @param value The ascii or enum value for the key. + */ + explicit Key(const int value = 0); + + enum + { + SPACE = ' ', + TAB = '\t', + ENTER = '\n', + // Negative values, to avoid conflicts with higher character codes. + LEFT_ALT = -1000, + RIGHT_ALT, + LEFT_SHIFT, + RIGHT_SHIFT, + LEFT_CONTROL, + RIGHT_CONTROL, + LEFT_META, + RIGHT_META, + LEFT_SUPER, + RIGHT_SUPER, + INSERT, + HOME, + PAGE_UP, + DELETE_, + END, + PAGE_DOWN, + ESCAPE, + CAPS_LOCK, + BACKSPACE, + F1, + F2, + F3, + F4, + F5, + F6, + F7, + F8, + F9, + F10, + F11, + F12, + F13, + F14, + F15, + PRINT_SCREEN, + SCROLL_LOCK, + PAUSE, + NUM_LOCK, + ALT_GR, + LEFT, + RIGHT, + UP, + DOWN, + TEXTINPUT + }; + + /** + * Checks if a key is a character. + * + * @return True if the key is a letter, number or whitespace, + * false otherwise. + */ + bool isCharacter() const A_WARN_UNUSED; + + /** + * Checks if a key is a number. + * + * @return True if the key is a number (0-9), + * false otherwise. + */ + bool isNumber() const A_WARN_UNUSED; + + /** + * Checks if a key is a letter. + * + * @return True if the key is a letter (a-z,A-Z), + * false otherwise. + */ + bool isLetter() const A_WARN_UNUSED; + + /** + * Gets the value of the key. If an ascii value exists it + * will be returned. Otherwise an enum value will be returned. + * + * @return the value of the key. + */ + int getValue() const A_WARN_UNUSED; + + /** + * Compares two keys. + * + * @param key The key to compare this key with. + * @return True if the keys are equal, false otherwise. + */ + bool operator==(const Key& key) const; + + /** + * Compares two keys. + * + * @param key The key to compare this key with. + * @return True if the keys are not equal, false otherwise. + */ + bool operator!=(const Key& key) const; + + protected: + /** + * Holds the value of the key. It may be an ascii value + * or an enum value. + */ + int mValue; +}; + +#endif // INPUT_KEY_H diff --git a/src/input/keyboardconfig.h b/src/input/keyboardconfig.h index 7f7102964..425a0c70c 100644 --- a/src/input/keyboardconfig.h +++ b/src/input/keyboardconfig.h @@ -27,7 +27,7 @@ #include "sdlshared.h" -#include "input/inputevent.h" +#include "events/inputevent.h" #include <string> diff --git a/src/input/keydata.h b/src/input/keydata.h index 2ceb957c5..62517b64b 100644 --- a/src/input/keydata.h +++ b/src/input/keydata.h @@ -23,7 +23,7 @@ #ifndef INPUT_KEYDATA_H #define INPUT_KEYDATA_H -#include "input/inputevent.h" +#include "events/inputevent.h" #include <string> diff --git a/src/input/keyevent.cpp b/src/input/keyevent.cpp deleted file mode 100644 index 5695cd99b..000000000 --- a/src/input/keyevent.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "input/keyevent.h" - -#include "debug.h" - -KeyEvent::KeyEvent(gcn::Widget *const source, - const bool shiftPressed, - const bool controlPressed, - const bool altPressed, - const bool metaPressed, - const unsigned int type, - const bool numericPad, - const int actionId, - const gcn::Key& key) : - gcn::KeyEvent(source, shiftPressed, controlPressed, altPressed, - metaPressed, type, numericPad, key), -#ifdef USE_SDL2 - mActionId(actionId), - mText() -#else - mActionId(actionId) -#endif -{ -} - -KeyEvent::~KeyEvent() -{ -} diff --git a/src/input/keyevent.h b/src/input/keyevent.h deleted file mode 100644 index e0b2e8e17..000000000 --- a/src/input/keyevent.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef INPUT_KEYEVENT_H -#define INPUT_KEYEVENT_H - -#include <guichan/key.hpp> -#include <guichan/keyevent.hpp> - -#include <string> - -#include "localconsts.h" - -class KeyEvent final : public gcn::KeyEvent -{ - public: - KeyEvent(gcn::Widget *const source, - const bool shiftPressed, - const bool controlPressed, - const bool altPressed, - const bool metaPressed, - const unsigned int type, - const bool numericPad, - const int actionId, - const gcn::Key& key); - - A_DELETE_COPY(KeyEvent) - - ~KeyEvent(); - - int getActionId() const A_WARN_UNUSED - { return mActionId; } - -#ifdef USE_SDL2 - void setText(const std::string &text) - { mText = text; } - - std::string getText() const - { return mText; } -#endif - - protected: - int mActionId; -#ifdef USE_SDL2 - std::string mText; -#endif -}; - -#endif // INPUT_KEYEVENT_H diff --git a/src/input/keyinput.cpp b/src/input/keyinput.cpp deleted file mode 100644 index d04305e0e..000000000 --- a/src/input/keyinput.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2014 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "input/keyinput.h" - -#include "debug.h" - -KeyInput::KeyInput() : - gcn::KeyInput(), -#ifdef USE_SDL2 - mActionId(-2), - mText() -#else - mActionId(-2) -#endif -{ -} - -KeyInput::~KeyInput() -{ -} diff --git a/src/input/keyinput.h b/src/input/keyinput.h index 25deeae19..9920cfa17 100644 --- a/src/input/keyinput.h +++ b/src/input/keyinput.h @@ -18,41 +18,226 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #ifndef INPUT_KEYINPUT_H #define INPUT_KEYINPUT_H -#include <guichan/keyinput.hpp> +#include "input/key.h" #include <string> #include "localconsts.h" -class KeyInput final : public gcn::KeyInput +class KeyInput final { public: - KeyInput(); + KeyInput() : + mKey(0), + mType(0), +#ifdef USE_SDL2 + mText(), +#endif + mActionId(-2), + mShiftPressed(false), + mControlPressed(false), + mAltPressed(false), + mMetaPressed(false), + mNumericPad(false) + { } + + ~KeyInput() + { } + + /** + * Key input types. This enum corresponds to the enum with event + * types on KeyEvent for easy mapping. + */ + enum + { + PRESSED = 0, + RELEASED + }; + + void setType(unsigned int type) + { + mType = type; + } + + int getType() const + { + return mType; + } + + void setKey(const Key& key) + { + mKey = key; + } + + const Key& getKey() const + { + return mKey; + } + + bool isShiftPressed() const + { + return mShiftPressed; + } + + void setShiftPressed(bool pressed) + { + mShiftPressed = pressed; + } - ~KeyInput(); + bool isControlPressed() const + { + return mControlPressed; + } + + void setControlPressed(bool pressed) + { + mControlPressed = pressed; + } + + bool isAltPressed() const + { + return mAltPressed; + } + + void setAltPressed(bool pressed) + { + mAltPressed = pressed; + } + + bool isMetaPressed() const + { + return mMetaPressed; + } + + void setMetaPressed(bool pressed) + { + mMetaPressed = pressed; + } + + bool isNumericPad() const + { + return mNumericPad; + } + + void setNumericPad(bool numpad) + { + mNumericPad = numpad; + } void setActionId(const int n) - { mActionId = n; } + { + mActionId = n; + } int getActionId() const A_WARN_UNUSED - { return mActionId; } + { + return mActionId; + } #ifdef USE_SDL2 void setText(const std::string &text) - { mText = text; } + { + mText = text; + } std::string getText() const - { return mText; } + { + return mText; + } #endif protected: - int mActionId; + /** + * Holds the key of the key input. + */ + Key mKey; + + /** + * Holds the type of the key input. + */ + unsigned int mType; + #ifdef USE_SDL2 std::string mText; #endif + + int mActionId; + + /** + * True if shift was pressed at the same time as the key, + * false otherwise. + */ + bool mShiftPressed; + + /** + * True if control was pressed at the same time as the key, + * false otherwise. + */ + bool mControlPressed; + + /** + * True if alt was pressed at the same time as the key, + * false otherwise. + */ + bool mAltPressed; + + /** + * True if meta was pressed at the same time as the key, + * false otherwise. + */ + bool mMetaPressed; + + /** + * True if the numeric pad was used when the key was pressed, + * false otherwise. + */ + bool mNumericPad; }; #endif // INPUT_KEYINPUT_H diff --git a/src/input/mouseinput.h b/src/input/mouseinput.h new file mode 100644 index 000000000..a90a1366d --- /dev/null +++ b/src/input/mouseinput.h @@ -0,0 +1,216 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef INPUT_MOUSEINPUT_H +#define INPUT_MOUSEINPUT_H + +#include "input/mouseinput.h" + +#include "localconsts.h" + +class MouseInput final +{ + public: + MouseInput() : + mType(0), + mButton(0), + mTimeStamp(0), + mX(0), + mY(0), + mRealX(0), + mRealY(0) + { } + + ~MouseInput() + { } + + /** + * Mouse input event types. This enum partially corresponds + * to the enum with event types in MouseEvent for easy mapping. + */ + enum + { + MOVED = 0, + PRESSED, + RELEASED, + WHEEL_MOVED_DOWN, + WHEEL_MOVED_UP + }; + + /** + * Mouse button types. + */ + enum + { + EMPTY = 0, + LEFT, + RIGHT, + MIDDLE + }; + + void setType(unsigned int type) + { + mType = type; + } + + unsigned int getType() const + { + return mType; + } + + void setButton(unsigned int button) + { + mButton = button; + } + + unsigned int getButton() const + { + return mButton; + } + + int getTimeStamp() const + { + return mTimeStamp; + } + + void setTimeStamp(int timeStamp) + { + mTimeStamp = timeStamp; + } + + void setX(int x) + { + mX = x; + } + + int getX() const + { + return mX; + } + + void setY(int y) + { + mY = y; + } + + int getY() const + { + return mY; + } + + void setReal(const int x, const int y) + { mRealX = x; mRealY = y; } + + int getRealX() const A_WARN_UNUSED + { return mRealX; } + + int getRealY() const A_WARN_UNUSED + { return mRealY; } + +#ifdef ANDROID + int getTouchX() const A_WARN_UNUSED + { return mRealX; } + + int getTouchY() const A_WARN_UNUSED + { return mRealY; } +#else + int getTouchX() const A_WARN_UNUSED + { return mX; } + + int getTouchY() const A_WARN_UNUSED + { return mY; } +#endif + + protected: + /** + * Holds the type of the mouse input. + */ + unsigned int mType; + + /** + * Holds the button of the mouse input. + */ + unsigned int mButton; + + /** + * Holds the timestamp of the mouse input. Used to + * check for double clicks. + */ + int mTimeStamp; + + /** + * Holds the x coordinate of the mouse input. + */ + int mX; + + /** + * Holds the y coordinate of the mouse input. + */ + int mY; + + int mRealX; + + int mRealY; +}; + +#endif // INPUT_MOUSEINPUT_H diff --git a/src/input/multitouchmanager.cpp b/src/input/multitouchmanager.cpp index 7e6798807..446e40aa1 100644 --- a/src/input/multitouchmanager.cpp +++ b/src/input/multitouchmanager.cpp @@ -82,7 +82,7 @@ void MultiTouchManager::checkDevice(const int touchId, const int w = mainGraphics->mWidth; const int h = mainGraphics->mHeight; guiInput->simulateMouseClick(finger0.x * w, finger0.y * h, - gcn::MouseInput::RIGHT); + MouseInput::RIGHT); } } } diff --git a/src/input/multitouchmanager.h b/src/input/multitouchmanager.h index 076ccb3a8..82bfd0881 100644 --- a/src/input/multitouchmanager.h +++ b/src/input/multitouchmanager.h @@ -25,7 +25,9 @@ #include "localconsts.h" +#ifdef USE_SDL2 union SDL_Event; +#endif struct MultiTouchEvent { |