diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-05-20 12:38:03 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-05-20 17:05:38 -0300 |
commit | 5b3709d3096df737b8bb2344446be818b0389bfe (patch) | |
tree | 649a0989b1494f3c4687d59e503310f4e6bbeb40 /platform | |
parent | 93f9a83062dbe74474a4a7928758c5cf5588238e (diff) |
Removal of InputEvent as built-in Variant type..
this might cause bugs I haven't found yet..
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/java_glue.cpp | 33 | ||||
-rw-r--r-- | platform/android/os_android.cpp | 140 | ||||
-rw-r--r-- | platform/android/os_android.h | 2 | ||||
-rw-r--r-- | platform/haiku/haiku_direct_window.cpp | 72 | ||||
-rw-r--r-- | platform/iphone/os_iphone.cpp | 98 | ||||
-rw-r--r-- | platform/iphone/os_iphone.h | 4 | ||||
-rw-r--r-- | platform/javascript/os_javascript.cpp | 120 | ||||
-rw-r--r-- | platform/javascript/os_javascript.h | 2 | ||||
-rw-r--r-- | platform/osx/os_osx.h | 2 | ||||
-rw-r--r-- | platform/osx/os_osx.mm | 140 | ||||
-rw-r--r-- | platform/uwp/app.cpp | 38 | ||||
-rw-r--r-- | platform/uwp/os_uwp.cpp | 16 | ||||
-rw-r--r-- | platform/uwp/os_uwp.h | 2 | ||||
-rw-r--r-- | platform/windows/os_windows.cpp | 263 | ||||
-rw-r--r-- | platform/windows/os_windows.h | 1 | ||||
-rw-r--r-- | platform/x11/os_x11.cpp | 117 | ||||
-rw-r--r-- | platform/x11/os_x11.h | 2 |
17 files changed, 501 insertions, 551 deletions
diff --git a/platform/android/java_glue.cpp b/platform/android/java_glue.cpp index 6882dad4f0..37f53a2478 100644 --- a/platform/android/java_glue.cpp +++ b/platform/android/java_glue.cpp @@ -610,7 +610,7 @@ struct JAndroidPointerEvent { }; static List<JAndroidPointerEvent> pointer_events; -static List<InputEvent> key_events; +static List<Ref<InputEvent> > key_events; static List<OS_Android::JoypadEvent> joy_events; static bool initialized = false; static Mutex *input_mutex = NULL; @@ -1036,7 +1036,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, job while (key_events.size()) { - InputEvent event = key_events.front()->get(); + Ref<InputEvent> event = key_events.front()->get(); os_android->process_event(event); key_events.pop_front(); @@ -1367,7 +1367,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env jevent.device = p_device; jevent.type = OS_Android::JOY_EVENT_BUTTON; jevent.index = p_button; - jevent.pressed = p_pressed; + jevent->is_pressed() = p_pressed; input_mutex->lock(); joy_events.push_back(jevent); @@ -1419,30 +1419,23 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged( JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jobject obj, jint p_scancode, jint p_unicode_char, jboolean p_pressed) { - InputEvent ievent; - ievent.type = InputEvent::KEY; - ievent.device = 0; + Ref<InputEventKey> ievent; int val = p_unicode_char; int scancode = android_get_keysym(p_scancode); - ievent.key.scancode = scancode; - ievent.key.unicode = val; - ievent.key.pressed = p_pressed; + ievent->set_scancode(scancode); + ievent->set_unicode(val); + ievent->set_pressed(p_pressed); - print_line("Scancode: " + String::num(p_scancode) + ":" + String::num(ievent.key.scancode) + " Unicode: " + String::num(val)); - - ievent.key.mod.shift = false; - ievent.key.mod.alt = false; - ievent.key.mod.control = false; - ievent.key.echo = false; + print_line("Scancode: " + String::num(p_scancode) + ":" + String::num(ievent->get_scancode()) + " Unicode: " + String::num(val)); if (val == '\n') { - ievent.key.scancode = KEY_ENTER; + ievent->set_scancode(KEY_ENTER); } else if (val == 61448) { - ievent.key.scancode = KEY_BACKSPACE; - ievent.key.unicode = KEY_BACKSPACE; + ievent->set_scancode(KEY_BACKSPACE); + ievent->set_unicode(KEY_BACKSPACE); } else if (val == 61453) { - ievent.key.scancode = KEY_ENTER; - ievent.key.unicode = KEY_ENTER; + ievent->set_scancode(KEY_ENTER); + ievent->set_unicode(KEY_ENTER); } else if (p_scancode == 4) { go_back_request = true; diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 6772964c2f..1c721c645c 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -344,7 +344,7 @@ void OS_Android::process_joy_event(OS_Android::JoypadEvent p_event) { switch (p_event.type) { case JOY_EVENT_BUTTON: - input->joy_button(p_event.device, p_event.index, p_event.pressed); + input->joy_button(p_event.device, p_event.index, p_event->is_pressed()); break; case JOY_EVENT_AXIS: InputDefault::JoyAxis value; @@ -360,7 +360,7 @@ void OS_Android::process_joy_event(OS_Android::JoypadEvent p_event) { } } -void OS_Android::process_event(InputEvent p_event) { +void OS_Android::process_event(Ref<InputEvent> p_event) { input->parse_input_event(p_event); } @@ -374,25 +374,24 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> if (touch.size()) { //end all if exist - InputEvent ev; - ev.type = InputEvent::MOUSE_BUTTON; - ev.mouse_button.button_index = BUTTON_LEFT; - ev.mouse_button.button_mask = BUTTON_MASK_LEFT; - ev.mouse_button.pressed = false; - ev.mouse_button.x = touch[0].pos.x; - ev.mouse_button.y = touch[0].pos.y; - ev.mouse_button.global_x = touch[0].pos.x; - ev.mouse_button.global_y = touch[0].pos.y; - input->parse_input_event(ev); + { + Ref<InputEventMouseButton> ev; + ev.instance(); + ev->set_button_index(BUTTON_LEFT); + ev->set_button_mask(BUTTON_MASK_LEFT); + ev->set_pressed(false); + ev->set_pos(touch[0].pos); + ev->set_global_pos(touch[0].pos); + input->parse_input_event(ev); + } for (int i = 0; i < touch.size(); i++) { - InputEvent ev; - ev.type = InputEvent::SCREEN_TOUCH; - ev.screen_touch.index = touch[i].id; - ev.screen_touch.pressed = false; - ev.screen_touch.x = touch[i].pos.x; - ev.screen_touch.y = touch[i].pos.y; + Ref<InputEventScreenTouch> ev; + ev.instance(); + ev->set_index(touch[i].id); + ev->set_pressed(false); + ev->set_pos(touch[i].pos); input->parse_input_event(ev); } } @@ -405,15 +404,14 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> { //send mouse - InputEvent ev; - ev.type = InputEvent::MOUSE_BUTTON; - ev.mouse_button.button_index = BUTTON_LEFT; - ev.mouse_button.button_mask = BUTTON_MASK_LEFT; - ev.mouse_button.pressed = true; - ev.mouse_button.x = touch[0].pos.x; - ev.mouse_button.y = touch[0].pos.y; - ev.mouse_button.global_x = touch[0].pos.x; - ev.mouse_button.global_y = touch[0].pos.y; + Ref<InputEventMouseButton> ev; + ev.instance(); + ev.type = Ref<InputEvent>::MOUSE_BUTTON; + ev->set_button_index(BUTTON_LEFT); + ev->set_button_mask(BUTTON_MASK_LEFT); + ev->set_pressed(true); + ev->set_pos(touch[0].pos); + ev->set_global_pos(touch[0].pos); input->set_mouse_position(Point2(touch[0].pos.x, touch[0].pos.y)); last_mouse = touch[0].pos; input->parse_input_event(ev); @@ -422,12 +420,11 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> //send touch for (int i = 0; i < touch.size(); i++) { - InputEvent ev; - ev.type = InputEvent::SCREEN_TOUCH; - ev.screen_touch.index = touch[i].id; - ev.screen_touch.pressed = true; - ev.screen_touch.x = touch[i].pos.x; - ev.screen_touch.y = touch[i].pos.y; + Ref<InputEventScreenTouch> ev; + ev.instance(); + ev->set_index(touch[i].id); + ev->set_pressed(true); + ev->set_pos(touch[i].pos.x); input->parse_input_event(ev); } @@ -436,16 +433,13 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> if (p_points.size()) { //send mouse, should look for point 0? - InputEvent ev; - ev.type = InputEvent::MOUSE_MOTION; - ev.mouse_motion.button_mask = BUTTON_MASK_LEFT; - ev.mouse_motion.x = p_points[0].pos.x; - ev.mouse_motion.y = p_points[0].pos.y; + Ref<InputEventMouseMotion> ev; + ev.instance(); + ev->set_button_mask(BUTTON_MASK_LEFT); + ev->set_pos(p_points[0].pos.x); input->set_mouse_position(Point2(ev.mouse_motion.x, ev.mouse_motion.y)); - ev.mouse_motion.speed_x = input->get_last_mouse_speed().x; - ev.mouse_motion.speed_y = input->get_last_mouse_speed().y; - ev.mouse_motion.relative_x = p_points[0].pos.x - last_mouse.x; - ev.mouse_motion.relative_y = p_points[0].pos.y - last_mouse.y; + ev->set_speed(input->get_last_mouse_speed()); + ev->set_relative(p_points[0].pos - last_mouse); last_mouse = p_points[0].pos; input->parse_input_event(ev); } @@ -468,13 +462,11 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> if (touch[i].pos == p_points[idx].pos) continue; //no move unncesearily - InputEvent ev; - ev.type = InputEvent::SCREEN_DRAG; - ev.screen_drag.index = touch[i].id; - ev.screen_drag.x = p_points[idx].pos.x; - ev.screen_drag.y = p_points[idx].pos.y; - ev.screen_drag.relative_x = p_points[idx].pos.x - touch[i].pos.x; - ev.screen_drag.relative_y = p_points[idx].pos.y - touch[i].pos.y; + Ref<InputEventScreenDrag> ev; + ev.instance(); + ev->set_index(touch[i].id); + ev->set_pos(p_points[idx].pos.x); + ev->set_relative(p_points[idx].pos - touch[i].pos); input->parse_input_event(ev); touch[i].pos = p_points[idx].pos; } @@ -484,26 +476,23 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> if (touch.size()) { //end all if exist - InputEvent ev; - ev.type = InputEvent::MOUSE_BUTTON; - ev.mouse_button.button_index = BUTTON_LEFT; - ev.mouse_button.button_mask = BUTTON_MASK_LEFT; - ev.mouse_button.pressed = false; - ev.mouse_button.x = touch[0].pos.x; - ev.mouse_button.y = touch[0].pos.y; - ev.mouse_button.global_x = touch[0].pos.x; - ev.mouse_button.global_y = touch[0].pos.y; + Ref<InputEventMouseButton> ev; + ev.instance(); + ev->set_button_index(BUTTON_LEFT); + ev->set_button_mask(BUTTON_MASK_LEFT); + ev->set_pressed(false); + ev->set_pos(touch[0].pos.x); + ev->set_global_pos(touch[0].pos.x); input->set_mouse_position(Point2(touch[0].pos.x, touch[0].pos.y)); input->parse_input_event(ev); for (int i = 0; i < touch.size(); i++) { - InputEvent ev; - ev.type = InputEvent::SCREEN_TOUCH; - ev.screen_touch.index = touch[i].id; - ev.screen_touch.pressed = false; - ev.screen_touch.x = touch[i].pos.x; - ev.screen_touch.y = touch[i].pos.y; + Ref<InputEventScreenTouch> ev; + ev.instance(); + ev->set_index(touch[i].id); + ev->set_pressed(false); + ev->set_pos(touch[i].pos); input->parse_input_event(ev); } touch.clear(); @@ -517,12 +506,12 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> TouchPos tp = p_points[p_pointer]; touch.push_back(tp); - InputEvent ev; - ev.type = InputEvent::SCREEN_TOUCH; - ev.screen_touch.index = tp.id; - ev.screen_touch.pressed = true; - ev.screen_touch.x = tp.pos.x; - ev.screen_touch.y = tp.pos.y; + Ref<InputEventScreenTouch> ev; + ev.instance(); + + ev->set_index(tp.id); + ev->set_pressed(true); + ev->set_pos(tp.pos); input->parse_input_event(ev); } break; @@ -531,12 +520,11 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos> for (int i = 0; i < touch.size(); i++) { if (touch[i].id == p_pointer) { - InputEvent ev; - ev.type = InputEvent::SCREEN_TOUCH; - ev.screen_touch.index = touch[i].id; - ev.screen_touch.pressed = false; - ev.screen_touch.x = touch[i].pos.x; - ev.screen_touch.y = touch[i].pos.y; + Ref<InputEventScreenTouch> ev; + ev.instance(); + ev->set_index(touch[i].id); + ev->set_pressed(false); + ev->set_pos(touch[i].pos); input->parse_input_event(ev); touch.remove(i); i--; diff --git a/platform/android/os_android.h b/platform/android/os_android.h index f1da2867f0..897c71a7df 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -231,7 +231,7 @@ public: void process_gyroscope(const Vector3 &p_gyroscope); void process_touch(int p_what, int p_pointer, const Vector<TouchPos> &p_points); void process_joy_event(JoypadEvent p_event); - void process_event(InputEvent p_event); + void process_event(Ref<InputEvent> p_event); void init_video_mode(int p_video_width, int p_video_height); virtual Error native_video_play(String p_path, float p_volume); diff --git a/platform/haiku/haiku_direct_window.cpp b/platform/haiku/haiku_direct_window.cpp index fb6d9afd85..4a9f8c780d 100644 --- a/platform/haiku/haiku_direct_window.cpp +++ b/platform/haiku/haiku_direct_window.cpp @@ -151,35 +151,35 @@ void HaikuDirectWindow::HandleMouseButton(BMessage *message) { } */ - InputEvent mouse_event; - mouse_event.type = InputEvent::MOUSE_BUTTON; + Ref<InputEvent> mouse_event; + mouse_event.type = Ref<InputEvent>::MOUSE_BUTTON; mouse_event.device = 0; mouse_event.mouse_button.mod = GetKeyModifierState(modifiers); - mouse_event.mouse_button.button_mask = GetMouseButtonState(buttons); - mouse_event.mouse_button.x = where.x; - mouse_event.mouse_button.y = where.y; + mouse_event->get_button_mask() = GetMouseButtonState(buttons); + mouse_event->get_pos().x = where.x; + mouse_event->get_pos().y = where.y; mouse_event.mouse_button.global_x = where.x; mouse_event.mouse_button.global_y = where.y; switch (button) { default: case B_PRIMARY_MOUSE_BUTTON: - mouse_event.mouse_button.button_index = 1; + mouse_event->get_button_index() = 1; break; case B_SECONDARY_MOUSE_BUTTON: - mouse_event.mouse_button.button_index = 2; + mouse_event->get_button_index() = 2; break; case B_TERTIARY_MOUSE_BUTTON: - mouse_event.mouse_button.button_index = 3; + mouse_event->get_button_index() = 3; break; } - mouse_event.mouse_button.pressed = (message->what == B_MOUSE_DOWN); + mouse_event->is_pressed() = (message->what == B_MOUSE_DOWN); - if (message->what == B_MOUSE_DOWN && mouse_event.mouse_button.button_index == 1) { + if (message->what == B_MOUSE_DOWN && mouse_event->get_button_index() == 1) { int32 clicks = message->FindInt32("clicks"); if (clicks > 1) { @@ -207,12 +207,12 @@ void HaikuDirectWindow::HandleMouseMoved(BMessage *message) { Point2i rel = pos - last_mouse_position; - InputEvent motion_event; - motion_event.type = InputEvent::MOUSE_MOTION; + Ref<InputEvent> motion_event; + motion_event.type = Ref<InputEvent>::MOUSE_MOTION; motion_event.device = 0; motion_event.mouse_motion.mod = GetKeyModifierState(modifiers); - motion_event.mouse_motion.button_mask = GetMouseButtonState(buttons); + motion_event->get_button_mask() = GetMouseButtonState(buttons); motion_event.mouse_motion.x = pos.x; motion_event.mouse_motion.y = pos.y; input->set_mouse_position(pos); @@ -221,8 +221,8 @@ void HaikuDirectWindow::HandleMouseMoved(BMessage *message) { motion_event.mouse_motion.speed_x = input->get_last_mouse_speed().x; motion_event.mouse_motion.speed_y = input->get_last_mouse_speed().y; - motion_event.mouse_motion.relative_x = rel.x; - motion_event.mouse_motion.relative_y = rel.y; + motion_event->get_relative().x = rel.x; + motion_event->get_relative().y = rel.y; last_mouse_position = pos; @@ -235,22 +235,22 @@ void HaikuDirectWindow::HandleMouseWheelChanged(BMessage *message) { return; } - InputEvent mouse_event; - mouse_event.type = InputEvent::MOUSE_BUTTON; + Ref<InputEvent> mouse_event; + mouse_event.type = Ref<InputEvent>::MOUSE_BUTTON; mouse_event.device = 0; - mouse_event.mouse_button.button_index = wheel_delta_y < 0 ? 4 : 5; + mouse_event->get_button_index() = wheel_delta_y < 0 ? 4 : 5; mouse_event.mouse_button.mod = GetKeyModifierState(last_key_modifier_state); - mouse_event.mouse_button.button_mask = last_button_mask; - mouse_event.mouse_button.x = last_mouse_position.x; - mouse_event.mouse_button.y = last_mouse_position.y; + mouse_event->get_button_mask() = last_button_mask; + mouse_event->get_pos().x = last_mouse_position.x; + mouse_event->get_pos().y = last_mouse_position.y; mouse_event.mouse_button.global_x = last_mouse_position.x; mouse_event.mouse_button.global_y = last_mouse_position.y; - mouse_event.mouse_button.pressed = true; + mouse_event->is_pressed() = true; input->parse_input_event(mouse_event); - mouse_event.mouse_button.pressed = false; + mouse_event->is_pressed() = false; input->parse_input_event(mouse_event); } @@ -271,13 +271,13 @@ void HaikuDirectWindow::HandleKeyboardEvent(BMessage *message) { return; } - InputEvent event; - event.type = InputEvent::KEY; + Ref<InputEvent> event; + event.type = Ref<InputEvent>::KEY; event.device = 0; event.key.mod = GetKeyModifierState(modifiers); - event.key.pressed = (message->what == B_KEY_DOWN); - event.key.scancode = KeyMappingHaiku::get_keysym(raw_char, key); - event.key.echo = message->HasInt32("be:key_repeat"); + event->is_pressed() = (message->what == B_KEY_DOWN); + event->get_scancode() = KeyMappingHaiku::get_keysym(raw_char, key); + event->is_echo() = message->HasInt32("be:key_repeat"); event.key.unicode = 0; const char *bytes = NULL; @@ -286,9 +286,9 @@ void HaikuDirectWindow::HandleKeyboardEvent(BMessage *message) { } //make it consistent across platforms. - if (event.key.scancode == KEY_BACKTAB) { - event.key.scancode = KEY_TAB; - event.key.mod.shift = true; + if (event->get_scancode() == KEY_BACKTAB) { + event->get_scancode() = KEY_TAB; + event->get_shift() = true; } input->parse_input_event(event); @@ -308,13 +308,13 @@ void HaikuDirectWindow::HandleKeyboardModifierEvent(BMessage *message) { int32 key = old_modifiers ^ modifiers; - InputEvent event; - event.type = InputEvent::KEY; + Ref<InputEvent> event; + event.type = Ref<InputEvent>::KEY; event.device = 0; event.key.mod = GetKeyModifierState(modifiers); - event.key.pressed = ((modifiers & key) != 0); - event.key.scancode = KeyMappingHaiku::get_modifier_keysym(key); - event.key.echo = false; + event->is_pressed() = ((modifiers & key) != 0); + event->get_scancode() = KeyMappingHaiku::get_modifier_keysym(key); + event->is_echo() = false; event.key.unicode = 0; input->parse_input_event(event); diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp index 0a9d776421..3e95d1a706 100644 --- a/platform/iphone/os_iphone.cpp +++ b/platform/iphone/os_iphone.cpp @@ -195,48 +195,45 @@ bool OSIPhone::iterate() { void OSIPhone::key(uint32_t p_key, bool p_pressed) { - InputEvent ev; - ev.type = InputEvent::KEY; - ev.key.echo = false; - ev.key.pressed = p_pressed; - ev.key.scancode = p_key; - ev.key.unicode = p_key; + Ref<InputEventKey> ev; + ev.instance() + ev->set_echo(false); + ev->set_pressed(p_pressed); + ev->set_scancode(p_key); + ev->set_unicode(p_key); queue_event(ev); }; void OSIPhone::mouse_button(int p_idx, int p_x, int p_y, bool p_pressed, bool p_doubleclick, bool p_use_as_mouse) { if (!GLOBAL_DEF("debug/disable_touch", false)) { - InputEvent ev; - ev.type = InputEvent::SCREEN_TOUCH; - ev.screen_touch.index = p_idx; - ev.screen_touch.pressed = p_pressed; - ev.screen_touch.x = p_x; - ev.screen_touch.y = p_y; + Ref<InputEventSreenTouch> ev; + ev.instance(); + + ev->set_index(p_idx); + ev->set_pressed(p_pressed); + ev->set_pos(Vector2(p_x, p_y)); queue_event(ev); }; - mouse_list.pressed[p_idx] = p_pressed; + mouse_list->is_pressed()[p_idx] = p_pressed; if (p_use_as_mouse) { - InputEvent ev; - ev.type = InputEvent::MOUSE_BUTTON; - ev.device = 0; - ev.mouse_button.pointer_index = p_idx; - + Ref<InputEventMouseButton> ev; + ev.instance(); // swaped it for tilted screen - //ev.mouse_button.x = ev.mouse_button.global_x = video_mode.height - p_y; - //ev.mouse_button.y = ev.mouse_button.global_y = p_x; - ev.mouse_button.x = ev.mouse_button.global_x = p_x; - ev.mouse_button.y = ev.mouse_button.global_y = p_y; + //ev->get_pos().x = ev.mouse_button.global_x = video_mode.height - p_y; + //ev->get_pos().y = ev.mouse_button.global_y = p_x; + ev->set_pos(Vector2(ev.mouse_button.global_x, ev.mouse_button.global_y)); + ev->set_global_pos(Vector2(ev.mouse_button.global_x, ev.mouse_button.global_y)); - //mouse_list.pressed[p_idx] = p_pressed; + //mouse_list->is_pressed()[p_idx] = p_pressed; - input->set_mouse_position(Point2(ev.mouse_motion.x, ev.mouse_motion.y)); - ev.mouse_button.button_index = BUTTON_LEFT; - ev.mouse_button.doubleclick = p_doubleclick; - ev.mouse_button.pressed = p_pressed; + input->set_mouse_position(ev->get_pos()); + ev->set_button_index(BUTTON_LEFT); + ev->set_doubleclick(p_doubleclick); + ev->set_pressed(p_pressed); queue_event(ev); }; @@ -246,46 +243,31 @@ void OSIPhone::mouse_move(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_ if (!GLOBAL_DEF("debug/disable_touch", false)) { - InputEvent ev; - ev.type = InputEvent::SCREEN_DRAG; - ev.screen_drag.index = p_idx; - ev.screen_drag.x = p_x; - ev.screen_drag.y = p_y; - ev.screen_drag.relative_x = p_x - p_prev_x; - ev.screen_drag.relative_y = p_y - p_prev_y; + Ref<InputEventScreenDrag> ev; + ev.instance(); + ev->set_index(p_idx); + ev->set_pos(Vector2(p_x, p_y)); + ev->set_relative(Vector2(p_x - p_prev_x, p_y - p_prev_y)); queue_event(ev); }; if (p_use_as_mouse) { - InputEvent ev; - ev.type = InputEvent::MOUSE_MOTION; - ev.device = 0; - ev.mouse_motion.pointer_index = p_idx; - - if (true) { // vertical + Ref<InputEventMouseMotion> ev; + ev.instance(); - ev.mouse_motion.x = ev.mouse_button.global_x = p_x; - ev.mouse_motion.y = ev.mouse_button.global_y = p_y; - ev.mouse_motion.relative_x = ev.mouse_motion.x - p_prev_x; - ev.mouse_motion.relative_y = ev.mouse_motion.y - p_prev_y; - - } else { // horizontal? - ev.mouse_motion.x = ev.mouse_button.global_x = video_mode.height - p_y; - ev.mouse_motion.y = ev.mouse_button.global_y = p_x; - ev.mouse_motion.relative_x = ev.mouse_motion.x - (video_mode.height - p_prev_x); - ev.mouse_motion.relative_y = ev.mouse_motion.y - p_prev_x; - }; + ev->set_pos(Vector2(p_x, p_y)); + ev->set_global_pos(Vector2(p_x, p_y)); + ev->set_relative(Vector2(p_x - p_prev_x, p_y - p_prev_y)); - input->set_mouse_position(Point2(ev.mouse_motion.x, ev.mouse_motion.y)); - ev.mouse_motion.speed_x = input->get_last_mouse_speed().x; - ev.mouse_motion.speed_y = input->get_last_mouse_speed().y; - ev.mouse_motion.button_mask = 1; // pressed + input->set_mouse_position(ev->get_pos()); + ev->set_speed(input->get_last_mouse_speed()); + ev->set_button_mask(BUTTON_LEFT); // pressed queue_event(ev); }; }; -void OSIPhone::queue_event(const InputEvent &p_event) { +void OSIPhone::queue_event(const Ref<InputEvent> &p_event) { ERR_FAIL_INDEX(event_count, MAX_EVENTS); @@ -296,7 +278,7 @@ void OSIPhone::touches_cancelled() { for (int i = 0; i < MAX_MOUSE_COUNT; i++) { - if (mouse_list.pressed[i]) { + if (mouse_list->is_pressed()[i]) { // send a mouse_up outside the screen mouse_button(i, -1, -1, false, false, false); @@ -416,7 +398,7 @@ Point2 OSIPhone::get_mouse_position() const { int OSIPhone::get_mouse_button_state() const { - return mouse_list.pressed[0]; + return mouse_list->is_pressed()[0]; }; void OSIPhone::set_window_title(const String &p_title){}; diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h index 209bf00788..0da7e6d081 100644 --- a/platform/iphone/os_iphone.h +++ b/platform/iphone/os_iphone.h @@ -118,9 +118,9 @@ private: Vector3 last_accel; - InputEvent event_queue[MAX_EVENTS]; + Ref<InputEvent> event_queue[MAX_EVENTS]; int event_count; - void queue_event(const InputEvent &p_event); + void queue_event(const Ref<InputEvent> &p_event); String data_dir; String unique_ID; diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index dda619a54d..ae00fb429e 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -151,26 +151,26 @@ static EM_BOOL _mousebutton_callback(int event_type, const EmscriptenMouseEvent ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_MOUSEDOWN && event_type != EMSCRIPTEN_EVENT_MOUSEUP, false); - InputEvent ev; - ev.type = InputEvent::MOUSE_BUTTON; - ev.mouse_button.pressed = event_type == EMSCRIPTEN_EVENT_MOUSEDOWN; - ev.mouse_button.global_x = ev.mouse_button.x = mouse_event->canvasX; - ev.mouse_button.global_y = ev.mouse_button.y = mouse_event->canvasY; + Ref<InputEvent> ev; + ev.type = Ref<InputEvent>::MOUSE_BUTTON; + ev->is_pressed() = event_type == EMSCRIPTEN_EVENT_MOUSEDOWN; + ev.mouse_button.global_x = ev->get_pos().x = mouse_event->canvasX; + ev.mouse_button.global_y = ev->get_pos().y = mouse_event->canvasY; ev.mouse_button.mod = dom2godot_mod(mouse_event); switch (mouse_event->button) { - case DOM_BUTTON_LEFT: ev.mouse_button.button_index = BUTTON_LEFT; break; - case DOM_BUTTON_MIDDLE: ev.mouse_button.button_index = BUTTON_MIDDLE; break; - case DOM_BUTTON_RIGHT: ev.mouse_button.button_index = BUTTON_RIGHT; break; + case DOM_BUTTON_LEFT: ev->get_button_index() = BUTTON_LEFT; break; + case DOM_BUTTON_MIDDLE: ev->get_button_index() = BUTTON_MIDDLE; break; + case DOM_BUTTON_RIGHT: ev->get_button_index() = BUTTON_RIGHT; break; default: return false; } - ev.mouse_button.button_mask = _input->get_mouse_button_mask(); - if (ev.mouse_button.pressed) - ev.mouse_button.button_mask |= 1 << ev.mouse_button.button_index; + ev->get_button_mask() = _input->get_mouse_button_mask(); + if (ev->is_pressed()) + ev->get_button_mask() |= 1 << ev->get_button_index(); else - ev.mouse_button.button_mask &= ~(1 << ev.mouse_button.button_index); - ev.mouse_button.button_mask >>= 1; + ev->get_button_mask() &= ~(1 << ev->get_button_index()); + ev->get_button_mask() >>= 1; _input->parse_input_event(ev); return true; @@ -180,16 +180,16 @@ static EM_BOOL _mousemove_callback(int event_type, const EmscriptenMouseEvent *m ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_MOUSEMOVE, false); - InputEvent ev; - ev.type = InputEvent::MOUSE_MOTION; + Ref<InputEvent> ev; + ev.type = Ref<InputEvent>::MOUSE_MOTION; ev.mouse_motion.mod = dom2godot_mod(mouse_event); - ev.mouse_motion.button_mask = _input->get_mouse_button_mask() >> 1; + ev->get_button_mask() = _input->get_mouse_button_mask() >> 1; ev.mouse_motion.global_x = ev.mouse_motion.x = mouse_event->canvasX; ev.mouse_motion.global_y = ev.mouse_motion.y = mouse_event->canvasY; - ev.mouse_motion.relative_x = _input->get_mouse_position().x - ev.mouse_motion.x; - ev.mouse_motion.relative_y = _input->get_mouse_position().y - ev.mouse_motion.y; + ev->get_relative().x = _input->get_mouse_position().x - ev.mouse_motion.x; + ev->get_relative().y = _input->get_mouse_position().y - ev.mouse_motion.y; _input->set_mouse_position(Point2(ev.mouse_motion.x, ev.mouse_motion.y)); ev.mouse_motion.speed_x = _input->get_last_mouse_speed().x; @@ -203,31 +203,31 @@ static EM_BOOL _wheel_callback(int event_type, const EmscriptenWheelEvent *wheel ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_WHEEL, false); - InputEvent ev; - ev.type = InputEvent::MOUSE_BUTTON; - ev.mouse_button.button_mask = _input->get_mouse_button_mask() >> 1; - ev.mouse_button.global_x = ev.mouse_button.x = _input->get_mouse_position().x; - ev.mouse_button.global_y = ev.mouse_button.y = _input->get_mouse_position().y; - ev.mouse_button.mod.shift = _input->is_key_pressed(KEY_SHIFT); - ev.mouse_button.mod.alt = _input->is_key_pressed(KEY_ALT); - ev.mouse_button.mod.control = _input->is_key_pressed(KEY_CONTROL); - ev.mouse_button.mod.meta = _input->is_key_pressed(KEY_META); + Ref<InputEvent> ev; + ev.type = Ref<InputEvent>::MOUSE_BUTTON; + ev->get_button_mask() = _input->get_mouse_button_mask() >> 1; + ev.mouse_button.global_x = ev->get_pos().x = _input->get_mouse_position().x; + ev.mouse_button.global_y = ev->get_pos().y = _input->get_mouse_position().y; + ev.mouse_button->get_shift() = _input->is_key_pressed(KEY_SHIFT); + ev.mouse_button->get_alt() = _input->is_key_pressed(KEY_ALT); + ev.mouse_button->get_control() = _input->is_key_pressed(KEY_CONTROL); + ev.mouse_button->get_metakey() = _input->is_key_pressed(KEY_META); if (wheel_event->deltaY < 0) - ev.mouse_button.button_index = BUTTON_WHEEL_UP; + ev->get_button_index() = BUTTON_WHEEL_UP; else if (wheel_event->deltaY > 0) - ev.mouse_button.button_index = BUTTON_WHEEL_DOWN; + ev->get_button_index() = BUTTON_WHEEL_DOWN; else if (wheel_event->deltaX > 0) - ev.mouse_button.button_index = BUTTON_WHEEL_LEFT; + ev->get_button_index() = BUTTON_WHEEL_LEFT; else if (wheel_event->deltaX < 0) - ev.mouse_button.button_index = BUTTON_WHEEL_RIGHT; + ev->get_button_index() = BUTTON_WHEEL_RIGHT; else return false; - ev.mouse_button.pressed = true; + ev->is_pressed() = true; _input->parse_input_event(ev); - ev.mouse_button.pressed = false; + ev->is_pressed() = false; _input->parse_input_event(ev); return true; @@ -243,8 +243,8 @@ static EM_BOOL _touchpress_callback(int event_type, const EmscriptenTouchEvent * event_type != EMSCRIPTEN_EVENT_TOUCHCANCEL, false); - InputEvent ev; - ev.type = InputEvent::SCREEN_TOUCH; + Ref<InputEvent> ev; + ev.type = Ref<InputEvent>::SCREEN_TOUCH; int lowest_id_index = -1; for (int i = 0; i < touch_event->numTouches; ++i) { @@ -256,20 +256,20 @@ static EM_BOOL _touchpress_callback(int event_type, const EmscriptenTouchEvent * ev.screen_touch.index = touch.identifier; _prev_touches[i].x = ev.screen_touch.x = touch.canvasX; _prev_touches[i].y = ev.screen_touch.y = touch.canvasY; - ev.screen_touch.pressed = event_type == EMSCRIPTEN_EVENT_TOUCHSTART; + ev.screen_touch->is_pressed() = event_type == EMSCRIPTEN_EVENT_TOUCHSTART; _input->parse_input_event(ev); } if (touch_event->touches[lowest_id_index].isChanged) { - ev.type = InputEvent::MOUSE_BUTTON; + ev.type = Ref<InputEvent>::MOUSE_BUTTON; ev.mouse_button.mod = dom2godot_mod(touch_event); - ev.mouse_button.button_mask = _input->get_mouse_button_mask() >> 1; - ev.mouse_button.global_x = ev.mouse_button.x = touch_event->touches[lowest_id_index].canvasX; - ev.mouse_button.global_y = ev.mouse_button.y = touch_event->touches[lowest_id_index].canvasY; - ev.mouse_button.button_index = BUTTON_LEFT; - ev.mouse_button.pressed = event_type == EMSCRIPTEN_EVENT_TOUCHSTART; + ev->get_button_mask() = _input->get_mouse_button_mask() >> 1; + ev.mouse_button.global_x = ev->get_pos().x = touch_event->touches[lowest_id_index].canvasX; + ev.mouse_button.global_y = ev->get_pos().y = touch_event->touches[lowest_id_index].canvasY; + ev->get_button_index() = BUTTON_LEFT; + ev->is_pressed() = event_type == EMSCRIPTEN_EVENT_TOUCHSTART; _input->parse_input_event(ev); } @@ -280,8 +280,8 @@ static EM_BOOL _touchmove_callback(int event_type, const EmscriptenTouchEvent *t ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_TOUCHMOVE, false); - InputEvent ev; - ev.type = InputEvent::SCREEN_DRAG; + Ref<InputEvent> ev; + ev.type = Ref<InputEvent>::SCREEN_DRAG; int lowest_id_index = -1; for (int i = 0; i < touch_event->numTouches; ++i) { @@ -304,13 +304,13 @@ static EM_BOOL _touchmove_callback(int event_type, const EmscriptenTouchEvent *t if (touch_event->touches[lowest_id_index].isChanged) { - ev.type = InputEvent::MOUSE_MOTION; + ev.type = Ref<InputEvent>::MOUSE_MOTION; ev.mouse_motion.mod = dom2godot_mod(touch_event); - ev.mouse_motion.button_mask = _input->get_mouse_button_mask() >> 1; + ev->get_button_mask() = _input->get_mouse_button_mask() >> 1; ev.mouse_motion.global_x = ev.mouse_motion.x = touch_event->touches[lowest_id_index].canvasX; ev.mouse_motion.global_y = ev.mouse_motion.y = touch_event->touches[lowest_id_index].canvasY; - ev.mouse_motion.relative_x = _input->get_mouse_position().x - ev.mouse_motion.x; - ev.mouse_motion.relative_y = _input->get_mouse_position().y - ev.mouse_motion.y; + ev->get_relative().x = _input->get_mouse_position().x - ev.mouse_motion.x; + ev->get_relative().y = _input->get_mouse_position().y - ev.mouse_motion.y; _input->set_mouse_position(Point2(ev.mouse_motion.x, ev.mouse_motion.y)); ev.mouse_motion.speed_x = _input->get_last_mouse_speed().x; @@ -321,13 +321,13 @@ static EM_BOOL _touchmove_callback(int event_type, const EmscriptenTouchEvent *t return true; } -static InputEvent _setup_key_event(const EmscriptenKeyboardEvent *emscripten_event) { +static Ref<InputEvent> _setup_key_event(const EmscriptenKeyboardEvent *emscripten_event) { - InputEvent ev; - ev.type = InputEvent::KEY; - ev.key.echo = emscripten_event->repeat; + Ref<InputEvent> ev; + ev.type = Ref<InputEvent>::KEY; + ev->is_echo() = emscripten_event->repeat; ev.key.mod = dom2godot_mod(emscripten_event); - ev.key.scancode = dom2godot_scancode(emscripten_event->keyCode); + ev->get_scancode() = dom2godot_scancode(emscripten_event->keyCode); String unicode = String::utf8(emscripten_event->key); // check if empty or multi-character (e.g. `CapsLock`) @@ -342,15 +342,15 @@ static InputEvent _setup_key_event(const EmscriptenKeyboardEvent *emscripten_eve return ev; } -static InputEvent deferred_key_event; +static Ref<InputEvent> deferred_key_event; static EM_BOOL _keydown_callback(int event_type, const EmscriptenKeyboardEvent *key_event, void *user_data) { ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_KEYDOWN, false); - InputEvent ev = _setup_key_event(key_event); - ev.key.pressed = true; - if (ev.key.unicode == 0 && keycode_has_unicode(ev.key.scancode)) { + Ref<InputEvent> ev = _setup_key_event(key_event); + ev->is_pressed() = true; + if (ev.key.unicode == 0 && keycode_has_unicode(ev->get_scancode())) { // defer to keypress event for legacy unicode retrieval deferred_key_event = ev; return false; // do not suppress keypress event @@ -372,10 +372,10 @@ static EM_BOOL _keyup_callback(int event_type, const EmscriptenKeyboardEvent *ke ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_KEYUP, false); - InputEvent ev = _setup_key_event(key_event); - ev.key.pressed = false; + Ref<InputEvent> ev = _setup_key_event(key_event); + ev->is_pressed() = false; _input->parse_input_event(ev); - return ev.key.scancode != KEY_UNKNOWN && ev.key.scancode != 0; + return ev->get_scancode() != KEY_UNKNOWN && ev->get_scancode() != 0; } static EM_BOOL joy_callback_func(int p_type, const EmscriptenGamepadEvent *p_event, void *p_user) { diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 2bc603d8d9..65269148ec 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -154,7 +154,7 @@ public: virtual String get_resource_dir() const; void process_accelerometer(const Vector3 &p_accelerometer); - void push_input(const InputEvent &p_ev); + void push_input(const Ref<InputEvent> &p_ev); virtual bool is_joy_known(int p_device); virtual String get_joy_guid(int p_device) const; diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index ff02bf0794..3a37d663ad 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -165,7 +165,7 @@ public: virtual void swap_buffers(); Error shell_open(String p_uri); - void push_input(const InputEvent &p_event); + void push_input(const Ref<InputEvent> &p_event); String get_locale() const; diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index d6647fc1d2..462a926674 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -288,15 +288,15 @@ static int button_mask = 0; //print_line("mouse down:"); button_mask |= BUTTON_MASK_LEFT; - InputEvent ev; + Ref<InputEvent> ev; ev.type = InputEvent::MOUSE_BUTTON; - ev.mouse_button.button_index = BUTTON_LEFT; - ev.mouse_button.pressed = true; - ev.mouse_button.x = mouse_x; - ev.mouse_button.y = mouse_y; + ev->get_button_index() = BUTTON_LEFT; + ev->is_pressed() = true; + ev->get_pos().x = mouse_x; + ev->get_pos().y = mouse_y; ev.mouse_button.global_x = mouse_x; ev.mouse_button.global_y = mouse_y; - ev.mouse_button.button_mask = button_mask; + ev->get_button_mask() = button_mask; ev.mouse_button.doubleclick = [event clickCount] == 2; ev.mouse_button.mod = translateFlags([event modifierFlags]); OS_OSX::singleton->push_input(ev); @@ -309,24 +309,24 @@ static int button_mask = 0; - (void)mouseUp:(NSEvent *)event { button_mask &= ~BUTTON_MASK_LEFT; - InputEvent ev; + Ref<InputEvent> ev; ev.type = InputEvent::MOUSE_BUTTON; - ev.mouse_button.button_index = BUTTON_LEFT; - ev.mouse_button.pressed = false; - ev.mouse_button.x = mouse_x; - ev.mouse_button.y = mouse_y; + ev->get_button_index() = BUTTON_LEFT; + ev->is_pressed() = false; + ev->get_pos().x = mouse_x; + ev->get_pos().y = mouse_y; ev.mouse_button.global_x = mouse_x; ev.mouse_button.global_y = mouse_y; - ev.mouse_button.button_mask = button_mask; + ev->get_button_mask() = button_mask; ev.mouse_button.mod = translateFlags([event modifierFlags]); OS_OSX::singleton->push_input(ev); } - (void)mouseMoved:(NSEvent *)event { - InputEvent ev; + Ref<InputEvent> ev; ev.type = InputEvent::MOUSE_MOTION; - ev.mouse_motion.button_mask = button_mask; + ev->get_button_mask() = button_mask; prev_mouse_x = mouse_x; prev_mouse_y = mouse_y; const NSRect contentRect = [OS_OSX::singleton->window_view frame]; @@ -337,8 +337,8 @@ static int button_mask = 0; ev.mouse_motion.y = mouse_y; ev.mouse_motion.global_x = mouse_x; ev.mouse_motion.global_y = mouse_y; - ev.mouse_motion.relative_x = [event deltaX] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); - ev.mouse_motion.relative_y = [event deltaY] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); + ev->get_relative().x = [event deltaX] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); + ev->get_relative().y = [event deltaY] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]); ev.mouse_motion.mod = translateFlags([event modifierFlags]); OS_OSX::singleton->input->set_mouse_position(Point2(mouse_x, mouse_y)); @@ -348,15 +348,15 @@ static int button_mask = 0; - (void)rightMouseDown:(NSEvent *)event { button_mask |= BUTTON_MASK_RIGHT; - InputEvent ev; + Ref<InputEvent> ev; ev.type = InputEvent::MOUSE_BUTTON; - ev.mouse_button.button_index = BUTTON_RIGHT; - ev.mouse_button.pressed = true; - ev.mouse_button.x = mouse_x; - ev.mouse_button.y = mouse_y; + ev->get_button_index() = BUTTON_RIGHT; + ev->is_pressed() = true; + ev->get_pos().x = mouse_x; + ev->get_pos().y = mouse_y; ev.mouse_button.global_x = mouse_x; ev.mouse_button.global_y = mouse_y; - ev.mouse_button.button_mask = button_mask; + ev->get_button_mask() = button_mask; ev.mouse_button.mod = translateFlags([event modifierFlags]); OS_OSX::singleton->push_input(ev); } @@ -368,15 +368,15 @@ static int button_mask = 0; - (void)rightMouseUp:(NSEvent *)event { button_mask &= ~BUTTON_MASK_RIGHT; - InputEvent ev; + Ref<InputEvent> ev; ev.type = InputEvent::MOUSE_BUTTON; - ev.mouse_button.button_index = BUTTON_RIGHT; - ev.mouse_button.pressed = false; - ev.mouse_button.x = mouse_x; - ev.mouse_button.y = mouse_y; + ev->get_button_index() = BUTTON_RIGHT; + ev->is_pressed() = false; + ev->get_pos().x = mouse_x; + ev->get_pos().y = mouse_y; ev.mouse_button.global_x = mouse_x; ev.mouse_button.global_y = mouse_y; - ev.mouse_button.button_mask = button_mask; + ev->get_button_mask() = button_mask; ev.mouse_button.mod = translateFlags([event modifierFlags]); OS_OSX::singleton->push_input(ev); } @@ -387,15 +387,15 @@ static int button_mask = 0; return; button_mask |= BUTTON_MASK_MIDDLE; - InputEvent ev; + Ref<InputEvent> ev; ev.type = InputEvent::MOUSE_BUTTON; - ev.mouse_button.button_index = BUTTON_MIDDLE; - ev.mouse_button.pressed = true; - ev.mouse_button.x = mouse_x; - ev.mouse_button.y = mouse_y; + ev->get_button_index() = BUTTON_MIDDLE; + ev->is_pressed() = true; + ev->get_pos().x = mouse_x; + ev->get_pos().y = mouse_y; ev.mouse_button.global_x = mouse_x; ev.mouse_button.global_y = mouse_y; - ev.mouse_button.button_mask = button_mask; + ev->get_button_mask() = button_mask; ev.mouse_button.mod = translateFlags([event modifierFlags]); OS_OSX::singleton->push_input(ev); } @@ -410,15 +410,15 @@ static int button_mask = 0; return; button_mask &= ~BUTTON_MASK_MIDDLE; - InputEvent ev; + Ref<InputEvent> ev; ev.type = InputEvent::MOUSE_BUTTON; - ev.mouse_button.button_index = BUTTON_MIDDLE; - ev.mouse_button.pressed = false; - ev.mouse_button.x = mouse_x; - ev.mouse_button.y = mouse_y; + ev->get_button_index() = BUTTON_MIDDLE; + ev->is_pressed() = false; + ev->get_pos().x = mouse_x; + ev->get_pos().y = mouse_y; ev.mouse_button.global_x = mouse_x; ev.mouse_button.global_y = mouse_y; - ev.mouse_button.button_mask = button_mask; + ev->get_button_mask() = button_mask; ev.mouse_button.mod = translateFlags([event modifierFlags]); OS_OSX::singleton->push_input(ev); } @@ -610,21 +610,21 @@ static int translateKey(unsigned int key) { } - (void)keyDown:(NSEvent *)event { - InputEvent ev; + Ref<InputEvent> ev; ev.type = InputEvent::KEY; - ev.key.pressed = true; + ev->is_pressed() = true; ev.key.mod = translateFlags([event modifierFlags]); - ev.key.scancode = latin_keyboard_keycode_convert(translateKey([event keyCode])); - ev.key.echo = [event isARepeat]; + ev->get_scancode() = latin_keyboard_keycode_convert(translateKey([event keyCode])); + ev->is_echo() = [event isARepeat]; NSString *characters = [event characters]; NSUInteger i, length = [characters length]; - if (length > 0 && keycode_has_unicode(ev.key.scancode)) { + if (length > 0 && keycode_has_unicode(ev->get_scancode())) { for (i = 0; i < length; i++) { ev.key.unicode = [characters characterAtIndex:i]; OS_OSX::singleton->push_input(ev); - ev.key.scancode = 0; + ev->get_scancode() = 0; } } else { OS_OSX::singleton->push_input(ev); @@ -632,7 +632,7 @@ static int translateKey(unsigned int key) { } - (void)flagsChanged:(NSEvent *)event { - InputEvent ev; + Ref<InputEvent> ev; int key = [event keyCode]; int mod = [event modifierFlags]; @@ -641,64 +641,64 @@ static int translateKey(unsigned int key) { if (key == 0x36 || key == 0x37) { if (mod & NSCommandKeyMask) { mod &= ~NSCommandKeyMask; - ev.key.pressed = true; + ev->is_pressed() = true; } else { - ev.key.pressed = false; + ev->is_pressed() = false; } } else if (key == 0x38 || key == 0x3c) { if (mod & NSShiftKeyMask) { mod &= ~NSShiftKeyMask; - ev.key.pressed = true; + ev->is_pressed() = true; } else { - ev.key.pressed = false; + ev->is_pressed() = false; } } else if (key == 0x3a || key == 0x3d) { if (mod & NSAlternateKeyMask) { mod &= ~NSAlternateKeyMask; - ev.key.pressed = true; + ev->is_pressed() = true; } else { - ev.key.pressed = false; + ev->is_pressed() = false; } } else if (key == 0x3b || key == 0x3e) { if (mod & NSControlKeyMask) { mod &= ~NSControlKeyMask; - ev.key.pressed = true; + ev->is_pressed() = true; } else { - ev.key.pressed = false; + ev->is_pressed() = false; } } else { return; } ev.key.mod = translateFlags(mod); - ev.key.scancode = latin_keyboard_keycode_convert(translateKey(key)); + ev->get_scancode() = latin_keyboard_keycode_convert(translateKey(key)); OS_OSX::singleton->push_input(ev); } - (void)keyUp:(NSEvent *)event { - InputEvent ev; + Ref<InputEvent> ev; ev.type = InputEvent::KEY; - ev.key.pressed = false; + ev->is_pressed() = false; ev.key.mod = translateFlags([event modifierFlags]); - ev.key.scancode = latin_keyboard_keycode_convert(translateKey([event keyCode])); + ev->get_scancode() = latin_keyboard_keycode_convert(translateKey([event keyCode])); OS_OSX::singleton->push_input(ev); } inline void sendScrollEvent(int button, double factor) { - InputEvent ev; - ev.type = InputEvent::MOUSE_BUTTON; - ev.mouse_button.button_index = button; - ev.mouse_button.factor = factor; - ev.mouse_button.pressed = true; - ev.mouse_button.x = mouse_x; - ev.mouse_button.y = mouse_y; + Ref<InputEvent> ev; + ev.type = Ref<InputEvent>::MOUSE_BUTTON; + ev->get_button_index() = button; + ev.mouse_button->get_factor() = factor; + ev->is_pressed() = true; + ev->get_pos().x = mouse_x; + ev->get_pos().y = mouse_y; ev.mouse_button.global_x = mouse_x; ev.mouse_button.global_y = mouse_y; - ev.mouse_button.button_mask = button_mask; + ev->get_button_mask() = button_mask; OS_OSX::singleton->push_input(ev); - ev.mouse_button.pressed = false; + ev->is_pressed() = false; OS_OSX::singleton->push_input(ev); } @@ -1515,9 +1515,9 @@ void OS_OSX::process_events() { autoreleasePool = [[NSAutoreleasePool alloc] init]; } -void OS_OSX::push_input(const InputEvent &p_event) { +void OS_OSX::push_input(const Ref<InputEvent> &p_event) { - InputEvent ev = p_event; + Ref<InputEvent> ev = p_event; input->parse_input_event(ev); } diff --git a/platform/uwp/app.cpp b/platform/uwp/app.cpp index 2946aa1eae..7c8f09b27b 100644 --- a/platform/uwp/app.cpp +++ b/platform/uwp/app.cpp @@ -259,10 +259,10 @@ void App::pointer_event(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Cor int but = _get_button(point); if (_is_touch(point)) { - InputEvent event; + Ref<InputEvent> event; event.type = InputEvent::SCREEN_TOUCH; event.device = 0; - event.screen_touch.pressed = p_pressed; + event.screen_touch->is_pressed() = p_pressed; event.screen_touch.x = pos.X; event.screen_touch.y = pos.Y; event.screen_touch.index = _get_finger(point->PointerId); @@ -276,21 +276,21 @@ void App::pointer_event(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Cor }; // fallthrought of sorts - InputEvent event; + Ref<InputEvent> event; event.type = InputEvent::MOUSE_BUTTON; event.device = 0; - event.mouse_button.pressed = p_pressed; - event.mouse_button.button_index = but; - event.mouse_button.x = pos.X; - event.mouse_button.y = pos.Y; + event->is_pressed() = p_pressed; + event->get_button_index() = but; + event->get_pos().x = pos.X; + event->get_pos().y = pos.Y; event.mouse_button.global_x = pos.X; event.mouse_button.global_y = pos.Y; if (p_is_wheel) { if (point->Properties->MouseWheelDelta > 0) { - event.mouse_button.button_index = point->Properties->IsHorizontalMouseWheel ? BUTTON_WHEEL_RIGHT : BUTTON_WHEEL_UP; + event->get_button_index() = point->Properties->IsHorizontalMouseWheel ? BUTTON_WHEEL_RIGHT : BUTTON_WHEEL_UP; } else if (point->Properties->MouseWheelDelta < 0) { - event.mouse_button.button_index = point->Properties->IsHorizontalMouseWheel ? BUTTON_WHEEL_LEFT : BUTTON_WHEEL_DOWN; + event->get_button_index() = point->Properties->IsHorizontalMouseWheel ? BUTTON_WHEEL_LEFT : BUTTON_WHEEL_DOWN; } } @@ -350,7 +350,7 @@ void App::OnPointerMoved(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Co if (point->IsInContact && _is_touch(point)) { InputEvent event; - event.type = InputEvent::SCREEN_DRAG; + event.type = Ref<InputEvent>::SCREEN_DRAG; event.device = 0; event.screen_drag.x = pos.X; event.screen_drag.y = pos.Y; @@ -369,14 +369,14 @@ void App::OnPointerMoved(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Co return; InputEvent event; - event.type = InputEvent::MOUSE_MOTION; + event.type = Ref<InputEvent>::MOUSE_MOTION; event.device = 0; event.mouse_motion.x = pos.X; event.mouse_motion.y = pos.Y; event.mouse_motion.global_x = pos.X; event.mouse_motion.global_y = pos.Y; - event.mouse_motion.relative_x = pos.X - last_touch_x[31]; - event.mouse_motion.relative_y = pos.Y - last_touch_y[31]; + event->get_relative().x = pos.X - last_touch_x[31]; + event->get_relative().y = pos.Y - last_touch_y[31]; last_mouse_pos = pos; @@ -394,14 +394,14 @@ void App::OnMouseMoved(MouseDevice ^ mouse_device, MouseEventArgs ^ args) { pos.Y = last_mouse_pos.Y + args->MouseDelta.Y; InputEvent event; - event.type = InputEvent::MOUSE_MOTION; + event.type = Ref<InputEvent>::MOUSE_MOTION; event.device = 0; event.mouse_motion.x = pos.X; event.mouse_motion.y = pos.Y; event.mouse_motion.global_x = pos.X; event.mouse_motion.global_y = pos.Y; - event.mouse_motion.relative_x = args->MouseDelta.X; - event.mouse_motion.relative_y = args->MouseDelta.Y; + event->get_relative().x = args->MouseDelta.X; + event->get_relative().y = args->MouseDelta.Y; last_mouse_pos = pos; @@ -420,20 +420,20 @@ void App::key_event(Windows::UI::Core::CoreWindow ^ sender, bool p_pressed, Wind mod.shift = sender->GetAsyncKeyState(VirtualKey::Shift) == CoreVirtualKeyStates::Down; ke.mod_state = mod; - ke.pressed = p_pressed; + ke->is_pressed() = p_pressed; if (key_args != nullptr) { ke.type = OSUWP::KeyEvent::MessageType::KEY_EVENT_MESSAGE; ke.unicode = 0; - ke.scancode = KeyMappingWindows::get_keysym((unsigned int)key_args->VirtualKey); + ke->get_scancode() = KeyMappingWindows::get_keysym((unsigned int)key_args->VirtualKey); ke.echo = (!p_pressed && !key_args->KeyStatus.IsKeyReleased) || (p_pressed && key_args->KeyStatus.WasKeyDown); } else { ke.type = OSUWP::KeyEvent::MessageType::CHAR_EVENT_MESSAGE; ke.unicode = char_args->KeyCode; - ke.scancode = 0; + ke->get_scancode() = 0; ke.echo = (!p_pressed && !char_args->KeyStatus.IsKeyReleased) || (p_pressed && char_args->KeyStatus.WasKeyDown); } diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index c68b2ffa33..47f4b3f3c8 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -330,14 +330,14 @@ String OSUWP::get_clipboard() const { return ""; }; -void OSUWP::input_event(InputEvent &p_event) { +void OSUWP::input_event(Ref<InputEvent> &p_event) { input->parse_input_event(p_event); - if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index > 3) { + if (p_event.type == Ref<InputEvent>::MOUSE_BUTTON && p_event->is_pressed() && p_event->get_button_index() > 3) { //send release for mouse wheel - p_event.mouse_button.pressed = false; + p_event->is_pressed() = false; input->parse_input_event(p_event); } }; @@ -663,14 +663,14 @@ void OSUWP::process_key_events() { for (int i = 0; i < key_event_pos; i++) { KeyEvent &kev = key_event_buffer[i]; - InputEvent iev; + Ref<InputEvent> iev; - iev.type = InputEvent::KEY; + iev.type = Ref<InputEvent>::KEY; iev.key.mod = kev.mod_state; - iev.key.echo = kev.echo; - iev.key.scancode = kev.scancode; + iev->is_echo() = kev.echo; + iev->get_scancode() = kev->get_scancode(); iev.key.unicode = kev.unicode; - iev.key.pressed = kev.pressed; + iev->is_pressed() = kev->is_pressed(); input_event(iev); } diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h index 22602e4564..d2a51aad4c 100644 --- a/platform/uwp/os_uwp.h +++ b/platform/uwp/os_uwp.h @@ -257,7 +257,7 @@ public: virtual bool get_swap_ok_cancel() { return true; } - void input_event(InputEvent &p_event); + void input_event(Ref<InputEvent> &p_event); virtual PowerState get_power_state(); virtual int get_power_seconds_left(); diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 42597f79c8..ba5db05dab 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -215,14 +215,11 @@ bool OS_Windows::can_draw() const { void OS_Windows::_touch_event(bool p_pressed, int p_x, int p_y, int idx) { - InputEvent event; - event.type = InputEvent::SCREEN_TOUCH; - event.screen_touch.index = idx; - - event.screen_touch.pressed = p_pressed; - - event.screen_touch.x = p_x; - event.screen_touch.y = p_y; + Ref<InputEventScreenTouch> event; + event.instance(); + event->set_index(idx); + event->set_pressed(p_pressed); + event->set_pos(Vector2(p_x, p_y)); if (main_loop) { input->parse_input_event(event); @@ -231,12 +228,10 @@ void OS_Windows::_touch_event(bool p_pressed, int p_x, int p_y, int idx) { void OS_Windows::_drag_event(int p_x, int p_y, int idx) { - InputEvent event; - event.type = InputEvent::SCREEN_DRAG; - event.screen_drag.index = idx; - - event.screen_drag.x = p_x; - event.screen_drag.y = p_y; + Ref<InputEventScreenDrag> event; + event.instance(); + event->set_index(idx); + event->set_pos(Vector2(p_x, p_y)); if (main_loop) input->parse_input_event(event); @@ -367,22 +362,23 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) }; */ - InputEvent event; - event.type = InputEvent::MOUSE_MOTION; - InputEventMouseMotion &mm = event.mouse_motion; + Ref<InputEventMouseMotion> mm; + mm.instance(); + + mm->set_control((wParam & MK_CONTROL) != 0); + mm->set_shift((wParam & MK_SHIFT) != 0); + mm->set_alt(alt_mem); - mm.mod.control = (wParam & MK_CONTROL) != 0; - mm.mod.shift = (wParam & MK_SHIFT) != 0; - mm.mod.alt = alt_mem; + int bmask = 0; + bmask |= (wParam & MK_LBUTTON) ? (1 << 0) : 0; + bmask |= (wParam & MK_RBUTTON) ? (1 << 1) : 0; + bmask |= (wParam & MK_MBUTTON) ? (1 << 2) : 0; + mm->set_button_mask(bmask); - mm.button_mask |= (wParam & MK_LBUTTON) ? (1 << 0) : 0; - mm.button_mask |= (wParam & MK_RBUTTON) ? (1 << 1) : 0; - mm.button_mask |= (wParam & MK_MBUTTON) ? (1 << 2) : 0; - last_button_state = mm.button_mask; - /*mm.button_mask|=(wParam&MK_XBUTTON1)?(1<<5):0; - mm.button_mask|=(wParam&MK_XBUTTON2)?(1<<6):0;*/ - mm.x = GET_X_LPARAM(lParam); - mm.y = GET_Y_LPARAM(lParam); + last_button_state = mm->get_button_mask(); + /*mm->get_button_mask()|=(wParam&MK_XBUTTON1)?(1<<5):0; + mm->get_button_mask()|=(wParam&MK_XBUTTON2)?(1<<6):0;*/ + mm->set_pos(Vector2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); if (mouse_mode == MOUSE_MODE_CAPTURED) { @@ -390,35 +386,33 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) old_x = c.x; old_y = c.y; - if (Point2i(mm.x, mm.y) == c) { + if (mm->get_pos() == c) { center = c; return 0; } - Point2i ncenter(mm.x, mm.y); + Point2i ncenter = mm->get_pos(); center = ncenter; POINT pos = { (int)c.x, (int)c.y }; ClientToScreen(hWnd, &pos); SetCursorPos(pos.x, pos.y); } - input->set_mouse_position(Point2(mm.x, mm.y)); - mm.speed_x = input->get_last_mouse_speed().x; - mm.speed_y = input->get_last_mouse_speed().y; + input->set_mouse_position(mm->get_pos()); + mm->set_speed(input->get_last_mouse_speed()); if (old_invalid) { - old_x = mm.x; - old_y = mm.y; + old_x = mm->get_pos().x; + old_y = mm->get_pos().y; old_invalid = false; } - mm.relative_x = mm.x - old_x; - mm.relative_y = mm.y - old_y; - old_x = mm.x; - old_y = mm.y; + mm->set_relative(Vector2(mm->get_pos() - Vector2(old_x, old_y))); + old_x = mm->get_pos().x; + old_y = mm->get_pos().y; if (window_has_focus && main_loop) - input->parse_input_event(event); + input->parse_input_event(mm); } break; case WM_LBUTTONDOWN: @@ -447,114 +441,112 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) }; */ - InputEvent event; - event.type = InputEvent::MOUSE_BUTTON; - InputEventMouseButton &mb = event.mouse_button; + Ref<InputEventMouseButton> mb; + mb.instance(); switch (uMsg) { case WM_LBUTTONDOWN: { - mb.pressed = true; - mb.button_index = 1; + mb->set_pressed(true); + mb->set_button_index(1); } break; case WM_LBUTTONUP: { - mb.pressed = false; - mb.button_index = 1; + mb->set_pressed(false); + mb->set_button_index(1); } break; case WM_MBUTTONDOWN: { - mb.pressed = true; - mb.button_index = 3; + mb->set_pressed(true); + mb->set_button_index(3); } break; case WM_MBUTTONUP: { - mb.pressed = false; - mb.button_index = 3; + mb->set_pressed(false); + mb->set_button_index(3); } break; case WM_RBUTTONDOWN: { - mb.pressed = true; - mb.button_index = 2; + mb->set_pressed(true); + mb->set_button_index(2); } break; case WM_RBUTTONUP: { - mb.pressed = false; - mb.button_index = 2; + mb->set_pressed(false); + mb->set_button_index(2); } break; case WM_LBUTTONDBLCLK: { - mb.pressed = true; - mb.button_index = 1; - mb.doubleclick = true; + mb->set_pressed(true); + mb->set_button_index(1); + mb->set_doubleclick(true); } break; case WM_RBUTTONDBLCLK: { - mb.pressed = true; - mb.button_index = 2; - mb.doubleclick = true; + mb->set_pressed(true); + mb->set_button_index(2); + mb->set_doubleclick(true); } break; case WM_MOUSEWHEEL: { - mb.pressed = true; + mb->set_pressed(true); int motion = (short)HIWORD(wParam); if (!motion) return 0; if (motion > 0) - mb.button_index = BUTTON_WHEEL_UP; + mb->set_button_index(BUTTON_WHEEL_UP); else - mb.button_index = BUTTON_WHEEL_DOWN; + mb->set_button_index(BUTTON_WHEEL_DOWN); } break; case WM_MOUSEHWHEEL: { - mb.pressed = true; + mb->set_pressed(true); int motion = (short)HIWORD(wParam); if (!motion) return 0; if (motion < 0) { - mb.button_index = BUTTON_WHEEL_LEFT; - mb.factor = fabs((double)motion / (double)WHEEL_DELTA); + mb->set_button_index(BUTTON_WHEEL_LEFT); + mb->set_factor(fabs((double)motion / (double)WHEEL_DELTA)); } else { - mb.button_index = BUTTON_WHEEL_RIGHT; - mb.factor = fabs((double)motion / (double)WHEEL_DELTA); + mb->set_button_index(BUTTON_WHEEL_RIGHT); + mb->set_factor(fabs((double)motion / (double)WHEEL_DELTA)); } } break; /* case WM_XBUTTONDOWN: { - mb.pressed=true; - mb.button_index=(HIWORD(wParam)==XBUTTON1)?6:7; + mb->is_pressed()=true; + mb->get_button_index()=(HIWORD(wParam)==XBUTTON1)?6:7; } break; case WM_XBUTTONUP: - mb.pressed=true; - mb.button_index=(HIWORD(wParam)==XBUTTON1)?6:7; + mb->is_pressed()=true; + mb->get_button_index()=(HIWORD(wParam)==XBUTTON1)?6:7; } break;*/ default: { return 0; } } - mb.mod.control = (wParam & MK_CONTROL) != 0; - mb.mod.shift = (wParam & MK_SHIFT) != 0; - mb.mod.alt = alt_mem; - //mb.mod.alt=(wParam&MK_MENU)!=0; - mb.button_mask |= (wParam & MK_LBUTTON) ? (1 << 0) : 0; - mb.button_mask |= (wParam & MK_RBUTTON) ? (1 << 1) : 0; - mb.button_mask |= (wParam & MK_MBUTTON) ? (1 << 2) : 0; - - last_button_state = mb.button_mask; + mb->set_control((wParam & MK_CONTROL) != 0); + mb->set_shift((wParam & MK_SHIFT) != 0); + mb->set_alt(alt_mem); + //mb->get_alt()=(wParam&MK_MENU)!=0; + int bmask = 0; + bmask |= (wParam & MK_LBUTTON) ? (1 << 0) : 0; + bmask |= (wParam & MK_RBUTTON) ? (1 << 1) : 0; + bmask |= (wParam & MK_MBUTTON) ? (1 << 2) : 0; + mb->set_button_mask(bmask); + + last_button_state = mb->get_button_mask(); /* - mb.button_mask|=(wParam&MK_XBUTTON1)?(1<<5):0; - mb.button_mask|=(wParam&MK_XBUTTON2)?(1<<6):0;*/ - mb.x = GET_X_LPARAM(lParam); - mb.y = GET_Y_LPARAM(lParam); + mb->get_button_mask()|=(wParam&MK_XBUTTON1)?(1<<5):0; + mb->get_button_mask()|=(wParam&MK_XBUTTON2)?(1<<6):0;*/ + mb->set_pos(Vector2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); if (mouse_mode == MOUSE_MODE_CAPTURED) { - mb.x = old_x; - mb.y = old_y; + mb->set_pos(Vector2(old_x, old_y)); } - mb.global_x = mb.x; - mb.global_y = mb.y; + mb->set_global_pos(mb->get_pos()); if (uMsg != WM_MOUSEWHEEL) { - if (mb.pressed) { + if (mb->is_pressed()) { if (++pressrc > 0) SetCapture(hWnd); @@ -568,21 +560,21 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) } else if (mouse_mode != MOUSE_MODE_CAPTURED) { // for reasons unknown to mankind, wheel comes in screen cordinates POINT coords; - coords.x = mb.x; - coords.y = mb.y; + coords.x = mb->get_pos().x; + coords.y = mb->get_pos().y; ScreenToClient(hWnd, &coords); - mb.x = coords.x; - mb.y = coords.y; + mb->set_pos(coords); } if (main_loop) { - input->parse_input_event(event); - if (mb.pressed && mb.button_index > 3) { + input->parse_input_event(mb); + if (mb->is_pressed() && mb->get_button_index() > 3) { //send release for mouse wheel - mb.pressed = false; - input->parse_input_event(event); + Ref<InputEventMouseButton> mbd = mb->duplicate(); + mbd->set_pressed(false); + input->parse_input_event(mbd); } } } @@ -638,10 +630,10 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) // Make sure we don't include modifiers for the modifier key itself. KeyEvent ke; - ke.mod_state.shift = (wParam != VK_SHIFT) ? shift_mem : false; - ke.mod_state.alt = (!(wParam == VK_MENU && (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN))) ? alt_mem : false; - ke.mod_state.control = (wParam != VK_CONTROL) ? control_mem : false; - ke.mod_state.meta = meta_mem; + ke.shift = (wParam != VK_SHIFT) ? shift_mem : false; + ke.alt = (!(wParam == VK_MENU && (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN))) ? alt_mem : false; + ke.control = (wParam != VK_CONTROL) ? control_mem : false; + ke.meta = meta_mem; ke.uMsg = uMsg; if (ke.uMsg == WM_SYSKEYDOWN) @@ -777,23 +769,25 @@ void OS_Windows::process_key_events() { case WM_CHAR: { if ((i == 0 && ke.uMsg == WM_CHAR) || (i > 0 && key_event_buffer[i - 1].uMsg == WM_CHAR)) { - InputEvent event; - event.type = InputEvent::KEY; - InputEventKey &k = event.key; - - k.mod = ke.mod_state; - k.pressed = true; - k.scancode = KeyMappingWindows::get_keysym(ke.wParam); - k.unicode = ke.wParam; - if (k.unicode && gr_mem) { - k.mod.alt = false; - k.mod.control = false; + Ref<InputEventKey> k; + k.instance(); + + k->set_shift(ke.shift); + k->set_alt(ke.alt); + k->set_control(ke.control); + k->set_metakey(ke.meta); + k->set_pressed(true); + k->set_scancode(KeyMappingWindows::get_keysym(ke.wParam)); + k->set_unicode(ke.wParam); + if (k->get_unicode() && gr_mem) { + k->set_alt(false); + k->set_control(false); } - if (k.unicode < 32) - k.unicode = 0; + if (k->get_unicode() < 32) + k->set_unicode(0); - input->parse_input_event(event); + input->parse_input_event(k); } //do nothing @@ -801,27 +795,32 @@ void OS_Windows::process_key_events() { case WM_KEYUP: case WM_KEYDOWN: { - InputEvent event; - event.type = InputEvent::KEY; - InputEventKey &k = event.key; + Ref<InputEventKey> k; + k.instance(); + + k->set_shift(ke.shift); + k->set_alt(ke.alt); + k->set_control(ke.control); + k->set_metakey(ke.meta); - k.mod = ke.mod_state; - k.pressed = (ke.uMsg == WM_KEYDOWN); + k->set_pressed(ke.uMsg == WM_KEYDOWN); - k.scancode = KeyMappingWindows::get_keysym(ke.wParam); - if (i + 1 < key_event_pos && key_event_buffer[i + 1].uMsg == WM_CHAR) - k.unicode = key_event_buffer[i + 1].wParam; - if (k.unicode && gr_mem) { - k.mod.alt = false; - k.mod.control = false; + k->set_scancode(KeyMappingWindows::get_keysym(ke.wParam)); + + if (i + 1 < key_event_pos && key_event_buffer[i + 1].uMsg == WM_CHAR) { + k->set_unicode(key_event_buffer[i + 1].wParam); + } + if (k->get_unicode() && gr_mem) { + k->set_alt(false); + k->set_control(false); } - if (k.unicode < 32) - k.unicode = 0; + if (k->get_unicode() < 32) + k->set_unicode(0); - k.echo = (ke.uMsg == WM_KEYDOWN && (ke.lParam & (1 << 30))); + k->set_echo((ke.uMsg == WM_KEYDOWN && (ke.lParam & (1 << 30)))); - input->parse_input_event(event); + input->parse_input_event(k); } break; } diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 4dd05928df..bd5acde417 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -69,6 +69,7 @@ class OS_Windows : public OS { struct KeyEvent { InputModifierState mod_state; + bool alt, shift, ctrl, meta; UINT uMsg; WPARAM wParam; LPARAM lParam; diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 59ac1fed96..8534185389 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -958,16 +958,12 @@ void OS_X11::request_attention() { XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); } -InputModifierState OS_X11::get_key_modifier_state(unsigned int p_x11_state) { +void OS_X11::get_key_modifier_state(unsigned int p_x11_state, Ref<InputEventWithModifiers> state) { - InputModifierState state; - - state.shift = (p_x11_state & ShiftMask); - state.control = (p_x11_state & ControlMask); - state.alt = (p_x11_state & Mod1Mask /*|| p_x11_state&Mod5Mask*/); //altgr should not count as alt - state.meta = (p_x11_state & Mod4Mask); - - return state; + state->set_shift((p_x11_state & ShiftMask)); + state->set_control((p_x11_state & ControlMask)); + state->set_alt((p_x11_state & Mod1Mask /*|| p_x11_state&Mod5Mask*/)); //altgr should not count as alt + state->set_metakey((p_x11_state & Mod4Mask)); } unsigned int OS_X11::get_mouse_button_state(unsigned int p_x11_state) { @@ -1099,7 +1095,10 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { //print_line("mod1: "+itos(xkeyevent->state&Mod1Mask)+" mod 5: "+itos(xkeyevent->state&Mod5Mask)); - InputModifierState state = get_key_modifier_state(xkeyevent->state); + Ref<InputEventKey> k; + k.instance(); + + get_key_modifier_state(xkeyevent->state, k); /* Phase 6, determine echo character */ @@ -1142,40 +1141,36 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { /* Phase 7, send event to Window */ - InputEvent event; - event.type = InputEvent::KEY; - event.device = 0; - event.key.mod = state; - event.key.pressed = keypress; + k->set_pressed(keypress); if (keycode >= 'a' && keycode <= 'z') keycode -= 'a' - 'A'; - event.key.scancode = keycode; - event.key.unicode = unicode; - event.key.echo = p_echo; + k->set_scancode(keycode); + k->set_unicode(unicode); + k->set_echo(p_echo); - if (event.key.scancode == KEY_BACKTAB) { + if (k->get_scancode() == KEY_BACKTAB) { //make it consistent across platforms. - event.key.scancode = KEY_TAB; - event.key.mod.shift = true; + k->set_scancode(KEY_TAB); + k->set_shift(true); } //don't set mod state if modifier keys are released by themselves //else event.is_action() will not work correctly here - if (!event.key.pressed) { - if (event.key.scancode == KEY_SHIFT) - event.key.mod.shift = false; - else if (event.key.scancode == KEY_CONTROL) - event.key.mod.control = false; - else if (event.key.scancode == KEY_ALT) - event.key.mod.alt = false; - else if (event.key.scancode == KEY_META) - event.key.mod.meta = false; + if (!k->is_pressed()) { + if (k->get_scancode() == KEY_SHIFT) + k->set_shift(false); + else if (k->get_scancode() == KEY_CONTROL) + k->set_control(false); + else if (k->get_scancode() == KEY_ALT) + k->set_alt(false); + else if (k->get_scancode() == KEY_META) + k->set_metakey(false); } - //printf("key: %x\n",event.key.scancode); - input->parse_input_event(event); + //printf("key: %x\n",k->get_scancode()); + input->parse_input_event(k); } struct Property { @@ -1332,22 +1327,20 @@ void OS_X11::process_xevents() { event.xbutton.y = last_mouse_pos.y; } - InputEvent mouse_event; - mouse_event.type = InputEvent::MOUSE_BUTTON; - mouse_event.device = 0; - mouse_event.mouse_button.mod = get_key_modifier_state(event.xbutton.state); - mouse_event.mouse_button.button_mask = get_mouse_button_state(event.xbutton.state); - mouse_event.mouse_button.x = event.xbutton.x; - mouse_event.mouse_button.y = event.xbutton.y; - mouse_event.mouse_button.global_x = event.xbutton.x; - mouse_event.mouse_button.global_y = event.xbutton.y; - mouse_event.mouse_button.button_index = event.xbutton.button; - if (mouse_event.mouse_button.button_index == 2) - mouse_event.mouse_button.button_index = 3; - else if (mouse_event.mouse_button.button_index == 3) - mouse_event.mouse_button.button_index = 2; - - mouse_event.mouse_button.pressed = (event.type == ButtonPress); + Ref<InputEventMouseButton> mb; + mb.instance(); + + get_key_modifier_state(event.xbutton.state, mb); + mb->set_button_mask(get_mouse_button_state(event.xbutton.state)); + mb->set_pos(Vector2(event.xbutton.x, event.xbutton.y)); + mb->set_global_pos(mb->get_pos()); + mb->set_button_index(event.xbutton.button); + if (mb->get_button_index() == 2) + mb->set_button_index(3); + else if (mb->get_button_index() == 3) + mb->set_button_index(2); + + mb->set_pressed((event.type == ButtonPress)); if (event.type == ButtonPress && event.xbutton.button == 1) { @@ -1357,7 +1350,7 @@ void OS_X11::process_xevents() { last_click_ms = 0; last_click_pos = Point2(-100, -100); - mouse_event.mouse_button.doubleclick = true; + mb->set_doubleclick(true); } else { last_click_ms += diff; @@ -1365,7 +1358,7 @@ void OS_X11::process_xevents() { } } - input->parse_input_event(mouse_event); + input->parse_input_event(mb); } break; case MotionNotify: { @@ -1443,22 +1436,16 @@ void OS_X11::process_xevents() { Point2i rel = pos - last_mouse_pos; - InputEvent motion_event; - motion_event.type = InputEvent::MOUSE_MOTION; - motion_event.device = 0; + Ref<InputEventMouseMotion> mm; + mm.instance(); - motion_event.mouse_motion.mod = get_key_modifier_state(event.xmotion.state); - motion_event.mouse_motion.button_mask = get_mouse_button_state(event.xmotion.state); - motion_event.mouse_motion.x = pos.x; - motion_event.mouse_motion.y = pos.y; + get_key_modifier_state(event.xmotion.state, mm); + mm->set_button_mask(get_mouse_button_state(event.xmotion.state)); + mm->set_pos(pos); + mm->set_global_pos(pos); input->set_mouse_position(pos); - motion_event.mouse_motion.global_x = pos.x; - motion_event.mouse_motion.global_y = pos.y; - motion_event.mouse_motion.speed_x = input->get_last_mouse_speed().x; - motion_event.mouse_motion.speed_y = input->get_last_mouse_speed().y; - - motion_event.mouse_motion.relative_x = rel.x; - motion_event.mouse_motion.relative_y = rel.y; + mm->set_speed(input->get_last_mouse_speed()); + mm->set_relative(rel); last_mouse_pos = pos; @@ -1467,7 +1454,7 @@ void OS_X11::process_xevents() { // this is so that the relative motion doesn't get messed up // after we regain focus. if (window_has_focus || !mouse_mode_grab) - input->parse_input_event(motion_event); + input->parse_input_event(mm); } break; case KeyPress: diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 7f01f9c617..d62186e5bd 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -121,7 +121,7 @@ class OS_X11 : public OS_Unix { PhysicsServer *physics_server; unsigned int get_mouse_button_state(unsigned int p_x11_state); - InputModifierState get_key_modifier_state(unsigned int p_x11_state); + void get_key_modifier_state(unsigned int p_x11_state, Ref<InputEventWithModifiers> state); Physics2DServer *physics_2d_server; MouseMode mouse_mode; |