23 #include <Rocket/Core/Input.h> 25 using namespace Rocket::Core::Input;
34 RocketInputHandler(
const std::string &name) :
37 _mouse_xy_changed(false),
41 _pixel_xy_input = define_input(
"pixel_xy", EventStoreVec2::get_class_type());
42 _button_events_input = define_input(
"button_events", ButtonEventList::get_class_type());
49 ~RocketInputHandler() {
61 if (keymap.size() > 0) {
64 if (it == keymap.end()) {
71 keymap[KeyboardButton::space().
get_index()] = KI_SPACE;
72 keymap[KeyboardButton::backspace().
get_index()] = KI_BACK;
73 keymap[KeyboardButton::tab().
get_index()] = KI_TAB;
74 keymap[KeyboardButton::enter().
get_index()] = KI_RETURN;
75 keymap[KeyboardButton::escape().
get_index()] = KI_ESCAPE;
76 keymap[KeyboardButton::end().
get_index()] = KI_END;
77 keymap[KeyboardButton::home().
get_index()] = KI_HOME;
78 keymap[KeyboardButton::left().
get_index()] = KI_LEFT;
79 keymap[KeyboardButton::up().
get_index()] = KI_UP;
80 keymap[KeyboardButton::right().
get_index()] = KI_RIGHT;
81 keymap[KeyboardButton::down().
get_index()] = KI_DOWN;
82 keymap[KeyboardButton::insert().
get_index()] = KI_INSERT;
83 keymap[KeyboardButton::del().
get_index()] = KI_DELETE;
84 keymap[KeyboardButton::caps_lock().
get_index()] = KI_CAPITAL;
85 keymap[KeyboardButton::f1().
get_index()] = KI_F1;
86 keymap[KeyboardButton::f10().
get_index()] = KI_F10;
87 keymap[KeyboardButton::f11().
get_index()] = KI_F11;
88 keymap[KeyboardButton::f12().
get_index()] = KI_F12;
89 keymap[KeyboardButton::f13().
get_index()] = KI_F13;
90 keymap[KeyboardButton::f14().
get_index()] = KI_F14;
91 keymap[KeyboardButton::f15().
get_index()] = KI_F15;
92 keymap[KeyboardButton::f16().
get_index()] = KI_F16;
93 keymap[KeyboardButton::f2().
get_index()] = KI_F2;
94 keymap[KeyboardButton::f3().
get_index()] = KI_F3;
95 keymap[KeyboardButton::f4().
get_index()] = KI_F4;
96 keymap[KeyboardButton::f5().
get_index()] = KI_F5;
97 keymap[KeyboardButton::f6().
get_index()] = KI_F6;
98 keymap[KeyboardButton::f7().
get_index()] = KI_F7;
99 keymap[KeyboardButton::f8().
get_index()] = KI_F8;
100 keymap[KeyboardButton::f9().
get_index()] = KI_F9;
101 keymap[KeyboardButton::help().
get_index()] = KI_HELP;
102 keymap[KeyboardButton::lcontrol().
get_index()] = KI_LCONTROL;
103 keymap[KeyboardButton::lshift().
get_index()] = KI_LSHIFT;
104 keymap[KeyboardButton::num_lock().
get_index()] = KI_NUMLOCK;
105 keymap[KeyboardButton::page_down().
get_index()] = KI_NEXT;
106 keymap[KeyboardButton::page_up().
get_index()] = KI_PRIOR;
107 keymap[KeyboardButton::pause().
get_index()] = KI_PAUSE;
108 keymap[KeyboardButton::print_screen().
get_index()] = KI_SNAPSHOT;
109 keymap[KeyboardButton::rcontrol().
get_index()] = KI_RCONTROL;
110 keymap[KeyboardButton::rshift().
get_index()] = KI_RSHIFT;
111 keymap[KeyboardButton::scroll_lock().
get_index()] = KI_SCROLL;
130 for (
char c =
'a'; c <=
'z'; ++c) {
133 for (
char c =
'0'; c <=
'9'; ++c) {
138 if (it != keymap.end()) {
152 void RocketInputHandler::
157 if (input.
has_data(_pixel_xy_input)) {
164 if (p != _mouse_xy) {
165 _mouse_xy_changed =
true;
173 if (input.
has_data(_button_events_input)) {
175 DCAST_INTO_V(this_button_events, input.
get_data(_button_events_input).
get_ptr());
177 for (
int i = 0; i < num_events; i++) {
180 int rocket_key = KI_UNKNOWN;
183 case ButtonEvent::T_down:
184 if (be._button == KeyboardButton::control()) {
185 _modifiers |= KM_CTRL;
186 }
else if (be._button == KeyboardButton::shift()) {
187 _modifiers |= KM_SHIFT;
188 }
else if (be._button == KeyboardButton::alt()) {
189 _modifiers |= KM_ALT;
190 }
else if (be._button == KeyboardButton::meta()) {
191 _modifiers |= KM_META;
193 }
else if (be._button == KeyboardButton::enter()) {
194 _text_input.push_back(
'\n');
202 _mouse_buttons[0] =
true;
204 _mouse_buttons[1] =
true;
206 _mouse_buttons[2] =
true;
208 _mouse_buttons[3] =
true;
210 _mouse_buttons[4] =
true;
214 if (rocket_key != KI_UNKNOWN) {
215 _keys[rocket_key] =
true;
219 case ButtonEvent::T_repeat:
220 if (be._button == KeyboardButton::enter()) {
221 _text_input.push_back(
'\n');
225 if (rocket_key != KI_UNKNOWN) {
226 _repeated_keys.push_back(rocket_key);
230 case ButtonEvent::T_up:
231 if (be._button == KeyboardButton::control()) {
232 _modifiers &= ~KM_CTRL;
233 }
else if (be._button == KeyboardButton::shift()) {
234 _modifiers &= ~KM_SHIFT;
235 }
else if (be._button == KeyboardButton::alt()) {
236 _modifiers &= ~KM_ALT;
237 }
else if (be._button == KeyboardButton::meta()) {
238 _modifiers &= ~KM_META;
241 _mouse_buttons[0] =
false;
243 _mouse_buttons[1] =
false;
245 _mouse_buttons[2] =
false;
247 _mouse_buttons[3] =
false;
249 _mouse_buttons[4] =
false;
253 if (rocket_key != KI_UNKNOWN) {
254 _keys[rocket_key] =
false;
258 case ButtonEvent::T_keystroke:
261 if (be._keycode > 0x1F && (be._keycode < 0x7F || be._keycode > 0x9F)) {
262 _text_input.push_back(be._keycode);
266 case ButtonEvent::T_resume_down:
269 case ButtonEvent::T_move:
272 case ButtonEvent::T_candidate:
275 case ButtonEvent::T_raw_down:
278 case ButtonEvent::T_raw_up:
293 if (_keys.size() > 0) {
294 ButtonActivityMap::const_iterator it;
295 for (it = _keys.begin(); it != _keys.end(); ++it) {
297 context->ProcessKeyDown((KeyIdentifier) it->first, _modifiers);
299 context->ProcessKeyUp((KeyIdentifier) it->first, _modifiers);
305 if (_repeated_keys.size() > 0) {
308 for (it = _repeated_keys.begin(); it != _repeated_keys.end(); ++it) {
309 context->ProcessKeyUp((KeyIdentifier) *it, _modifiers);
310 context->ProcessKeyDown((KeyIdentifier) *it, _modifiers);
312 _repeated_keys.clear();
315 if (_text_input.size() > 0) {
317 for (it = _text_input.begin(); it != _text_input.end(); ++it) {
318 context->ProcessTextInput(*it);
323 if (_mouse_xy_changed) {
324 _mouse_xy_changed =
false;
326 context->ProcessMouseMove(_mouse_xy.get_x() - xoffs,
327 _mouse_xy.get_y() - yoffs, _modifiers);
330 if (_mouse_buttons.size() > 0) {
331 ButtonActivityMap::const_iterator it;
332 for (it = _mouse_buttons.begin(); it != _mouse_buttons.end(); ++it) {
334 context->ProcessMouseButtonDown(it->first, _modifiers);
336 context->ProcessMouseButtonUp(it->first, _modifiers);
339 _mouse_buttons.clear();
342 if (_wheel_delta != 0) {
343 context->ProcessMouseWheel(_wheel_delta, _modifiers);
The fundamental type of node for the data graph.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
get_value
Retrieves the value stored in the parameter.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
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...
TypeHandle is the identifier used to differentiate C++ class types.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...