15 #include "rocketInputHandler.h" 16 #include "buttonEventList.h" 17 #include "dataGraphTraverser.h" 18 #include "linmath_events.h" 19 #include "rocketRenderInterface.h" 20 #include "keyboardButton.h" 21 #include "mouseButton.h" 23 #include <Rocket/Core/Input.h> 35 RocketInputHandler(
const string &name) :
38 _mouse_xy_changed(false),
42 _pixel_xy_input = define_input(
"pixel_xy", EventStoreVec2::get_class_type());
43 _button_events_input = define_input(
"button_events", ButtonEventList::get_class_type());
52 ~RocketInputHandler() {
66 if (keymap.size() > 0) {
69 if (it == keymap.end()) {
76 keymap[KeyboardButton::space().
get_index()] = KI_SPACE;
77 keymap[KeyboardButton::backspace().
get_index()] = KI_BACK;
78 keymap[KeyboardButton::tab().
get_index()] = KI_TAB;
79 keymap[KeyboardButton::enter().
get_index()] = KI_RETURN;
80 keymap[KeyboardButton::escape().
get_index()] = KI_ESCAPE;
81 keymap[KeyboardButton::end().
get_index()] = KI_END;
82 keymap[KeyboardButton::home().
get_index()] = KI_HOME;
83 keymap[KeyboardButton::left().
get_index()] = KI_LEFT;
84 keymap[KeyboardButton::up().
get_index()] = KI_UP;
85 keymap[KeyboardButton::right().
get_index()] = KI_RIGHT;
86 keymap[KeyboardButton::down().
get_index()] = KI_DOWN;
87 keymap[KeyboardButton::insert().
get_index()] = KI_INSERT;
88 keymap[KeyboardButton::del().
get_index()] = KI_DELETE;
89 keymap[KeyboardButton::caps_lock().
get_index()] = KI_CAPITAL;
90 keymap[KeyboardButton::f1().
get_index()] = KI_F1;
91 keymap[KeyboardButton::f10().
get_index()] = KI_F10;
92 keymap[KeyboardButton::f11().
get_index()] = KI_F11;
93 keymap[KeyboardButton::f12().
get_index()] = KI_F12;
94 keymap[KeyboardButton::f13().
get_index()] = KI_F13;
95 keymap[KeyboardButton::f14().
get_index()] = KI_F14;
96 keymap[KeyboardButton::f15().
get_index()] = KI_F15;
97 keymap[KeyboardButton::f16().
get_index()] = KI_F16;
98 keymap[KeyboardButton::f2().
get_index()] = KI_F2;
99 keymap[KeyboardButton::f3().
get_index()] = KI_F3;
100 keymap[KeyboardButton::f4().
get_index()] = KI_F4;
101 keymap[KeyboardButton::f5().
get_index()] = KI_F5;
102 keymap[KeyboardButton::f6().
get_index()] = KI_F6;
103 keymap[KeyboardButton::f7().
get_index()] = KI_F7;
104 keymap[KeyboardButton::f8().
get_index()] = KI_F8;
105 keymap[KeyboardButton::f9().
get_index()] = KI_F9;
106 keymap[KeyboardButton::help().
get_index()] = KI_HELP;
107 keymap[KeyboardButton::lcontrol().
get_index()] = KI_LCONTROL;
108 keymap[KeyboardButton::lshift().
get_index()] = KI_LSHIFT;
109 keymap[KeyboardButton::num_lock().
get_index()] = KI_NUMLOCK;
110 keymap[KeyboardButton::page_down().
get_index()] = KI_NEXT;
111 keymap[KeyboardButton::page_up().
get_index()] = KI_PRIOR;
112 keymap[KeyboardButton::pause().
get_index()] = KI_PAUSE;
113 keymap[KeyboardButton::print_screen().
get_index()] = KI_SNAPSHOT;
114 keymap[KeyboardButton::rcontrol().
get_index()] = KI_RCONTROL;
115 keymap[KeyboardButton::rshift().
get_index()] = KI_RSHIFT;
116 keymap[KeyboardButton::scroll_lock().
get_index()] = KI_SCROLL;
134 for (
char c =
'a'; c <=
'z'; ++c) {
137 for (
char c =
'0'; c <=
'9'; ++c) {
142 if (it != keymap.end()) {
161 void RocketInputHandler::
167 if (input.
has_data(_pixel_xy_input)) {
174 if (p != _mouse_xy) {
175 _mouse_xy_changed =
true;
183 if (input.
has_data(_button_events_input)) {
185 DCAST_INTO_V(this_button_events, input.
get_data(_button_events_input).
get_ptr());
187 for (
int i = 0; i < num_events; i++) {
190 int rocket_key = KI_UNKNOWN;
193 case ButtonEvent::T_down:
194 if (be._button == KeyboardButton::control()) {
195 _modifiers |= KM_CTRL;
196 }
else if (be._button == KeyboardButton::shift()) {
197 _modifiers |= KM_SHIFT;
198 }
else if (be._button == KeyboardButton::alt()) {
199 _modifiers |= KM_ALT;
200 }
else if (be._button == KeyboardButton::meta()) {
201 _modifiers |= KM_META;
203 }
else if (be._button == KeyboardButton::enter()) {
204 _text_input.push_back(
'\n');
212 _mouse_buttons[0] =
true;
214 _mouse_buttons[1] =
true;
216 _mouse_buttons[2] =
true;
218 _mouse_buttons[3] =
true;
220 _mouse_buttons[4] =
true;
224 if (rocket_key != KI_UNKNOWN) {
225 _keys[rocket_key] =
true;
229 case ButtonEvent::T_repeat:
230 if (be._button == KeyboardButton::enter()) {
231 _text_input.push_back(
'\n');
235 if (rocket_key != KI_UNKNOWN) {
236 _repeated_keys.push_back(rocket_key);
240 case ButtonEvent::T_up:
241 if (be._button == KeyboardButton::control()) {
242 _modifiers &= ~KM_CTRL;
243 }
else if (be._button == KeyboardButton::shift()) {
244 _modifiers &= ~KM_SHIFT;
245 }
else if (be._button == KeyboardButton::alt()) {
246 _modifiers &= ~KM_ALT;
247 }
else if (be._button == KeyboardButton::meta()) {
248 _modifiers &= ~KM_META;
251 _mouse_buttons[0] =
false;
253 _mouse_buttons[1] =
false;
255 _mouse_buttons[2] =
false;
257 _mouse_buttons[3] =
false;
259 _mouse_buttons[4] =
false;
263 if (rocket_key != KI_UNKNOWN) {
264 _keys[rocket_key] =
false;
268 case ButtonEvent::T_keystroke:
270 if (be._keycode > 0x1F && (be._keycode < 0x7F || be._keycode > 0x9F)) {
271 _text_input.push_back(be._keycode);
275 case ButtonEvent::T_resume_down:
278 case ButtonEvent::T_move:
281 case ButtonEvent::T_candidate:
284 case ButtonEvent::T_raw_down:
287 case ButtonEvent::T_raw_up:
305 if (_keys.size() > 0) {
306 ButtonActivityMap::const_iterator it;
307 for (it = _keys.begin(); it != _keys.end(); ++it) {
309 context->ProcessKeyDown((KeyIdentifier) it->first, _modifiers);
311 context->ProcessKeyUp((KeyIdentifier) it->first, _modifiers);
317 if (_repeated_keys.size() > 0) {
320 for (it = _repeated_keys.begin(); it != _repeated_keys.end(); ++it) {
321 context->ProcessKeyUp((KeyIdentifier) *it, _modifiers);
322 context->ProcessKeyDown((KeyIdentifier) *it, _modifiers);
324 _repeated_keys.clear();
327 if (_text_input.size() > 0) {
329 for (it = _text_input.begin(); it != _text_input.end(); ++it) {
330 context->ProcessTextInput(*it);
335 if (_mouse_xy_changed) {
336 _mouse_xy_changed =
false;
338 context->ProcessMouseMove(_mouse_xy.get_x() - xoffs,
339 _mouse_xy.get_y() - yoffs, _modifiers);
342 if (_mouse_buttons.size() > 0) {
343 ButtonActivityMap::const_iterator it;
344 for (it = _mouse_buttons.begin(); it != _mouse_buttons.end(); ++it) {
346 context->ProcessMouseButtonDown(it->first, _modifiers);
348 context->ProcessMouseButtonUp(it->first, _modifiers);
351 _mouse_buttons.clear();
354 if (_wheel_delta != 0) {
355 context->ProcessMouseWheel(_wheel_delta, _modifiers);
The fundamental type of node for the data graph.
A lightweight C++ object whose constructor calls acquire() and whose destructor calls release() on a ...
bool has_data(int index) const
Returns true if the indicated parameter has been stored, false otherwise.
A handy class object for storing simple values (like integers or strings) passed along with an Event ...
This is our own Panda specialization on the default STL vector.
Thread * get_current_thread() const
Returns the currently-executing thread object, as passed to the DataGraphTraverser constructor...
This is the base class for all two-component vectors and points.
const Type & get_value() const
Retrieves the value stored in the parameter.
TypedWritableReferenceCount * get_ptr() const
Retrieves a pointer to the actual value stored in the parameter.
const EventParameter & get_data(int index) const
Extracts the data for the indicated index, if it has been stored, or the empty parameter if it has no...
A thread; that is, a lightweight process.
TypeHandle is the identifier used to differentiate C++ class types.
Encapsulates the data generated from (or sent into) any particular DataNode.
This object supervises the traversal of the data graph and the moving of data from one DataNode to it...