| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2019 by the FIFE team * |
| 3 |
* http://www.fifengine.net * |
| 4 |
* This file is part of FIFE. * |
| 5 |
* * |
| 6 |
* FIFE is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Lesser General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2.1 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 14 |
* Lesser General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Lesser General Public * |
| 17 |
* License along with this library; if not, write to the * |
| 18 |
* Free Software Foundation, Inc., * |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
| 20 |
***************************************************************************/ |
| 21 |
|
| 22 |
#ifndef FIFE_GUI_LIBROCKETINPUTPROCESSOR_H |
| 23 |
#define FIFE_GUI_LIBROCKETINPUTPROCESSOR_H |
| 24 |
|
| 25 |
// Standard C++ library includes |
| 26 |
#include <map> |
| 27 |
|
| 28 |
// 3rd party library includes |
| 29 |
#include <Rocket/Core/Input.h> |
| 30 |
#include <Rocket/Core/Types.h> |
| 31 |
#include <SDL_events.h> |
| 32 |
|
| 33 |
// FIFE includes |
| 34 |
// These includes are split up in two parts, separated by one empty line |
| 35 |
// First block: files included from the FIFE root src directory |
| 36 |
// Second block: files included from the same folder |
| 37 |
#include "util/base/fife_stdint.h" |
| 38 |
|
| 39 |
namespace Rocket { |
| 40 |
namespace Core { |
| 41 |
class Context; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
namespace FIFE { |
| 46 |
|
| 47 |
class LibRocketInputProcessor { |
| 48 |
public: |
| 49 |
|
| 50 |
/** Constructor |
| 51 |
*/ |
| 52 |
LibRocketInputProcessor(Rocket::Core::Context* context); |
| 53 |
|
| 54 |
/** Destructor |
| 55 |
*/ |
| 56 |
~LibRocketInputProcessor(); |
| 57 |
|
| 58 |
/** Processes SDL input and converts it to librocket input, then forwards it to |
| 59 |
* the librocket context. |
| 60 |
* |
| 61 |
* NOTE There is no way to get, if an event is consumed by Rocket currently. |
| 62 |
* This is for in case it gets implemented in the future. |
| 63 |
* |
| 64 |
* @param evt The SDL input. |
| 65 |
* @return A boolean value indicating if the event was consumed by librocket or not. |
| 66 |
|
| 67 |
*/ |
| 68 |
bool onSdlEvent(SDL_Event &evt); |
| 69 |
|
| 70 |
/** |
| 71 |
* Called each frame to perform update operations. |
| 72 |
*/ |
| 73 |
void turn(); |
| 74 |
|
| 75 |
private: |
| 76 |
|
| 77 |
/** Updates the key mod state bitmask. |
| 78 |
*/ |
| 79 |
void updateKeyModState(); |
| 80 |
|
| 81 |
/** Process a mouse motion event. |
| 82 |
*/ |
| 83 |
bool processMouseMotion(SDL_Event& event); |
| 84 |
|
| 85 |
/** Process a mouse input event. |
| 86 |
*/ |
| 87 |
bool processMouseInput(SDL_Event& event); |
| 88 |
|
| 89 |
/** Process a mouse wheel motion event. |
| 90 |
*/ |
| 91 |
bool processMouseWheelMotion(SDL_Event& event); |
| 92 |
|
| 93 |
/** Process a key input event. |
| 94 |
*/ |
| 95 |
bool processKeyInput(SDL_Event& event); |
| 96 |
|
| 97 |
/** Process a text input event. |
| 98 |
*/ |
| 99 |
bool processTextInput(SDL_Event& event); |
| 100 |
|
| 101 |
/** Creates the key map. |
| 102 |
*/ |
| 103 |
void populateKeyMap(); |
| 104 |
|
| 105 |
/** Reference to librocket's context. |
| 106 |
*/ |
| 107 |
Rocket::Core::Context* m_context; |
| 108 |
|
| 109 |
/** Bitmask that stores key modifiers. |
| 110 |
*/ |
| 111 |
uint32_t m_keyModState; |
| 112 |
|
| 113 |
/** Counts how many times the wheel has been moved. Negative |
| 114 |
* value means that the wheel has been moved abs(m_wheelCounter) upwards, |
| 115 |
* positive value means that the wheel has been moved m_wheelCounter times downwards. |
| 116 |
*/ |
| 117 |
int32_t m_wheelCounter; |
| 118 |
|
| 119 |
/** Keymap to convert SDL key to Librocket key. |
| 120 |
*/ |
| 121 |
std::map<SDL_Keycode, Rocket::Core::Input::KeyIdentifier> m_keyMap; |
| 122 |
}; |
| 123 |
|
| 124 |
}; |
| 125 |
|
| 126 |
#endif //FIFE_GUI_LIBROCKETINPUTPROCESSOR_H |