From fdf58a585839804c89798392dd93025dbe8654e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Tue, 28 Apr 2020 15:19:37 +0200 Subject: Rename InputFilter back to Input It changed name as part of the DisplayServer and input refactoring in #37317, with the rationale that input no longer goes through the main loop, so the previous Input singleton now only does filtering. But the gains in consistency are quite limited in the renaming, and it breaks compatibility for all scripts and tutorials that access the Input singleton via the scripting language. A temporary option was suggested to keep the scripting singleton named `Input` even if its type is `InputFilter`, but that adds inconsistency and breaks C#. Fixes godotengine/godot-proposals#639. Fixes #37319. Fixes #37690. --- core/debugger/remote_debugger.cpp | 12 +- core/input/input.cpp | 1309 ++++++++++++++++++++ core/input/input.h | 337 +++++ core/input/input_filter.cpp | 1309 -------------------- core/input/input_filter.h | 337 ----- core/os/midi_driver.cpp | 4 +- core/os/os.cpp | 2 +- core/register_core_types.cpp | 6 +- doc/classes/@GlobalScope.xml | 4 +- doc/classes/Input.xml | 477 +++++++ doc/classes/InputFilter.xml | 477 ------- editor/animation_track_editor.cpp | 4 +- editor/code_editor.cpp | 6 +- editor/editor_audio_buses.cpp | 6 +- editor/editor_help.cpp | 4 +- editor/editor_node.cpp | 12 +- editor/editor_spin_slider.cpp | 16 +- editor/export_template_manager.cpp | 4 +- editor/plugins/animation_blend_space_2d_editor.cpp | 2 +- .../plugins/animation_blend_tree_editor_plugin.cpp | 2 +- editor/plugins/animation_player_editor_plugin.cpp | 4 +- editor/plugins/animation_state_machine_editor.cpp | 2 +- editor/plugins/animation_tree_editor_plugin.cpp | 2 +- editor/plugins/asset_library_editor_plugin.cpp | 2 +- editor/plugins/canvas_item_editor_plugin.cpp | 28 +- .../plugins/collision_polygon_3d_editor_plugin.cpp | 4 +- editor/plugins/curve_editor_plugin.cpp | 4 +- editor/plugins/node_3d_editor_plugin.cpp | 24 +- editor/plugins/polygon_2d_editor_plugin.cpp | 4 +- editor/plugins/script_editor_plugin.cpp | 4 +- editor/plugins/texture_region_editor_plugin.cpp | 6 +- editor/plugins/tile_map_editor_plugin.cpp | 6 +- editor/plugins/tile_set_editor_plugin.cpp | 6 +- editor/plugins/visual_shader_editor_plugin.cpp | 6 +- editor/property_editor.cpp | 4 +- editor/scene_tree_dock.cpp | 6 +- main/main.cpp | 10 +- modules/arkit/arkit_interface.mm | 2 +- modules/gdnative/xr/xr_interface_gdnative.cpp | 12 +- modules/gridmap/grid_map_editor_plugin.cpp | 2 +- modules/mobile_vr/mobile_vr_interface.cpp | 5 +- modules/visual_script/visual_script_editor.cpp | 28 +- .../visual_script/visual_script_flow_control.cpp | 2 +- modules/visual_script/visual_script_nodes.cpp | 10 +- platform/android/display_server_android.cpp | 38 +- platform/android/java_godot_lib_jni.cpp | 12 +- platform/android/os_android.cpp | 2 +- platform/haiku/haiku_direct_window.h | 2 +- platform/haiku/os_haiku.h | 2 +- platform/iphone/os_iphone.h | 2 +- platform/javascript/os_javascript.h | 2 +- platform/linuxbsd/display_server_x11.cpp | 32 +- platform/linuxbsd/display_server_x11.h | 2 +- platform/linuxbsd/joypad_linux.cpp | 22 +- platform/linuxbsd/joypad_linux.h | 10 +- platform/linuxbsd/os_linuxbsd.cpp | 2 +- platform/linuxbsd/os_linuxbsd.h | 2 +- platform/osx/display_server_osx.h | 2 +- platform/osx/display_server_osx.mm | 32 +- platform/osx/joypad_osx.cpp | 26 +- platform/osx/joypad_osx.h | 6 +- platform/osx/os_osx.h | 2 +- platform/osx/os_osx.mm | 2 +- platform/server/os_server.h | 2 +- platform/uwp/joypad_uwp.h | 2 +- platform/uwp/os_uwp.h | 2 +- platform/windows/display_server_windows.cpp | 44 +- platform/windows/display_server_windows.h | 2 +- platform/windows/joypad_windows.cpp | 24 +- platform/windows/joypad_windows.h | 4 +- platform/windows/os_windows.h | 2 +- scene/2d/touch_screen_button.cpp | 6 +- scene/3d/xr_nodes.cpp | 8 +- scene/gui/color_picker.cpp | 2 +- scene/gui/graph_edit.cpp | 20 +- scene/gui/popup_menu.cpp | 4 +- scene/gui/spin_box.cpp | 8 +- scene/gui/text_edit.cpp | 4 +- scene/gui/tree.cpp | 18 +- scene/main/canvas_item.cpp | 2 +- scene/main/scene_tree.cpp | 4 +- scene/main/viewport.cpp | 12 +- servers/display_server.cpp | 26 +- servers/display_server.h | 10 +- servers/xr/xr_positional_tracker.cpp | 3 +- 85 files changed, 2462 insertions(+), 2460 deletions(-) create mode 100644 core/input/input.cpp create mode 100644 core/input/input.h delete mode 100644 core/input/input_filter.cpp delete mode 100644 core/input/input_filter.h create mode 100644 doc/classes/Input.xml delete mode 100644 doc/classes/InputFilter.xml diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp index e6bcc5f77e..fd109c62b6 100644 --- a/core/debugger/remote_debugger.cpp +++ b/core/debugger/remote_debugger.cpp @@ -33,7 +33,7 @@ #include "core/debugger/debugger_marshalls.h" #include "core/debugger/engine_debugger.h" #include "core/debugger/script_debugger.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/os.h" #include "core/project_settings.h" #include "core/script_language.h" @@ -659,9 +659,9 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { servers_profiler->skip_profile_frame = true; // Avoid frame time spike in debug. - InputFilter::MouseMode mouse_mode = InputFilter::get_singleton()->get_mouse_mode(); - if (mouse_mode != InputFilter::MOUSE_MODE_VISIBLE) - InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_VISIBLE); + Input::MouseMode mouse_mode = Input::get_singleton()->get_mouse_mode(); + if (mouse_mode != Input::MOUSE_MODE_VISIBLE) + Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); uint64_t loop_begin_usec = 0; uint64_t loop_time_sec = 0; @@ -779,8 +779,8 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { send_message("debug_exit", Array()); - if (mouse_mode != InputFilter::MOUSE_MODE_VISIBLE) - InputFilter::get_singleton()->set_mouse_mode(mouse_mode); + if (mouse_mode != Input::MOUSE_MODE_VISIBLE) + Input::get_singleton()->set_mouse_mode(mouse_mode); } void RemoteDebugger::poll_events(bool p_is_idle) { diff --git a/core/input/input.cpp b/core/input/input.cpp new file mode 100644 index 0000000000..5301f5f4ee --- /dev/null +++ b/core/input/input.cpp @@ -0,0 +1,1309 @@ +/*************************************************************************/ +/* input.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "input.h" + +#include "core/input/default_controller_mappings.h" +#include "core/input/input_map.h" +#include "core/os/os.h" +#include "core/project_settings.h" + +#ifdef TOOLS_ENABLED +#include "editor/editor_settings.h" +#endif + +Input *Input::singleton = nullptr; + +void (*Input::set_mouse_mode_func)(Input::MouseMode) = nullptr; +Input::MouseMode (*Input::get_mouse_mode_func)() = nullptr; +void (*Input::warp_mouse_func)(const Vector2 &p_to_pos) = nullptr; +Input::CursorShape (*Input::get_current_cursor_shape_func)() = nullptr; +void (*Input::set_custom_mouse_cursor_func)(const RES &, Input::CursorShape, const Vector2 &) = nullptr; + +Input *Input::get_singleton() { + + return singleton; +} + +void Input::set_mouse_mode(MouseMode p_mode) { + ERR_FAIL_INDEX((int)p_mode, 4); + set_mouse_mode_func(p_mode); +} + +Input::MouseMode Input::get_mouse_mode() const { + + return get_mouse_mode_func(); +} + +void Input::_bind_methods() { + + ClassDB::bind_method(D_METHOD("is_key_pressed", "keycode"), &Input::is_key_pressed); + ClassDB::bind_method(D_METHOD("is_mouse_button_pressed", "button"), &Input::is_mouse_button_pressed); + ClassDB::bind_method(D_METHOD("is_joy_button_pressed", "device", "button"), &Input::is_joy_button_pressed); + ClassDB::bind_method(D_METHOD("is_action_pressed", "action"), &Input::is_action_pressed); + ClassDB::bind_method(D_METHOD("is_action_just_pressed", "action"), &Input::is_action_just_pressed); + ClassDB::bind_method(D_METHOD("is_action_just_released", "action"), &Input::is_action_just_released); + ClassDB::bind_method(D_METHOD("get_action_strength", "action"), &Input::get_action_strength); + ClassDB::bind_method(D_METHOD("add_joy_mapping", "mapping", "update_existing"), &Input::add_joy_mapping, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("remove_joy_mapping", "guid"), &Input::remove_joy_mapping); + ClassDB::bind_method(D_METHOD("joy_connection_changed", "device", "connected", "name", "guid"), &Input::joy_connection_changed); + ClassDB::bind_method(D_METHOD("is_joy_known", "device"), &Input::is_joy_known); + ClassDB::bind_method(D_METHOD("get_joy_axis", "device", "axis"), &Input::get_joy_axis); + ClassDB::bind_method(D_METHOD("get_joy_name", "device"), &Input::get_joy_name); + ClassDB::bind_method(D_METHOD("get_joy_guid", "device"), &Input::get_joy_guid); + ClassDB::bind_method(D_METHOD("get_connected_joypads"), &Input::get_connected_joypads); + ClassDB::bind_method(D_METHOD("get_joy_vibration_strength", "device"), &Input::get_joy_vibration_strength); + ClassDB::bind_method(D_METHOD("get_joy_vibration_duration", "device"), &Input::get_joy_vibration_duration); + ClassDB::bind_method(D_METHOD("get_joy_button_string", "button_index"), &Input::get_joy_button_string); + ClassDB::bind_method(D_METHOD("get_joy_button_index_from_string", "button"), &Input::get_joy_button_index_from_string); + ClassDB::bind_method(D_METHOD("get_joy_axis_string", "axis_index"), &Input::get_joy_axis_string); + ClassDB::bind_method(D_METHOD("get_joy_axis_index_from_string", "axis"), &Input::get_joy_axis_index_from_string); + ClassDB::bind_method(D_METHOD("start_joy_vibration", "device", "weak_magnitude", "strong_magnitude", "duration"), &Input::start_joy_vibration, DEFVAL(0)); + ClassDB::bind_method(D_METHOD("stop_joy_vibration", "device"), &Input::stop_joy_vibration); + ClassDB::bind_method(D_METHOD("vibrate_handheld", "duration_ms"), &Input::vibrate_handheld, DEFVAL(500)); + ClassDB::bind_method(D_METHOD("get_gravity"), &Input::get_gravity); + ClassDB::bind_method(D_METHOD("get_accelerometer"), &Input::get_accelerometer); + ClassDB::bind_method(D_METHOD("get_magnetometer"), &Input::get_magnetometer); + ClassDB::bind_method(D_METHOD("get_gyroscope"), &Input::get_gyroscope); + ClassDB::bind_method(D_METHOD("get_last_mouse_speed"), &Input::get_last_mouse_speed); + ClassDB::bind_method(D_METHOD("get_mouse_button_mask"), &Input::get_mouse_button_mask); + ClassDB::bind_method(D_METHOD("set_mouse_mode", "mode"), &Input::set_mouse_mode); + ClassDB::bind_method(D_METHOD("get_mouse_mode"), &Input::get_mouse_mode); + ClassDB::bind_method(D_METHOD("warp_mouse_position", "to"), &Input::warp_mouse_position); + ClassDB::bind_method(D_METHOD("action_press", "action", "strength"), &Input::action_press, DEFVAL(1.f)); + ClassDB::bind_method(D_METHOD("action_release", "action"), &Input::action_release); + ClassDB::bind_method(D_METHOD("set_default_cursor_shape", "shape"), &Input::set_default_cursor_shape, DEFVAL(CURSOR_ARROW)); + ClassDB::bind_method(D_METHOD("get_current_cursor_shape"), &Input::get_current_cursor_shape); + ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor", "image", "shape", "hotspot"), &Input::set_custom_mouse_cursor, DEFVAL(CURSOR_ARROW), DEFVAL(Vector2())); + ClassDB::bind_method(D_METHOD("parse_input_event", "event"), &Input::parse_input_event); + ClassDB::bind_method(D_METHOD("set_use_accumulated_input", "enable"), &Input::set_use_accumulated_input); + + BIND_ENUM_CONSTANT(MOUSE_MODE_VISIBLE); + BIND_ENUM_CONSTANT(MOUSE_MODE_HIDDEN); + BIND_ENUM_CONSTANT(MOUSE_MODE_CAPTURED); + BIND_ENUM_CONSTANT(MOUSE_MODE_CONFINED); + + BIND_ENUM_CONSTANT(CURSOR_ARROW); + BIND_ENUM_CONSTANT(CURSOR_IBEAM); + BIND_ENUM_CONSTANT(CURSOR_POINTING_HAND); + BIND_ENUM_CONSTANT(CURSOR_CROSS); + BIND_ENUM_CONSTANT(CURSOR_WAIT); + BIND_ENUM_CONSTANT(CURSOR_BUSY); + BIND_ENUM_CONSTANT(CURSOR_DRAG); + BIND_ENUM_CONSTANT(CURSOR_CAN_DROP); + BIND_ENUM_CONSTANT(CURSOR_FORBIDDEN); + BIND_ENUM_CONSTANT(CURSOR_VSIZE); + BIND_ENUM_CONSTANT(CURSOR_HSIZE); + BIND_ENUM_CONSTANT(CURSOR_BDIAGSIZE); + BIND_ENUM_CONSTANT(CURSOR_FDIAGSIZE); + BIND_ENUM_CONSTANT(CURSOR_MOVE); + BIND_ENUM_CONSTANT(CURSOR_VSPLIT); + BIND_ENUM_CONSTANT(CURSOR_HSPLIT); + BIND_ENUM_CONSTANT(CURSOR_HELP); + + ADD_SIGNAL(MethodInfo("joy_connection_changed", PropertyInfo(Variant::INT, "device"), PropertyInfo(Variant::BOOL, "connected"))); +} + +void Input::get_argument_options(const StringName &p_function, int p_idx, List *r_options) const { +#ifdef TOOLS_ENABLED + + const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\""; + + String pf = p_function; + if (p_idx == 0 && (pf == "is_action_pressed" || pf == "action_press" || pf == "action_release" || pf == "is_action_just_pressed" || pf == "is_action_just_released" || pf == "get_action_strength")) { + + List pinfo; + ProjectSettings::get_singleton()->get_property_list(&pinfo); + + for (List::Element *E = pinfo.front(); E; E = E->next()) { + const PropertyInfo &pi = E->get(); + + if (!pi.name.begins_with("input/")) + continue; + + String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length()); + r_options->push_back(quote_style + name + quote_style); + } + } +#endif +} + +void Input::SpeedTrack::update(const Vector2 &p_delta_p) { + + uint64_t tick = OS::get_singleton()->get_ticks_usec(); + uint32_t tdiff = tick - last_tick; + float delta_t = tdiff / 1000000.0; + last_tick = tick; + + accum += p_delta_p; + accum_t += delta_t; + + if (accum_t > max_ref_frame * 10) + accum_t = max_ref_frame * 10; + + while (accum_t >= min_ref_frame) { + + float slice_t = min_ref_frame / accum_t; + Vector2 slice = accum * slice_t; + accum = accum - slice; + accum_t -= min_ref_frame; + + speed = (slice / min_ref_frame).linear_interpolate(speed, min_ref_frame / max_ref_frame); + } +} + +void Input::SpeedTrack::reset() { + last_tick = OS::get_singleton()->get_ticks_usec(); + speed = Vector2(); + accum_t = 0; +} + +Input::SpeedTrack::SpeedTrack() { + + min_ref_frame = 0.1; + max_ref_frame = 0.3; + reset(); +} + +bool Input::is_key_pressed(int p_keycode) const { + + _THREAD_SAFE_METHOD_ + return keys_pressed.has(p_keycode); +} + +bool Input::is_mouse_button_pressed(int p_button) const { + + _THREAD_SAFE_METHOD_ + return (mouse_button_mask & (1 << (p_button - 1))) != 0; +} + +static int _combine_device(int p_value, int p_device) { + + return p_value | (p_device << 20); +} + +bool Input::is_joy_button_pressed(int p_device, int p_button) const { + + _THREAD_SAFE_METHOD_ + return joy_buttons_pressed.has(_combine_device(p_button, p_device)); +} + +bool Input::is_action_pressed(const StringName &p_action) const { + + return action_state.has(p_action) && action_state[p_action].pressed; +} + +bool Input::is_action_just_pressed(const StringName &p_action) const { + + const Map::Element *E = action_state.find(p_action); + if (!E) + return false; + + if (Engine::get_singleton()->is_in_physics_frame()) { + return E->get().pressed && E->get().physics_frame == Engine::get_singleton()->get_physics_frames(); + } else { + return E->get().pressed && E->get().idle_frame == Engine::get_singleton()->get_idle_frames(); + } +} + +bool Input::is_action_just_released(const StringName &p_action) const { + + const Map::Element *E = action_state.find(p_action); + if (!E) + return false; + + if (Engine::get_singleton()->is_in_physics_frame()) { + return !E->get().pressed && E->get().physics_frame == Engine::get_singleton()->get_physics_frames(); + } else { + return !E->get().pressed && E->get().idle_frame == Engine::get_singleton()->get_idle_frames(); + } +} + +float Input::get_action_strength(const StringName &p_action) const { + const Map::Element *E = action_state.find(p_action); + if (!E) + return 0.0f; + + return E->get().strength; +} + +float Input::get_joy_axis(int p_device, int p_axis) const { + + _THREAD_SAFE_METHOD_ + int c = _combine_device(p_axis, p_device); + if (_joy_axis.has(c)) { + return _joy_axis[c]; + } else { + return 0; + } +} + +String Input::get_joy_name(int p_idx) { + + _THREAD_SAFE_METHOD_ + return joy_names[p_idx].name; +}; + +Vector2 Input::get_joy_vibration_strength(int p_device) { + if (joy_vibration.has(p_device)) { + return Vector2(joy_vibration[p_device].weak_magnitude, joy_vibration[p_device].strong_magnitude); + } else { + return Vector2(0, 0); + } +} + +uint64_t Input::get_joy_vibration_timestamp(int p_device) { + if (joy_vibration.has(p_device)) { + return joy_vibration[p_device].timestamp; + } else { + return 0; + } +} + +float Input::get_joy_vibration_duration(int p_device) { + if (joy_vibration.has(p_device)) { + return joy_vibration[p_device].duration; + } else { + return 0.f; + } +} + +static String _hex_str(uint8_t p_byte) { + + static const char *dict = "0123456789abcdef"; + char ret[3]; + ret[2] = 0; + + ret[0] = dict[p_byte >> 4]; + ret[1] = dict[p_byte & 0xf]; + + return ret; +}; + +void Input::joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid) { + + _THREAD_SAFE_METHOD_ + Joypad js; + js.name = p_connected ? p_name : ""; + js.uid = p_connected ? p_guid : ""; + + if (p_connected) { + + String uidname = p_guid; + if (p_guid == "") { + int uidlen = MIN(p_name.length(), 16); + for (int i = 0; i < uidlen; i++) { + uidname = uidname + _hex_str(p_name[i]); + }; + }; + js.uid = uidname; + js.connected = true; + int mapping = fallback_mapping; + for (int i = 0; i < map_db.size(); i++) { + if (js.uid == map_db[i].uid) { + mapping = i; + js.name = map_db[i].name; + }; + }; + js.mapping = mapping; + } else { + js.connected = false; + for (int i = 0; i < JOY_BUTTON_MAX; i++) { + + if (i < JOY_AXIS_MAX) + set_joy_axis(p_idx, i, 0.0f); + + int c = _combine_device(i, p_idx); + joy_buttons_pressed.erase(c); + }; + }; + joy_names[p_idx] = js; + + emit_signal("joy_connection_changed", p_idx, p_connected); +}; + +Vector3 Input::get_gravity() const { + + _THREAD_SAFE_METHOD_ + return gravity; +} + +Vector3 Input::get_accelerometer() const { + + _THREAD_SAFE_METHOD_ + return accelerometer; +} + +Vector3 Input::get_magnetometer() const { + + _THREAD_SAFE_METHOD_ + return magnetometer; +} + +Vector3 Input::get_gyroscope() const { + + _THREAD_SAFE_METHOD_ + return gyroscope; +} + +void Input::parse_input_event(const Ref &p_event) { + + _parse_input_event_impl(p_event, false); +} + +void Input::_parse_input_event_impl(const Ref &p_event, bool p_is_emulated) { + + // Notes on mouse-touch emulation: + // - Emulated mouse events are parsed, that is, re-routed to this method, so they make the same effects + // as true mouse events. The only difference is the situation is flagged as emulated so they are not + // emulated back to touch events in an endless loop. + // - Emulated touch events are handed right to the main loop (i.e., the SceneTree) because they don't + // require additional handling by this class. + + _THREAD_SAFE_METHOD_ + + Ref k = p_event; + if (k.is_valid() && !k->is_echo() && k->get_keycode() != 0) { + if (k->is_pressed()) + keys_pressed.insert(k->get_keycode()); + else + keys_pressed.erase(k->get_keycode()); + } + + Ref mb = p_event; + + if (mb.is_valid()) { + + if (mb->is_pressed()) { + mouse_button_mask |= (1 << (mb->get_button_index() - 1)); + } else { + mouse_button_mask &= ~(1 << (mb->get_button_index() - 1)); + } + + Point2 pos = mb->get_global_position(); + if (mouse_pos != pos) { + set_mouse_position(pos); + } + + if (event_dispatch_function && emulate_touch_from_mouse && !p_is_emulated && mb->get_button_index() == 1) { + Ref touch_event; + touch_event.instance(); + touch_event->set_pressed(mb->is_pressed()); + touch_event->set_position(mb->get_position()); + event_dispatch_function(touch_event); + } + } + + Ref mm = p_event; + + if (mm.is_valid()) { + + Point2 pos = mm->get_global_position(); + if (mouse_pos != pos) { + set_mouse_position(pos); + } + + if (event_dispatch_function && emulate_touch_from_mouse && !p_is_emulated && mm->get_button_mask() & 1) { + Ref drag_event; + drag_event.instance(); + + drag_event->set_position(mm->get_position()); + drag_event->set_relative(mm->get_relative()); + drag_event->set_speed(mm->get_speed()); + + event_dispatch_function(drag_event); + } + } + + Ref st = p_event; + + if (st.is_valid()) { + + if (st->is_pressed()) { + SpeedTrack &track = touch_speed_track[st->get_index()]; + track.reset(); + } else { + // Since a pointer index may not occur again (OSs may or may not reuse them), + // imperatively remove it from the map to keep no fossil entries in it + touch_speed_track.erase(st->get_index()); + } + + if (emulate_mouse_from_touch) { + + bool translate = false; + if (st->is_pressed()) { + if (mouse_from_touch_index == -1) { + translate = true; + mouse_from_touch_index = st->get_index(); + } + } else { + if (st->get_index() == mouse_from_touch_index) { + translate = true; + mouse_from_touch_index = -1; + } + } + + if (translate) { + Ref button_event; + button_event.instance(); + + button_event->set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE); + button_event->set_position(st->get_position()); + button_event->set_global_position(st->get_position()); + button_event->set_pressed(st->is_pressed()); + button_event->set_button_index(BUTTON_LEFT); + if (st->is_pressed()) { + button_event->set_button_mask(mouse_button_mask | (1 << (BUTTON_LEFT - 1))); + } else { + button_event->set_button_mask(mouse_button_mask & ~(1 << (BUTTON_LEFT - 1))); + } + + _parse_input_event_impl(button_event, true); + } + } + } + + Ref sd = p_event; + + if (sd.is_valid()) { + + SpeedTrack &track = touch_speed_track[sd->get_index()]; + track.update(sd->get_relative()); + sd->set_speed(track.speed); + + if (emulate_mouse_from_touch && sd->get_index() == mouse_from_touch_index) { + + Ref motion_event; + motion_event.instance(); + + motion_event->set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE); + motion_event->set_position(sd->get_position()); + motion_event->set_global_position(sd->get_position()); + motion_event->set_relative(sd->get_relative()); + motion_event->set_speed(sd->get_speed()); + motion_event->set_button_mask(mouse_button_mask); + + _parse_input_event_impl(motion_event, true); + } + } + + Ref jb = p_event; + + if (jb.is_valid()) { + + int c = _combine_device(jb->get_button_index(), jb->get_device()); + + if (jb->is_pressed()) + joy_buttons_pressed.insert(c); + else + joy_buttons_pressed.erase(c); + } + + Ref jm = p_event; + + if (jm.is_valid()) { + set_joy_axis(jm->get_device(), jm->get_axis(), jm->get_axis_value()); + } + + Ref ge = p_event; + + if (ge.is_valid()) { + + if (event_dispatch_function) { + event_dispatch_function(ge); + } + } + + for (const Map::Element *E = InputMap::get_singleton()->get_action_map().front(); E; E = E->next()) { + if (InputMap::get_singleton()->event_is_action(p_event, E->key())) { + + // Save the action's state + if (!p_event->is_echo() && is_action_pressed(E->key()) != p_event->is_action_pressed(E->key())) { + Action action; + action.physics_frame = Engine::get_singleton()->get_physics_frames(); + action.idle_frame = Engine::get_singleton()->get_idle_frames(); + action.pressed = p_event->is_action_pressed(E->key()); + action.strength = 0.f; + action_state[E->key()] = action; + } + action_state[E->key()].strength = p_event->get_action_strength(E->key()); + } + } + + if (event_dispatch_function) + event_dispatch_function(p_event); +} + +void Input::set_joy_axis(int p_device, int p_axis, float p_value) { + + _THREAD_SAFE_METHOD_ + int c = _combine_device(p_axis, p_device); + _joy_axis[c] = p_value; +} + +void Input::start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration) { + _THREAD_SAFE_METHOD_ + if (p_weak_magnitude < 0.f || p_weak_magnitude > 1.f || p_strong_magnitude < 0.f || p_strong_magnitude > 1.f) { + return; + } + VibrationInfo vibration; + vibration.weak_magnitude = p_weak_magnitude; + vibration.strong_magnitude = p_strong_magnitude; + vibration.duration = p_duration; + vibration.timestamp = OS::get_singleton()->get_ticks_usec(); + joy_vibration[p_device] = vibration; +} + +void Input::stop_joy_vibration(int p_device) { + _THREAD_SAFE_METHOD_ + VibrationInfo vibration; + vibration.weak_magnitude = 0; + vibration.strong_magnitude = 0; + vibration.duration = 0; + vibration.timestamp = OS::get_singleton()->get_ticks_usec(); + joy_vibration[p_device] = vibration; +} + +void Input::vibrate_handheld(int p_duration_ms) { + OS::get_singleton()->vibrate_handheld(p_duration_ms); +} + +void Input::set_gravity(const Vector3 &p_gravity) { + + _THREAD_SAFE_METHOD_ + + gravity = p_gravity; +} + +void Input::set_accelerometer(const Vector3 &p_accel) { + + _THREAD_SAFE_METHOD_ + + accelerometer = p_accel; +} + +void Input::set_magnetometer(const Vector3 &p_magnetometer) { + + _THREAD_SAFE_METHOD_ + + magnetometer = p_magnetometer; +} + +void Input::set_gyroscope(const Vector3 &p_gyroscope) { + + _THREAD_SAFE_METHOD_ + + gyroscope = p_gyroscope; +} + +void Input::set_mouse_position(const Point2 &p_posf) { + + mouse_speed_track.update(p_posf - mouse_pos); + mouse_pos = p_posf; +} + +Point2 Input::get_mouse_position() const { + + return mouse_pos; +} +Point2 Input::get_last_mouse_speed() const { + + return mouse_speed_track.speed; +} + +int Input::get_mouse_button_mask() const { + + return mouse_button_mask; // do not trust OS implementation, should remove it - OS::get_singleton()->get_mouse_button_state(); +} + +void Input::warp_mouse_position(const Vector2 &p_to) { + warp_mouse_func(p_to); +} + +Point2i Input::warp_mouse_motion(const Ref &p_motion, const Rect2 &p_rect) { + + // The relative distance reported for the next event after a warp is in the boundaries of the + // size of the rect on that axis, but it may be greater, in which case there's not problem as fmod() + // will warp it, but if the pointer has moved in the opposite direction between the pointer relocation + // and the subsequent event, the reported relative distance will be less than the size of the rect + // and thus fmod() will be disabled for handling the situation. + // And due to this mouse warping mechanism being stateless, we need to apply some heuristics to + // detect the warp: if the relative distance is greater than the half of the size of the relevant rect + // (checked per each axis), it will be considered as the consequence of a former pointer warp. + + const Point2i rel_sgn(p_motion->get_relative().x >= 0.0f ? 1 : -1, p_motion->get_relative().y >= 0.0 ? 1 : -1); + const Size2i warp_margin = p_rect.size * 0.5f; + const Point2i rel_warped( + Math::fmod(p_motion->get_relative().x + rel_sgn.x * warp_margin.x, p_rect.size.x) - rel_sgn.x * warp_margin.x, + Math::fmod(p_motion->get_relative().y + rel_sgn.y * warp_margin.y, p_rect.size.y) - rel_sgn.y * warp_margin.y); + + const Point2i pos_local = p_motion->get_global_position() - p_rect.position; + const Point2i pos_warped(Math::fposmod(pos_local.x, p_rect.size.x), Math::fposmod(pos_local.y, p_rect.size.y)); + if (pos_warped != pos_local) { + warp_mouse_position(pos_warped + p_rect.position); + } + + return rel_warped; +} + +void Input::iteration(float p_step) { +} + +void Input::action_press(const StringName &p_action, float p_strength) { + + Action action; + + action.physics_frame = Engine::get_singleton()->get_physics_frames(); + action.idle_frame = Engine::get_singleton()->get_idle_frames(); + action.pressed = true; + action.strength = p_strength; + + action_state[p_action] = action; +} + +void Input::action_release(const StringName &p_action) { + + Action action; + + action.physics_frame = Engine::get_singleton()->get_physics_frames(); + action.idle_frame = Engine::get_singleton()->get_idle_frames(); + action.pressed = false; + action.strength = 0.f; + + action_state[p_action] = action; +} + +void Input::set_emulate_touch_from_mouse(bool p_emulate) { + + emulate_touch_from_mouse = p_emulate; +} + +bool Input::is_emulating_touch_from_mouse() const { + + return emulate_touch_from_mouse; +} + +// Calling this whenever the game window is focused helps unstucking the "touch mouse" +// if the OS or its abstraction class hasn't properly reported that touch pointers raised +void Input::ensure_touch_mouse_raised() { + + if (mouse_from_touch_index != -1) { + mouse_from_touch_index = -1; + + Ref button_event; + button_event.instance(); + + button_event->set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE); + button_event->set_position(mouse_pos); + button_event->set_global_position(mouse_pos); + button_event->set_pressed(false); + button_event->set_button_index(BUTTON_LEFT); + button_event->set_button_mask(mouse_button_mask & ~(1 << (BUTTON_LEFT - 1))); + + _parse_input_event_impl(button_event, true); + } +} + +void Input::set_emulate_mouse_from_touch(bool p_emulate) { + + emulate_mouse_from_touch = p_emulate; +} + +bool Input::is_emulating_mouse_from_touch() const { + + return emulate_mouse_from_touch; +} + +Input::CursorShape Input::get_default_cursor_shape() const { + + return default_shape; +} + +void Input::set_default_cursor_shape(CursorShape p_shape) { + + if (default_shape == p_shape) + return; + + default_shape = p_shape; + // The default shape is set in Viewport::_gui_input_event. To instantly + // see the shape in the viewport we need to trigger a mouse motion event. + Ref mm; + mm.instance(); + mm->set_position(mouse_pos); + mm->set_global_position(mouse_pos); + parse_input_event(mm); +} + +Input::CursorShape Input::get_current_cursor_shape() const { + + return get_current_cursor_shape_func(); +} + +void Input::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { + if (Engine::get_singleton()->is_editor_hint()) + return; + + set_custom_mouse_cursor_func(p_cursor, p_shape, p_hotspot); +} + +void Input::accumulate_input_event(const Ref &p_event) { + ERR_FAIL_COND(p_event.is_null()); + + if (!use_accumulated_input) { + parse_input_event(p_event); + return; + } + if (!accumulated_events.empty() && accumulated_events.back()->get()->accumulate(p_event)) { + return; //event was accumulated, exit + } + + accumulated_events.push_back(p_event); +} +void Input::flush_accumulated_events() { + + while (accumulated_events.front()) { + parse_input_event(accumulated_events.front()->get()); + accumulated_events.pop_front(); + } +} + +void Input::set_use_accumulated_input(bool p_enable) { + + use_accumulated_input = p_enable; +} + +void Input::release_pressed_events() { + + flush_accumulated_events(); // this is needed to release actions strengths + + keys_pressed.clear(); + joy_buttons_pressed.clear(); + _joy_axis.clear(); + + for (Map::Element *E = action_state.front(); E; E = E->next()) { + if (E->get().pressed) + action_release(E->key()); + } +} + +void Input::set_event_dispatch_function(EventDispatchFunc p_function) { + event_dispatch_function = p_function; +} + +void Input::joy_button(int p_device, int p_button, bool p_pressed) { + + _THREAD_SAFE_METHOD_; + Joypad &joy = joy_names[p_device]; + //printf("got button %i, mapping is %i\n", p_button, joy.mapping); + if (joy.last_buttons[p_button] == p_pressed) { + return; + } + joy.last_buttons[p_button] = p_pressed; + if (joy.mapping == -1) { + _button_event(p_device, p_button, p_pressed); + return; + } + + const Map::Element *el = map_db[joy.mapping].buttons.find(p_button); + if (!el) { + //don't process un-mapped events for now, it could mess things up badly for devices with additional buttons/axis + //return _button_event(p_last_id, p_device, p_button, p_pressed); + return; + } + + JoyEvent map = el->get(); + if (map.type == TYPE_BUTTON) { + //fake additional axis event for triggers + if (map.index == JOY_L2 || map.index == JOY_R2) { + float value = p_pressed ? 1.0f : 0.0f; + int axis = map.index == JOY_L2 ? JOY_ANALOG_L2 : JOY_ANALOG_R2; + _axis_event(p_device, axis, value); + } + _button_event(p_device, map.index, p_pressed); + return; + } + + if (map.type == TYPE_AXIS) { + _axis_event(p_device, map.index, p_pressed ? 1.0 : 0.0); + } + // no event? +} + +void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { + + _THREAD_SAFE_METHOD_; + + ERR_FAIL_INDEX(p_axis, JOY_AXIS_MAX); + + Joypad &joy = joy_names[p_device]; + + if (joy.last_axis[p_axis] == p_value.value) { + return; + } + + if (p_value.value > joy.last_axis[p_axis]) { + + if (p_value.value < joy.last_axis[p_axis] + joy.filter) { + + return; + } + } else if (p_value.value > joy.last_axis[p_axis] - joy.filter) { + + return; + } + + //when changing direction quickly, insert fake event to release pending inputmap actions + float last = joy.last_axis[p_axis]; + if (p_value.min == 0 && (last < 0.25 || last > 0.75) && (last - 0.5) * (p_value.value - 0.5) < 0) { + JoyAxis jx; + jx.min = p_value.min; + jx.value = p_value.value < 0.5 ? 0.6 : 0.4; + joy_axis(p_device, p_axis, jx); + } else if (ABS(last) > 0.5 && last * p_value.value < 0) { + JoyAxis jx; + jx.min = p_value.min; + jx.value = p_value.value < 0 ? 0.1 : -0.1; + joy_axis(p_device, p_axis, jx); + } + + joy.last_axis[p_axis] = p_value.value; + float val = p_value.min == 0 ? -1.0f + 2.0f * p_value.value : p_value.value; + + if (joy.mapping == -1) { + _axis_event(p_device, p_axis, val); + return; + }; + + const Map::Element *el = map_db[joy.mapping].axis.find(p_axis); + if (!el) { + //return _axis_event(p_last_id, p_device, p_axis, p_value); + return; + }; + + JoyEvent map = el->get(); + + if (map.type == TYPE_BUTTON) { + //send axis event for triggers + if (map.index == JOY_L2 || map.index == JOY_R2) { + float value = p_value.min == 0 ? p_value.value : 0.5f + p_value.value / 2.0f; + int axis = map.index == JOY_L2 ? JOY_ANALOG_L2 : JOY_ANALOG_R2; + _axis_event(p_device, axis, value); + } + + if (map.index == JOY_DPAD_UP || map.index == JOY_DPAD_DOWN) { + bool pressed = p_value.value != 0.0f; + int button = p_value.value < 0 ? JOY_DPAD_UP : JOY_DPAD_DOWN; + + if (!pressed) { + if (joy_buttons_pressed.has(_combine_device(JOY_DPAD_UP, p_device))) { + _button_event(p_device, JOY_DPAD_UP, false); + } + if (joy_buttons_pressed.has(_combine_device(JOY_DPAD_DOWN, p_device))) { + _button_event(p_device, JOY_DPAD_DOWN, false); + } + } + if (pressed == joy_buttons_pressed.has(_combine_device(button, p_device))) { + return; + } + _button_event(p_device, button, true); + return; + } + if (map.index == JOY_DPAD_LEFT || map.index == JOY_DPAD_RIGHT) { + bool pressed = p_value.value != 0.0f; + int button = p_value.value < 0 ? JOY_DPAD_LEFT : JOY_DPAD_RIGHT; + + if (!pressed) { + if (joy_buttons_pressed.has(_combine_device(JOY_DPAD_LEFT, p_device))) { + _button_event(p_device, JOY_DPAD_LEFT, false); + } + if (joy_buttons_pressed.has(_combine_device(JOY_DPAD_RIGHT, p_device))) { + _button_event(p_device, JOY_DPAD_RIGHT, false); + } + } + if (pressed == joy_buttons_pressed.has(_combine_device(button, p_device))) { + return; + } + _button_event(p_device, button, true); + return; + } + float deadzone = p_value.min == 0 ? 0.5f : 0.0f; + bool pressed = p_value.value > deadzone; + if (pressed == joy_buttons_pressed.has(_combine_device(map.index, p_device))) { + // button already pressed or released, this is an axis bounce value + return; + } + _button_event(p_device, map.index, pressed); + return; + } + + if (map.type == TYPE_AXIS) { + + _axis_event(p_device, map.index, val); + return; + } + //printf("invalid mapping\n"); +} + +void Input::joy_hat(int p_device, int p_val) { + + _THREAD_SAFE_METHOD_; + const Joypad &joy = joy_names[p_device]; + + const JoyEvent *map; + + if (joy.mapping == -1) { + map = hat_map_default; + } else { + map = map_db[joy.mapping].hat; + }; + + int cur_val = joy_names[p_device].hat_current; + + if ((p_val & HAT_MASK_UP) != (cur_val & HAT_MASK_UP)) { + _button_event(p_device, map[HAT_UP].index, p_val & HAT_MASK_UP); + } + + if ((p_val & HAT_MASK_RIGHT) != (cur_val & HAT_MASK_RIGHT)) { + _button_event(p_device, map[HAT_RIGHT].index, p_val & HAT_MASK_RIGHT); + } + if ((p_val & HAT_MASK_DOWN) != (cur_val & HAT_MASK_DOWN)) { + _button_event(p_device, map[HAT_DOWN].index, p_val & HAT_MASK_DOWN); + } + if ((p_val & HAT_MASK_LEFT) != (cur_val & HAT_MASK_LEFT)) { + _button_event(p_device, map[HAT_LEFT].index, p_val & HAT_MASK_LEFT); + } + + joy_names[p_device].hat_current = p_val; +} + +void Input::_button_event(int p_device, int p_index, bool p_pressed) { + + Ref ievent; + ievent.instance(); + ievent->set_device(p_device); + ievent->set_button_index(p_index); + ievent->set_pressed(p_pressed); + + parse_input_event(ievent); +} + +void Input::_axis_event(int p_device, int p_axis, float p_value) { + + Ref ievent; + ievent.instance(); + ievent->set_device(p_device); + ievent->set_axis(p_axis); + ievent->set_axis_value(p_value); + + parse_input_event(ievent); +}; + +Input::JoyEvent Input::_find_to_event(String p_to) { + + // string names of the SDL buttons in the same order as input_event.h godot buttons + static const char *buttons[] = { "a", "b", "x", "y", "leftshoulder", "rightshoulder", "lefttrigger", "righttrigger", "leftstick", "rightstick", "back", "start", "dpup", "dpdown", "dpleft", "dpright", "guide", nullptr }; + + static const char *axis[] = { "leftx", "lefty", "rightx", "righty", nullptr }; + + JoyEvent ret; + ret.type = -1; + ret.index = 0; + + int i = 0; + while (buttons[i]) { + + if (p_to == buttons[i]) { + ret.type = TYPE_BUTTON; + ret.index = i; + ret.value = 0; + return ret; + }; + ++i; + }; + + i = 0; + while (axis[i]) { + + if (p_to == axis[i]) { + ret.type = TYPE_AXIS; + ret.index = i; + ret.value = 0; + return ret; + }; + ++i; + }; + + return ret; +}; + +void Input::parse_mapping(String p_mapping) { + + _THREAD_SAFE_METHOD_; + JoyDeviceMapping mapping; + for (int i = 0; i < HAT_MAX; ++i) + mapping.hat[i].index = 1024 + i; + + Vector entry = p_mapping.split(","); + if (entry.size() < 2) { + return; + } + + CharString uid; + uid.resize(17); + + mapping.uid = entry[0]; + mapping.name = entry[1]; + + int idx = 1; + while (++idx < entry.size()) { + + if (entry[idx] == "") + continue; + + String from = entry[idx].get_slice(":", 1).replace(" ", ""); + String to = entry[idx].get_slice(":", 0).replace(" ", ""); + + JoyEvent to_event = _find_to_event(to); + if (to_event.type == -1) + continue; + + String etype = from.substr(0, 1); + if (etype == "a") { + + int aid = from.substr(1, from.length() - 1).to_int(); + mapping.axis[aid] = to_event; + + } else if (etype == "b") { + + int bid = from.substr(1, from.length() - 1).to_int(); + mapping.buttons[bid] = to_event; + + } else if (etype == "h") { + + int hat_value = from.get_slice(".", 1).to_int(); + switch (hat_value) { + case 1: + mapping.hat[HAT_UP] = to_event; + break; + case 2: + mapping.hat[HAT_RIGHT] = to_event; + break; + case 4: + mapping.hat[HAT_DOWN] = to_event; + break; + case 8: + mapping.hat[HAT_LEFT] = to_event; + break; + }; + }; + }; + map_db.push_back(mapping); + //printf("added mapping with uuid %ls\n", mapping.uid.c_str()); +}; + +void Input::add_joy_mapping(String p_mapping, bool p_update_existing) { + parse_mapping(p_mapping); + if (p_update_existing) { + Vector entry = p_mapping.split(","); + String uid = entry[0]; + for (int i = 0; i < joy_names.size(); i++) { + if (uid == joy_names[i].uid) { + joy_names[i].mapping = map_db.size() - 1; + } + } + } +} + +void Input::remove_joy_mapping(String p_guid) { + for (int i = map_db.size() - 1; i >= 0; i--) { + if (p_guid == map_db[i].uid) { + map_db.remove(i); + } + } + for (int i = 0; i < joy_names.size(); i++) { + if (joy_names[i].uid == p_guid) { + joy_names[i].mapping = -1; + } + } +} + +void Input::set_fallback_mapping(String p_guid) { + + for (int i = 0; i < map_db.size(); i++) { + if (map_db[i].uid == p_guid) { + fallback_mapping = i; + return; + } + } +} + +//platforms that use the remapping system can override and call to these ones +bool Input::is_joy_known(int p_device) { + int mapping = joy_names[p_device].mapping; + return mapping != -1 ? (mapping != fallback_mapping) : false; +} + +String Input::get_joy_guid(int p_device) const { + ERR_FAIL_COND_V(!joy_names.has(p_device), ""); + return joy_names[p_device].uid; +} + +Array Input::get_connected_joypads() { + Array ret; + Map::Element *elem = joy_names.front(); + while (elem) { + if (elem->get().connected) { + ret.push_back(elem->key()); + } + elem = elem->next(); + } + return ret; +} + +static const char *_buttons[JOY_BUTTON_MAX] = { + "Face Button Bottom", + "Face Button Right", + "Face Button Left", + "Face Button Top", + "L", + "R", + "L2", + "R2", + "L3", + "R3", + "Select", + "Start", + "DPAD Up", + "DPAD Down", + "DPAD Left", + "DPAD Right" +}; + +static const char *_axes[JOY_AXIS_MAX] = { + "Left Stick X", + "Left Stick Y", + "Right Stick X", + "Right Stick Y", + "", + "", + "L2", + "R2", + "", + "" +}; + +String Input::get_joy_button_string(int p_button) { + ERR_FAIL_INDEX_V(p_button, JOY_BUTTON_MAX, ""); + return _buttons[p_button]; +} + +int Input::get_joy_button_index_from_string(String p_button) { + for (int i = 0; i < JOY_BUTTON_MAX; i++) { + if (p_button == _buttons[i]) { + return i; + } + } + ERR_FAIL_V(-1); +} + +int Input::get_unused_joy_id() { + for (int i = 0; i < JOYPADS_MAX; i++) { + if (!joy_names.has(i) || !joy_names[i].connected) { + return i; + } + } + return -1; +} + +String Input::get_joy_axis_string(int p_axis) { + ERR_FAIL_INDEX_V(p_axis, JOY_AXIS_MAX, ""); + return _axes[p_axis]; +} + +int Input::get_joy_axis_index_from_string(String p_axis) { + for (int i = 0; i < JOY_AXIS_MAX; i++) { + if (p_axis == _axes[i]) { + return i; + } + } + ERR_FAIL_V(-1); +} + +Input::Input() { + + singleton = this; + use_accumulated_input = true; + mouse_button_mask = 0; + mouse_window = 0; + emulate_touch_from_mouse = false; + emulate_mouse_from_touch = false; + mouse_from_touch_index = -1; + event_dispatch_function = nullptr; + default_shape = CURSOR_ARROW; + + hat_map_default[HAT_UP].type = TYPE_BUTTON; + hat_map_default[HAT_UP].index = JOY_DPAD_UP; + hat_map_default[HAT_UP].value = 0; + + hat_map_default[HAT_RIGHT].type = TYPE_BUTTON; + hat_map_default[HAT_RIGHT].index = JOY_DPAD_RIGHT; + hat_map_default[HAT_RIGHT].value = 0; + + hat_map_default[HAT_DOWN].type = TYPE_BUTTON; + hat_map_default[HAT_DOWN].index = JOY_DPAD_DOWN; + hat_map_default[HAT_DOWN].value = 0; + + hat_map_default[HAT_LEFT].type = TYPE_BUTTON; + hat_map_default[HAT_LEFT].index = JOY_DPAD_LEFT; + hat_map_default[HAT_LEFT].value = 0; + + fallback_mapping = -1; + + // Parse default mappings. + { + int i = 0; + while (DefaultControllerMappings::mappings[i]) { + parse_mapping(DefaultControllerMappings::mappings[i++]); + } + } + + // If defined, parse SDL_GAMECONTROLLERCONFIG for possible new mappings/overrides. + String env_mapping = OS::get_singleton()->get_environment("SDL_GAMECONTROLLERCONFIG"); + if (env_mapping != "") { + Vector entries = env_mapping.split("\n"); + for (int i = 0; i < entries.size(); i++) { + if (entries[i] == "") + continue; + parse_mapping(entries[i]); + } + } +} + +////////////////////////////////////////////////////////// diff --git a/core/input/input.h b/core/input/input.h new file mode 100644 index 0000000000..477de1e879 --- /dev/null +++ b/core/input/input.h @@ -0,0 +1,337 @@ +/*************************************************************************/ +/* input.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef INPUT_H +#define INPUT_H + +#include "core/input/input_event.h" +#include "core/object.h" +#include "core/os/thread_safe.h" + +class Input : public Object { + + GDCLASS(Input, Object); + _THREAD_SAFE_CLASS_ + + static Input *singleton; + +public: + enum MouseMode { + MOUSE_MODE_VISIBLE, + MOUSE_MODE_HIDDEN, + MOUSE_MODE_CAPTURED, + MOUSE_MODE_CONFINED + }; + +#undef CursorShape + enum CursorShape { + CURSOR_ARROW, + CURSOR_IBEAM, + CURSOR_POINTING_HAND, + CURSOR_CROSS, + CURSOR_WAIT, + CURSOR_BUSY, + CURSOR_DRAG, + CURSOR_CAN_DROP, + CURSOR_FORBIDDEN, + CURSOR_VSIZE, + CURSOR_HSIZE, + CURSOR_BDIAGSIZE, + CURSOR_FDIAGSIZE, + CURSOR_MOVE, + CURSOR_VSPLIT, + CURSOR_HSPLIT, + CURSOR_HELP, + CURSOR_MAX + }; + + enum HatMask { + HAT_MASK_CENTER = 0, + HAT_MASK_UP = 1, + HAT_MASK_RIGHT = 2, + HAT_MASK_DOWN = 4, + HAT_MASK_LEFT = 8, + }; + + enum HatDir { + HAT_UP, + HAT_RIGHT, + HAT_DOWN, + HAT_LEFT, + HAT_MAX, + }; + + enum { + JOYPADS_MAX = 16, + }; + + struct JoyAxis { + int min; + float value; + }; + + typedef void (*EventDispatchFunc)(const Ref &p_event); + +private: + int mouse_button_mask; + + Set keys_pressed; + Set joy_buttons_pressed; + Map _joy_axis; + //Map custom_action_press; + Vector3 gravity; + Vector3 accelerometer; + Vector3 magnetometer; + Vector3 gyroscope; + Vector2 mouse_pos; + int64_t mouse_window; + + struct Action { + uint64_t physics_frame; + uint64_t idle_frame; + bool pressed; + float strength; + }; + + Map action_state; + + bool emulate_touch_from_mouse; + bool emulate_mouse_from_touch; + + int mouse_from_touch_index; + + struct VibrationInfo { + float weak_magnitude; + float strong_magnitude; + float duration; // Duration in seconds + uint64_t timestamp; + }; + + Map joy_vibration; + + struct SpeedTrack { + + uint64_t last_tick; + Vector2 speed; + Vector2 accum; + float accum_t; + float min_ref_frame; + float max_ref_frame; + + void update(const Vector2 &p_delta_p); + void reset(); + SpeedTrack(); + }; + + struct Joypad { + StringName name; + StringName uid; + bool connected; + bool last_buttons[JOY_BUTTON_MAX + 19]; //apparently SDL specifies 35 possible buttons on android + float last_axis[JOY_AXIS_MAX]; + float filter; + int last_hat; + int mapping; + int hat_current; + + Joypad() { + for (int i = 0; i < JOY_AXIS_MAX; i++) { + + last_axis[i] = 0.0f; + } + for (int i = 0; i < JOY_BUTTON_MAX + 19; i++) { + + last_buttons[i] = false; + } + connected = false; + last_hat = HAT_MASK_CENTER; + filter = 0.01f; + mapping = -1; + hat_current = 0; + } + }; + + SpeedTrack mouse_speed_track; + Map touch_speed_track; + Map joy_names; + int fallback_mapping; + + CursorShape default_shape; + + enum JoyType { + TYPE_BUTTON, + TYPE_AXIS, + TYPE_HAT, + TYPE_MAX, + }; + + struct JoyEvent { + int type; + int index; + int value; + }; + + struct JoyDeviceMapping { + + String uid; + String name; + Map buttons; + Map axis; + JoyEvent hat[HAT_MAX]; + }; + + JoyEvent hat_map_default[HAT_MAX]; + + Vector map_db; + + JoyEvent _find_to_event(String p_to); + void _button_event(int p_device, int p_index, bool p_pressed); + void _axis_event(int p_device, int p_axis, float p_value); + float _handle_deadzone(int p_device, int p_axis, float p_value); + + void _parse_input_event_impl(const Ref &p_event, bool p_is_emulated); + + List> accumulated_events; + bool use_accumulated_input; + friend class DisplayServer; + + static void (*set_mouse_mode_func)(MouseMode); + static MouseMode (*get_mouse_mode_func)(); + static void (*warp_mouse_func)(const Vector2 &p_to_pos); + + static CursorShape (*get_current_cursor_shape_func)(); + static void (*set_custom_mouse_cursor_func)(const RES &, CursorShape, const Vector2 &); + + EventDispatchFunc event_dispatch_function; + +protected: + static void _bind_methods(); + +public: + void set_mouse_mode(MouseMode p_mode); + MouseMode get_mouse_mode() const; + void get_argument_options(const StringName &p_function, int p_idx, List *r_options) const; + + static Input *get_singleton(); + + bool is_key_pressed(int p_keycode) const; + bool is_mouse_button_pressed(int p_button) const; + bool is_joy_button_pressed(int p_device, int p_button) const; + bool is_action_pressed(const StringName &p_action) const; + bool is_action_just_pressed(const StringName &p_action) const; + bool is_action_just_released(const StringName &p_action) const; + float get_action_strength(const StringName &p_action) const; + + float get_joy_axis(int p_device, int p_axis) const; + String get_joy_name(int p_idx); + Array get_connected_joypads(); + Vector2 get_joy_vibration_strength(int p_device); + float get_joy_vibration_duration(int p_device); + uint64_t get_joy_vibration_timestamp(int p_device); + void joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid = ""); + void parse_joypad_mapping(String p_mapping, bool p_update_existing); + + Vector3 get_gravity() const; + Vector3 get_accelerometer() const; + Vector3 get_magnetometer() const; + Vector3 get_gyroscope() const; + + Point2 get_mouse_position() const; + Point2 get_last_mouse_speed() const; + int get_mouse_button_mask() const; + + void warp_mouse_position(const Vector2 &p_to); + Point2i warp_mouse_motion(const Ref &p_motion, const Rect2 &p_rect); + + void parse_input_event(const Ref &p_event); + + void set_gravity(const Vector3 &p_gravity); + void set_accelerometer(const Vector3 &p_accel); + void set_magnetometer(const Vector3 &p_magnetometer); + void set_gyroscope(const Vector3 &p_gyroscope); + void set_joy_axis(int p_device, int p_axis, float p_value); + + void start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration = 0); + void stop_joy_vibration(int p_device); + void vibrate_handheld(int p_duration_ms = 500); + + void set_mouse_position(const Point2 &p_posf); + + void action_press(const StringName &p_action, float p_strength = 1.f); + void action_release(const StringName &p_action); + + void iteration(float p_step); + + void set_emulate_touch_from_mouse(bool p_emulate); + bool is_emulating_touch_from_mouse() const; + void ensure_touch_mouse_raised(); + + void set_emulate_mouse_from_touch(bool p_emulate); + bool is_emulating_mouse_from_touch() const; + + CursorShape get_default_cursor_shape() const; + void set_default_cursor_shape(CursorShape p_shape); + CursorShape get_current_cursor_shape() const; + void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = Input::CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()); + + void parse_mapping(String p_mapping); + void joy_button(int p_device, int p_button, bool p_pressed); + void joy_axis(int p_device, int p_axis, const JoyAxis &p_value); + void joy_hat(int p_device, int p_val); + + void add_joy_mapping(String p_mapping, bool p_update_existing = false); + void remove_joy_mapping(String p_guid); + + String get_joy_button_string(int p_button); + String get_joy_axis_string(int p_axis); + int get_joy_axis_index_from_string(String p_axis); + int get_joy_button_index_from_string(String p_button); + + int get_unused_joy_id(); + + bool is_joy_known(int p_device); + String get_joy_guid(int p_device) const; + void set_fallback_mapping(String p_guid); + + void accumulate_input_event(const Ref &p_event); + void flush_accumulated_events(); + void set_use_accumulated_input(bool p_enable); + + void release_pressed_events(); + + void set_event_dispatch_function(EventDispatchFunc p_function); + + Input(); +}; + +VARIANT_ENUM_CAST(Input::MouseMode); +VARIANT_ENUM_CAST(Input::CursorShape); + +#endif // INPUT_H diff --git a/core/input/input_filter.cpp b/core/input/input_filter.cpp deleted file mode 100644 index 2e8442a905..0000000000 --- a/core/input/input_filter.cpp +++ /dev/null @@ -1,1309 +0,0 @@ -/*************************************************************************/ -/* input_filter.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "input_filter.h" - -#include "core/input/default_controller_mappings.h" -#include "core/input/input_map.h" -#include "core/os/os.h" -#include "core/project_settings.h" - -#ifdef TOOLS_ENABLED -#include "editor/editor_settings.h" -#endif - -InputFilter *InputFilter::singleton = nullptr; - -void (*InputFilter::set_mouse_mode_func)(InputFilter::MouseMode) = nullptr; -InputFilter::MouseMode (*InputFilter::get_mouse_mode_func)() = nullptr; -void (*InputFilter::warp_mouse_func)(const Vector2 &p_to_pos) = nullptr; -InputFilter::CursorShape (*InputFilter::get_current_cursor_shape_func)() = nullptr; -void (*InputFilter::set_custom_mouse_cursor_func)(const RES &, InputFilter::CursorShape, const Vector2 &) = nullptr; - -InputFilter *InputFilter::get_singleton() { - - return singleton; -} - -void InputFilter::set_mouse_mode(MouseMode p_mode) { - ERR_FAIL_INDEX((int)p_mode, 4); - set_mouse_mode_func(p_mode); -} - -InputFilter::MouseMode InputFilter::get_mouse_mode() const { - - return get_mouse_mode_func(); -} - -void InputFilter::_bind_methods() { - - ClassDB::bind_method(D_METHOD("is_key_pressed", "keycode"), &InputFilter::is_key_pressed); - ClassDB::bind_method(D_METHOD("is_mouse_button_pressed", "button"), &InputFilter::is_mouse_button_pressed); - ClassDB::bind_method(D_METHOD("is_joy_button_pressed", "device", "button"), &InputFilter::is_joy_button_pressed); - ClassDB::bind_method(D_METHOD("is_action_pressed", "action"), &InputFilter::is_action_pressed); - ClassDB::bind_method(D_METHOD("is_action_just_pressed", "action"), &InputFilter::is_action_just_pressed); - ClassDB::bind_method(D_METHOD("is_action_just_released", "action"), &InputFilter::is_action_just_released); - ClassDB::bind_method(D_METHOD("get_action_strength", "action"), &InputFilter::get_action_strength); - ClassDB::bind_method(D_METHOD("add_joy_mapping", "mapping", "update_existing"), &InputFilter::add_joy_mapping, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("remove_joy_mapping", "guid"), &InputFilter::remove_joy_mapping); - ClassDB::bind_method(D_METHOD("joy_connection_changed", "device", "connected", "name", "guid"), &InputFilter::joy_connection_changed); - ClassDB::bind_method(D_METHOD("is_joy_known", "device"), &InputFilter::is_joy_known); - ClassDB::bind_method(D_METHOD("get_joy_axis", "device", "axis"), &InputFilter::get_joy_axis); - ClassDB::bind_method(D_METHOD("get_joy_name", "device"), &InputFilter::get_joy_name); - ClassDB::bind_method(D_METHOD("get_joy_guid", "device"), &InputFilter::get_joy_guid); - ClassDB::bind_method(D_METHOD("get_connected_joypads"), &InputFilter::get_connected_joypads); - ClassDB::bind_method(D_METHOD("get_joy_vibration_strength", "device"), &InputFilter::get_joy_vibration_strength); - ClassDB::bind_method(D_METHOD("get_joy_vibration_duration", "device"), &InputFilter::get_joy_vibration_duration); - ClassDB::bind_method(D_METHOD("get_joy_button_string", "button_index"), &InputFilter::get_joy_button_string); - ClassDB::bind_method(D_METHOD("get_joy_button_index_from_string", "button"), &InputFilter::get_joy_button_index_from_string); - ClassDB::bind_method(D_METHOD("get_joy_axis_string", "axis_index"), &InputFilter::get_joy_axis_string); - ClassDB::bind_method(D_METHOD("get_joy_axis_index_from_string", "axis"), &InputFilter::get_joy_axis_index_from_string); - ClassDB::bind_method(D_METHOD("start_joy_vibration", "device", "weak_magnitude", "strong_magnitude", "duration"), &InputFilter::start_joy_vibration, DEFVAL(0)); - ClassDB::bind_method(D_METHOD("stop_joy_vibration", "device"), &InputFilter::stop_joy_vibration); - ClassDB::bind_method(D_METHOD("vibrate_handheld", "duration_ms"), &InputFilter::vibrate_handheld, DEFVAL(500)); - ClassDB::bind_method(D_METHOD("get_gravity"), &InputFilter::get_gravity); - ClassDB::bind_method(D_METHOD("get_accelerometer"), &InputFilter::get_accelerometer); - ClassDB::bind_method(D_METHOD("get_magnetometer"), &InputFilter::get_magnetometer); - ClassDB::bind_method(D_METHOD("get_gyroscope"), &InputFilter::get_gyroscope); - ClassDB::bind_method(D_METHOD("get_last_mouse_speed"), &InputFilter::get_last_mouse_speed); - ClassDB::bind_method(D_METHOD("get_mouse_button_mask"), &InputFilter::get_mouse_button_mask); - ClassDB::bind_method(D_METHOD("set_mouse_mode", "mode"), &InputFilter::set_mouse_mode); - ClassDB::bind_method(D_METHOD("get_mouse_mode"), &InputFilter::get_mouse_mode); - ClassDB::bind_method(D_METHOD("warp_mouse_position", "to"), &InputFilter::warp_mouse_position); - ClassDB::bind_method(D_METHOD("action_press", "action", "strength"), &InputFilter::action_press, DEFVAL(1.f)); - ClassDB::bind_method(D_METHOD("action_release", "action"), &InputFilter::action_release); - ClassDB::bind_method(D_METHOD("set_default_cursor_shape", "shape"), &InputFilter::set_default_cursor_shape, DEFVAL(CURSOR_ARROW)); - ClassDB::bind_method(D_METHOD("get_current_cursor_shape"), &InputFilter::get_current_cursor_shape); - ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor", "image", "shape", "hotspot"), &InputFilter::set_custom_mouse_cursor, DEFVAL(CURSOR_ARROW), DEFVAL(Vector2())); - ClassDB::bind_method(D_METHOD("parse_input_event", "event"), &InputFilter::parse_input_event); - ClassDB::bind_method(D_METHOD("set_use_accumulated_input", "enable"), &InputFilter::set_use_accumulated_input); - - BIND_ENUM_CONSTANT(MOUSE_MODE_VISIBLE); - BIND_ENUM_CONSTANT(MOUSE_MODE_HIDDEN); - BIND_ENUM_CONSTANT(MOUSE_MODE_CAPTURED); - BIND_ENUM_CONSTANT(MOUSE_MODE_CONFINED); - - BIND_ENUM_CONSTANT(CURSOR_ARROW); - BIND_ENUM_CONSTANT(CURSOR_IBEAM); - BIND_ENUM_CONSTANT(CURSOR_POINTING_HAND); - BIND_ENUM_CONSTANT(CURSOR_CROSS); - BIND_ENUM_CONSTANT(CURSOR_WAIT); - BIND_ENUM_CONSTANT(CURSOR_BUSY); - BIND_ENUM_CONSTANT(CURSOR_DRAG); - BIND_ENUM_CONSTANT(CURSOR_CAN_DROP); - BIND_ENUM_CONSTANT(CURSOR_FORBIDDEN); - BIND_ENUM_CONSTANT(CURSOR_VSIZE); - BIND_ENUM_CONSTANT(CURSOR_HSIZE); - BIND_ENUM_CONSTANT(CURSOR_BDIAGSIZE); - BIND_ENUM_CONSTANT(CURSOR_FDIAGSIZE); - BIND_ENUM_CONSTANT(CURSOR_MOVE); - BIND_ENUM_CONSTANT(CURSOR_VSPLIT); - BIND_ENUM_CONSTANT(CURSOR_HSPLIT); - BIND_ENUM_CONSTANT(CURSOR_HELP); - - ADD_SIGNAL(MethodInfo("joy_connection_changed", PropertyInfo(Variant::INT, "device"), PropertyInfo(Variant::BOOL, "connected"))); -} - -void InputFilter::get_argument_options(const StringName &p_function, int p_idx, List *r_options) const { -#ifdef TOOLS_ENABLED - - const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\""; - - String pf = p_function; - if (p_idx == 0 && (pf == "is_action_pressed" || pf == "action_press" || pf == "action_release" || pf == "is_action_just_pressed" || pf == "is_action_just_released" || pf == "get_action_strength")) { - - List pinfo; - ProjectSettings::get_singleton()->get_property_list(&pinfo); - - for (List::Element *E = pinfo.front(); E; E = E->next()) { - const PropertyInfo &pi = E->get(); - - if (!pi.name.begins_with("input/")) - continue; - - String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length()); - r_options->push_back(quote_style + name + quote_style); - } - } -#endif -} - -void InputFilter::SpeedTrack::update(const Vector2 &p_delta_p) { - - uint64_t tick = OS::get_singleton()->get_ticks_usec(); - uint32_t tdiff = tick - last_tick; - float delta_t = tdiff / 1000000.0; - last_tick = tick; - - accum += p_delta_p; - accum_t += delta_t; - - if (accum_t > max_ref_frame * 10) - accum_t = max_ref_frame * 10; - - while (accum_t >= min_ref_frame) { - - float slice_t = min_ref_frame / accum_t; - Vector2 slice = accum * slice_t; - accum = accum - slice; - accum_t -= min_ref_frame; - - speed = (slice / min_ref_frame).linear_interpolate(speed, min_ref_frame / max_ref_frame); - } -} - -void InputFilter::SpeedTrack::reset() { - last_tick = OS::get_singleton()->get_ticks_usec(); - speed = Vector2(); - accum_t = 0; -} - -InputFilter::SpeedTrack::SpeedTrack() { - - min_ref_frame = 0.1; - max_ref_frame = 0.3; - reset(); -} - -bool InputFilter::is_key_pressed(int p_keycode) const { - - _THREAD_SAFE_METHOD_ - return keys_pressed.has(p_keycode); -} - -bool InputFilter::is_mouse_button_pressed(int p_button) const { - - _THREAD_SAFE_METHOD_ - return (mouse_button_mask & (1 << (p_button - 1))) != 0; -} - -static int _combine_device(int p_value, int p_device) { - - return p_value | (p_device << 20); -} - -bool InputFilter::is_joy_button_pressed(int p_device, int p_button) const { - - _THREAD_SAFE_METHOD_ - return joy_buttons_pressed.has(_combine_device(p_button, p_device)); -} - -bool InputFilter::is_action_pressed(const StringName &p_action) const { - - return action_state.has(p_action) && action_state[p_action].pressed; -} - -bool InputFilter::is_action_just_pressed(const StringName &p_action) const { - - const Map::Element *E = action_state.find(p_action); - if (!E) - return false; - - if (Engine::get_singleton()->is_in_physics_frame()) { - return E->get().pressed && E->get().physics_frame == Engine::get_singleton()->get_physics_frames(); - } else { - return E->get().pressed && E->get().idle_frame == Engine::get_singleton()->get_idle_frames(); - } -} - -bool InputFilter::is_action_just_released(const StringName &p_action) const { - - const Map::Element *E = action_state.find(p_action); - if (!E) - return false; - - if (Engine::get_singleton()->is_in_physics_frame()) { - return !E->get().pressed && E->get().physics_frame == Engine::get_singleton()->get_physics_frames(); - } else { - return !E->get().pressed && E->get().idle_frame == Engine::get_singleton()->get_idle_frames(); - } -} - -float InputFilter::get_action_strength(const StringName &p_action) const { - const Map::Element *E = action_state.find(p_action); - if (!E) - return 0.0f; - - return E->get().strength; -} - -float InputFilter::get_joy_axis(int p_device, int p_axis) const { - - _THREAD_SAFE_METHOD_ - int c = _combine_device(p_axis, p_device); - if (_joy_axis.has(c)) { - return _joy_axis[c]; - } else { - return 0; - } -} - -String InputFilter::get_joy_name(int p_idx) { - - _THREAD_SAFE_METHOD_ - return joy_names[p_idx].name; -}; - -Vector2 InputFilter::get_joy_vibration_strength(int p_device) { - if (joy_vibration.has(p_device)) { - return Vector2(joy_vibration[p_device].weak_magnitude, joy_vibration[p_device].strong_magnitude); - } else { - return Vector2(0, 0); - } -} - -uint64_t InputFilter::get_joy_vibration_timestamp(int p_device) { - if (joy_vibration.has(p_device)) { - return joy_vibration[p_device].timestamp; - } else { - return 0; - } -} - -float InputFilter::get_joy_vibration_duration(int p_device) { - if (joy_vibration.has(p_device)) { - return joy_vibration[p_device].duration; - } else { - return 0.f; - } -} - -static String _hex_str(uint8_t p_byte) { - - static const char *dict = "0123456789abcdef"; - char ret[3]; - ret[2] = 0; - - ret[0] = dict[p_byte >> 4]; - ret[1] = dict[p_byte & 0xf]; - - return ret; -}; - -void InputFilter::joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid) { - - _THREAD_SAFE_METHOD_ - Joypad js; - js.name = p_connected ? p_name : ""; - js.uid = p_connected ? p_guid : ""; - - if (p_connected) { - - String uidname = p_guid; - if (p_guid == "") { - int uidlen = MIN(p_name.length(), 16); - for (int i = 0; i < uidlen; i++) { - uidname = uidname + _hex_str(p_name[i]); - }; - }; - js.uid = uidname; - js.connected = true; - int mapping = fallback_mapping; - for (int i = 0; i < map_db.size(); i++) { - if (js.uid == map_db[i].uid) { - mapping = i; - js.name = map_db[i].name; - }; - }; - js.mapping = mapping; - } else { - js.connected = false; - for (int i = 0; i < JOY_BUTTON_MAX; i++) { - - if (i < JOY_AXIS_MAX) - set_joy_axis(p_idx, i, 0.0f); - - int c = _combine_device(i, p_idx); - joy_buttons_pressed.erase(c); - }; - }; - joy_names[p_idx] = js; - - emit_signal("joy_connection_changed", p_idx, p_connected); -}; - -Vector3 InputFilter::get_gravity() const { - - _THREAD_SAFE_METHOD_ - return gravity; -} - -Vector3 InputFilter::get_accelerometer() const { - - _THREAD_SAFE_METHOD_ - return accelerometer; -} - -Vector3 InputFilter::get_magnetometer() const { - - _THREAD_SAFE_METHOD_ - return magnetometer; -} - -Vector3 InputFilter::get_gyroscope() const { - - _THREAD_SAFE_METHOD_ - return gyroscope; -} - -void InputFilter::parse_input_event(const Ref &p_event) { - - _parse_input_event_impl(p_event, false); -} - -void InputFilter::_parse_input_event_impl(const Ref &p_event, bool p_is_emulated) { - - // Notes on mouse-touch emulation: - // - Emulated mouse events are parsed, that is, re-routed to this method, so they make the same effects - // as true mouse events. The only difference is the situation is flagged as emulated so they are not - // emulated back to touch events in an endless loop. - // - Emulated touch events are handed right to the main loop (i.e., the SceneTree) because they don't - // require additional handling by this class. - - _THREAD_SAFE_METHOD_ - - Ref k = p_event; - if (k.is_valid() && !k->is_echo() && k->get_keycode() != 0) { - if (k->is_pressed()) - keys_pressed.insert(k->get_keycode()); - else - keys_pressed.erase(k->get_keycode()); - } - - Ref mb = p_event; - - if (mb.is_valid()) { - - if (mb->is_pressed()) { - mouse_button_mask |= (1 << (mb->get_button_index() - 1)); - } else { - mouse_button_mask &= ~(1 << (mb->get_button_index() - 1)); - } - - Point2 pos = mb->get_global_position(); - if (mouse_pos != pos) { - set_mouse_position(pos); - } - - if (event_dispatch_function && emulate_touch_from_mouse && !p_is_emulated && mb->get_button_index() == 1) { - Ref touch_event; - touch_event.instance(); - touch_event->set_pressed(mb->is_pressed()); - touch_event->set_position(mb->get_position()); - event_dispatch_function(touch_event); - } - } - - Ref mm = p_event; - - if (mm.is_valid()) { - - Point2 pos = mm->get_global_position(); - if (mouse_pos != pos) { - set_mouse_position(pos); - } - - if (event_dispatch_function && emulate_touch_from_mouse && !p_is_emulated && mm->get_button_mask() & 1) { - Ref drag_event; - drag_event.instance(); - - drag_event->set_position(mm->get_position()); - drag_event->set_relative(mm->get_relative()); - drag_event->set_speed(mm->get_speed()); - - event_dispatch_function(drag_event); - } - } - - Ref st = p_event; - - if (st.is_valid()) { - - if (st->is_pressed()) { - SpeedTrack &track = touch_speed_track[st->get_index()]; - track.reset(); - } else { - // Since a pointer index may not occur again (OSs may or may not reuse them), - // imperatively remove it from the map to keep no fossil entries in it - touch_speed_track.erase(st->get_index()); - } - - if (emulate_mouse_from_touch) { - - bool translate = false; - if (st->is_pressed()) { - if (mouse_from_touch_index == -1) { - translate = true; - mouse_from_touch_index = st->get_index(); - } - } else { - if (st->get_index() == mouse_from_touch_index) { - translate = true; - mouse_from_touch_index = -1; - } - } - - if (translate) { - Ref button_event; - button_event.instance(); - - button_event->set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE); - button_event->set_position(st->get_position()); - button_event->set_global_position(st->get_position()); - button_event->set_pressed(st->is_pressed()); - button_event->set_button_index(BUTTON_LEFT); - if (st->is_pressed()) { - button_event->set_button_mask(mouse_button_mask | (1 << (BUTTON_LEFT - 1))); - } else { - button_event->set_button_mask(mouse_button_mask & ~(1 << (BUTTON_LEFT - 1))); - } - - _parse_input_event_impl(button_event, true); - } - } - } - - Ref sd = p_event; - - if (sd.is_valid()) { - - SpeedTrack &track = touch_speed_track[sd->get_index()]; - track.update(sd->get_relative()); - sd->set_speed(track.speed); - - if (emulate_mouse_from_touch && sd->get_index() == mouse_from_touch_index) { - - Ref motion_event; - motion_event.instance(); - - motion_event->set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE); - motion_event->set_position(sd->get_position()); - motion_event->set_global_position(sd->get_position()); - motion_event->set_relative(sd->get_relative()); - motion_event->set_speed(sd->get_speed()); - motion_event->set_button_mask(mouse_button_mask); - - _parse_input_event_impl(motion_event, true); - } - } - - Ref jb = p_event; - - if (jb.is_valid()) { - - int c = _combine_device(jb->get_button_index(), jb->get_device()); - - if (jb->is_pressed()) - joy_buttons_pressed.insert(c); - else - joy_buttons_pressed.erase(c); - } - - Ref jm = p_event; - - if (jm.is_valid()) { - set_joy_axis(jm->get_device(), jm->get_axis(), jm->get_axis_value()); - } - - Ref ge = p_event; - - if (ge.is_valid()) { - - if (event_dispatch_function) { - event_dispatch_function(ge); - } - } - - for (const Map::Element *E = InputMap::get_singleton()->get_action_map().front(); E; E = E->next()) { - if (InputMap::get_singleton()->event_is_action(p_event, E->key())) { - - // Save the action's state - if (!p_event->is_echo() && is_action_pressed(E->key()) != p_event->is_action_pressed(E->key())) { - Action action; - action.physics_frame = Engine::get_singleton()->get_physics_frames(); - action.idle_frame = Engine::get_singleton()->get_idle_frames(); - action.pressed = p_event->is_action_pressed(E->key()); - action.strength = 0.f; - action_state[E->key()] = action; - } - action_state[E->key()].strength = p_event->get_action_strength(E->key()); - } - } - - if (event_dispatch_function) - event_dispatch_function(p_event); -} - -void InputFilter::set_joy_axis(int p_device, int p_axis, float p_value) { - - _THREAD_SAFE_METHOD_ - int c = _combine_device(p_axis, p_device); - _joy_axis[c] = p_value; -} - -void InputFilter::start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration) { - _THREAD_SAFE_METHOD_ - if (p_weak_magnitude < 0.f || p_weak_magnitude > 1.f || p_strong_magnitude < 0.f || p_strong_magnitude > 1.f) { - return; - } - VibrationInfo vibration; - vibration.weak_magnitude = p_weak_magnitude; - vibration.strong_magnitude = p_strong_magnitude; - vibration.duration = p_duration; - vibration.timestamp = OS::get_singleton()->get_ticks_usec(); - joy_vibration[p_device] = vibration; -} - -void InputFilter::stop_joy_vibration(int p_device) { - _THREAD_SAFE_METHOD_ - VibrationInfo vibration; - vibration.weak_magnitude = 0; - vibration.strong_magnitude = 0; - vibration.duration = 0; - vibration.timestamp = OS::get_singleton()->get_ticks_usec(); - joy_vibration[p_device] = vibration; -} - -void InputFilter::vibrate_handheld(int p_duration_ms) { - OS::get_singleton()->vibrate_handheld(p_duration_ms); -} - -void InputFilter::set_gravity(const Vector3 &p_gravity) { - - _THREAD_SAFE_METHOD_ - - gravity = p_gravity; -} - -void InputFilter::set_accelerometer(const Vector3 &p_accel) { - - _THREAD_SAFE_METHOD_ - - accelerometer = p_accel; -} - -void InputFilter::set_magnetometer(const Vector3 &p_magnetometer) { - - _THREAD_SAFE_METHOD_ - - magnetometer = p_magnetometer; -} - -void InputFilter::set_gyroscope(const Vector3 &p_gyroscope) { - - _THREAD_SAFE_METHOD_ - - gyroscope = p_gyroscope; -} - -void InputFilter::set_mouse_position(const Point2 &p_posf) { - - mouse_speed_track.update(p_posf - mouse_pos); - mouse_pos = p_posf; -} - -Point2 InputFilter::get_mouse_position() const { - - return mouse_pos; -} -Point2 InputFilter::get_last_mouse_speed() const { - - return mouse_speed_track.speed; -} - -int InputFilter::get_mouse_button_mask() const { - - return mouse_button_mask; // do not trust OS implementation, should remove it - OS::get_singleton()->get_mouse_button_state(); -} - -void InputFilter::warp_mouse_position(const Vector2 &p_to) { - warp_mouse_func(p_to); -} - -Point2i InputFilter::warp_mouse_motion(const Ref &p_motion, const Rect2 &p_rect) { - - // The relative distance reported for the next event after a warp is in the boundaries of the - // size of the rect on that axis, but it may be greater, in which case there's not problem as fmod() - // will warp it, but if the pointer has moved in the opposite direction between the pointer relocation - // and the subsequent event, the reported relative distance will be less than the size of the rect - // and thus fmod() will be disabled for handling the situation. - // And due to this mouse warping mechanism being stateless, we need to apply some heuristics to - // detect the warp: if the relative distance is greater than the half of the size of the relevant rect - // (checked per each axis), it will be considered as the consequence of a former pointer warp. - - const Point2i rel_sgn(p_motion->get_relative().x >= 0.0f ? 1 : -1, p_motion->get_relative().y >= 0.0 ? 1 : -1); - const Size2i warp_margin = p_rect.size * 0.5f; - const Point2i rel_warped( - Math::fmod(p_motion->get_relative().x + rel_sgn.x * warp_margin.x, p_rect.size.x) - rel_sgn.x * warp_margin.x, - Math::fmod(p_motion->get_relative().y + rel_sgn.y * warp_margin.y, p_rect.size.y) - rel_sgn.y * warp_margin.y); - - const Point2i pos_local = p_motion->get_global_position() - p_rect.position; - const Point2i pos_warped(Math::fposmod(pos_local.x, p_rect.size.x), Math::fposmod(pos_local.y, p_rect.size.y)); - if (pos_warped != pos_local) { - warp_mouse_position(pos_warped + p_rect.position); - } - - return rel_warped; -} - -void InputFilter::iteration(float p_step) { -} - -void InputFilter::action_press(const StringName &p_action, float p_strength) { - - Action action; - - action.physics_frame = Engine::get_singleton()->get_physics_frames(); - action.idle_frame = Engine::get_singleton()->get_idle_frames(); - action.pressed = true; - action.strength = p_strength; - - action_state[p_action] = action; -} - -void InputFilter::action_release(const StringName &p_action) { - - Action action; - - action.physics_frame = Engine::get_singleton()->get_physics_frames(); - action.idle_frame = Engine::get_singleton()->get_idle_frames(); - action.pressed = false; - action.strength = 0.f; - - action_state[p_action] = action; -} - -void InputFilter::set_emulate_touch_from_mouse(bool p_emulate) { - - emulate_touch_from_mouse = p_emulate; -} - -bool InputFilter::is_emulating_touch_from_mouse() const { - - return emulate_touch_from_mouse; -} - -// Calling this whenever the game window is focused helps unstucking the "touch mouse" -// if the OS or its abstraction class hasn't properly reported that touch pointers raised -void InputFilter::ensure_touch_mouse_raised() { - - if (mouse_from_touch_index != -1) { - mouse_from_touch_index = -1; - - Ref button_event; - button_event.instance(); - - button_event->set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE); - button_event->set_position(mouse_pos); - button_event->set_global_position(mouse_pos); - button_event->set_pressed(false); - button_event->set_button_index(BUTTON_LEFT); - button_event->set_button_mask(mouse_button_mask & ~(1 << (BUTTON_LEFT - 1))); - - _parse_input_event_impl(button_event, true); - } -} - -void InputFilter::set_emulate_mouse_from_touch(bool p_emulate) { - - emulate_mouse_from_touch = p_emulate; -} - -bool InputFilter::is_emulating_mouse_from_touch() const { - - return emulate_mouse_from_touch; -} - -InputFilter::CursorShape InputFilter::get_default_cursor_shape() const { - - return default_shape; -} - -void InputFilter::set_default_cursor_shape(CursorShape p_shape) { - - if (default_shape == p_shape) - return; - - default_shape = p_shape; - // The default shape is set in Viewport::_gui_input_event. To instantly - // see the shape in the viewport we need to trigger a mouse motion event. - Ref mm; - mm.instance(); - mm->set_position(mouse_pos); - mm->set_global_position(mouse_pos); - parse_input_event(mm); -} - -InputFilter::CursorShape InputFilter::get_current_cursor_shape() const { - - return get_current_cursor_shape_func(); -} - -void InputFilter::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { - if (Engine::get_singleton()->is_editor_hint()) - return; - - set_custom_mouse_cursor_func(p_cursor, p_shape, p_hotspot); -} - -void InputFilter::accumulate_input_event(const Ref &p_event) { - ERR_FAIL_COND(p_event.is_null()); - - if (!use_accumulated_input) { - parse_input_event(p_event); - return; - } - if (!accumulated_events.empty() && accumulated_events.back()->get()->accumulate(p_event)) { - return; //event was accumulated, exit - } - - accumulated_events.push_back(p_event); -} -void InputFilter::flush_accumulated_events() { - - while (accumulated_events.front()) { - parse_input_event(accumulated_events.front()->get()); - accumulated_events.pop_front(); - } -} - -void InputFilter::set_use_accumulated_input(bool p_enable) { - - use_accumulated_input = p_enable; -} - -void InputFilter::release_pressed_events() { - - flush_accumulated_events(); // this is needed to release actions strengths - - keys_pressed.clear(); - joy_buttons_pressed.clear(); - _joy_axis.clear(); - - for (Map::Element *E = action_state.front(); E; E = E->next()) { - if (E->get().pressed) - action_release(E->key()); - } -} - -void InputFilter::set_event_dispatch_function(EventDispatchFunc p_function) { - event_dispatch_function = p_function; -} - -void InputFilter::joy_button(int p_device, int p_button, bool p_pressed) { - - _THREAD_SAFE_METHOD_; - Joypad &joy = joy_names[p_device]; - //printf("got button %i, mapping is %i\n", p_button, joy.mapping); - if (joy.last_buttons[p_button] == p_pressed) { - return; - } - joy.last_buttons[p_button] = p_pressed; - if (joy.mapping == -1) { - _button_event(p_device, p_button, p_pressed); - return; - } - - const Map::Element *el = map_db[joy.mapping].buttons.find(p_button); - if (!el) { - //don't process un-mapped events for now, it could mess things up badly for devices with additional buttons/axis - //return _button_event(p_last_id, p_device, p_button, p_pressed); - return; - } - - JoyEvent map = el->get(); - if (map.type == TYPE_BUTTON) { - //fake additional axis event for triggers - if (map.index == JOY_L2 || map.index == JOY_R2) { - float value = p_pressed ? 1.0f : 0.0f; - int axis = map.index == JOY_L2 ? JOY_ANALOG_L2 : JOY_ANALOG_R2; - _axis_event(p_device, axis, value); - } - _button_event(p_device, map.index, p_pressed); - return; - } - - if (map.type == TYPE_AXIS) { - _axis_event(p_device, map.index, p_pressed ? 1.0 : 0.0); - } - // no event? -} - -void InputFilter::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) { - - _THREAD_SAFE_METHOD_; - - ERR_FAIL_INDEX(p_axis, JOY_AXIS_MAX); - - Joypad &joy = joy_names[p_device]; - - if (joy.last_axis[p_axis] == p_value.value) { - return; - } - - if (p_value.value > joy.last_axis[p_axis]) { - - if (p_value.value < joy.last_axis[p_axis] + joy.filter) { - - return; - } - } else if (p_value.value > joy.last_axis[p_axis] - joy.filter) { - - return; - } - - //when changing direction quickly, insert fake event to release pending inputmap actions - float last = joy.last_axis[p_axis]; - if (p_value.min == 0 && (last < 0.25 || last > 0.75) && (last - 0.5) * (p_value.value - 0.5) < 0) { - JoyAxis jx; - jx.min = p_value.min; - jx.value = p_value.value < 0.5 ? 0.6 : 0.4; - joy_axis(p_device, p_axis, jx); - } else if (ABS(last) > 0.5 && last * p_value.value < 0) { - JoyAxis jx; - jx.min = p_value.min; - jx.value = p_value.value < 0 ? 0.1 : -0.1; - joy_axis(p_device, p_axis, jx); - } - - joy.last_axis[p_axis] = p_value.value; - float val = p_value.min == 0 ? -1.0f + 2.0f * p_value.value : p_value.value; - - if (joy.mapping == -1) { - _axis_event(p_device, p_axis, val); - return; - }; - - const Map::Element *el = map_db[joy.mapping].axis.find(p_axis); - if (!el) { - //return _axis_event(p_last_id, p_device, p_axis, p_value); - return; - }; - - JoyEvent map = el->get(); - - if (map.type == TYPE_BUTTON) { - //send axis event for triggers - if (map.index == JOY_L2 || map.index == JOY_R2) { - float value = p_value.min == 0 ? p_value.value : 0.5f + p_value.value / 2.0f; - int axis = map.index == JOY_L2 ? JOY_ANALOG_L2 : JOY_ANALOG_R2; - _axis_event(p_device, axis, value); - } - - if (map.index == JOY_DPAD_UP || map.index == JOY_DPAD_DOWN) { - bool pressed = p_value.value != 0.0f; - int button = p_value.value < 0 ? JOY_DPAD_UP : JOY_DPAD_DOWN; - - if (!pressed) { - if (joy_buttons_pressed.has(_combine_device(JOY_DPAD_UP, p_device))) { - _button_event(p_device, JOY_DPAD_UP, false); - } - if (joy_buttons_pressed.has(_combine_device(JOY_DPAD_DOWN, p_device))) { - _button_event(p_device, JOY_DPAD_DOWN, false); - } - } - if (pressed == joy_buttons_pressed.has(_combine_device(button, p_device))) { - return; - } - _button_event(p_device, button, true); - return; - } - if (map.index == JOY_DPAD_LEFT || map.index == JOY_DPAD_RIGHT) { - bool pressed = p_value.value != 0.0f; - int button = p_value.value < 0 ? JOY_DPAD_LEFT : JOY_DPAD_RIGHT; - - if (!pressed) { - if (joy_buttons_pressed.has(_combine_device(JOY_DPAD_LEFT, p_device))) { - _button_event(p_device, JOY_DPAD_LEFT, false); - } - if (joy_buttons_pressed.has(_combine_device(JOY_DPAD_RIGHT, p_device))) { - _button_event(p_device, JOY_DPAD_RIGHT, false); - } - } - if (pressed == joy_buttons_pressed.has(_combine_device(button, p_device))) { - return; - } - _button_event(p_device, button, true); - return; - } - float deadzone = p_value.min == 0 ? 0.5f : 0.0f; - bool pressed = p_value.value > deadzone; - if (pressed == joy_buttons_pressed.has(_combine_device(map.index, p_device))) { - // button already pressed or released, this is an axis bounce value - return; - } - _button_event(p_device, map.index, pressed); - return; - } - - if (map.type == TYPE_AXIS) { - - _axis_event(p_device, map.index, val); - return; - } - //printf("invalid mapping\n"); -} - -void InputFilter::joy_hat(int p_device, int p_val) { - - _THREAD_SAFE_METHOD_; - const Joypad &joy = joy_names[p_device]; - - const JoyEvent *map; - - if (joy.mapping == -1) { - map = hat_map_default; - } else { - map = map_db[joy.mapping].hat; - }; - - int cur_val = joy_names[p_device].hat_current; - - if ((p_val & HAT_MASK_UP) != (cur_val & HAT_MASK_UP)) { - _button_event(p_device, map[HAT_UP].index, p_val & HAT_MASK_UP); - } - - if ((p_val & HAT_MASK_RIGHT) != (cur_val & HAT_MASK_RIGHT)) { - _button_event(p_device, map[HAT_RIGHT].index, p_val & HAT_MASK_RIGHT); - } - if ((p_val & HAT_MASK_DOWN) != (cur_val & HAT_MASK_DOWN)) { - _button_event(p_device, map[HAT_DOWN].index, p_val & HAT_MASK_DOWN); - } - if ((p_val & HAT_MASK_LEFT) != (cur_val & HAT_MASK_LEFT)) { - _button_event(p_device, map[HAT_LEFT].index, p_val & HAT_MASK_LEFT); - } - - joy_names[p_device].hat_current = p_val; -} - -void InputFilter::_button_event(int p_device, int p_index, bool p_pressed) { - - Ref ievent; - ievent.instance(); - ievent->set_device(p_device); - ievent->set_button_index(p_index); - ievent->set_pressed(p_pressed); - - parse_input_event(ievent); -} - -void InputFilter::_axis_event(int p_device, int p_axis, float p_value) { - - Ref ievent; - ievent.instance(); - ievent->set_device(p_device); - ievent->set_axis(p_axis); - ievent->set_axis_value(p_value); - - parse_input_event(ievent); -}; - -InputFilter::JoyEvent InputFilter::_find_to_event(String p_to) { - - // string names of the SDL buttons in the same order as input_event.h godot buttons - static const char *buttons[] = { "a", "b", "x", "y", "leftshoulder", "rightshoulder", "lefttrigger", "righttrigger", "leftstick", "rightstick", "back", "start", "dpup", "dpdown", "dpleft", "dpright", "guide", nullptr }; - - static const char *axis[] = { "leftx", "lefty", "rightx", "righty", nullptr }; - - JoyEvent ret; - ret.type = -1; - ret.index = 0; - - int i = 0; - while (buttons[i]) { - - if (p_to == buttons[i]) { - ret.type = TYPE_BUTTON; - ret.index = i; - ret.value = 0; - return ret; - }; - ++i; - }; - - i = 0; - while (axis[i]) { - - if (p_to == axis[i]) { - ret.type = TYPE_AXIS; - ret.index = i; - ret.value = 0; - return ret; - }; - ++i; - }; - - return ret; -}; - -void InputFilter::parse_mapping(String p_mapping) { - - _THREAD_SAFE_METHOD_; - JoyDeviceMapping mapping; - for (int i = 0; i < HAT_MAX; ++i) - mapping.hat[i].index = 1024 + i; - - Vector entry = p_mapping.split(","); - if (entry.size() < 2) { - return; - } - - CharString uid; - uid.resize(17); - - mapping.uid = entry[0]; - mapping.name = entry[1]; - - int idx = 1; - while (++idx < entry.size()) { - - if (entry[idx] == "") - continue; - - String from = entry[idx].get_slice(":", 1).replace(" ", ""); - String to = entry[idx].get_slice(":", 0).replace(" ", ""); - - JoyEvent to_event = _find_to_event(to); - if (to_event.type == -1) - continue; - - String etype = from.substr(0, 1); - if (etype == "a") { - - int aid = from.substr(1, from.length() - 1).to_int(); - mapping.axis[aid] = to_event; - - } else if (etype == "b") { - - int bid = from.substr(1, from.length() - 1).to_int(); - mapping.buttons[bid] = to_event; - - } else if (etype == "h") { - - int hat_value = from.get_slice(".", 1).to_int(); - switch (hat_value) { - case 1: - mapping.hat[HAT_UP] = to_event; - break; - case 2: - mapping.hat[HAT_RIGHT] = to_event; - break; - case 4: - mapping.hat[HAT_DOWN] = to_event; - break; - case 8: - mapping.hat[HAT_LEFT] = to_event; - break; - }; - }; - }; - map_db.push_back(mapping); - //printf("added mapping with uuid %ls\n", mapping.uid.c_str()); -}; - -void InputFilter::add_joy_mapping(String p_mapping, bool p_update_existing) { - parse_mapping(p_mapping); - if (p_update_existing) { - Vector entry = p_mapping.split(","); - String uid = entry[0]; - for (int i = 0; i < joy_names.size(); i++) { - if (uid == joy_names[i].uid) { - joy_names[i].mapping = map_db.size() - 1; - } - } - } -} - -void InputFilter::remove_joy_mapping(String p_guid) { - for (int i = map_db.size() - 1; i >= 0; i--) { - if (p_guid == map_db[i].uid) { - map_db.remove(i); - } - } - for (int i = 0; i < joy_names.size(); i++) { - if (joy_names[i].uid == p_guid) { - joy_names[i].mapping = -1; - } - } -} - -void InputFilter::set_fallback_mapping(String p_guid) { - - for (int i = 0; i < map_db.size(); i++) { - if (map_db[i].uid == p_guid) { - fallback_mapping = i; - return; - } - } -} - -//platforms that use the remapping system can override and call to these ones -bool InputFilter::is_joy_known(int p_device) { - int mapping = joy_names[p_device].mapping; - return mapping != -1 ? (mapping != fallback_mapping) : false; -} - -String InputFilter::get_joy_guid(int p_device) const { - ERR_FAIL_COND_V(!joy_names.has(p_device), ""); - return joy_names[p_device].uid; -} - -Array InputFilter::get_connected_joypads() { - Array ret; - Map::Element *elem = joy_names.front(); - while (elem) { - if (elem->get().connected) { - ret.push_back(elem->key()); - } - elem = elem->next(); - } - return ret; -} - -static const char *_buttons[JOY_BUTTON_MAX] = { - "Face Button Bottom", - "Face Button Right", - "Face Button Left", - "Face Button Top", - "L", - "R", - "L2", - "R2", - "L3", - "R3", - "Select", - "Start", - "DPAD Up", - "DPAD Down", - "DPAD Left", - "DPAD Right" -}; - -static const char *_axes[JOY_AXIS_MAX] = { - "Left Stick X", - "Left Stick Y", - "Right Stick X", - "Right Stick Y", - "", - "", - "L2", - "R2", - "", - "" -}; - -String InputFilter::get_joy_button_string(int p_button) { - ERR_FAIL_INDEX_V(p_button, JOY_BUTTON_MAX, ""); - return _buttons[p_button]; -} - -int InputFilter::get_joy_button_index_from_string(String p_button) { - for (int i = 0; i < JOY_BUTTON_MAX; i++) { - if (p_button == _buttons[i]) { - return i; - } - } - ERR_FAIL_V(-1); -} - -int InputFilter::get_unused_joy_id() { - for (int i = 0; i < JOYPADS_MAX; i++) { - if (!joy_names.has(i) || !joy_names[i].connected) { - return i; - } - } - return -1; -} - -String InputFilter::get_joy_axis_string(int p_axis) { - ERR_FAIL_INDEX_V(p_axis, JOY_AXIS_MAX, ""); - return _axes[p_axis]; -} - -int InputFilter::get_joy_axis_index_from_string(String p_axis) { - for (int i = 0; i < JOY_AXIS_MAX; i++) { - if (p_axis == _axes[i]) { - return i; - } - } - ERR_FAIL_V(-1); -} - -InputFilter::InputFilter() { - - singleton = this; - use_accumulated_input = true; - mouse_button_mask = 0; - mouse_window = 0; - emulate_touch_from_mouse = false; - emulate_mouse_from_touch = false; - mouse_from_touch_index = -1; - event_dispatch_function = nullptr; - default_shape = CURSOR_ARROW; - - hat_map_default[HAT_UP].type = TYPE_BUTTON; - hat_map_default[HAT_UP].index = JOY_DPAD_UP; - hat_map_default[HAT_UP].value = 0; - - hat_map_default[HAT_RIGHT].type = TYPE_BUTTON; - hat_map_default[HAT_RIGHT].index = JOY_DPAD_RIGHT; - hat_map_default[HAT_RIGHT].value = 0; - - hat_map_default[HAT_DOWN].type = TYPE_BUTTON; - hat_map_default[HAT_DOWN].index = JOY_DPAD_DOWN; - hat_map_default[HAT_DOWN].value = 0; - - hat_map_default[HAT_LEFT].type = TYPE_BUTTON; - hat_map_default[HAT_LEFT].index = JOY_DPAD_LEFT; - hat_map_default[HAT_LEFT].value = 0; - - fallback_mapping = -1; - - // Parse default mappings. - { - int i = 0; - while (DefaultControllerMappings::mappings[i]) { - parse_mapping(DefaultControllerMappings::mappings[i++]); - } - } - - // If defined, parse SDL_GAMECONTROLLERCONFIG for possible new mappings/overrides. - String env_mapping = OS::get_singleton()->get_environment("SDL_GAMECONTROLLERCONFIG"); - if (env_mapping != "") { - Vector entries = env_mapping.split("\n"); - for (int i = 0; i < entries.size(); i++) { - if (entries[i] == "") - continue; - parse_mapping(entries[i]); - } - } -} - -////////////////////////////////////////////////////////// diff --git a/core/input/input_filter.h b/core/input/input_filter.h deleted file mode 100644 index 908a005228..0000000000 --- a/core/input/input_filter.h +++ /dev/null @@ -1,337 +0,0 @@ -/*************************************************************************/ -/* input_filter.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef INPUT_H -#define INPUT_H - -#include "core/input/input_event.h" -#include "core/object.h" -#include "core/os/thread_safe.h" - -class InputFilter : public Object { - - GDCLASS(InputFilter, Object); - _THREAD_SAFE_CLASS_ - - static InputFilter *singleton; - -public: - enum MouseMode { - MOUSE_MODE_VISIBLE, - MOUSE_MODE_HIDDEN, - MOUSE_MODE_CAPTURED, - MOUSE_MODE_CONFINED - }; - -#undef CursorShape - enum CursorShape { - CURSOR_ARROW, - CURSOR_IBEAM, - CURSOR_POINTING_HAND, - CURSOR_CROSS, - CURSOR_WAIT, - CURSOR_BUSY, - CURSOR_DRAG, - CURSOR_CAN_DROP, - CURSOR_FORBIDDEN, - CURSOR_VSIZE, - CURSOR_HSIZE, - CURSOR_BDIAGSIZE, - CURSOR_FDIAGSIZE, - CURSOR_MOVE, - CURSOR_VSPLIT, - CURSOR_HSPLIT, - CURSOR_HELP, - CURSOR_MAX - }; - - enum HatMask { - HAT_MASK_CENTER = 0, - HAT_MASK_UP = 1, - HAT_MASK_RIGHT = 2, - HAT_MASK_DOWN = 4, - HAT_MASK_LEFT = 8, - }; - - enum HatDir { - HAT_UP, - HAT_RIGHT, - HAT_DOWN, - HAT_LEFT, - HAT_MAX, - }; - - enum { - JOYPADS_MAX = 16, - }; - - struct JoyAxis { - int min; - float value; - }; - - typedef void (*EventDispatchFunc)(const Ref &p_event); - -private: - int mouse_button_mask; - - Set keys_pressed; - Set joy_buttons_pressed; - Map _joy_axis; - //Map custom_action_press; - Vector3 gravity; - Vector3 accelerometer; - Vector3 magnetometer; - Vector3 gyroscope; - Vector2 mouse_pos; - int64_t mouse_window; - - struct Action { - uint64_t physics_frame; - uint64_t idle_frame; - bool pressed; - float strength; - }; - - Map action_state; - - bool emulate_touch_from_mouse; - bool emulate_mouse_from_touch; - - int mouse_from_touch_index; - - struct VibrationInfo { - float weak_magnitude; - float strong_magnitude; - float duration; // Duration in seconds - uint64_t timestamp; - }; - - Map joy_vibration; - - struct SpeedTrack { - - uint64_t last_tick; - Vector2 speed; - Vector2 accum; - float accum_t; - float min_ref_frame; - float max_ref_frame; - - void update(const Vector2 &p_delta_p); - void reset(); - SpeedTrack(); - }; - - struct Joypad { - StringName name; - StringName uid; - bool connected; - bool last_buttons[JOY_BUTTON_MAX + 19]; //apparently SDL specifies 35 possible buttons on android - float last_axis[JOY_AXIS_MAX]; - float filter; - int last_hat; - int mapping; - int hat_current; - - Joypad() { - for (int i = 0; i < JOY_AXIS_MAX; i++) { - - last_axis[i] = 0.0f; - } - for (int i = 0; i < JOY_BUTTON_MAX + 19; i++) { - - last_buttons[i] = false; - } - connected = false; - last_hat = HAT_MASK_CENTER; - filter = 0.01f; - mapping = -1; - hat_current = 0; - } - }; - - SpeedTrack mouse_speed_track; - Map touch_speed_track; - Map joy_names; - int fallback_mapping; - - CursorShape default_shape; - - enum JoyType { - TYPE_BUTTON, - TYPE_AXIS, - TYPE_HAT, - TYPE_MAX, - }; - - struct JoyEvent { - int type; - int index; - int value; - }; - - struct JoyDeviceMapping { - - String uid; - String name; - Map buttons; - Map axis; - JoyEvent hat[HAT_MAX]; - }; - - JoyEvent hat_map_default[HAT_MAX]; - - Vector map_db; - - JoyEvent _find_to_event(String p_to); - void _button_event(int p_device, int p_index, bool p_pressed); - void _axis_event(int p_device, int p_axis, float p_value); - float _handle_deadzone(int p_device, int p_axis, float p_value); - - void _parse_input_event_impl(const Ref &p_event, bool p_is_emulated); - - List> accumulated_events; - bool use_accumulated_input; - friend class DisplayServer; - - static void (*set_mouse_mode_func)(MouseMode); - static MouseMode (*get_mouse_mode_func)(); - static void (*warp_mouse_func)(const Vector2 &p_to_pos); - - static CursorShape (*get_current_cursor_shape_func)(); - static void (*set_custom_mouse_cursor_func)(const RES &, CursorShape, const Vector2 &); - - EventDispatchFunc event_dispatch_function; - -protected: - static void _bind_methods(); - -public: - void set_mouse_mode(MouseMode p_mode); - MouseMode get_mouse_mode() const; - void get_argument_options(const StringName &p_function, int p_idx, List *r_options) const; - - static InputFilter *get_singleton(); - - bool is_key_pressed(int p_keycode) const; - bool is_mouse_button_pressed(int p_button) const; - bool is_joy_button_pressed(int p_device, int p_button) const; - bool is_action_pressed(const StringName &p_action) const; - bool is_action_just_pressed(const StringName &p_action) const; - bool is_action_just_released(const StringName &p_action) const; - float get_action_strength(const StringName &p_action) const; - - float get_joy_axis(int p_device, int p_axis) const; - String get_joy_name(int p_idx); - Array get_connected_joypads(); - Vector2 get_joy_vibration_strength(int p_device); - float get_joy_vibration_duration(int p_device); - uint64_t get_joy_vibration_timestamp(int p_device); - void joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid = ""); - void parse_joypad_mapping(String p_mapping, bool p_update_existing); - - Vector3 get_gravity() const; - Vector3 get_accelerometer() const; - Vector3 get_magnetometer() const; - Vector3 get_gyroscope() const; - - Point2 get_mouse_position() const; - Point2 get_last_mouse_speed() const; - int get_mouse_button_mask() const; - - void warp_mouse_position(const Vector2 &p_to); - Point2i warp_mouse_motion(const Ref &p_motion, const Rect2 &p_rect); - - void parse_input_event(const Ref &p_event); - - void set_gravity(const Vector3 &p_gravity); - void set_accelerometer(const Vector3 &p_accel); - void set_magnetometer(const Vector3 &p_magnetometer); - void set_gyroscope(const Vector3 &p_gyroscope); - void set_joy_axis(int p_device, int p_axis, float p_value); - - void start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration = 0); - void stop_joy_vibration(int p_device); - void vibrate_handheld(int p_duration_ms = 500); - - void set_mouse_position(const Point2 &p_posf); - - void action_press(const StringName &p_action, float p_strength = 1.f); - void action_release(const StringName &p_action); - - void iteration(float p_step); - - void set_emulate_touch_from_mouse(bool p_emulate); - bool is_emulating_touch_from_mouse() const; - void ensure_touch_mouse_raised(); - - void set_emulate_mouse_from_touch(bool p_emulate); - bool is_emulating_mouse_from_touch() const; - - CursorShape get_default_cursor_shape() const; - void set_default_cursor_shape(CursorShape p_shape); - CursorShape get_current_cursor_shape() const; - void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = InputFilter::CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()); - - void parse_mapping(String p_mapping); - void joy_button(int p_device, int p_button, bool p_pressed); - void joy_axis(int p_device, int p_axis, const JoyAxis &p_value); - void joy_hat(int p_device, int p_val); - - void add_joy_mapping(String p_mapping, bool p_update_existing = false); - void remove_joy_mapping(String p_guid); - - String get_joy_button_string(int p_button); - String get_joy_axis_string(int p_axis); - int get_joy_axis_index_from_string(String p_axis); - int get_joy_button_index_from_string(String p_button); - - int get_unused_joy_id(); - - bool is_joy_known(int p_device); - String get_joy_guid(int p_device) const; - void set_fallback_mapping(String p_guid); - - void accumulate_input_event(const Ref &p_event); - void flush_accumulated_events(); - void set_use_accumulated_input(bool p_enable); - - void release_pressed_events(); - - void set_event_dispatch_function(EventDispatchFunc p_function); - - InputFilter(); -}; - -VARIANT_ENUM_CAST(InputFilter::MouseMode); -VARIANT_ENUM_CAST(InputFilter::CursorShape); - -#endif // INPUT_H diff --git a/core/os/midi_driver.cpp b/core/os/midi_driver.cpp index 985f6f38e5..efd87d3ab6 100644 --- a/core/os/midi_driver.cpp +++ b/core/os/midi_driver.cpp @@ -30,7 +30,7 @@ #include "midi_driver.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/os.h" uint8_t MIDIDriver::last_received_message = 0x00; @@ -117,7 +117,7 @@ void MIDIDriver::receive_input_packet(uint64_t timestamp, uint8_t *data, uint32_ break; } - InputFilter *id = InputFilter::get_singleton(); + Input *id = Input::get_singleton(); id->parse_input_event(event); } diff --git a/core/os/os.cpp b/core/os/os.cpp index 0636810e4b..425132fbec 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -30,7 +30,7 @@ #include "os.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/dir_access.h" #include "core/os/file_access.h" #include "core/os/midi_driver.h" diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index 905f43d61b..23f549be1a 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -38,7 +38,7 @@ #include "core/crypto/hashing_context.h" #include "core/engine.h" #include "core/func_ref.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/input/input_map.h" #include "core/io/config_file.h" #include "core/io/dtls_server.h" @@ -249,7 +249,7 @@ void register_core_singletons() { ClassDB::register_class<_ClassDB>(); ClassDB::register_class<_Marshalls>(); ClassDB::register_class(); - ClassDB::register_virtual_class(); + ClassDB::register_virtual_class(); ClassDB::register_class(); ClassDB::register_class<_JSON>(); ClassDB::register_class(); @@ -264,7 +264,7 @@ void register_core_singletons() { Engine::get_singleton()->add_singleton(Engine::Singleton("ClassDB", _classdb)); Engine::get_singleton()->add_singleton(Engine::Singleton("Marshalls", _Marshalls::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("TranslationServer", TranslationServer::get_singleton())); - Engine::get_singleton()->add_singleton(Engine::Singleton("Input", InputFilter::get_singleton())); + Engine::get_singleton()->add_singleton(Engine::Singleton("Input", Input::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("InputMap", InputMap::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("JSON", _JSON::get_singleton())); } diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index 602d0e4d0e..47b9c80f3f 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -33,8 +33,8 @@ The [IP] singleton. - - The [InputFilter] singleton. + + The [Input] singleton. The [InputMap] singleton. diff --git a/doc/classes/Input.xml b/doc/classes/Input.xml new file mode 100644 index 0000000000..0f212e7498 --- /dev/null +++ b/doc/classes/Input.xml @@ -0,0 +1,477 @@ + + + + A singleton that deals with inputs. + + + A singleton that deals with inputs. This includes key presses, mouse buttons and movement, joypads, and input actions. Actions and their events can be set in the [b]Input Map[/b] tab in the [b]Project > Project Settings[/b], or with the [InputMap] class. + + + https://docs.godotengine.org/en/latest/tutorials/inputs/index.html + + + + + + + + + + + This will simulate pressing the specified action. + The strength can be used for non-boolean actions, it's ranged between 0 and 1 representing the intensity of the given action. + [b]Note:[/b] This method will not cause any [method Node._input] calls. It is intended to be used with [method is_action_pressed] and [method is_action_just_pressed]. If you want to simulate [code]_input[/code], use [method parse_input_event] instead. + + + + + + + + + If the specified action is already pressed, this will release it. + + + + + + + + + + + Adds a new mapping entry (in SDL2 format) to the mapping database. Optionally update already connected devices. + + + + + + + If the device has an accelerometer, this will return the acceleration. Otherwise, it returns an empty [Vector3]. + Note this method returns an empty [Vector3] when running from the editor even when your device has an accelerometer. You must export your project to a supported device to read values from the accelerometer. + + + + + + + + + Returns a value between 0 and 1 representing the intensity of the given action. In a joypad, for example, the further away the axis (analog sticks or L2, R2 triggers) is from the dead zone, the closer the value will be to 1. If the action is mapped to a control that has no axis as the keyboard, the value returned will be 0 or 1. + + + + + + + Returns an [Array] containing the device IDs of all currently connected joypads. + + + + + + + Returns the currently assigned cursor shape (see [enum CursorShape]). + + + + + + + If the device has an accelerometer, this will return the gravity. Otherwise, it returns an empty [Vector3]. + + + + + + + If the device has a gyroscope, this will return the rate of rotation in rad/s around a device's X, Y, and Z axes. Otherwise, it returns an empty [Vector3]. + + + + + + + + + + + Returns the current value of the joypad axis at given index (see [enum JoystickList]). + + + + + + + + + Returns the index of the provided axis name. + + + + + + + + + Receives a [enum JoystickList] axis and returns its equivalent name as a string. + + + + + + + + + Returns the index of the provided button name. + + + + + + + + + Receives a gamepad button from [enum JoystickList] and returns its equivalent name as a string. + + + + + + + + + Returns a SDL2-compatible device GUID on platforms that use gamepad remapping. Returns [code]"Default Gamepad"[/code] otherwise. + + + + + + + + + Returns the name of the joypad at the specified device index. + + + + + + + + + Returns the duration of the current vibration effect in seconds. + + + + + + + + + Returns the strength of the joypad vibration: x is the strength of the weak motor, and y is the strength of the strong motor. + + + + + + + Returns the mouse speed for the last time the cursor was moved, and this until the next frame where the mouse moves. This means that even if the mouse is not moving, this function will still return the value of the last motion. + + + + + + + If the device has a magnetometer, this will return the magnetic field strength in micro-Tesla for all axes. + + + + + + + Returns mouse buttons as a bitmask. If multiple mouse buttons are pressed at the same time, the bits are added together. + + + + + + + Returns the mouse mode. See the constants for more information. + + + + + + + + + Returns [code]true[/code] when the user starts pressing the action event, meaning it's [code]true[/code] only on the frame that the user pressed down the button. + This is useful for code that needs to run only once when an action is pressed, instead of every frame while it's pressed. + + + + + + + + + Returns [code]true[/code] when the user stops pressing the action event, meaning it's [code]true[/code] only on the frame that the user released the button. + + + + + + + + + Returns [code]true[/code] if you are pressing the action event. Note that if an action has multiple buttons assigned and more than one of them is pressed, releasing one button will release the action, even if some other button assigned to this action is still pressed. + + + + + + + + + + + Returns [code]true[/code] if you are pressing the joypad button (see [enum JoystickList]). + + + + + + + + + Returns [code]true[/code] if the system knows the specified device. This means that it sets all button and axis indices exactly as defined in [enum JoystickList]. Unknown joypads are not expected to match these constants, but you can still retrieve events from them. + + + + + + + + + Returns [code]true[/code] if you are pressing the key in the current keyboard layout. You can pass a [enum KeyList] constant. + + + + + + + + + Returns [code]true[/code] if you are pressing the mouse button specified with [enum ButtonList]. + + + + + + + + + + + + + + + Notifies the [Input] singleton that a connection has changed, to update the state for the [code]device[/code] index. + This is used internally and should not have to be called from user scripts. See [signal joy_connection_changed] for the signal emitted when this is triggered internally. + + + + + + + + + Feeds an [InputEvent] to the game. Can be used to artificially trigger input events from code. Also generates [method Node._input] calls. + Example: + [codeblock] + var a = InputEventAction.new() + a.action = "ui_cancel" + a.pressed = true + Input.parse_input_event(a) + [/codeblock] + + + + + + + + + Removes all mappings from the internal database that match the given GUID. + + + + + + + + + + + + + Sets a custom mouse cursor image, which is only visible inside the game window. The hotspot can also be specified. Passing [code]null[/code] to the image parameter resets to the system cursor. See [enum CursorShape] for the list of shapes. + [code]image[/code]'s size must be lower than 256×256. + [code]hotspot[/code] must be within [code]image[/code]'s size. + [b]Note:[/b] [AnimatedTexture]s aren't supported as custom mouse cursors. If using an [AnimatedTexture], only the first frame will be displayed. + [b]Note:[/b] Only images imported with the [b]Lossless[/b], [b]Lossy[/b] or [b]Uncompressed[/b] compression modes are supported. The [b]Video RAM[/b] compression mode can't be used for custom cursors. + + + + + + + + + Sets the default cursor shape to be used in the viewport instead of [constant CURSOR_ARROW]. + [b]Note:[/b] If you want to change the default cursor shape for [Control]'s nodes, use [member Control.mouse_default_cursor_shape] instead. + [b]Note:[/b] This method generates an [InputEventMouseMotion] to update cursor immediately. + + + + + + + + + Sets the mouse mode. See the constants for more information. + + + + + + + + + Enables or disables the accumulation of similar input events sent by the operating system. When input accumulation is enabled, all input events generated during a frame will be merged and emitted when the frame is done rendering. Therefore, this limits the number of input method calls per second to the rendering FPS. + Input accumulation is enabled by default. It can be disabled to get slightly more precise/reactive input at the cost of increased CPU usage. In applications where drawing freehand lines is required, input accumulation should generally be disabled while the user is drawing the line to get results that closely follow the actual input. + + + + + + + + + + + + + + + Starts to vibrate the joypad. Joypads usually come with two rumble motors, a strong and a weak one. [code]weak_magnitude[/code] is the strength of the weak motor (between 0 and 1) and [code]strong_magnitude[/code] is the strength of the strong motor (between 0 and 1). [code]duration[/code] is the duration of the effect in seconds (a duration of 0 will try to play the vibration indefinitely). + [b]Note:[/b] Not every hardware is compatible with long effect durations; it is recommended to restart an effect if it has to be played for more than a few seconds. + + + + + + + + + Stops the vibration of the joypad. + + + + + + + + + Vibrate Android and iOS devices. + [b]Note:[/b] It needs VIBRATE permission for Android at export settings. iOS does not support duration. + + + + + + + + + Sets the mouse position to the specified vector. + + + + + + + + + + + Emitted when a joypad device has been connected or disconnected. + + + + + + Makes the mouse cursor visible if it is hidden. + + + Makes the mouse cursor hidden if it is visible. + + + Captures the mouse. The mouse will be hidden and unable to leave the game window, but it will still register movement and mouse button presses. On Windows and Linux, the mouse will use raw input mode, which means the reported movement will be unaffected by the OS' mouse acceleration settings. + + + Makes the mouse cursor visible but confines it to the game window. + + + Arrow cursor. Standard, default pointing cursor. + + + I-beam cursor. Usually used to show where the text cursor will appear when the mouse is clicked. + + + Pointing hand cursor. Usually used to indicate the pointer is over a link or other interactable item. + + + Cross cursor. Typically appears over regions in which a drawing operation can be performed or for selections. + + + Wait cursor. Indicates that the application is busy performing an operation. This cursor shape denotes that the application is still usable during the operation. + + + Busy cursor. Indicates that the application is busy performing an operation. This cursor shape denotes that the application isn't usable during the operation (e.g. something is blocking its main thread). + + + Drag cursor. Usually displayed when dragging something. + + + Can drop cursor. Usually displayed when dragging something to indicate that it can be dropped at the current position. + + + Forbidden cursor. Indicates that the current action is forbidden (for example, when dragging something) or that the control at a position is disabled. + + + Vertical resize mouse cursor. A double-headed vertical arrow. It tells the user they can resize the window or the panel vertically. + + + Horizontal resize mouse cursor. A double-headed horizontal arrow. It tells the user they can resize the window or the panel horizontally. + + + Window resize mouse cursor. The cursor is a double-headed arrow that goes from the bottom left to the top right. It tells the user they can resize the window or the panel both horizontally and vertically. + + + Window resize mouse cursor. The cursor is a double-headed arrow that goes from the top left to the bottom right, the opposite of [constant CURSOR_BDIAGSIZE]. It tells the user they can resize the window or the panel both horizontally and vertically. + + + Move cursor. Indicates that something can be moved. + + + Vertical split mouse cursor. On Windows, it's the same as [constant CURSOR_VSIZE]. + + + Horizontal split mouse cursor. On Windows, it's the same as [constant CURSOR_HSIZE]. + + + Help cursor. Usually a question mark. + + + diff --git a/doc/classes/InputFilter.xml b/doc/classes/InputFilter.xml deleted file mode 100644 index 54184ae8a3..0000000000 --- a/doc/classes/InputFilter.xml +++ /dev/null @@ -1,477 +0,0 @@ - - - - A singleton that deals with inputs. - - - A singleton that deals with inputs. This includes key presses, mouse buttons and movement, joypads, and input actions. Actions and their events can be set in the [b]Input Map[/b] tab in the [b]Project > Project Settings[/b], or with the [InputMap] class. - - - https://docs.godotengine.org/en/latest/tutorials/inputs/index.html - - - - - - - - - - - This will simulate pressing the specified action. - The strength can be used for non-boolean actions, it's ranged between 0 and 1 representing the intensity of the given action. - [b]Note:[/b] This method will not cause any [method Node._input] calls. It is intended to be used with [method is_action_pressed] and [method is_action_just_pressed]. If you want to simulate [code]_input[/code], use [method parse_input_event] instead. - - - - - - - - - If the specified action is already pressed, this will release it. - - - - - - - - - - - Adds a new mapping entry (in SDL2 format) to the mapping database. Optionally update already connected devices. - - - - - - - If the device has an accelerometer, this will return the acceleration. Otherwise, it returns an empty [Vector3]. - Note this method returns an empty [Vector3] when running from the editor even when your device has an accelerometer. You must export your project to a supported device to read values from the accelerometer. - - - - - - - - - Returns a value between 0 and 1 representing the intensity of the given action. In a joypad, for example, the further away the axis (analog sticks or L2, R2 triggers) is from the dead zone, the closer the value will be to 1. If the action is mapped to a control that has no axis as the keyboard, the value returned will be 0 or 1. - - - - - - - Returns an [Array] containing the device IDs of all currently connected joypads. - - - - - - - Returns the currently assigned cursor shape (see [enum CursorShape]). - - - - - - - If the device has an accelerometer, this will return the gravity. Otherwise, it returns an empty [Vector3]. - - - - - - - If the device has a gyroscope, this will return the rate of rotation in rad/s around a device's X, Y, and Z axes. Otherwise, it returns an empty [Vector3]. - - - - - - - - - - - Returns the current value of the joypad axis at given index (see [enum JoystickList]). - - - - - - - - - Returns the index of the provided axis name. - - - - - - - - - Receives a [enum JoystickList] axis and returns its equivalent name as a string. - - - - - - - - - Returns the index of the provided button name. - - - - - - - - - Receives a gamepad button from [enum JoystickList] and returns its equivalent name as a string. - - - - - - - - - Returns a SDL2-compatible device GUID on platforms that use gamepad remapping. Returns [code]"Default Gamepad"[/code] otherwise. - - - - - - - - - Returns the name of the joypad at the specified device index. - - - - - - - - - Returns the duration of the current vibration effect in seconds. - - - - - - - - - Returns the strength of the joypad vibration: x is the strength of the weak motor, and y is the strength of the strong motor. - - - - - - - Returns the mouse speed for the last time the cursor was moved, and this until the next frame where the mouse moves. This means that even if the mouse is not moving, this function will still return the value of the last motion. - - - - - - - If the device has a magnetometer, this will return the magnetic field strength in micro-Tesla for all axes. - - - - - - - Returns mouse buttons as a bitmask. If multiple mouse buttons are pressed at the same time, the bits are added together. - - - - - - - Returns the mouse mode. See the constants for more information. - - - - - - - - - Returns [code]true[/code] when the user starts pressing the action event, meaning it's [code]true[/code] only on the frame that the user pressed down the button. - This is useful for code that needs to run only once when an action is pressed, instead of every frame while it's pressed. - - - - - - - - - Returns [code]true[/code] when the user stops pressing the action event, meaning it's [code]true[/code] only on the frame that the user released the button. - - - - - - - - - Returns [code]true[/code] if you are pressing the action event. Note that if an action has multiple buttons assigned and more than one of them is pressed, releasing one button will release the action, even if some other button assigned to this action is still pressed. - - - - - - - - - - - Returns [code]true[/code] if you are pressing the joypad button (see [enum JoystickList]). - - - - - - - - - Returns [code]true[/code] if the system knows the specified device. This means that it sets all button and axis indices exactly as defined in [enum JoystickList]. Unknown joypads are not expected to match these constants, but you can still retrieve events from them. - - - - - - - - - Returns [code]true[/code] if you are pressing the key in the current keyboard layout. You can pass a [enum KeyList] constant. - - - - - - - - - Returns [code]true[/code] if you are pressing the mouse button specified with [enum ButtonList]. - - - - - - - - - - - - - - - Notifies the [InputFilter] singleton that a connection has changed, to update the state for the [code]device[/code] index. - This is used internally and should not have to be called from user scripts. See [signal joy_connection_changed] for the signal emitted when this is triggered internally. - - - - - - - - - Feeds an [InputEvent] to the game. Can be used to artificially trigger input events from code. Also generates [method Node._input] calls. - Example: - [codeblock] - var a = InputEventAction.new() - a.action = "ui_cancel" - a.pressed = true - InputFilter.parse_input_event(a) - [/codeblock] - - - - - - - - - Removes all mappings from the internal database that match the given GUID. - - - - - - - - - - - - - Sets a custom mouse cursor image, which is only visible inside the game window. The hotspot can also be specified. Passing [code]null[/code] to the image parameter resets to the system cursor. See [enum CursorShape] for the list of shapes. - [code]image[/code]'s size must be lower than 256×256. - [code]hotspot[/code] must be within [code]image[/code]'s size. - [b]Note:[/b] [AnimatedTexture]s aren't supported as custom mouse cursors. If using an [AnimatedTexture], only the first frame will be displayed. - [b]Note:[/b] Only images imported with the [b]Lossless[/b], [b]Lossy[/b] or [b]Uncompressed[/b] compression modes are supported. The [b]Video RAM[/b] compression mode can't be used for custom cursors. - - - - - - - - - Sets the default cursor shape to be used in the viewport instead of [constant CURSOR_ARROW]. - [b]Note:[/b] If you want to change the default cursor shape for [Control]'s nodes, use [member Control.mouse_default_cursor_shape] instead. - [b]Note:[/b] This method generates an [InputEventMouseMotion] to update cursor immediately. - - - - - - - - - Sets the mouse mode. See the constants for more information. - - - - - - - - - Enables or disables the accumulation of similar input events sent by the operating system. When input accumulation is enabled, all input events generated during a frame will be merged and emitted when the frame is done rendering. Therefore, this limits the number of input method calls per second to the rendering FPS. - Input accumulation is enabled by default. It can be disabled to get slightly more precise/reactive input at the cost of increased CPU usage. In applications where drawing freehand lines is required, input accumulation should generally be disabled while the user is drawing the line to get results that closely follow the actual input. - - - - - - - - - - - - - - - Starts to vibrate the joypad. Joypads usually come with two rumble motors, a strong and a weak one. [code]weak_magnitude[/code] is the strength of the weak motor (between 0 and 1) and [code]strong_magnitude[/code] is the strength of the strong motor (between 0 and 1). [code]duration[/code] is the duration of the effect in seconds (a duration of 0 will try to play the vibration indefinitely). - [b]Note:[/b] Not every hardware is compatible with long effect durations; it is recommended to restart an effect if it has to be played for more than a few seconds. - - - - - - - - - Stops the vibration of the joypad. - - - - - - - - - Vibrate Android and iOS devices. - [b]Note:[/b] It needs VIBRATE permission for Android at export settings. iOS does not support duration. - - - - - - - - - Sets the mouse position to the specified vector. - - - - - - - - - - - Emitted when a joypad device has been connected or disconnected. - - - - - - Makes the mouse cursor visible if it is hidden. - - - Makes the mouse cursor hidden if it is visible. - - - Captures the mouse. The mouse will be hidden and unable to leave the game window, but it will still register movement and mouse button presses. On Windows and Linux, the mouse will use raw input mode, which means the reported movement will be unaffected by the OS' mouse acceleration settings. - - - Makes the mouse cursor visible but confines it to the game window. - - - Arrow cursor. Standard, default pointing cursor. - - - I-beam cursor. Usually used to show where the text cursor will appear when the mouse is clicked. - - - Pointing hand cursor. Usually used to indicate the pointer is over a link or other interactable item. - - - Cross cursor. Typically appears over regions in which a drawing operation can be performed or for selections. - - - Wait cursor. Indicates that the application is busy performing an operation. This cursor shape denotes that the application is still usable during the operation. - - - Busy cursor. Indicates that the application is busy performing an operation. This cursor shape denotes that the application isn't usable during the operation (e.g. something is blocking its main thread). - - - Drag cursor. Usually displayed when dragging something. - - - Can drop cursor. Usually displayed when dragging something to indicate that it can be dropped at the current position. - - - Forbidden cursor. Indicates that the current action is forbidden (for example, when dragging something) or that the control at a position is disabled. - - - Vertical resize mouse cursor. A double-headed vertical arrow. It tells the user they can resize the window or the panel vertically. - - - Horizontal resize mouse cursor. A double-headed horizontal arrow. It tells the user they can resize the window or the panel horizontally. - - - Window resize mouse cursor. The cursor is a double-headed arrow that goes from the bottom left to the top right. It tells the user they can resize the window or the panel both horizontally and vertically. - - - Window resize mouse cursor. The cursor is a double-headed arrow that goes from the top left to the bottom right, the opposite of [constant CURSOR_BDIAGSIZE]. It tells the user they can resize the window or the panel both horizontally and vertically. - - - Move cursor. Indicates that something can be moved. - - - Vertical split mouse cursor. On Windows, it's the same as [constant CURSOR_VSIZE]. - - - Horizontal split mouse cursor. On Windows, it's the same as [constant CURSOR_HSIZE]. - - - Help cursor. Usually a question mark. - - - diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index b7c8769f64..09f55bea0c 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -31,7 +31,7 @@ #include "animation_track_editor.h" #include "animation_track_editor_plugins.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/keyboard.h" #include "editor/animation_bezier_editor.h" #include "editor/plugins/animation_player_editor_plugin.h" @@ -4103,7 +4103,7 @@ bool AnimationTrackEditor::is_selection_active() const { } bool AnimationTrackEditor::is_snap_enabled() const { - return snap->is_pressed() ^ InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL); + return snap->is_pressed() ^ Input::get_singleton()->is_key_pressed(KEY_CONTROL); } void AnimationTrackEditor::_update_tracks() { diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 77e20b971c..987d5649b1 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -30,7 +30,7 @@ #include "code_editor.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/keyboard.h" #include "core/string_builder.h" #include "editor/editor_scale.h" @@ -513,7 +513,7 @@ void FindReplaceBar::_search_text_changed(const String &p_text) { void FindReplaceBar::_search_text_entered(const String &p_text) { - if (InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) { + if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { search_prev(); } else { search_next(); @@ -525,7 +525,7 @@ void FindReplaceBar::_replace_text_entered(const String &p_text) { if (selection_only->is_pressed() && text_edit->is_selection_active()) { _replace_all(); _hide_bar(); - } else if (InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) { + } else if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { _replace(); search_prev(); } else { diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index 7e499facd5..c80ae5f21b 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -30,7 +30,7 @@ #include "editor_audio_buses.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/io/resource_saver.h" #include "core/os/keyboard.h" #include "editor_node.h" @@ -325,7 +325,7 @@ void EditorAudioBus::_volume_changed(float p_normalized) { const float p_db = this->_normalized_volume_to_scaled_db(p_normalized); - if (InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL)) { + if (Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { // Snap the value when holding Ctrl for easier editing. // To do so, it needs to be converted back to normalized volume (as the slider uses that unit). slider->set_value(_scaled_db_to_normalized_volume(Math::round(p_db))); @@ -386,7 +386,7 @@ float EditorAudioBus::_scaled_db_to_normalized_volume(float db) { void EditorAudioBus::_show_value(float slider_value) { float db; - if (InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL)) { + if (Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { // Display the correct (snapped) value when holding Ctrl db = Math::round(_normalized_volume_to_scaled_db(slider_value)); } else { diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index bad70d9714..050b0a5f33 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -30,7 +30,7 @@ #include "editor_help.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/keyboard.h" #include "doc_data_compressed.gen.h" #include "editor/plugins/script_editor_plugin.h" @@ -1844,7 +1844,7 @@ void FindBar::_search_text_changed(const String &p_text) { void FindBar::_search_text_entered(const String &p_text) { - if (InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) { + if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { search_prev(); } else { search_next(); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 3569cd411d..c4584e3dfb 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -32,7 +32,7 @@ #include "core/bind/core_bind.h" #include "core/class_db.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/io/config_file.h" #include "core/io/image_loader.h" #include "core/io/resource_loader.h" @@ -2366,7 +2366,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { case EDIT_UNDO: { - if (InputFilter::get_singleton()->get_mouse_button_mask() & 0x7) { + if (Input::get_singleton()->get_mouse_button_mask() & 0x7) { log->add_message("Can't undo while mouse buttons are pressed.", EditorLog::MSG_TYPE_EDITOR); } else { String action = editor_data.get_undo_redo().get_current_action_name(); @@ -2380,7 +2380,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case EDIT_REDO: { - if (InputFilter::get_singleton()->get_mouse_button_mask() & 0x7) { + if (Input::get_singleton()->get_mouse_button_mask() & 0x7) { log->add_message("Can't redo while mouse buttons are pressed.", EditorLog::MSG_TYPE_EDITOR); } else { if (!editor_data.get_undo_redo().redo()) { @@ -5566,7 +5566,7 @@ int EditorNode::execute_and_show_output(const String &p_title, const String &p_p EditorNode::EditorNode() { - InputFilter::get_singleton()->set_use_accumulated_input(true); + Input::get_singleton()->set_use_accumulated_input(true); Resource::_get_local_scene_func = _resource_get_edited_scene; RenderingServer::get_singleton()->set_debug_generate_wireframes(true); @@ -5582,7 +5582,7 @@ EditorNode::EditorNode() { ResourceLoader::clear_translation_remaps(); //no remaps using during editor ResourceLoader::clear_path_remaps(); - InputFilter *id = InputFilter::get_singleton(); + Input *id = Input::get_singleton(); if (id) { @@ -5593,7 +5593,7 @@ EditorNode::EditorNode() { } } - if (!found_touchscreen && InputFilter::get_singleton()) { + if (!found_touchscreen && Input::get_singleton()) { //only if no touchscreen ui hint, set emulation id->set_emulate_touch_from_mouse(false); //just disable just in case } diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index 4eefe844d2..1506c574dd 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -30,7 +30,7 @@ #include "editor_spin_slider.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/math/expression.h" #include "editor_node.h" #include "editor_scale.h" @@ -68,7 +68,7 @@ void EditorSpinSlider::_gui_input(const Ref &p_event) { grabbing_spinner_dist_cache = 0; pre_grab_value = get_value(); grabbing_spinner = false; - grabbing_spinner_mouse_pos = InputFilter::get_singleton()->get_mouse_position(); + grabbing_spinner_mouse_pos = Input::get_singleton()->get_mouse_position(); } } else { @@ -76,8 +76,8 @@ void EditorSpinSlider::_gui_input(const Ref &p_event) { if (grabbing_spinner) { - InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_VISIBLE); - InputFilter::get_singleton()->warp_mouse_position(grabbing_spinner_mouse_pos); + Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); + Input::get_singleton()->warp_mouse_position(grabbing_spinner_mouse_pos); update(); } else { _focus_entered(); @@ -106,7 +106,7 @@ void EditorSpinSlider::_gui_input(const Ref &p_event) { grabbing_spinner_dist_cache += diff_x; if (!grabbing_spinner && ABS(grabbing_spinner_dist_cache) > 4 * EDSCALE) { - InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_CAPTURED); + Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED); grabbing_spinner = true; } @@ -181,7 +181,7 @@ void EditorSpinSlider::_notification(int p_what) { p_what == NOTIFICATION_WM_FOCUS_IN || p_what == NOTIFICATION_EXIT_TREE) { if (grabbing_spinner) { - InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_VISIBLE); + Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); grabbing_spinner = false; grabbing_spinner_attempt = false; } @@ -298,7 +298,7 @@ void EditorSpinSlider::_notification(int p_what) { grabber->set_position(get_global_position() + grabber_rect.position + grabber_rect.size * 0.5 - grabber->get_size() * 0.5); if (mousewheel_over_grabber) { - InputFilter::get_singleton()->warp_mouse_position(grabber->get_position() + grabber_rect.size); + Input::get_singleton()->warp_mouse_position(grabber->get_position() + grabber_rect.size); } grabber_range = width; @@ -317,7 +317,7 @@ void EditorSpinSlider::_notification(int p_what) { update(); } if (p_what == NOTIFICATION_FOCUS_ENTER) { - if ((InputFilter::get_singleton()->is_action_pressed("ui_focus_next") || InputFilter::get_singleton()->is_action_pressed("ui_focus_prev")) && !value_input_just_closed) { + if ((Input::get_singleton()->is_action_pressed("ui_focus_next") || Input::get_singleton()->is_action_pressed("ui_focus_prev")) && !value_input_just_closed) { _focus_entered(); } value_input_just_closed = false; diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp index 7cb18432a7..f0ee5d451f 100644 --- a/editor/export_template_manager.cpp +++ b/editor/export_template_manager.cpp @@ -30,7 +30,7 @@ #include "export_template_manager.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/io/json.h" #include "core/io/zip_io.h" #include "core/os/dir_access.h" @@ -446,7 +446,7 @@ void ExportTemplateManager::_http_download_templates_completed(int p_status, int void ExportTemplateManager::_begin_template_download(const String &p_url) { - if (InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) { + if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { OS::get_singleton()->shell_open(p_url); return; } diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp index 4343535eb6..17cb68df3a 100644 --- a/editor/plugins/animation_blend_space_2d_editor.cpp +++ b/editor/plugins/animation_blend_space_2d_editor.cpp @@ -30,7 +30,7 @@ #include "animation_blend_space_2d_editor.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/io/resource_loader.h" #include "core/math/delaunay.h" #include "core/os/keyboard.h" diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 54c60aba71..23e547f55d 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -30,7 +30,7 @@ #include "animation_blend_tree_editor_plugin.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/io/resource_loader.h" #include "core/os/keyboard.h" #include "core/project_settings.h" diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index d96a3b0bab..db51c5c6ba 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -30,7 +30,7 @@ #include "animation_player_editor_plugin.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/io/resource_loader.h" #include "core/io/resource_saver.h" #include "core/os/keyboard.h" @@ -488,7 +488,7 @@ double AnimationPlayerEditor::_get_editor_step() const { ERR_FAIL_COND_V(!anim.is_valid(), 0.0); // Use more precise snapping when holding Shift - return InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT) ? anim->get_step() * 0.25 : anim->get_step(); + return Input::get_singleton()->is_key_pressed(KEY_SHIFT) ? anim->get_step() * 0.25 : anim->get_step(); } return 0.0; diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index c06f62a8c1..c28f533958 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -30,7 +30,7 @@ #include "animation_state_machine_editor.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/io/resource_loader.h" #include "core/math/delaunay.h" #include "core/os/keyboard.h" diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp index e771c5610f..9452c0f11b 100644 --- a/editor/plugins/animation_tree_editor_plugin.cpp +++ b/editor/plugins/animation_tree_editor_plugin.cpp @@ -34,7 +34,7 @@ #include "animation_blend_space_2d_editor.h" #include "animation_blend_tree_editor_plugin.h" #include "animation_state_machine_editor.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/io/resource_loader.h" #include "core/math/delaunay.h" #include "core/os/keyboard.h" diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index 14c44b7973..bb5147972c 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -30,7 +30,7 @@ #include "asset_library_editor_plugin.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/io/json.h" #include "core/os/keyboard.h" #include "core/version.h" diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index cd3df08276..79111762b2 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -30,7 +30,7 @@ #include "canvas_item_editor_plugin.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/keyboard.h" #include "core/print_string.h" #include "core/project_settings.h" @@ -334,7 +334,7 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, unsig snap_target[0] = SNAP_TARGET_NONE; snap_target[1] = SNAP_TARGET_NONE; - bool is_snap_active = smart_snap_active ^ InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL); + bool is_snap_active = smart_snap_active ^ Input::get_singleton()->is_key_pressed(KEY_CONTROL); // Smart snap using the canvas position Vector2 output = p_target; @@ -462,7 +462,7 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, unsig } float CanvasItemEditor::snap_angle(float p_target, float p_start) const { - if (((smart_snap_active || snap_rotation) ^ InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL)) && snap_rotation_step != 0) { + if (((smart_snap_active || snap_rotation) ^ Input::get_singleton()->is_key_pressed(KEY_CONTROL)) && snap_rotation_step != 0) { if (snap_relative) { return Math::stepify(p_target - snap_rotation_offset, snap_rotation_step) + snap_rotation_offset + (p_start - (int)(p_start / snap_rotation_step) * snap_rotation_step); } else { @@ -1284,7 +1284,7 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref &p_event, bo // Pan the viewport Point2i relative; if (bool(EditorSettings::get_singleton()->get("editors/2d/warped_mouse_panning"))) { - relative = InputFilter::get_singleton()->warp_mouse_motion(m, viewport->get_global_rect()); + relative = Input::get_singleton()->warp_mouse_motion(m, viewport->get_global_rect()); } else { relative = m->get_relative(); } @@ -1912,7 +1912,7 @@ bool CanvasItemEditor::_gui_input_scale(const Ref &p_event) { Transform2D simple_xform = (viewport->get_transform() * unscaled_transform).affine_inverse() * transform; bool uniform = m->get_shift(); - bool is_ctrl = InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL); + bool is_ctrl = Input::get_singleton()->is_key_pressed(KEY_CONTROL); Point2 drag_from_local = simple_xform.xform(drag_from); Point2 drag_to_local = simple_xform.xform(drag_to); @@ -2214,10 +2214,10 @@ bool CanvasItemEditor::_gui_input_move(const Ref &p_event) { if (k.is_valid() && !k->is_pressed() && drag_type == DRAG_KEY_MOVE && tool == TOOL_SELECT && (k->get_keycode() == KEY_UP || k->get_keycode() == KEY_DOWN || k->get_keycode() == KEY_LEFT || k->get_keycode() == KEY_RIGHT)) { // Confirm canvas items move by arrow keys - if ((!InputFilter::get_singleton()->is_key_pressed(KEY_UP)) && - (!InputFilter::get_singleton()->is_key_pressed(KEY_DOWN)) && - (!InputFilter::get_singleton()->is_key_pressed(KEY_LEFT)) && - (!InputFilter::get_singleton()->is_key_pressed(KEY_RIGHT))) { + if ((!Input::get_singleton()->is_key_pressed(KEY_UP)) && + (!Input::get_singleton()->is_key_pressed(KEY_DOWN)) && + (!Input::get_singleton()->is_key_pressed(KEY_LEFT)) && + (!Input::get_singleton()->is_key_pressed(KEY_RIGHT))) { _commit_canvas_item_state(drag_selection, TTR("Move CanvasItem"), true); drag_type = DRAG_NONE; } @@ -3310,8 +3310,8 @@ void CanvasItemEditor::_draw_selection() { } // Draw the move handles - bool is_ctrl = InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL); - bool is_alt = InputFilter::get_singleton()->is_key_pressed(KEY_ALT); + bool is_ctrl = Input::get_singleton()->is_key_pressed(KEY_CONTROL); + bool is_alt = Input::get_singleton()->is_key_pressed(KEY_ALT); if (tool == TOOL_MOVE && show_transformation_gizmos) { if (_is_node_movable(canvas_item)) { Transform2D unscaled_transform = (xform * canvas_item->get_transform().affine_inverse() * canvas_item->_edit_get_transform()).orthonormalized(); @@ -3347,7 +3347,7 @@ void CanvasItemEditor::_draw_selection() { Transform2D simple_xform = viewport->get_transform() * unscaled_transform; Size2 scale_factor = Size2(SCALE_HANDLE_DISTANCE, SCALE_HANDLE_DISTANCE); - bool uniform = InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT); + bool uniform = Input::get_singleton()->is_key_pressed(KEY_SHIFT); Point2 offset = (simple_xform.affine_inverse().xform(drag_to) - simple_xform.affine_inverse().xform(drag_from)) * zoom; if (drag_type == DRAG_SCALE_X) { @@ -6204,8 +6204,8 @@ bool CanvasItemEditorViewport::_only_packed_scenes_selected() const { } void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p_data) { - bool is_shift = InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT); - bool is_alt = InputFilter::get_singleton()->is_key_pressed(KEY_ALT); + bool is_shift = Input::get_singleton()->is_key_pressed(KEY_SHIFT); + bool is_alt = Input::get_singleton()->is_key_pressed(KEY_ALT); selected_files.clear(); Dictionary d = p_data; diff --git a/editor/plugins/collision_polygon_3d_editor_plugin.cpp b/editor/plugins/collision_polygon_3d_editor_plugin.cpp index 26adc5156b..1cee1a040f 100644 --- a/editor/plugins/collision_polygon_3d_editor_plugin.cpp +++ b/editor/plugins/collision_polygon_3d_editor_plugin.cpp @@ -31,7 +31,7 @@ #include "collision_polygon_3d_editor_plugin.h" #include "canvas_item_editor_plugin.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/file_access.h" #include "core/os/keyboard.h" #include "editor/editor_settings.h" @@ -342,7 +342,7 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con Vector2 cpoint(spoint.x, spoint.y); - if (snap_ignore && !InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL)) { + if (snap_ignore && !Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { snap_ignore = false; } diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp index 71c5a78e0b..9b5c6bae3b 100644 --- a/editor/plugins/curve_editor_plugin.cpp +++ b/editor/plugins/curve_editor_plugin.cpp @@ -32,7 +32,7 @@ #include "canvas_item_editor_plugin.h" #include "core/core_string_names.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/keyboard.h" #include "editor/editor_scale.h" @@ -210,7 +210,7 @@ void CurveEditor::on_gui_input(const Ref &p_event) { else tangent = 9999 * (dir.y >= 0 ? 1 : -1); - bool link = !InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT); + bool link = !Input::get_singleton()->is_key_pressed(KEY_SHIFT); if (_selected_tangent == TANGENT_LEFT) { curve.set_point_left_tangent(_selected_point, tangent); diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index f51b9b20e4..af34dd5cab 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -30,7 +30,7 @@ #include "node_3d_editor_plugin.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/math/camera_matrix.h" #include "core/os/keyboard.h" #include "core/print_string.h" @@ -298,10 +298,10 @@ void Node3DEditorViewport::_update_camera(float p_interp_delta) { float zoom_inertia = EDITOR_GET("editors/3d/navigation_feel/zoom_inertia"); //determine if being manipulated - bool manipulated = InputFilter::get_singleton()->get_mouse_button_mask() & (2 | 4); - manipulated |= InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT); - manipulated |= InputFilter::get_singleton()->is_key_pressed(KEY_ALT); - manipulated |= InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL); + bool manipulated = Input::get_singleton()->get_mouse_button_mask() & (2 | 4); + manipulated |= Input::get_singleton()->is_key_pressed(KEY_SHIFT); + manipulated |= Input::get_singleton()->is_key_pressed(KEY_ALT); + manipulated |= Input::get_singleton()->is_key_pressed(KEY_CONTROL); float orbit_inertia = MAX(0.00001, manipulated ? manip_orbit_inertia : free_orbit_inertia); float translation_inertia = MAX(0.0001, manipulated ? manip_translation_inertia : free_translation_inertia); @@ -2260,7 +2260,7 @@ void Node3DEditorViewport::scale_freelook_speed(real_t scale) { Point2i Node3DEditorViewport::_get_warped_mouse_motion(const Ref &p_ev_mouse_motion) const { Point2i relative; if (bool(EDITOR_DEF("editors/3d/navigation/warped_mouse_panning", false))) { - relative = InputFilter::get_singleton()->warp_mouse_motion(p_ev_mouse_motion, surface->get_global_rect()); + relative = Input::get_singleton()->warp_mouse_motion(p_ev_mouse_motion, surface->get_global_rect()); } else { relative = p_ev_mouse_motion->get_relative(); } @@ -2276,7 +2276,7 @@ static bool is_shortcut_pressed(const String &p_path) { if (k == nullptr) { return false; } - const InputFilter &input = *InputFilter::get_singleton(); + const Input &input = *Input::get_singleton(); int keycode = k->get_keycode(); return input.is_key_pressed(keycode); } @@ -3828,7 +3828,7 @@ void Node3DEditorViewport::drop_data_fw(const Point2 &p_point, const Variant &p_ if (!can_drop_data_fw(p_point, p_data, p_from)) return; - bool is_shift = InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT); + bool is_shift = Input::get_singleton()->is_key_pressed(KEY_SHIFT); selected_files.clear(); Dictionary d = p_data; @@ -5785,7 +5785,7 @@ void Node3DEditor::_unhandled_key_input(Ref p_event) { if (!is_visible_in_tree()) return; - snap_key_enabled = InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL); + snap_key_enabled = Input::get_singleton()->is_key_pressed(KEY_CONTROL); } void Node3DEditor::_notification(int p_what) { @@ -6446,7 +6446,7 @@ Vector3 Node3DEditor::snap_point(Vector3 p_target, Vector3 p_start) const { float Node3DEditor::get_translate_snap() const { float snap_value; - if (InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) { + if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { snap_value = snap_translate->get_text().to_double() / 10.0; } else { snap_value = snap_translate->get_text().to_double(); @@ -6457,7 +6457,7 @@ float Node3DEditor::get_translate_snap() const { float Node3DEditor::get_rotate_snap() const { float snap_value; - if (InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) { + if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { snap_value = snap_rotate->get_text().to_double() / 3.0; } else { snap_value = snap_rotate->get_text().to_double(); @@ -6468,7 +6468,7 @@ float Node3DEditor::get_rotate_snap() const { float Node3DEditor::get_scale_snap() const { float snap_value; - if (InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) { + if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { snap_value = snap_scale->get_text().to_double() / 2.0; } else { snap_value = snap_scale->get_text().to_double(); diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index 1f7a5b9968..e15d8556e4 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -31,7 +31,7 @@ #include "polygon_2d_editor_plugin.h" #include "canvas_item_editor_plugin.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/file_access.h" #include "core/os/keyboard.h" #include "editor/editor_scale.h" @@ -810,7 +810,7 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { if (mm.is_valid()) { - if ((mm->get_button_mask() & BUTTON_MASK_MIDDLE) || InputFilter::get_singleton()->is_key_pressed(KEY_SPACE)) { + if ((mm->get_button_mask() & BUTTON_MASK_MIDDLE) || Input::get_singleton()->is_key_pressed(KEY_SPACE)) { Vector2 drag(mm->get_relative().x, mm->get_relative().y); uv_hscroll->set_value(uv_hscroll->get_value() - drag.x); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 2c831979de..7af98cf346 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -30,7 +30,7 @@ #include "script_editor_plugin.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/io/resource_loader.h" #include "core/os/file_access.h" #include "core/os/keyboard.h" @@ -1545,7 +1545,7 @@ void ScriptEditor::_help_overview_selected(int p_idx) { void ScriptEditor::_script_selected(int p_idx) { - grab_focus_block = !InputFilter::get_singleton()->is_mouse_button_pressed(1); //amazing hack, simply amazing + grab_focus_block = !Input::get_singleton()->is_mouse_button_pressed(1); //amazing hack, simply amazing _go_to_tab(script_list->get_item_metadata(p_idx)); grab_focus_block = false; diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 8892d13f51..099c9ceb5d 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -31,7 +31,7 @@ #include "texture_region_editor_plugin.h" #include "core/core_string_names.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/keyboard.h" #include "editor/editor_scale.h" #include "scene/gui/check_box.h" @@ -307,7 +307,7 @@ void TextureRegionEditor::_region_input(const Ref &p_input) { for (List::Element *E = autoslice_cache.front(); E; E = E->next()) { if (E->get().has_point(point)) { rect = E->get(); - if (InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL) && !(InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT | KEY_ALT))) { + if (Input::get_singleton()->is_key_pressed(KEY_CONTROL) && !(Input::get_singleton()->is_key_pressed(KEY_SHIFT | KEY_ALT))) { Rect2 r; if (node_sprite) r = node_sprite->get_region_rect(); @@ -449,7 +449,7 @@ void TextureRegionEditor::_region_input(const Ref &p_input) { if (mm.is_valid()) { - if (mm->get_button_mask() & BUTTON_MASK_MIDDLE || InputFilter::get_singleton()->is_key_pressed(KEY_SPACE)) { + if (mm->get_button_mask() & BUTTON_MASK_MIDDLE || Input::get_singleton()->is_key_pressed(KEY_SPACE)) { Vector2 dragged(mm->get_relative().x / draw_zoom, mm->get_relative().y / draw_zoom); hscroll->set_value(hscroll->get_value() - dragged.x); diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index 9e88cd8889..e22e0cc052 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -31,7 +31,7 @@ #include "tile_map_editor_plugin.h" #include "canvas_item_editor_plugin.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/math/math_funcs.h" #include "core/os/keyboard.h" #include "editor/editor_scale.h" @@ -997,7 +997,7 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { if (mb->is_pressed()) { - if (InputFilter::get_singleton()->is_key_pressed(KEY_SPACE)) + if (Input::get_singleton()->is_key_pressed(KEY_SPACE)) return false; // Drag. if (tool == TOOL_NONE) { @@ -1378,7 +1378,7 @@ bool TileMapEditor::forward_gui_input(const Ref &p_event) { return true; } - if (tool == TOOL_PICKING && InputFilter::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { + if (tool == TOOL_PICKING && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { _pick_tile(over_tile); diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index d1dda68c1d..c393b15a97 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -30,7 +30,7 @@ #include "tile_set_editor_plugin.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/keyboard.h" #include "editor/editor_scale.h" #include "editor/plugins/canvas_item_editor_plugin.h" @@ -1113,7 +1113,7 @@ void TileSetEditor::_on_workspace_draw() { void TileSetEditor::_on_workspace_process() { - if (InputFilter::get_singleton()->is_key_pressed(KEY_ALT) || tools[VISIBLE_INFO]->is_pressed()) { + if (Input::get_singleton()->is_key_pressed(KEY_ALT) || tools[VISIBLE_INFO]->is_pressed()) { if (!tile_names_visible) { tile_names_visible = true; workspace_overlay->update(); @@ -1395,7 +1395,7 @@ void TileSetEditor::_on_workspace_input(const Ref &p_ie) { if ((mb->get_button_index() == BUTTON_RIGHT || mb->get_button_index() == BUTTON_LEFT) && current_tile_region.has_point(mb->get_position())) { dragging = true; erasing = (mb->get_button_index() == BUTTON_RIGHT); - alternative = InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT); + alternative = Input::get_singleton()->is_key_pressed(KEY_SHIFT); Vector2 coord((int)((mb->get_position().x - current_tile_region.position.x) / (spacing + size.x)), (int)((mb->get_position().y - current_tile_region.position.y) / (spacing + size.y))); Vector2 pos(coord.x * (spacing + size.x), coord.y * (spacing + size.y)); pos = mb->get_position() - (pos + current_tile_region.position); diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index d5128db0d5..a7e737fdd2 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -30,7 +30,7 @@ #include "visual_shader_editor_plugin.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/io/resource_loader.h" #include "core/math/math_defs.h" #include "core/os/keyboard.h" @@ -1635,7 +1635,7 @@ void VisualShaderEditor::_graph_gui_input(const Ref &p_event) { popup_menu->set_item_disabled(NodeMenuOptions::DELETE, to_change.empty()); popup_menu->set_item_disabled(NodeMenuOptions::DUPLICATE, to_change.empty()); menu_point = graph->get_local_mouse_position(); - Point2 gpos = InputFilter::get_singleton()->get_mouse_position(); + Point2 gpos = Input::get_singleton()->get_mouse_position(); popup_menu->set_position(gpos); popup_menu->popup(); } @@ -1648,7 +1648,7 @@ void VisualShaderEditor::_show_members_dialog(bool at_mouse_pos) { saved_node_pos_dirty = true; saved_node_pos = graph->get_local_mouse_position(); - Point2 gpos = InputFilter::get_singleton()->get_mouse_position(); + Point2 gpos = Input::get_singleton()->get_mouse_position(); members_dialog->popup(); members_dialog->set_position(gpos); } else { diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 978c95b9c8..60329fb7bc 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -31,7 +31,7 @@ #include "property_editor.h" #include "core/class_db.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/io/image_loader.h" #include "core/io/marshalls.h" #include "core/io/resource_loader.h" @@ -1720,7 +1720,7 @@ real_t CustomPropertyEditor::_parse_real_expression(String text) { void CustomPropertyEditor::_emit_changed_whole_or_field() { - if (!InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) { + if (!Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { emit_signal("variant_changed"); } else { emit_signal("variant_field_changed", field_names[focused_value_editor]); diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 4041256dd5..92f899a35d 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -30,7 +30,7 @@ #include "scene_tree_dock.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/io/resource_saver.h" #include "core/os/keyboard.h" #include "core/project_settings.h" @@ -1030,7 +1030,7 @@ void SceneTreeDock::_node_collapsed(Object *p_obj) { if (!ti) return; - if (InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) { + if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { _set_collapsed_recursive(ti, ti->is_collapsed()); } } @@ -2346,7 +2346,7 @@ void SceneTreeDock::_nodes_dragged(Array p_nodes, NodePath p_to, int p_type) { int to_pos = -1; _normalize_drop(to_node, to_pos, p_type); - _do_reparent(to_node, to_pos, nodes, !InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)); + _do_reparent(to_node, to_pos, nodes, !Input::get_singleton()->is_key_pressed(KEY_SHIFT)); } void SceneTreeDock::_add_children_to_popup(Object *p_obj, int p_depth) { diff --git a/main/main.cpp b/main/main.cpp index ad8e8dadfe..dff7907e72 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -32,7 +32,7 @@ #include "core/crypto/crypto.h" #include "core/debugger/engine_debugger.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/input/input_map.h" #include "core/io/file_access_network.h" #include "core/io/file_access_pack.h" @@ -90,7 +90,7 @@ // Initialized in setup() static Engine *engine = nullptr; static ProjectSettings *globals = nullptr; -static InputFilter *input = nullptr; +static Input *input = nullptr; static InputMap *input_map = nullptr; static TranslationServer *translation_server = nullptr; static Performance *performance = nullptr; @@ -1249,7 +1249,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { /* Initialize Input */ - input = memnew(InputFilter); + input = memnew(Input); /* Iniitalize Display Server */ @@ -1403,7 +1403,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { GLOBAL_DEF("application/config/windows_native_icon", String()); ProjectSettings::get_singleton()->set_custom_property_info("application/config/windows_native_icon", PropertyInfo(Variant::STRING, "application/config/windows_native_icon", PROPERTY_HINT_FILE, "*.ico")); - InputFilter *id = InputFilter::get_singleton(); + Input *id = Input::get_singleton(); if (id) { if (bool(GLOBAL_DEF("input_devices/pointing/emulate_touch_from_mouse", false)) && !(editor || project_manager)) { @@ -1438,7 +1438,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { Ref cursor = ResourceLoader::load(ProjectSettings::get_singleton()->get("display/mouse_cursor/custom_image")); if (cursor.is_valid()) { Vector2 hotspot = ProjectSettings::get_singleton()->get("display/mouse_cursor/custom_image_hotspot"); - InputFilter::get_singleton()->set_custom_mouse_cursor(cursor, InputFilter::CURSOR_ARROW, hotspot); + Input::get_singleton()->set_custom_mouse_cursor(cursor, Input::CURSOR_ARROW, hotspot); } } #ifdef TOOLS_ENABLED diff --git a/modules/arkit/arkit_interface.mm b/modules/arkit/arkit_interface.mm index 79f09e2a7e..7de824815a 100644 --- a/modules/arkit/arkit_interface.mm +++ b/modules/arkit/arkit_interface.mm @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/os.h" #include "scene/resources/surface_tool.h" #include "servers/rendering/rendering_server_globals.h" diff --git a/modules/gdnative/xr/xr_interface_gdnative.cpp b/modules/gdnative/xr/xr_interface_gdnative.cpp index 0451945139..d65089a123 100644 --- a/modules/gdnative/xr/xr_interface_gdnative.cpp +++ b/modules/gdnative/xr/xr_interface_gdnative.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "xr_interface_gdnative.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "servers/rendering/rendering_server_globals.h" #include "servers/xr/xr_positional_tracker.h" @@ -306,7 +306,7 @@ godot_int GDAPI godot_xr_add_controller(char *p_device_name, godot_int p_hand, g XRServer *xr_server = XRServer::get_singleton(); ERR_FAIL_NULL_V(xr_server, 0); - InputFilter *input = InputFilter::get_singleton(); + Input *input = Input::get_singleton(); ERR_FAIL_NULL_V(input, 0); XRPositionalTracker *new_tracker = memnew(XRPositionalTracker); @@ -345,7 +345,7 @@ void GDAPI godot_xr_remove_controller(godot_int p_controller_id) { XRServer *xr_server = XRServer::get_singleton(); ERR_FAIL_NULL(xr_server); - InputFilter *input = InputFilter::get_singleton(); + Input *input = Input::get_singleton(); ERR_FAIL_NULL(input); XRPositionalTracker *remove_tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id); @@ -383,7 +383,7 @@ void GDAPI godot_xr_set_controller_button(godot_int p_controller_id, godot_int p XRServer *xr_server = XRServer::get_singleton(); ERR_FAIL_NULL(xr_server); - InputFilter *input = InputFilter::get_singleton(); + Input *input = Input::get_singleton(); ERR_FAIL_NULL(input); XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id); @@ -399,14 +399,14 @@ void GDAPI godot_xr_set_controller_axis(godot_int p_controller_id, godot_int p_a XRServer *xr_server = XRServer::get_singleton(); ERR_FAIL_NULL(xr_server); - InputFilter *input = InputFilter::get_singleton(); + Input *input = Input::get_singleton(); ERR_FAIL_NULL(input); XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id); if (tracker != nullptr) { int joyid = tracker->get_joy_id(); if (joyid != -1) { - InputFilter::JoyAxis jx; + Input::JoyAxis jx; jx.min = p_can_be_negative ? -1 : 0; jx.value = p_value; input->joy_axis(joyid, p_axis, jx); diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index eb8feb5bc7..9c3101945a 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "grid_map_editor_plugin.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/plugins/node_3d_editor_plugin.h" diff --git a/modules/mobile_vr/mobile_vr_interface.cpp b/modules/mobile_vr/mobile_vr_interface.cpp index 2f0a15f20b..48276c0d3d 100644 --- a/modules/mobile_vr/mobile_vr_interface.cpp +++ b/modules/mobile_vr/mobile_vr_interface.cpp @@ -29,7 +29,8 @@ /*************************************************************************/ #include "mobile_vr_interface.h" -#include "core/input/input_filter.h" + +#include "core/input/input.h" #include "core/os/os.h" #include "servers/display_server.h" #include "servers/rendering/rendering_server_globals.h" @@ -118,7 +119,7 @@ void MobileVRInterface::set_position_from_sensors() { float delta_time = (double)ticks_elapsed / 1000000.0; // few things we need - InputFilter *input = InputFilter::get_singleton(); + Input *input = Input::get_singleton(); Vector3 down(0.0, -1.0, 0.0); // Down is Y negative Vector3 north(0.0, 0.0, 1.0); // North is Z positive diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 59b1bcdd96..9a4076bec4 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -30,7 +30,7 @@ #include "visual_script_editor.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/object.h" #include "core/os/keyboard.h" #include "core/script_language.h" @@ -1073,9 +1073,9 @@ void VisualScriptEditor::_member_selected() { if (ti->get_parent() == members->get_root()->get_children()) { #ifdef OSX_ENABLED - bool held_ctrl = InputFilter::get_singleton()->is_key_pressed(KEY_META); + bool held_ctrl = Input::get_singleton()->is_key_pressed(KEY_META); #else - bool held_ctrl = InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL); + bool held_ctrl = Input::get_singleton()->is_key_pressed(KEY_CONTROL); #endif if (held_ctrl) { ERR_FAIL_COND(!script->has_function(selected)); @@ -1378,7 +1378,7 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt } } else if (ti->get_parent() == root->get_children()) { selected = ti->get_text(0); - function_name_edit->set_position(InputFilter::get_singleton()->get_mouse_position() - Vector2(60, -10)); + function_name_edit->set_position(Input::get_singleton()->get_mouse_position() - Vector2(60, -10)); function_name_edit->popup(); function_name_box->set_text(selected); function_name_box->select_all(); @@ -1740,7 +1740,7 @@ void VisualScriptEditor::_input(const Ref &p_event) { Ref key = p_event; if (key.is_valid() && !key->is_pressed()) { - mouse_up_position = InputFilter::get_singleton()->get_mouse_position(); + mouse_up_position = Input::get_singleton()->get_mouse_position(); } } @@ -1750,7 +1750,7 @@ void VisualScriptEditor::_graph_gui_input(const Ref &p_event) { if (key.is_valid() && key->is_pressed() && key->get_button_mask() == BUTTON_RIGHT) { saved_position = graph->get_local_mouse_position(); - Point2 gpos = InputFilter::get_singleton()->get_mouse_position(); + Point2 gpos = Input::get_singleton()->get_mouse_position(); _generic_search(script->get_instance_base_type(), gpos); } } @@ -2004,9 +2004,9 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da if (String(d["type"]) == "visual_script_variable_drag") { #ifdef OSX_ENABLED - bool use_set = InputFilter::get_singleton()->is_key_pressed(KEY_META); + bool use_set = Input::get_singleton()->is_key_pressed(KEY_META); #else - bool use_set = InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL); + bool use_set = Input::get_singleton()->is_key_pressed(KEY_CONTROL); #endif Vector2 ofs = graph->get_scroll_ofs() + p_point; if (graph->is_using_snap()) { @@ -2199,9 +2199,9 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } #ifdef OSX_ENABLED - bool use_node = InputFilter::get_singleton()->is_key_pressed(KEY_META); + bool use_node = Input::get_singleton()->is_key_pressed(KEY_META); #else - bool use_node = InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL); + bool use_node = Input::get_singleton()->is_key_pressed(KEY_CONTROL); #endif Array nodes = d["nodes"]; @@ -2263,7 +2263,7 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script); - if (!sn && !InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) { + if (!sn && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { EditorNode::get_singleton()->show_warning(vformat(TTR("Can't drop properties because script '%s' is not used in this scene.\nDrop holding 'Shift' to just copy the signature."), get_name())); return; } @@ -2283,12 +2283,12 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da ofs /= EDSCALE; #ifdef OSX_ENABLED - bool use_get = InputFilter::get_singleton()->is_key_pressed(KEY_META); + bool use_get = Input::get_singleton()->is_key_pressed(KEY_META); #else - bool use_get = InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL); + bool use_get = Input::get_singleton()->is_key_pressed(KEY_CONTROL); #endif - if (!node || InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) { + if (!node || Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { if (use_get) undo_redo->create_action(TTR("Add Getter Property")); diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp index 475893e86d..8a644c6860 100644 --- a/modules/visual_script/visual_script_flow_control.cpp +++ b/modules/visual_script/visual_script_flow_control.cpp @@ -934,6 +934,6 @@ void register_visual_script_flow_control_nodes() { VisualScriptLanguage::singleton->add_register_func("flow_control/iterator", create_node_generic); VisualScriptLanguage::singleton->add_register_func("flow_control/sequence", create_node_generic); VisualScriptLanguage::singleton->add_register_func("flow_control/switch", create_node_generic); - //VisualScriptLanguage::singleton->add_register_func("flow_control/input_filter", create_node_generic); + //VisualScriptLanguage::singleton->add_register_func("flow_control/input", create_node_generic); VisualScriptLanguage::singleton->add_register_func("flow_control/type_cast", create_node_generic); } diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index c860e08943..52399d29d0 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -32,7 +32,7 @@ #include "core/engine.h" #include "core/global_constants.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/os.h" #include "core/project_settings.h" #include "scene/main/node.h" @@ -3870,16 +3870,16 @@ public: switch (mode) { case VisualScriptInputAction::MODE_PRESSED: { - *p_outputs[0] = InputFilter::get_singleton()->is_action_pressed(action); + *p_outputs[0] = Input::get_singleton()->is_action_pressed(action); } break; case VisualScriptInputAction::MODE_RELEASED: { - *p_outputs[0] = !InputFilter::get_singleton()->is_action_pressed(action); + *p_outputs[0] = !Input::get_singleton()->is_action_pressed(action); } break; case VisualScriptInputAction::MODE_JUST_PRESSED: { - *p_outputs[0] = InputFilter::get_singleton()->is_action_just_pressed(action); + *p_outputs[0] = Input::get_singleton()->is_action_just_pressed(action); } break; case VisualScriptInputAction::MODE_JUST_RELEASED: { - *p_outputs[0] = InputFilter::get_singleton()->is_action_just_released(action); + *p_outputs[0] = Input::get_singleton()->is_action_just_released(action); } break; } diff --git a/platform/android/display_server_android.cpp b/platform/android/display_server_android.cpp index 9534387d35..60d10b2457 100644 --- a/platform/android/display_server_android.cpp +++ b/platform/android/display_server_android.cpp @@ -424,7 +424,7 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis } #endif - InputFilter::get_singleton()->set_event_dispatch_function(_dispatch_input_events); + Input::get_singleton()->set_event_dispatch_function(_dispatch_input_events); } DisplayServerAndroid::~DisplayServerAndroid() { @@ -445,16 +445,16 @@ DisplayServerAndroid::~DisplayServerAndroid() { void DisplayServerAndroid::process_joy_event(DisplayServerAndroid::JoypadEvent p_event) { switch (p_event.type) { case JOY_EVENT_BUTTON: - InputFilter::get_singleton()->joy_button(p_event.device, p_event.index, p_event.pressed); + Input::get_singleton()->joy_button(p_event.device, p_event.index, p_event.pressed); break; case JOY_EVENT_AXIS: - InputFilter::JoyAxis value; + Input::JoyAxis value; value.min = -1; value.value = p_event.value; - InputFilter::get_singleton()->joy_axis(p_event.device, p_event.index, value); + Input::get_singleton()->joy_axis(p_event.device, p_event.index, value); break; case JOY_EVENT_HAT: - InputFilter::get_singleton()->joy_hat(p_event.device, p_event.hat); + Input::get_singleton()->joy_hat(p_event.device, p_event.hat); break; default: return; @@ -484,7 +484,7 @@ void DisplayServerAndroid::process_key_event(int p_keycode, int p_scancode, int OS_Android::get_singleton()->main_loop_request_go_back(); } - InputFilter::get_singleton()->parse_input_event(ev); + Input::get_singleton()->parse_input_event(ev); } void DisplayServerAndroid::process_touch(int p_what, int p_pointer, const Vector &p_points) { @@ -499,7 +499,7 @@ void DisplayServerAndroid::process_touch(int p_what, int p_pointer, const Vector ev->set_index(touch[i].id); ev->set_pressed(false); ev->set_position(touch[i].pos); - InputFilter::get_singleton()->parse_input_event(ev); + Input::get_singleton()->parse_input_event(ev); } } @@ -517,7 +517,7 @@ void DisplayServerAndroid::process_touch(int p_what, int p_pointer, const Vector ev->set_index(touch[i].id); ev->set_pressed(true); ev->set_position(touch[i].pos); - InputFilter::get_singleton()->parse_input_event(ev); + Input::get_singleton()->parse_input_event(ev); } } break; @@ -545,7 +545,7 @@ void DisplayServerAndroid::process_touch(int p_what, int p_pointer, const Vector ev->set_index(touch[i].id); ev->set_position(p_points[idx].pos); ev->set_relative(p_points[idx].pos - touch[i].pos); - InputFilter::get_singleton()->parse_input_event(ev); + Input::get_singleton()->parse_input_event(ev); touch.write[i].pos = p_points[idx].pos; } @@ -560,7 +560,7 @@ void DisplayServerAndroid::process_touch(int p_what, int p_pointer, const Vector ev->set_index(touch[i].id); ev->set_pressed(false); ev->set_position(touch[i].pos); - InputFilter::get_singleton()->parse_input_event(ev); + Input::get_singleton()->parse_input_event(ev); } touch.clear(); } @@ -577,7 +577,7 @@ void DisplayServerAndroid::process_touch(int p_what, int p_pointer, const Vector ev->set_index(tp.id); ev->set_pressed(true); ev->set_position(tp.pos); - InputFilter::get_singleton()->parse_input_event(ev); + Input::get_singleton()->parse_input_event(ev); break; } @@ -592,7 +592,7 @@ void DisplayServerAndroid::process_touch(int p_what, int p_pointer, const Vector ev->set_index(touch[i].id); ev->set_pressed(false); ev->set_position(touch[i].pos); - InputFilter::get_singleton()->parse_input_event(ev); + Input::get_singleton()->parse_input_event(ev); touch.remove(i); break; @@ -613,7 +613,7 @@ void DisplayServerAndroid::process_hover(int p_type, Point2 p_pos) { ev->set_position(p_pos); ev->set_global_position(p_pos); ev->set_relative(p_pos - hover_prev_pos); - InputFilter::get_singleton()->parse_input_event(ev); + Input::get_singleton()->parse_input_event(ev); hover_prev_pos = p_pos; } break; } @@ -626,7 +626,7 @@ void DisplayServerAndroid::process_double_tap(Point2 p_pos) { ev->set_global_position(p_pos); ev->set_pressed(false); ev->set_doubleclick(true); - InputFilter::get_singleton()->parse_input_event(ev); + Input::get_singleton()->parse_input_event(ev); } void DisplayServerAndroid::process_scroll(Point2 p_pos) { @@ -634,22 +634,22 @@ void DisplayServerAndroid::process_scroll(Point2 p_pos) { ev.instance(); ev->set_position(p_pos); ev->set_delta(p_pos - scroll_prev_pos); - InputFilter::get_singleton()->parse_input_event(ev); + Input::get_singleton()->parse_input_event(ev); scroll_prev_pos = p_pos; } void DisplayServerAndroid::process_accelerometer(const Vector3 &p_accelerometer) { - InputFilter::get_singleton()->set_accelerometer(p_accelerometer); + Input::get_singleton()->set_accelerometer(p_accelerometer); } void DisplayServerAndroid::process_gravity(const Vector3 &p_gravity) { - InputFilter::get_singleton()->set_gravity(p_gravity); + Input::get_singleton()->set_gravity(p_gravity); } void DisplayServerAndroid::process_magnetometer(const Vector3 &p_magnetometer) { - InputFilter::get_singleton()->set_magnetometer(p_magnetometer); + Input::get_singleton()->set_magnetometer(p_magnetometer); } void DisplayServerAndroid::process_gyroscope(const Vector3 &p_gyroscope) { - InputFilter::get_singleton()->set_gyroscope(p_gyroscope); + Input::get_singleton()->set_gyroscope(p_gyroscope); } diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp index 8b38113e09..a6730903cc 100644 --- a/platform/android/java_godot_lib_jni.cpp +++ b/platform/android/java_godot_lib_jni.cpp @@ -38,7 +38,7 @@ #include "api/jni_singleton.h" #include "audio_driver_jandroid.h" #include "core/engine.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/project_settings.h" #include "dir_access_jandroid.h" #include "display_server_android.h" @@ -311,15 +311,15 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, j int hat = 0; if (p_hat_x != 0) { if (p_hat_x < 0) - hat |= InputFilter::HAT_MASK_LEFT; + hat |= Input::HAT_MASK_LEFT; else - hat |= InputFilter::HAT_MASK_RIGHT; + hat |= Input::HAT_MASK_RIGHT; } if (p_hat_y != 0) { if (p_hat_y < 0) - hat |= InputFilter::HAT_MASK_UP; + hat |= Input::HAT_MASK_UP; else - hat |= InputFilter::HAT_MASK_DOWN; + hat |= Input::HAT_MASK_DOWN; } jevent.hat = hat; @@ -329,7 +329,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, j JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged(JNIEnv *env, jclass clazz, jint p_device, jboolean p_connected, jstring p_name) { if (os_android) { String name = jstring_to_string(p_name, env); - InputFilter::get_singleton()->joy_connection_changed(p_device, p_connected, name); + Input::get_singleton()->joy_connection_changed(p_device, p_connected, name); } } diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 760157595c..9ae18415ba 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -88,7 +88,7 @@ void OS_Android::initialize() { } void OS_Android::initialize_joypads() { - InputFilter::get_singleton()->set_fallback_mapping(godot_java->get_input_fallback_mapping()); + Input::get_singleton()->set_fallback_mapping(godot_java->get_input_fallback_mapping()); // This queries/updates the currently connected devices/joypads. godot_java->init_input_devices(); diff --git a/platform/haiku/haiku_direct_window.h b/platform/haiku/haiku_direct_window.h index 925bb9ac5d..4817abbb7a 100644 --- a/platform/haiku/haiku_direct_window.h +++ b/platform/haiku/haiku_direct_window.h @@ -35,7 +35,7 @@ #include -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/os.h" #include "haiku_gl_view.h" diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h index 64f5690dd1..d3ef9400d4 100644 --- a/platform/haiku/os_haiku.h +++ b/platform/haiku/os_haiku.h @@ -33,7 +33,7 @@ #include "audio_driver_media_kit.h" #include "context_gl_haiku.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "drivers/unix/os_unix.h" #include "haiku_application.h" #include "haiku_direct_window.h" diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h index 96cf041c37..eb94e1d69b 100644 --- a/platform/iphone/os_iphone.h +++ b/platform/iphone/os_iphone.h @@ -33,7 +33,7 @@ #ifndef OS_IPHONE_H #define OS_IPHONE_H -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "drivers/coreaudio/audio_driver_coreaudio.h" #include "drivers/unix/os_unix.h" #include "game_center.h" diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 81fe4cf0cc..feb0f0651a 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -32,7 +32,7 @@ #define OS_JAVASCRIPT_H #include "audio_driver_javascript.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "drivers/unix/os_unix.h" #include "servers/audio_server.h" #include "servers/rendering/rasterizer.h" diff --git a/platform/linuxbsd/display_server_x11.cpp b/platform/linuxbsd/display_server_x11.cpp index 78ddef5ff6..22790a3fe5 100644 --- a/platform/linuxbsd/display_server_x11.cpp +++ b/platform/linuxbsd/display_server_x11.cpp @@ -208,7 +208,7 @@ void DisplayServerX11::_update_real_mouse_position(const WindowData &wd) { last_mouse_pos.x = win_x; last_mouse_pos.y = win_y; last_mouse_pos_valid = true; - InputFilter::get_singleton()->set_mouse_position(last_mouse_pos); + Input::get_singleton()->set_mouse_position(last_mouse_pos); } } } @@ -392,7 +392,7 @@ void DisplayServerX11::mouse_set_mode(MouseMode p_mode) { XWarpPointer(x11_display, None, main_window.x11_window, 0, 0, 0, 0, (int)center.x, (int)center.y); - InputFilter::get_singleton()->set_mouse_position(center); + Input::get_singleton()->set_mouse_position(center); } } else { do_mouse_warp = false; @@ -2077,7 +2077,7 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event, k->set_shift(true); } - InputFilter::get_singleton()->accumulate_input_event(k); + Input::get_singleton()->accumulate_input_event(k); } memfree(utf8string); return; @@ -2220,14 +2220,14 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event, k->set_metakey(false); } - bool last_is_pressed = InputFilter::get_singleton()->is_key_pressed(k->get_keycode()); + bool last_is_pressed = Input::get_singleton()->is_key_pressed(k->get_keycode()); if (k->is_pressed()) { if (last_is_pressed) { k->set_echo(true); } } - InputFilter::get_singleton()->accumulate_input_event(k); + Input::get_singleton()->accumulate_input_event(k); } void DisplayServerX11::_xim_destroy_callback(::XIM im, ::XPointer client_data, @@ -2486,12 +2486,12 @@ void DisplayServerX11::process_events() { // in a spurious mouse motion event being sent to Godot; remember it to be able to filter it out xi.mouse_pos_to_filter = pos; } - InputFilter::get_singleton()->accumulate_input_event(st); + Input::get_singleton()->accumulate_input_event(st); } else { if (!xi.state.has(index)) // Defensive break; xi.state.erase(index); - InputFilter::get_singleton()->accumulate_input_event(st); + Input::get_singleton()->accumulate_input_event(st); } } break; @@ -2510,7 +2510,7 @@ void DisplayServerX11::process_events() { sd->set_index(index); sd->set_position(pos); sd->set_relative(pos - curr_pos_elem->value()); - InputFilter::get_singleton()->accumulate_input_event(sd); + Input::get_singleton()->accumulate_input_event(sd); curr_pos_elem->value() = pos; } @@ -2580,7 +2580,7 @@ void DisplayServerX11::process_events() { case FocusOut: window_has_focus = false; - InputFilter::get_singleton()->release_pressed_events(); + Input::get_singleton()->release_pressed_events(); _send_window_event(windows[window_id], WINDOW_EVENT_FOCUS_OUT); window_focused = false; @@ -2609,7 +2609,7 @@ void DisplayServerX11::process_events() { st->set_index(E->key()); st->set_window_id(window_id); st->set_position(E->get()); - InputFilter::get_singleton()->accumulate_input_event(st); + Input::get_singleton()->accumulate_input_event(st); } xi.state.clear(); #endif @@ -2671,7 +2671,7 @@ void DisplayServerX11::process_events() { } } - InputFilter::get_singleton()->accumulate_input_event(mb); + Input::get_singleton()->accumulate_input_event(mb); } break; case MotionNotify: { @@ -2773,8 +2773,8 @@ void DisplayServerX11::process_events() { mm->set_button_mask(mouse_get_button_state()); mm->set_position(posi); mm->set_global_position(posi); - InputFilter::get_singleton()->set_mouse_position(posi); - mm->set_speed(InputFilter::get_singleton()->get_last_mouse_speed()); + Input::get_singleton()->set_mouse_position(posi); + mm->set_speed(Input::get_singleton()->get_last_mouse_speed()); mm->set_relative(rel); @@ -2785,7 +2785,7 @@ void DisplayServerX11::process_events() { // this is so that the relative motion doesn't get messed up // after we regain focus. if (window_has_focus || !mouse_mode_grab) - InputFilter::get_singleton()->accumulate_input_event(mm); + Input::get_singleton()->accumulate_input_event(mm); } break; case KeyPress: @@ -2978,7 +2978,7 @@ void DisplayServerX11::process_events() { */ } - InputFilter::get_singleton()->flush_accumulated_events(); + Input::get_singleton()->flush_accumulated_events(); } void DisplayServerX11::release_rendering_thread() { @@ -3373,7 +3373,7 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, u DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { - InputFilter::get_singleton()->set_event_dispatch_function(_dispatch_input_events); + Input::get_singleton()->set_event_dispatch_function(_dispatch_input_events); r_error = OK; diff --git a/platform/linuxbsd/display_server_x11.h b/platform/linuxbsd/display_server_x11.h index 113e504e9b..8f090d3fad 100644 --- a/platform/linuxbsd/display_server_x11.h +++ b/platform/linuxbsd/display_server_x11.h @@ -35,7 +35,7 @@ #include "servers/display_server.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "drivers/alsa/audio_driver_alsa.h" #include "drivers/alsamidi/midi_driver_alsamidi.h" diff --git a/platform/linuxbsd/joypad_linux.cpp b/platform/linuxbsd/joypad_linux.cpp index 381eb909ba..5ceea788e0 100644 --- a/platform/linuxbsd/joypad_linux.cpp +++ b/platform/linuxbsd/joypad_linux.cpp @@ -71,7 +71,7 @@ void JoypadLinux::Joypad::reset() { dpad = 0; fd = -1; - InputFilter::JoyAxis jx; + Input::JoyAxis jx; jx.min = -1; jx.value = 0.0f; for (int i = 0; i < MAX_ABS; i++) { @@ -80,7 +80,7 @@ void JoypadLinux::Joypad::reset() { } } -JoypadLinux::JoypadLinux(InputFilter *in) { +JoypadLinux::JoypadLinux(Input *in) { exit_udev = false; input = in; joy_thread = Thread::create(joy_thread_func, this); @@ -436,11 +436,11 @@ void JoypadLinux::joypad_vibration_stop(int p_id, uint64_t p_timestamp) { joy.ff_effect_timestamp = p_timestamp; } -InputFilter::JoyAxis JoypadLinux::axis_correct(const input_absinfo *p_abs, int p_value) const { +Input::JoyAxis JoypadLinux::axis_correct(const input_absinfo *p_abs, int p_value) const { int min = p_abs->minimum; int max = p_abs->maximum; - InputFilter::JoyAxis jx; + Input::JoyAxis jx; if (min < 0) { jx.min = -1; @@ -492,11 +492,11 @@ void JoypadLinux::process_joypads() { case ABS_HAT0X: if (ev.value != 0) { if (ev.value < 0) - joy->dpad |= InputFilter::HAT_MASK_LEFT; + joy->dpad |= Input::HAT_MASK_LEFT; else - joy->dpad |= InputFilter::HAT_MASK_RIGHT; + joy->dpad |= Input::HAT_MASK_RIGHT; } else - joy->dpad &= ~(InputFilter::HAT_MASK_LEFT | InputFilter::HAT_MASK_RIGHT); + joy->dpad &= ~(Input::HAT_MASK_LEFT | Input::HAT_MASK_RIGHT); input->joy_hat(i, joy->dpad); break; @@ -504,11 +504,11 @@ void JoypadLinux::process_joypads() { case ABS_HAT0Y: if (ev.value != 0) { if (ev.value < 0) - joy->dpad |= InputFilter::HAT_MASK_UP; + joy->dpad |= Input::HAT_MASK_UP; else - joy->dpad |= InputFilter::HAT_MASK_DOWN; + joy->dpad |= Input::HAT_MASK_DOWN; } else - joy->dpad &= ~(InputFilter::HAT_MASK_UP | InputFilter::HAT_MASK_DOWN); + joy->dpad &= ~(Input::HAT_MASK_UP | Input::HAT_MASK_DOWN); input->joy_hat(i, joy->dpad); break; @@ -517,7 +517,7 @@ void JoypadLinux::process_joypads() { if (ev.code >= MAX_ABS) return; if (joy->abs_map[ev.code] != -1 && joy->abs_info[ev.code]) { - InputFilter::JoyAxis value = axis_correct(joy->abs_info[ev.code], ev.value); + Input::JoyAxis value = axis_correct(joy->abs_info[ev.code], ev.value); joy->curr_axis[joy->abs_map[ev.code]] = value; } break; diff --git a/platform/linuxbsd/joypad_linux.h b/platform/linuxbsd/joypad_linux.h index 1d2ed5bbc1..0d175193a5 100644 --- a/platform/linuxbsd/joypad_linux.h +++ b/platform/linuxbsd/joypad_linux.h @@ -33,7 +33,7 @@ #define JOYPAD_LINUX_H #ifdef JOYDEV_ENABLED -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/mutex.h" #include "core/os/thread.h" @@ -41,7 +41,7 @@ struct input_absinfo; class JoypadLinux { public: - JoypadLinux(InputFilter *in); + JoypadLinux(Input *in); ~JoypadLinux(); void process_joypads(); @@ -53,7 +53,7 @@ private: }; struct Joypad { - InputFilter::JoyAxis curr_axis[MAX_ABS]; + Input::JoyAxis curr_axis[MAX_ABS]; int key_map[MAX_KEY]; int abs_map[MAX_ABS]; int dpad; @@ -74,7 +74,7 @@ private: bool exit_udev; Mutex joy_mutex; Thread *joy_thread; - InputFilter *input; + Input *input; Joypad joypads[JOYPADS_MAX]; Vector attached_devices; @@ -95,7 +95,7 @@ private: void joypad_vibration_start(int p_id, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp); void joypad_vibration_stop(int p_id, uint64_t p_timestamp); - InputFilter::JoyAxis axis_correct(const input_absinfo *p_abs, int p_value) const; + Input::JoyAxis axis_correct(const input_absinfo *p_abs, int p_value) const; }; #endif diff --git a/platform/linuxbsd/os_linuxbsd.cpp b/platform/linuxbsd/os_linuxbsd.cpp index 5b9a25bd8b..7b76f7394b 100644 --- a/platform/linuxbsd/os_linuxbsd.cpp +++ b/platform/linuxbsd/os_linuxbsd.cpp @@ -64,7 +64,7 @@ void OS_LinuxBSD::initialize() { void OS_LinuxBSD::initialize_joypads() { #ifdef JOYDEV_ENABLED - joypad = memnew(JoypadLinux(InputFilter::get_singleton())); + joypad = memnew(JoypadLinux(Input::get_singleton())); #endif } diff --git a/platform/linuxbsd/os_linuxbsd.h b/platform/linuxbsd/os_linuxbsd.h index 100cb53ba3..391f29e8a3 100644 --- a/platform/linuxbsd/os_linuxbsd.h +++ b/platform/linuxbsd/os_linuxbsd.h @@ -31,7 +31,7 @@ #ifndef OS_LINUXBSD_H #define OS_LINUXBSD_H -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "crash_handler_linuxbsd.h" #include "drivers/alsa/audio_driver_alsa.h" #include "drivers/alsamidi/midi_driver_alsamidi.h" diff --git a/platform/osx/display_server_osx.h b/platform/osx/display_server_osx.h index 86ceb51763..8133dfe2c4 100644 --- a/platform/osx/display_server_osx.h +++ b/platform/osx/display_server_osx.h @@ -33,7 +33,7 @@ #define BitMap _QDBitMap // Suppress deprecated QuickDraw definition. -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "servers/display_server.h" #if defined(OPENGL_ENABLED) diff --git a/platform/osx/display_server_osx.mm b/platform/osx/display_server_osx.mm index fd14ec1f1d..a44bfef94c 100644 --- a/platform/osx/display_server_osx.mm +++ b/platform/osx/display_server_osx.mm @@ -74,7 +74,7 @@ static Vector2i _get_mouse_pos(DisplayServerOSX::WindowData &p_wd, NSPoint p_loc p_wd.mouse_pos.x = p.x * p_backingScaleFactor; p_wd.mouse_pos.y = (contentRect.size.height - p.y) * p_backingScaleFactor; DS_OSX->last_mouse_pos = p_wd.mouse_pos; - InputFilter::get_singleton()->set_mouse_position(p_wd.mouse_pos); + Input::get_singleton()->set_mouse_position(p_wd.mouse_pos); return p_wd.mouse_pos; } @@ -124,7 +124,7 @@ static NSCursor *_cursorFromSelector(SEL selector, SEL fallback = nil) { k->set_physical_keycode(KEY_PERIOD); k->set_echo([event isARepeat]); - InputFilter::get_singleton()->accumulate_input_event(k); + Input::get_singleton()->accumulate_input_event(k); } } @@ -433,7 +433,7 @@ static NSCursor *_cursorFromSelector(SEL selector, SEL fallback = nil) { const CGFloat backingScaleFactor = (OS::get_singleton()->is_hidpi_allowed()) ? [wd.window_view backingScaleFactor] : 1.0; _get_mouse_pos(wd, [wd.window_object mouseLocationOutsideOfEventStream], backingScaleFactor); - InputFilter::get_singleton()->set_mouse_position(wd.mouse_pos); + Input::get_singleton()->set_mouse_position(wd.mouse_pos); DS_OSX->window_focused = true; DS_OSX->_send_window_event(wd, DisplayServerOSX::WINDOW_EVENT_FOCUS_IN); @@ -759,7 +759,7 @@ static void _mouseDownEvent(DisplayServer::WindowID window_id, NSEvent *event, i mb->set_doubleclick([event clickCount] == 2); } - InputFilter::get_singleton()->accumulate_input_event(mb); + Input::get_singleton()->accumulate_input_event(mb); } - (void)mouseDown:(NSEvent *)event { @@ -808,15 +808,15 @@ static void _mouseDownEvent(DisplayServer::WindowID window_id, NSEvent *event, i mm->set_tilt(Vector2(p.x, p.y)); } mm->set_global_position(pos); - mm->set_speed(InputFilter::get_singleton()->get_last_mouse_speed()); + mm->set_speed(Input::get_singleton()->get_last_mouse_speed()); Vector2i relativeMotion = Vector2i(); relativeMotion.x = [event deltaX] * backingScaleFactor; relativeMotion.y = [event deltaY] * backingScaleFactor; mm->set_relative(relativeMotion); _get_key_modifier_state([event modifierFlags], mm); - InputFilter::get_singleton()->set_mouse_position(wd.mouse_pos); - InputFilter::get_singleton()->accumulate_input_event(mm); + Input::get_singleton()->set_mouse_position(wd.mouse_pos); + Input::get_singleton()->accumulate_input_event(mm); } - (void)rightMouseDown:(NSEvent *)event { @@ -891,7 +891,7 @@ static void _mouseDownEvent(DisplayServer::WindowID window_id, NSEvent *event, i ev->set_position(_get_mouse_pos(wd, [event locationInWindow], backingScaleFactor)); ev->set_factor([event magnification] + 1.0); - InputFilter::get_singleton()->accumulate_input_event(ev); + Input::get_singleton()->accumulate_input_event(ev); } - (void)viewDidChangeBackingProperties { @@ -1357,7 +1357,7 @@ inline void sendScrollEvent(DisplayServer::WindowID window_id, int button, doubl DS_OSX->last_button_state |= mask; sc->set_button_mask(DS_OSX->last_button_state); - InputFilter::get_singleton()->accumulate_input_event(sc); + Input::get_singleton()->accumulate_input_event(sc); sc.instance(); sc->set_window_id(window_id); @@ -1369,7 +1369,7 @@ inline void sendScrollEvent(DisplayServer::WindowID window_id, int button, doubl DS_OSX->last_button_state &= ~mask; sc->set_button_mask(DS_OSX->last_button_state); - InputFilter::get_singleton()->accumulate_input_event(sc); + Input::get_singleton()->accumulate_input_event(sc); } inline void sendPanEvent(DisplayServer::WindowID window_id, double dx, double dy, int modifierFlags) { @@ -1384,7 +1384,7 @@ inline void sendPanEvent(DisplayServer::WindowID window_id, double dx, double dy pg->set_position(wd.mouse_pos); pg->set_delta(Vector2(-dx, -dy)); - InputFilter::get_singleton()->accumulate_input_event(pg); + Input::get_singleton()->accumulate_input_event(pg); } - (void)scrollWheel:(NSEvent *)event { @@ -3006,13 +3006,13 @@ DisplayServerOSX::LatinKeyboardVariant DisplayServerOSX::get_latin_keyboard_vari void DisplayServerOSX::_push_input(const Ref &p_event) { Ref ev = p_event; - InputFilter::get_singleton()->accumulate_input_event(ev); + Input::get_singleton()->accumulate_input_event(ev); } void DisplayServerOSX::_release_pressed_events() { _THREAD_SAFE_METHOD_ - if (InputFilter::get_singleton()) { - InputFilter::get_singleton()->release_pressed_events(); + if (Input::get_singleton()) { + Input::get_singleton()->release_pressed_events(); } } @@ -3088,7 +3088,7 @@ void DisplayServerOSX::process_events() { if (!drop_events) { _process_key_events(); - InputFilter::get_singleton()->flush_accumulated_events(); + Input::get_singleton()->flush_accumulated_events(); } [autoreleasePool drain]; @@ -3397,7 +3397,7 @@ bool DisplayServerOSX::is_console_visible() const { } DisplayServerOSX::DisplayServerOSX(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { - InputFilter::get_singleton()->set_event_dispatch_function(_dispatch_input_events); + Input::get_singleton()->set_event_dispatch_function(_dispatch_input_events); r_error = OK; drop_events = false; diff --git a/platform/osx/joypad_osx.cpp b/platform/osx/joypad_osx.cpp index 643acd8944..7f5ec05967 100644 --- a/platform/osx/joypad_osx.cpp +++ b/platform/osx/joypad_osx.cpp @@ -395,38 +395,38 @@ bool joypad::check_ff_features() { static int process_hat_value(int p_min, int p_max, int p_value) { int range = (p_max - p_min + 1); int value = p_value - p_min; - int hat_value = InputFilter::HAT_MASK_CENTER; + int hat_value = Input::HAT_MASK_CENTER; if (range == 4) { value *= 2; } switch (value) { case 0: - hat_value = InputFilter::HAT_MASK_UP; + hat_value = Input::HAT_MASK_UP; break; case 1: - hat_value = InputFilter::HAT_MASK_UP | InputFilter::HAT_MASK_RIGHT; + hat_value = Input::HAT_MASK_UP | Input::HAT_MASK_RIGHT; break; case 2: - hat_value = InputFilter::HAT_MASK_RIGHT; + hat_value = Input::HAT_MASK_RIGHT; break; case 3: - hat_value = InputFilter::HAT_MASK_DOWN | InputFilter::HAT_MASK_RIGHT; + hat_value = Input::HAT_MASK_DOWN | Input::HAT_MASK_RIGHT; break; case 4: - hat_value = InputFilter::HAT_MASK_DOWN; + hat_value = Input::HAT_MASK_DOWN; break; case 5: - hat_value = InputFilter::HAT_MASK_DOWN | InputFilter::HAT_MASK_LEFT; + hat_value = Input::HAT_MASK_DOWN | Input::HAT_MASK_LEFT; break; case 6: - hat_value = InputFilter::HAT_MASK_LEFT; + hat_value = Input::HAT_MASK_LEFT; break; case 7: - hat_value = InputFilter::HAT_MASK_UP | InputFilter::HAT_MASK_LEFT; + hat_value = Input::HAT_MASK_UP | Input::HAT_MASK_LEFT; break; default: - hat_value = InputFilter::HAT_MASK_CENTER; + hat_value = Input::HAT_MASK_CENTER; break; } return hat_value; @@ -438,8 +438,8 @@ void JoypadOSX::poll_joypads() const { } } -static const InputFilter::JoyAxis axis_correct(int p_value, int p_min, int p_max) { - InputFilter::JoyAxis jx; +static const Input::JoyAxis axis_correct(int p_value, int p_min, int p_max) { + Input::JoyAxis jx; if (p_min < 0) { jx.min = -1; if (p_value < 0) { @@ -571,7 +571,7 @@ void JoypadOSX::config_hid_manager(CFArrayRef p_matching_array) const { } } -JoypadOSX::JoypadOSX(InputFilter *in) { +JoypadOSX::JoypadOSX(Input *in) { self = this; input = in; diff --git a/platform/osx/joypad_osx.h b/platform/osx/joypad_osx.h index 62027c6a30..fc176b0990 100644 --- a/platform/osx/joypad_osx.h +++ b/platform/osx/joypad_osx.h @@ -40,7 +40,7 @@ #include #include -#include "core/input/input_filter.h" +#include "core/input/input.h" struct rec_element { IOHIDElementRef ref; @@ -94,7 +94,7 @@ class JoypadOSX { }; private: - InputFilter *input; + Input *input; IOHIDManagerRef hid_manager; Vector device_list; @@ -118,7 +118,7 @@ public: void _device_added(IOReturn p_res, IOHIDDeviceRef p_device); void _device_removed(IOReturn p_res, IOHIDDeviceRef p_device); - JoypadOSX(InputFilter *in); + JoypadOSX(Input *in); ~JoypadOSX(); }; diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index d2c67cff9f..9204a145bf 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -31,7 +31,7 @@ #ifndef OS_OSX_H #define OS_OSX_H -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "crash_handler_osx.h" #include "drivers/coreaudio/audio_driver_coreaudio.h" #include "drivers/coremidi/midi_driver_coremidi.h" diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index a1c4cf8270..f132ed9514 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -128,7 +128,7 @@ void OS_OSX::initialize_core() { } void OS_OSX::initialize_joypads() { - joypad_osx = memnew(JoypadOSX(InputFilter::get_singleton())); + joypad_osx = memnew(JoypadOSX(Input::get_singleton())); } void OS_OSX::initialize() { diff --git a/platform/server/os_server.h b/platform/server/os_server.h index 62028b26e4..b273e8d4e4 100644 --- a/platform/server/os_server.h +++ b/platform/server/os_server.h @@ -31,7 +31,7 @@ #ifndef OS_SERVER_H #define OS_SERVER_H -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "drivers/dummy/texture_loader_dummy.h" #include "drivers/unix/os_unix.h" #ifdef __APPLE__ diff --git a/platform/uwp/joypad_uwp.h b/platform/uwp/joypad_uwp.h index 054b67ddc8..69431052e5 100644 --- a/platform/uwp/joypad_uwp.h +++ b/platform/uwp/joypad_uwp.h @@ -31,7 +31,7 @@ #ifndef JOYPAD_UWP_H #define JOYPAD_UWP_H -#include "core/input/input_filter.h" +#include "core/input/input.h" ref class JoypadUWP sealed { diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h index ad0efa1d03..2233f6a413 100644 --- a/platform/uwp/os_uwp.h +++ b/platform/uwp/os_uwp.h @@ -32,7 +32,7 @@ #define OS_UWP_H #include "context_egl_uwp.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/math/transform_2d.h" #include "core/os/os.h" #include "core/ustring.h" diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index ebe9a7d27a..4d4273a073 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -666,7 +666,7 @@ void DisplayServerWindows::_update_real_mouse_position(WindowID p_window) { old_x = mouse_pos.x; old_y = mouse_pos.y; old_invalid = false; - InputFilter::get_singleton()->set_mouse_position(Point2i(mouse_pos.x, mouse_pos.y)); + Input::get_singleton()->set_mouse_position(Point2i(mouse_pos.x, mouse_pos.y)); } } } @@ -1511,7 +1511,7 @@ void DisplayServerWindows::process_events() { if (!drop_events) { _process_key_events(); - InputFilter::get_singleton()->flush_accumulated_events(); + Input::get_singleton()->flush_accumulated_events(); } } @@ -1715,7 +1715,7 @@ void DisplayServerWindows::_touch_event(WindowID p_window, bool p_pressed, float event->set_pressed(p_pressed); event->set_position(Vector2(p_x, p_y)); - InputFilter::get_singleton()->accumulate_input_event(event); + Input::get_singleton()->accumulate_input_event(event); } void DisplayServerWindows::_drag_event(WindowID p_window, float p_x, float p_y, int idx) { @@ -1735,7 +1735,7 @@ void DisplayServerWindows::_drag_event(WindowID p_window, float p_x, float p_y, event->set_position(Vector2(p_x, p_y)); event->set_relative(Vector2(p_x, p_y) - curr->get()); - InputFilter::get_singleton()->accumulate_input_event(event); + Input::get_singleton()->accumulate_input_event(event); curr->get() = Vector2(p_x, p_y); } @@ -1843,7 +1843,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA control_mem = false; shift_mem = false; } else { // WM_INACTIVE - InputFilter::get_singleton()->release_pressed_events(); + Input::get_singleton()->release_pressed_events(); _send_window_event(windows[window_id], WINDOW_EVENT_FOCUS_OUT); windows[window_id].window_focused = false; alt_mem = false; @@ -1940,7 +1940,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA mm->set_position(c); mm->set_global_position(c); - InputFilter::get_singleton()->set_mouse_position(c); + Input::get_singleton()->set_mouse_position(c); mm->set_speed(Vector2(0, 0)); if (raw->data.mouse.usFlags == MOUSE_MOVE_RELATIVE) { @@ -1973,7 +1973,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } if (windows[window_id].window_has_focus && mm->get_relative() != Vector2()) - InputFilter::get_singleton()->accumulate_input_event(mm); + Input::get_singleton()->accumulate_input_event(mm); } delete[] lpb; } break; @@ -2001,7 +2001,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA break; } - if (InputFilter::get_singleton()->is_emulating_mouse_from_touch()) { + if (Input::get_singleton()->is_emulating_mouse_from_touch()) { // Universal translation enabled; ignore OS translation LPARAM extra = GetMessageExtraInfo(); if (IsTouchEvent(extra)) { @@ -2074,8 +2074,8 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA SetCursorPos(pos.x, pos.y); } - InputFilter::get_singleton()->set_mouse_position(mm->get_position()); - mm->set_speed(InputFilter::get_singleton()->get_last_mouse_speed()); + Input::get_singleton()->set_mouse_position(mm->get_position()); + mm->set_speed(Input::get_singleton()->get_last_mouse_speed()); if (old_invalid) { @@ -2088,7 +2088,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA old_x = mm->get_position().x; old_y = mm->get_position().y; if (windows[window_id].window_has_focus) { - InputFilter::get_singleton()->parse_input_event(mm); + Input::get_singleton()->parse_input_event(mm); } return 0; //Pointer event handled return 0 to avoid duplicate WM_MOUSEMOVE event @@ -2098,7 +2098,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA break; } - if (InputFilter::get_singleton()->is_emulating_mouse_from_touch()) { + if (Input::get_singleton()->is_emulating_mouse_from_touch()) { // Universal translation enabled; ignore OS translation LPARAM extra = GetMessageExtraInfo(); if (IsTouchEvent(extra)) { @@ -2161,8 +2161,8 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA SetCursorPos(pos.x, pos.y); } - InputFilter::get_singleton()->set_mouse_position(mm->get_position()); - mm->set_speed(InputFilter::get_singleton()->get_last_mouse_speed()); + Input::get_singleton()->set_mouse_position(mm->get_position()); + mm->set_speed(Input::get_singleton()->get_last_mouse_speed()); if (old_invalid) { @@ -2175,12 +2175,12 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA old_x = mm->get_position().x; old_y = mm->get_position().y; if (windows[window_id].window_has_focus) - InputFilter::get_singleton()->accumulate_input_event(mm); + Input::get_singleton()->accumulate_input_event(mm); } break; case WM_LBUTTONDOWN: case WM_LBUTTONUP: - if (InputFilter::get_singleton()->is_emulating_mouse_from_touch()) { + if (Input::get_singleton()->is_emulating_mouse_from_touch()) { // Universal translation enabled; ignore OS translations for left button LPARAM extra = GetMessageExtraInfo(); if (IsTouchEvent(extra)) { @@ -2347,7 +2347,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA mb->set_global_position(mb->get_position()); - InputFilter::get_singleton()->accumulate_input_event(mb); + Input::get_singleton()->accumulate_input_event(mb); if (mb->is_pressed() && mb->get_button_index() > 3 && mb->get_button_index() < 8) { //send release for mouse wheel Ref mbd = mb->duplicate(); @@ -2355,7 +2355,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA last_button_state &= ~(1 << (mbd->get_button_index() - 1)); mbd->set_button_mask(last_button_state); mbd->set_pressed(false); - InputFilter::get_singleton()->accumulate_input_event(mbd); + Input::get_singleton()->accumulate_input_event(mbd); } } break; @@ -2444,7 +2444,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA } break; case WM_ENTERSIZEMOVE: { - InputFilter::get_singleton()->release_pressed_events(); + Input::get_singleton()->release_pressed_events(); move_timer_id = SetTimer(windows[window_id].hWnd, 1, USER_TIMER_MINIMUM, (TIMERPROC) nullptr); } break; case WM_EXITSIZEMOVE: { @@ -2652,7 +2652,7 @@ void DisplayServerWindows::_process_key_events() { if (k->get_unicode() < 32) k->set_unicode(0); - InputFilter::get_singleton()->accumulate_input_event(k); + Input::get_singleton()->accumulate_input_event(k); } //do nothing @@ -2693,7 +2693,7 @@ void DisplayServerWindows::_process_key_events() { k->set_echo((ke.uMsg == WM_KEYDOWN && (ke.lParam & (1 << 30)))); - InputFilter::get_singleton()->accumulate_input_event(k); + Input::get_singleton()->accumulate_input_event(k); } break; } @@ -2945,7 +2945,7 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win r_error = OK; ((OS_Windows *)OS::get_singleton())->set_main_window(windows[MAIN_WINDOW_ID].hWnd); - InputFilter::get_singleton()->set_event_dispatch_function(_dispatch_input_events); + Input::get_singleton()->set_event_dispatch_function(_dispatch_input_events); } Vector DisplayServerWindows::get_rendering_drivers_func() { diff --git a/platform/windows/display_server_windows.h b/platform/windows/display_server_windows.h index 5cd240ffb0..6243f54cfa 100644 --- a/platform/windows/display_server_windows.h +++ b/platform/windows/display_server_windows.h @@ -33,7 +33,7 @@ #include "servers/display_server.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/os.h" #include "core/project_settings.h" #include "crash_handler_windows.h" diff --git a/platform/windows/joypad_windows.cpp b/platform/windows/joypad_windows.cpp index 437c3b733d..2adf2a8652 100644 --- a/platform/windows/joypad_windows.cpp +++ b/platform/windows/joypad_windows.cpp @@ -54,7 +54,7 @@ JoypadWindows::JoypadWindows() { JoypadWindows::JoypadWindows(HWND *hwnd) { - input = InputFilter::get_singleton(); + input = Input::get_singleton(); hWnd = hwnd; joypad_count = 0; dinput = nullptr; @@ -436,46 +436,46 @@ void JoypadWindows::post_hat(int p_device, DWORD p_dpad) { // BOOL POVCentered = (LOWORD(dwPOV) == 0xFFFF);" // https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ee416628(v%3Dvs.85)#remarks if (LOWORD(p_dpad) == 0xFFFF) { - dpad_val = InputFilter::HAT_MASK_CENTER; + dpad_val = Input::HAT_MASK_CENTER; } if (p_dpad == 0) { - dpad_val = InputFilter::HAT_MASK_UP; + dpad_val = Input::HAT_MASK_UP; } else if (p_dpad == 4500) { - dpad_val = (InputFilter::HAT_MASK_UP | InputFilter::HAT_MASK_RIGHT); + dpad_val = (Input::HAT_MASK_UP | Input::HAT_MASK_RIGHT); } else if (p_dpad == 9000) { - dpad_val = InputFilter::HAT_MASK_RIGHT; + dpad_val = Input::HAT_MASK_RIGHT; } else if (p_dpad == 13500) { - dpad_val = (InputFilter::HAT_MASK_RIGHT | InputFilter::HAT_MASK_DOWN); + dpad_val = (Input::HAT_MASK_RIGHT | Input::HAT_MASK_DOWN); } else if (p_dpad == 18000) { - dpad_val = InputFilter::HAT_MASK_DOWN; + dpad_val = Input::HAT_MASK_DOWN; } else if (p_dpad == 22500) { - dpad_val = (InputFilter::HAT_MASK_DOWN | InputFilter::HAT_MASK_LEFT); + dpad_val = (Input::HAT_MASK_DOWN | Input::HAT_MASK_LEFT); } else if (p_dpad == 27000) { - dpad_val = InputFilter::HAT_MASK_LEFT; + dpad_val = Input::HAT_MASK_LEFT; } else if (p_dpad == 31500) { - dpad_val = (InputFilter::HAT_MASK_LEFT | InputFilter::HAT_MASK_UP); + dpad_val = (Input::HAT_MASK_LEFT | Input::HAT_MASK_UP); } input->joy_hat(p_device, dpad_val); }; -InputFilter::JoyAxis JoypadWindows::axis_correct(int p_val, bool p_xinput, bool p_trigger, bool p_negate) const { +Input::JoyAxis JoypadWindows::axis_correct(int p_val, bool p_xinput, bool p_trigger, bool p_negate) const { - InputFilter::JoyAxis jx; + Input::JoyAxis jx; if (Math::abs(p_val) < MIN_JOY_AXIS) { jx.min = p_trigger ? 0 : -1; jx.value = 0.0f; diff --git a/platform/windows/joypad_windows.h b/platform/windows/joypad_windows.h index 0db789c335..fefdcf1673 100644 --- a/platform/windows/joypad_windows.h +++ b/platform/windows/joypad_windows.h @@ -117,7 +117,7 @@ private: HWND *hWnd; HANDLE xinput_dll; LPDIRECTINPUT8 dinput; - InputFilter *input; + Input *input; int id_to_change; int joypad_count; @@ -141,7 +141,7 @@ private: void joypad_vibration_start_xinput(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp); void joypad_vibration_stop_xinput(int p_device, uint64_t p_timestamp); - InputFilter::JoyAxis axis_correct(int p_val, bool p_xinput = false, bool p_trigger = false, bool p_negate = false) const; + Input::JoyAxis axis_correct(int p_val, bool p_xinput = false, bool p_trigger = false, bool p_negate = false) const; XInputGetState_t xinput_get_state; XInputSetState_t xinput_set_state; }; diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 6bdfc75ebb..7226109e57 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -31,7 +31,7 @@ #ifndef OS_WINDOWS_H #define OS_WINDOWS_H -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/os.h" #include "core/project_settings.h" #include "crash_handler_windows.h" diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp index 2cb979a0e0..85fd05ac15 100644 --- a/scene/2d/touch_screen_button.cpp +++ b/scene/2d/touch_screen_button.cpp @@ -30,7 +30,7 @@ #include "touch_screen_button.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/input/input_map.h" #include "core/os/os.h" #include "scene/main/window.h" @@ -290,7 +290,7 @@ void TouchScreenButton::_press(int p_finger_pressed) { if (action != StringName()) { - InputFilter::get_singleton()->action_press(action); + Input::get_singleton()->action_press(action); Ref iea; iea.instance(); iea->set_action(action); @@ -308,7 +308,7 @@ void TouchScreenButton::_release(bool p_exiting_tree) { if (action != StringName()) { - InputFilter::get_singleton()->action_release(action); + Input::get_singleton()->action_release(action); if (!p_exiting_tree) { Ref iea; diff --git a/scene/3d/xr_nodes.cpp b/scene/3d/xr_nodes.cpp index 0373114e7d..6f41629bac 100644 --- a/scene/3d/xr_nodes.cpp +++ b/scene/3d/xr_nodes.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "xr_nodes.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "servers/xr/xr_interface.h" #include "servers/xr_server.h" @@ -206,7 +206,7 @@ void XRController3D::_notification(int p_what) { // check button states for (int i = 0; i < 16; i++) { bool was_pressed = (button_states & mask) == mask; - bool is_pressed = InputFilter::get_singleton()->is_joy_button_pressed(joy_id, i); + bool is_pressed = Input::get_singleton()->is_joy_button_pressed(joy_id, i); if (!was_pressed && is_pressed) { emit_signal("button_pressed", i); @@ -306,7 +306,7 @@ bool XRController3D::is_button_pressed(int p_button) const { return false; }; - return InputFilter::get_singleton()->is_joy_button_pressed(joy_id, p_button); + return Input::get_singleton()->is_joy_button_pressed(joy_id, p_button); }; float XRController3D::get_joystick_axis(int p_axis) const { @@ -315,7 +315,7 @@ float XRController3D::get_joystick_axis(int p_axis) const { return 0.0; }; - return InputFilter::get_singleton()->get_joy_axis(joy_id, p_axis); + return Input::get_singleton()->get_joy_axis(joy_id, p_axis); }; real_t XRController3D::get_rumble() const { diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 5e0f4c91e8..63878a0b26 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -30,7 +30,7 @@ #include "color_picker.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/keyboard.h" #include "core/os/os.h" diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 0fe65462e4..3af730de23 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -30,7 +30,7 @@ #include "graph_edit.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/keyboard.h" #include "scene/gui/box_container.h" @@ -804,7 +804,7 @@ void GraphEdit::set_selected(Node *p_child) { void GraphEdit::_gui_input(const Ref &p_ev) { Ref mm = p_ev; - if (mm.is_valid() && (mm->get_button_mask() & BUTTON_MASK_MIDDLE || (mm->get_button_mask() & BUTTON_MASK_LEFT && InputFilter::get_singleton()->is_key_pressed(KEY_SPACE)))) { + if (mm.is_valid() && (mm->get_button_mask() & BUTTON_MASK_MIDDLE || (mm->get_button_mask() & BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) { h_scroll->set_value(h_scroll->get_value() - mm->get_relative().x); v_scroll->set_value(v_scroll->get_value() - mm->get_relative().y); } @@ -823,7 +823,7 @@ void GraphEdit::_gui_input(const Ref &p_ev) { // Snapping can be toggled temporarily by holding down Ctrl. // This is done here as to not toggle the grid when holding down Ctrl. - if (is_using_snap() ^ InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL)) { + if (is_using_snap() ^ Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { const int snap = get_snap(); pos = pos.snapped(Vector2(snap, snap)); } @@ -886,7 +886,7 @@ void GraphEdit::_gui_input(const Ref &p_ev) { } if (b->get_button_index() == BUTTON_LEFT && !b->is_pressed() && dragging) { - if (!just_selected && drag_accum == Vector2() && InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL)) { + if (!just_selected && drag_accum == Vector2() && Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { //deselect current node for (int i = get_child_count() - 1; i >= 0; i--) { GraphNode *gn = Object::cast_to(get_child(i)); @@ -948,7 +948,7 @@ void GraphEdit::_gui_input(const Ref &p_ev) { drag_accum = Vector2(); drag_origin = get_local_mouse_position(); just_selected = !gn->is_selected(); - if (!gn->is_selected() && !InputFilter::get_singleton()->is_key_pressed(KEY_CONTROL)) { + if (!gn->is_selected() && !Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { for (int i = 0; i < get_child_count(); i++) { GraphNode *o_gn = Object::cast_to(get_child(i)); if (o_gn) { @@ -976,7 +976,7 @@ void GraphEdit::_gui_input(const Ref &p_ev) { } else { if (_filter_input(b->get_position())) return; - if (InputFilter::get_singleton()->is_key_pressed(KEY_SPACE)) + if (Input::get_singleton()->is_key_pressed(KEY_SPACE)) return; box_selecting = true; @@ -1035,16 +1035,16 @@ void GraphEdit::_gui_input(const Ref &p_ev) { //too difficult to get right //set_zoom(zoom/ZOOM_SCALE); } - if (b->get_button_index() == BUTTON_WHEEL_UP && !InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) { + if (b->get_button_index() == BUTTON_WHEEL_UP && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * b->get_factor() / 8); } - if (b->get_button_index() == BUTTON_WHEEL_DOWN && !InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT)) { + if (b->get_button_index() == BUTTON_WHEEL_DOWN && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * b->get_factor() / 8); } - if (b->get_button_index() == BUTTON_WHEEL_RIGHT || (b->get_button_index() == BUTTON_WHEEL_DOWN && InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT))) { + if (b->get_button_index() == BUTTON_WHEEL_RIGHT || (b->get_button_index() == BUTTON_WHEEL_DOWN && Input::get_singleton()->is_key_pressed(KEY_SHIFT))) { h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * b->get_factor() / 8); } - if (b->get_button_index() == BUTTON_WHEEL_LEFT || (b->get_button_index() == BUTTON_WHEEL_UP && InputFilter::get_singleton()->is_key_pressed(KEY_SHIFT))) { + if (b->get_button_index() == BUTTON_WHEEL_LEFT || (b->get_button_index() == BUTTON_WHEEL_UP && Input::get_singleton()->is_key_pressed(KEY_SHIFT))) { h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() * b->get_factor() / 8); } } diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 1e933c9aa1..a247863298 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -30,7 +30,7 @@ #include "popup_menu.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/keyboard.h" #include "core/os/os.h" #include "core/print_string.h" @@ -594,7 +594,7 @@ void PopupMenu::_notification(int p_what) { } break; case NOTIFICATION_POST_POPUP: { - initial_button_mask = InputFilter::get_singleton()->get_mouse_button_mask(); + initial_button_mask = Input::get_singleton()->get_mouse_button_mask(); during_grabbed_click = (bool)initial_button_mask; } break; case NOTIFICATION_WM_SIZE_CHANGED: { diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 8572d570fb..94628f7cea 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -30,7 +30,7 @@ #include "spin_box.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/math/expression.h" Size2 SpinBox::get_minimum_size() const { @@ -77,7 +77,7 @@ void SpinBox::_line_edit_input(const Ref &p_event) { void SpinBox::_range_click_timeout() { - if (!drag.enabled && InputFilter::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { + if (!drag.enabled && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { bool up = get_local_mouse_position().y < (get_size().height / 2); set_value(get_value() + (up ? get_step() : -get_step())); @@ -149,7 +149,7 @@ void SpinBox::_gui_input(const Ref &p_event) { if (drag.enabled) { drag.enabled = false; - InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_VISIBLE); + Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); warp_mouse(drag.capture_pos); } drag.allowed = false; @@ -166,7 +166,7 @@ void SpinBox::_gui_input(const Ref &p_event) { set_value(CLAMP(drag.base_val + get_step() * diff_y, get_min(), get_max())); } else if (drag.allowed && drag.capture_pos.distance_to(mm->get_position()) > 2) { - InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_CAPTURED); + Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED); drag.enabled = true; drag.base_val = get_value(); drag.diff_y = 0; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 36e35897d1..c83ca6f73d 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -30,7 +30,7 @@ #include "text_edit.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/message_queue.h" #include "core/os/keyboard.h" #include "core/os/os.h" @@ -446,7 +446,7 @@ void TextEdit::_click_selection_held() { // Warning: is_mouse_button_pressed(BUTTON_LEFT) returns false for double+ clicks, so this doesn't work for MODE_WORD // and MODE_LINE. However, moving the mouse triggers _gui_input, which calls these functions too, so that's not a huge problem. // I'm unsure if there's an actual fix that doesn't have a ton of side effects. - if (InputFilter::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && selection.selecting_mode != Selection::MODE_NONE) { + if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && selection.selecting_mode != Selection::MODE_NONE) { switch (selection.selecting_mode) { case Selection::MODE_POINTER: { _update_selection_mode_pointer(); diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 509a52d36a..aad36ebf02 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -30,7 +30,7 @@ #include "tree.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/math/math_funcs.h" #include "core/os/keyboard.h" #include "core/os/os.h" @@ -1425,7 +1425,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 if (p_item->cells[i].custom_button) { if (cache.hover_item == p_item && cache.hover_cell == i) { - if (InputFilter::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { + if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { draw_style_box(cache.custom_button_pressed, ir); } else { draw_style_box(cache.custom_button_hover, ir); @@ -1661,7 +1661,7 @@ Rect2 Tree::search_item_rect(TreeItem *p_from, TreeItem *p_item) { void Tree::_range_click_timeout() { - if (range_item_last && !range_drag_enabled && InputFilter::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { + if (range_item_last && !range_drag_enabled && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { Point2 pos = get_local_mouse_position() - cache.bg->get_offset(); if (show_column_titles) { @@ -2048,9 +2048,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool void Tree::_text_editor_modal_close() { - if (InputFilter::get_singleton()->is_key_pressed(KEY_ESCAPE) || - InputFilter::get_singleton()->is_key_pressed(KEY_KP_ENTER) || - InputFilter::get_singleton()->is_key_pressed(KEY_ENTER)) { + if (Input::get_singleton()->is_key_pressed(KEY_ESCAPE) || + Input::get_singleton()->is_key_pressed(KEY_KP_ENTER) || + Input::get_singleton()->is_key_pressed(KEY_ENTER)) { return; } @@ -2532,7 +2532,7 @@ void Tree::_gui_input(Ref p_event) { range_drag_enabled = true; range_drag_capture_pos = cpos; range_drag_base = popup_edited_item->get_range(popup_edited_item_col); - InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_CAPTURED); + Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED); } } else { @@ -2594,7 +2594,7 @@ void Tree::_gui_input(Ref p_event) { if (range_drag_enabled) { range_drag_enabled = false; - InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_VISIBLE); + Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); warp_mouse(range_drag_capture_pos); } else { Rect2 rect = get_selected()->get_meta("__focus_rect"); @@ -3238,7 +3238,7 @@ void Tree::clear() { if (pressing_for_editor) { if (range_drag_enabled) { range_drag_enabled = false; - InputFilter::get_singleton()->set_mouse_mode(InputFilter::MOUSE_MODE_VISIBLE); + Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); warp_mouse(range_drag_capture_pos); } pressing_for_editor = false; diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index 2eacad68c3..b5d54b2199 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -30,7 +30,7 @@ #include "canvas_item.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/message_queue.h" #include "core/method_bind_ext.gen.inc" #include "scene/main/canvas_layer.h" diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index f30a899d69..22cd1c98ab 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -31,7 +31,7 @@ #include "scene_tree.h" #include "core/debugger/engine_debugger.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/io/marshalls.h" #include "core/io/resource_loader.h" #include "core/message_queue.h" @@ -576,7 +576,7 @@ void SceneTree::_main_window_go_back() { } void SceneTree::_main_window_focus_in() { - InputFilter *id = InputFilter::get_singleton(); + Input *id = Input::get_singleton(); if (id) { id->ensure_touch_mouse_raised(); } diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 51dd22db81..b0718eed79 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -32,7 +32,7 @@ #include "core/core_string_names.h" #include "core/debugger/engine_debugger.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/os.h" #include "core/project_settings.h" #include "scene/2d/collision_object_2d.h" @@ -582,7 +582,7 @@ void Viewport::_notification(int p_what) { RS::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh, point_count); } - if (physics_object_picking && (to_screen_rect == Rect2i() || InputFilter::get_singleton()->get_mouse_mode() != InputFilter::MOUSE_MODE_CAPTURED)) { + if (physics_object_picking && (to_screen_rect == Rect2i() || Input::get_singleton()->get_mouse_mode() != Input::MOUSE_MODE_CAPTURED)) { #ifndef _3D_DISABLED Vector2 last_pos(1e20, 1e20); @@ -1517,7 +1517,7 @@ Vector2 Viewport::get_mouse_position() const { void Viewport::warp_mouse(const Vector2 &p_pos) { Vector2 gpos = (get_final_transform().affine_inverse() * _get_input_pre_xform()).affine_inverse().xform(p_pos); - InputFilter::get_singleton()->warp_mouse_position(gpos); + Input::get_singleton()->warp_mouse_position(gpos); } void Viewport::_gui_sort_roots() { @@ -2091,7 +2091,7 @@ void Viewport::_gui_input_event(Ref p_event) { gui.mouse_over = over; - DisplayServer::CursorShape ds_cursor_shape = (DisplayServer::CursorShape)InputFilter::get_singleton()->get_default_cursor_shape(); + DisplayServer::CursorShape ds_cursor_shape = (DisplayServer::CursorShape)Input::get_singleton()->get_default_cursor_shape(); if (over) { @@ -2411,7 +2411,7 @@ void Viewport::_gui_input_event(Ref p_event) { if (from && p_event->is_pressed()) { Control *next = nullptr; - InputFilter *input = InputFilter::get_singleton(); + Input *input = Input::get_singleton(); if (p_event->is_action_pressed("ui_focus_next") && input->is_action_just_pressed("ui_focus_next")) { @@ -3064,7 +3064,7 @@ void Viewport::unhandled_input(const Ref &p_event, bool p_local_coor if (physics_object_picking && !is_input_handled()) { - if (InputFilter::get_singleton()->get_mouse_mode() != InputFilter::MOUSE_MODE_CAPTURED && + if (Input::get_singleton()->get_mouse_mode() != Input::MOUSE_MODE_CAPTURED && (Object::cast_to(*ev) || Object::cast_to(*ev) || Object::cast_to(*ev) || diff --git a/servers/display_server.cpp b/servers/display_server.cpp index da1a68a179..ff8b10cbb6 100644 --- a/servers/display_server.cpp +++ b/servers/display_server.cpp @@ -30,7 +30,7 @@ #include "display_server.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "scene/resources/texture.h" DisplayServer *DisplayServer::singleton = nullptr; @@ -164,7 +164,7 @@ float DisplayServer::screen_get_scale(int p_screen) const { bool DisplayServer::screen_is_touchscreen(int p_screen) const { //return false; - return InputFilter::get_singleton() && InputFilter::get_singleton()->is_emulating_touch_from_mouse(); + return Input::get_singleton() && Input::get_singleton()->is_emulating_touch_from_mouse(); } void DisplayServer::screen_set_keep_on(bool p_enable) { @@ -563,31 +563,31 @@ DisplayServer *DisplayServer::create(int p_index, const String &p_rendering_driv return server_create_functions[p_index].create_function(p_rendering_driver, p_mode, p_flags, p_resolution, r_error); } -void DisplayServer::_input_set_mouse_mode(InputFilter::MouseMode p_mode) { +void DisplayServer::_input_set_mouse_mode(Input::MouseMode p_mode) { singleton->mouse_set_mode(MouseMode(p_mode)); } -InputFilter::MouseMode DisplayServer::_input_get_mouse_mode() { - return InputFilter::MouseMode(singleton->mouse_get_mode()); +Input::MouseMode DisplayServer::_input_get_mouse_mode() { + return Input::MouseMode(singleton->mouse_get_mode()); } void DisplayServer::_input_warp(const Vector2 &p_to_pos) { singleton->mouse_warp_to_position(p_to_pos); } -InputFilter::CursorShape DisplayServer::_input_get_current_cursor_shape() { - return (InputFilter::CursorShape)singleton->cursor_get_shape(); +Input::CursorShape DisplayServer::_input_get_current_cursor_shape() { + return (Input::CursorShape)singleton->cursor_get_shape(); } -void DisplayServer::_input_set_custom_mouse_cursor_func(const RES &p_image, InputFilter::CursorShape p_shape, const Vector2 &p_hostspot) { +void DisplayServer::_input_set_custom_mouse_cursor_func(const RES &p_image, Input::CursorShape p_shape, const Vector2 &p_hostspot) { singleton->cursor_set_custom_image(p_image, (CursorShape)p_shape, p_hostspot); } DisplayServer::DisplayServer() { singleton = this; - InputFilter::set_mouse_mode_func = _input_set_mouse_mode; - InputFilter::get_mouse_mode_func = _input_get_mouse_mode; - InputFilter::warp_mouse_func = _input_warp; - InputFilter::get_current_cursor_shape_func = _input_get_current_cursor_shape; - InputFilter::set_custom_mouse_cursor_func = _input_set_custom_mouse_cursor_func; + Input::set_mouse_mode_func = _input_set_mouse_mode; + Input::get_mouse_mode_func = _input_get_mouse_mode; + Input::warp_mouse_func = _input_warp; + Input::get_current_cursor_shape_func = _input_get_current_cursor_shape; + Input::set_custom_mouse_cursor_func = _input_set_custom_mouse_cursor_func; } DisplayServer::~DisplayServer() { } diff --git a/servers/display_server.h b/servers/display_server.h index 93db7ef844..f6ba26fc6f 100644 --- a/servers/display_server.h +++ b/servers/display_server.h @@ -32,7 +32,7 @@ #define DISPLAY_SERVER_H #include "core/callable.h" -#include "core/input/input_filter.h" +#include "core/input/input.h" #include "core/os/os.h" #include "core/resource.h" @@ -61,11 +61,11 @@ public: typedef Vector (*GetRenderingDriversFunction)(); private: - static void _input_set_mouse_mode(InputFilter::MouseMode p_mode); - static InputFilter::MouseMode _input_get_mouse_mode(); + static void _input_set_mouse_mode(Input::MouseMode p_mode); + static Input::MouseMode _input_get_mouse_mode(); static void _input_warp(const Vector2 &p_to_pos); - static InputFilter::CursorShape _input_get_current_cursor_shape(); - static void _input_set_custom_mouse_cursor_func(const RES &, InputFilter::CursorShape, const Vector2 &p_hostspot); + static Input::CursorShape _input_get_current_cursor_shape(); + static void _input_set_custom_mouse_cursor_func(const RES &, Input::CursorShape, const Vector2 &p_hostspot); protected: static void _bind_methods(); diff --git a/servers/xr/xr_positional_tracker.cpp b/servers/xr/xr_positional_tracker.cpp index 808b0a608f..20853c9027 100644 --- a/servers/xr/xr_positional_tracker.cpp +++ b/servers/xr/xr_positional_tracker.cpp @@ -29,7 +29,8 @@ /*************************************************************************/ #include "xr_positional_tracker.h" -#include "core/input/input_filter.h" + +#include "core/input/input.h" void XRPositionalTracker::_bind_methods() { BIND_ENUM_CONSTANT(TRACKER_HAND_UNKNOWN); -- cgit v1.2.3