|
@@ -1,5 +1,5 @@
|
|
|
/*************************************************************************/
|
|
|
-/* input_filter.cpp */
|
|
|
+/* input.cpp */
|
|
|
/*************************************************************************/
|
|
|
/* This file is part of: */
|
|
|
/* GODOT ENGINE */
|
|
@@ -28,7 +28,7 @@
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
/*************************************************************************/
|
|
|
|
|
|
-#include "input_filter.h"
|
|
|
+#include "input.h"
|
|
|
|
|
|
#include "core/input/default_controller_mappings.h"
|
|
|
#include "core/input/input_map.h"
|
|
@@ -39,71 +39,71 @@
|
|
|
#include "editor/editor_settings.h"
|
|
|
#endif
|
|
|
|
|
|
-InputFilter *InputFilter::singleton = nullptr;
|
|
|
+Input *Input::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;
|
|
|
+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;
|
|
|
|
|
|
-InputFilter *InputFilter::get_singleton() {
|
|
|
+Input *Input::get_singleton() {
|
|
|
|
|
|
return singleton;
|
|
|
}
|
|
|
|
|
|
-void InputFilter::set_mouse_mode(MouseMode p_mode) {
|
|
|
+void Input::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 {
|
|
|
+Input::MouseMode Input::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);
|
|
|
+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);
|
|
@@ -131,7 +131,7 @@ void InputFilter::_bind_methods() {
|
|
|
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<String> *r_options) const {
|
|
|
+void Input::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
|
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\"";
|
|
@@ -155,7 +155,7 @@ void InputFilter::get_argument_options(const StringName &p_function, int p_idx,
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
-void InputFilter::SpeedTrack::update(const Vector2 &p_delta_p) {
|
|
|
+void Input::SpeedTrack::update(const Vector2 &p_delta_p) {
|
|
|
|
|
|
uint64_t tick = OS::get_singleton()->get_ticks_usec();
|
|
|
uint32_t tdiff = tick - last_tick;
|
|
@@ -179,26 +179,26 @@ void InputFilter::SpeedTrack::update(const Vector2 &p_delta_p) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void InputFilter::SpeedTrack::reset() {
|
|
|
+void Input::SpeedTrack::reset() {
|
|
|
last_tick = OS::get_singleton()->get_ticks_usec();
|
|
|
speed = Vector2();
|
|
|
accum_t = 0;
|
|
|
}
|
|
|
|
|
|
-InputFilter::SpeedTrack::SpeedTrack() {
|
|
|
+Input::SpeedTrack::SpeedTrack() {
|
|
|
|
|
|
min_ref_frame = 0.1;
|
|
|
max_ref_frame = 0.3;
|
|
|
reset();
|
|
|
}
|
|
|
|
|
|
-bool InputFilter::is_key_pressed(int p_keycode) const {
|
|
|
+bool Input::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 {
|
|
|
+bool Input::is_mouse_button_pressed(int p_button) const {
|
|
|
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
return (mouse_button_mask & (1 << (p_button - 1))) != 0;
|
|
@@ -209,18 +209,18 @@ 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 {
|
|
|
+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 InputFilter::is_action_pressed(const StringName &p_action) const {
|
|
|
+bool Input::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 {
|
|
|
+bool Input::is_action_just_pressed(const StringName &p_action) const {
|
|
|
|
|
|
const Map<StringName, Action>::Element *E = action_state.find(p_action);
|
|
|
if (!E)
|
|
@@ -233,7 +233,7 @@ bool InputFilter::is_action_just_pressed(const StringName &p_action) const {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-bool InputFilter::is_action_just_released(const StringName &p_action) const {
|
|
|
+bool Input::is_action_just_released(const StringName &p_action) const {
|
|
|
|
|
|
const Map<StringName, Action>::Element *E = action_state.find(p_action);
|
|
|
if (!E)
|
|
@@ -246,7 +246,7 @@ bool InputFilter::is_action_just_released(const StringName &p_action) const {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-float InputFilter::get_action_strength(const StringName &p_action) const {
|
|
|
+float Input::get_action_strength(const StringName &p_action) const {
|
|
|
const Map<StringName, Action>::Element *E = action_state.find(p_action);
|
|
|
if (!E)
|
|
|
return 0.0f;
|
|
@@ -254,7 +254,7 @@ float InputFilter::get_action_strength(const StringName &p_action) const {
|
|
|
return E->get().strength;
|
|
|
}
|
|
|
|
|
|
-float InputFilter::get_joy_axis(int p_device, int p_axis) const {
|
|
|
+float Input::get_joy_axis(int p_device, int p_axis) const {
|
|
|
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
int c = _combine_device(p_axis, p_device);
|
|
@@ -265,13 +265,13 @@ float InputFilter::get_joy_axis(int p_device, int p_axis) const {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-String InputFilter::get_joy_name(int p_idx) {
|
|
|
+String Input::get_joy_name(int p_idx) {
|
|
|
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
return joy_names[p_idx].name;
|
|
|
};
|
|
|
|
|
|
-Vector2 InputFilter::get_joy_vibration_strength(int p_device) {
|
|
|
+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 {
|
|
@@ -279,7 +279,7 @@ Vector2 InputFilter::get_joy_vibration_strength(int p_device) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-uint64_t InputFilter::get_joy_vibration_timestamp(int p_device) {
|
|
|
+uint64_t Input::get_joy_vibration_timestamp(int p_device) {
|
|
|
if (joy_vibration.has(p_device)) {
|
|
|
return joy_vibration[p_device].timestamp;
|
|
|
} else {
|
|
@@ -287,7 +287,7 @@ uint64_t InputFilter::get_joy_vibration_timestamp(int p_device) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-float InputFilter::get_joy_vibration_duration(int p_device) {
|
|
|
+float Input::get_joy_vibration_duration(int p_device) {
|
|
|
if (joy_vibration.has(p_device)) {
|
|
|
return joy_vibration[p_device].duration;
|
|
|
} else {
|
|
@@ -307,7 +307,7 @@ static String _hex_str(uint8_t p_byte) {
|
|
|
return ret;
|
|
|
};
|
|
|
|
|
|
-void InputFilter::joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid) {
|
|
|
+void Input::joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid) {
|
|
|
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
Joypad js;
|
|
@@ -349,36 +349,36 @@ void InputFilter::joy_connection_changed(int p_idx, bool p_connected, String p_n
|
|
|
emit_signal("joy_connection_changed", p_idx, p_connected);
|
|
|
};
|
|
|
|
|
|
-Vector3 InputFilter::get_gravity() const {
|
|
|
+Vector3 Input::get_gravity() const {
|
|
|
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
return gravity;
|
|
|
}
|
|
|
|
|
|
-Vector3 InputFilter::get_accelerometer() const {
|
|
|
+Vector3 Input::get_accelerometer() const {
|
|
|
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
return accelerometer;
|
|
|
}
|
|
|
|
|
|
-Vector3 InputFilter::get_magnetometer() const {
|
|
|
+Vector3 Input::get_magnetometer() const {
|
|
|
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
return magnetometer;
|
|
|
}
|
|
|
|
|
|
-Vector3 InputFilter::get_gyroscope() const {
|
|
|
+Vector3 Input::get_gyroscope() const {
|
|
|
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
return gyroscope;
|
|
|
}
|
|
|
|
|
|
-void InputFilter::parse_input_event(const Ref<InputEvent> &p_event) {
|
|
|
+void Input::parse_input_event(const Ref<InputEvent> &p_event) {
|
|
|
|
|
|
_parse_input_event_impl(p_event, false);
|
|
|
}
|
|
|
|
|
|
-void InputFilter::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated) {
|
|
|
+void Input::_parse_input_event_impl(const Ref<InputEvent> &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
|
|
@@ -561,14 +561,14 @@ void InputFilter::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p
|
|
|
event_dispatch_function(p_event);
|
|
|
}
|
|
|
|
|
|
-void InputFilter::set_joy_axis(int p_device, int p_axis, float p_value) {
|
|
|
+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 InputFilter::start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration) {
|
|
|
+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;
|
|
@@ -581,7 +581,7 @@ void InputFilter::start_joy_vibration(int p_device, float p_weak_magnitude, floa
|
|
|
joy_vibration[p_device] = vibration;
|
|
|
}
|
|
|
|
|
|
-void InputFilter::stop_joy_vibration(int p_device) {
|
|
|
+void Input::stop_joy_vibration(int p_device) {
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
VibrationInfo vibration;
|
|
|
vibration.weak_magnitude = 0;
|
|
@@ -591,63 +591,63 @@ void InputFilter::stop_joy_vibration(int p_device) {
|
|
|
joy_vibration[p_device] = vibration;
|
|
|
}
|
|
|
|
|
|
-void InputFilter::vibrate_handheld(int p_duration_ms) {
|
|
|
+void Input::vibrate_handheld(int p_duration_ms) {
|
|
|
OS::get_singleton()->vibrate_handheld(p_duration_ms);
|
|
|
}
|
|
|
|
|
|
-void InputFilter::set_gravity(const Vector3 &p_gravity) {
|
|
|
+void Input::set_gravity(const Vector3 &p_gravity) {
|
|
|
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
|
|
|
gravity = p_gravity;
|
|
|
}
|
|
|
|
|
|
-void InputFilter::set_accelerometer(const Vector3 &p_accel) {
|
|
|
+void Input::set_accelerometer(const Vector3 &p_accel) {
|
|
|
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
|
|
|
accelerometer = p_accel;
|
|
|
}
|
|
|
|
|
|
-void InputFilter::set_magnetometer(const Vector3 &p_magnetometer) {
|
|
|
+void Input::set_magnetometer(const Vector3 &p_magnetometer) {
|
|
|
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
|
|
|
magnetometer = p_magnetometer;
|
|
|
}
|
|
|
|
|
|
-void InputFilter::set_gyroscope(const Vector3 &p_gyroscope) {
|
|
|
+void Input::set_gyroscope(const Vector3 &p_gyroscope) {
|
|
|
|
|
|
_THREAD_SAFE_METHOD_
|
|
|
|
|
|
gyroscope = p_gyroscope;
|
|
|
}
|
|
|
|
|
|
-void InputFilter::set_mouse_position(const Point2 &p_posf) {
|
|
|
+void Input::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 {
|
|
|
+Point2 Input::get_mouse_position() const {
|
|
|
|
|
|
return mouse_pos;
|
|
|
}
|
|
|
-Point2 InputFilter::get_last_mouse_speed() const {
|
|
|
+Point2 Input::get_last_mouse_speed() const {
|
|
|
|
|
|
return mouse_speed_track.speed;
|
|
|
}
|
|
|
|
|
|
-int InputFilter::get_mouse_button_mask() const {
|
|
|
+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 InputFilter::warp_mouse_position(const Vector2 &p_to) {
|
|
|
+void Input::warp_mouse_position(const Vector2 &p_to) {
|
|
|
warp_mouse_func(p_to);
|
|
|
}
|
|
|
|
|
|
-Point2i InputFilter::warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect) {
|
|
|
+Point2i Input::warp_mouse_motion(const Ref<InputEventMouseMotion> &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()
|
|
@@ -673,10 +673,10 @@ Point2i InputFilter::warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motio
|
|
|
return rel_warped;
|
|
|
}
|
|
|
|
|
|
-void InputFilter::iteration(float p_step) {
|
|
|
+void Input::iteration(float p_step) {
|
|
|
}
|
|
|
|
|
|
-void InputFilter::action_press(const StringName &p_action, float p_strength) {
|
|
|
+void Input::action_press(const StringName &p_action, float p_strength) {
|
|
|
|
|
|
Action action;
|
|
|
|
|
@@ -688,7 +688,7 @@ void InputFilter::action_press(const StringName &p_action, float p_strength) {
|
|
|
action_state[p_action] = action;
|
|
|
}
|
|
|
|
|
|
-void InputFilter::action_release(const StringName &p_action) {
|
|
|
+void Input::action_release(const StringName &p_action) {
|
|
|
|
|
|
Action action;
|
|
|
|
|
@@ -700,19 +700,19 @@ void InputFilter::action_release(const StringName &p_action) {
|
|
|
action_state[p_action] = action;
|
|
|
}
|
|
|
|
|
|
-void InputFilter::set_emulate_touch_from_mouse(bool p_emulate) {
|
|
|
+void Input::set_emulate_touch_from_mouse(bool p_emulate) {
|
|
|
|
|
|
emulate_touch_from_mouse = p_emulate;
|
|
|
}
|
|
|
|
|
|
-bool InputFilter::is_emulating_touch_from_mouse() const {
|
|
|
+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 InputFilter::ensure_touch_mouse_raised() {
|
|
|
+void Input::ensure_touch_mouse_raised() {
|
|
|
|
|
|
if (mouse_from_touch_index != -1) {
|
|
|
mouse_from_touch_index = -1;
|
|
@@ -731,22 +731,22 @@ void InputFilter::ensure_touch_mouse_raised() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void InputFilter::set_emulate_mouse_from_touch(bool p_emulate) {
|
|
|
+void Input::set_emulate_mouse_from_touch(bool p_emulate) {
|
|
|
|
|
|
emulate_mouse_from_touch = p_emulate;
|
|
|
}
|
|
|
|
|
|
-bool InputFilter::is_emulating_mouse_from_touch() const {
|
|
|
+bool Input::is_emulating_mouse_from_touch() const {
|
|
|
|
|
|
return emulate_mouse_from_touch;
|
|
|
}
|
|
|
|
|
|
-InputFilter::CursorShape InputFilter::get_default_cursor_shape() const {
|
|
|
+Input::CursorShape Input::get_default_cursor_shape() const {
|
|
|
|
|
|
return default_shape;
|
|
|
}
|
|
|
|
|
|
-void InputFilter::set_default_cursor_shape(CursorShape p_shape) {
|
|
|
+void Input::set_default_cursor_shape(CursorShape p_shape) {
|
|
|
|
|
|
if (default_shape == p_shape)
|
|
|
return;
|
|
@@ -761,19 +761,19 @@ void InputFilter::set_default_cursor_shape(CursorShape p_shape) {
|
|
|
parse_input_event(mm);
|
|
|
}
|
|
|
|
|
|
-InputFilter::CursorShape InputFilter::get_current_cursor_shape() const {
|
|
|
+Input::CursorShape Input::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) {
|
|
|
+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 InputFilter::accumulate_input_event(const Ref<InputEvent> &p_event) {
|
|
|
+void Input::accumulate_input_event(const Ref<InputEvent> &p_event) {
|
|
|
ERR_FAIL_COND(p_event.is_null());
|
|
|
|
|
|
if (!use_accumulated_input) {
|
|
@@ -786,7 +786,7 @@ void InputFilter::accumulate_input_event(const Ref<InputEvent> &p_event) {
|
|
|
|
|
|
accumulated_events.push_back(p_event);
|
|
|
}
|
|
|
-void InputFilter::flush_accumulated_events() {
|
|
|
+void Input::flush_accumulated_events() {
|
|
|
|
|
|
while (accumulated_events.front()) {
|
|
|
parse_input_event(accumulated_events.front()->get());
|
|
@@ -794,12 +794,12 @@ void InputFilter::flush_accumulated_events() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void InputFilter::set_use_accumulated_input(bool p_enable) {
|
|
|
+void Input::set_use_accumulated_input(bool p_enable) {
|
|
|
|
|
|
use_accumulated_input = p_enable;
|
|
|
}
|
|
|
|
|
|
-void InputFilter::release_pressed_events() {
|
|
|
+void Input::release_pressed_events() {
|
|
|
|
|
|
flush_accumulated_events(); // this is needed to release actions strengths
|
|
|
|
|
@@ -807,17 +807,17 @@ void InputFilter::release_pressed_events() {
|
|
|
joy_buttons_pressed.clear();
|
|
|
_joy_axis.clear();
|
|
|
|
|
|
- for (Map<StringName, InputFilter::Action>::Element *E = action_state.front(); E; E = E->next()) {
|
|
|
+ for (Map<StringName, Input::Action>::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) {
|
|
|
+void Input::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) {
|
|
|
+void Input::joy_button(int p_device, int p_button, bool p_pressed) {
|
|
|
|
|
|
_THREAD_SAFE_METHOD_;
|
|
|
Joypad &joy = joy_names[p_device];
|
|
@@ -856,7 +856,7 @@ void InputFilter::joy_button(int p_device, int p_button, bool p_pressed) {
|
|
|
// no event?
|
|
|
}
|
|
|
|
|
|
-void InputFilter::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
|
|
|
+void Input::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
|
|
|
|
|
|
_THREAD_SAFE_METHOD_;
|
|
|
|
|
@@ -971,7 +971,7 @@ void InputFilter::joy_axis(int p_device, int p_axis, const JoyAxis &p_value) {
|
|
|
//printf("invalid mapping\n");
|
|
|
}
|
|
|
|
|
|
-void InputFilter::joy_hat(int p_device, int p_val) {
|
|
|
+void Input::joy_hat(int p_device, int p_val) {
|
|
|
|
|
|
_THREAD_SAFE_METHOD_;
|
|
|
const Joypad &joy = joy_names[p_device];
|
|
@@ -1003,7 +1003,7 @@ void InputFilter::joy_hat(int p_device, int p_val) {
|
|
|
joy_names[p_device].hat_current = p_val;
|
|
|
}
|
|
|
|
|
|
-void InputFilter::_button_event(int p_device, int p_index, bool p_pressed) {
|
|
|
+void Input::_button_event(int p_device, int p_index, bool p_pressed) {
|
|
|
|
|
|
Ref<InputEventJoypadButton> ievent;
|
|
|
ievent.instance();
|
|
@@ -1014,7 +1014,7 @@ void InputFilter::_button_event(int p_device, int p_index, bool p_pressed) {
|
|
|
parse_input_event(ievent);
|
|
|
}
|
|
|
|
|
|
-void InputFilter::_axis_event(int p_device, int p_axis, float p_value) {
|
|
|
+void Input::_axis_event(int p_device, int p_axis, float p_value) {
|
|
|
|
|
|
Ref<InputEventJoypadMotion> ievent;
|
|
|
ievent.instance();
|
|
@@ -1025,7 +1025,7 @@ void InputFilter::_axis_event(int p_device, int p_axis, float p_value) {
|
|
|
parse_input_event(ievent);
|
|
|
};
|
|
|
|
|
|
-InputFilter::JoyEvent InputFilter::_find_to_event(String p_to) {
|
|
|
+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 };
|
|
@@ -1063,7 +1063,7 @@ InputFilter::JoyEvent InputFilter::_find_to_event(String p_to) {
|
|
|
return ret;
|
|
|
};
|
|
|
|
|
|
-void InputFilter::parse_mapping(String p_mapping) {
|
|
|
+void Input::parse_mapping(String p_mapping) {
|
|
|
|
|
|
_THREAD_SAFE_METHOD_;
|
|
|
JoyDeviceMapping mapping;
|
|
@@ -1128,7 +1128,7 @@ void InputFilter::parse_mapping(String p_mapping) {
|
|
|
//printf("added mapping with uuid %ls\n", mapping.uid.c_str());
|
|
|
};
|
|
|
|
|
|
-void InputFilter::add_joy_mapping(String p_mapping, bool p_update_existing) {
|
|
|
+void Input::add_joy_mapping(String p_mapping, bool p_update_existing) {
|
|
|
parse_mapping(p_mapping);
|
|
|
if (p_update_existing) {
|
|
|
Vector<String> entry = p_mapping.split(",");
|
|
@@ -1141,7 +1141,7 @@ void InputFilter::add_joy_mapping(String p_mapping, bool p_update_existing) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void InputFilter::remove_joy_mapping(String p_guid) {
|
|
|
+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);
|
|
@@ -1154,7 +1154,7 @@ void InputFilter::remove_joy_mapping(String p_guid) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void InputFilter::set_fallback_mapping(String p_guid) {
|
|
|
+void Input::set_fallback_mapping(String p_guid) {
|
|
|
|
|
|
for (int i = 0; i < map_db.size(); i++) {
|
|
|
if (map_db[i].uid == p_guid) {
|
|
@@ -1165,17 +1165,17 @@ void InputFilter::set_fallback_mapping(String p_guid) {
|
|
|
}
|
|
|
|
|
|
//platforms that use the remapping system can override and call to these ones
|
|
|
-bool InputFilter::is_joy_known(int p_device) {
|
|
|
+bool Input::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 {
|
|
|
+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 InputFilter::get_connected_joypads() {
|
|
|
+Array Input::get_connected_joypads() {
|
|
|
Array ret;
|
|
|
Map<int, Joypad>::Element *elem = joy_names.front();
|
|
|
while (elem) {
|
|
@@ -1219,12 +1219,12 @@ static const char *_axes[JOY_AXIS_MAX] = {
|
|
|
""
|
|
|
};
|
|
|
|
|
|
-String InputFilter::get_joy_button_string(int p_button) {
|
|
|
+String Input::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) {
|
|
|
+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;
|
|
@@ -1233,7 +1233,7 @@ int InputFilter::get_joy_button_index_from_string(String p_button) {
|
|
|
ERR_FAIL_V(-1);
|
|
|
}
|
|
|
|
|
|
-int InputFilter::get_unused_joy_id() {
|
|
|
+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;
|
|
@@ -1242,12 +1242,12 @@ int InputFilter::get_unused_joy_id() {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
-String InputFilter::get_joy_axis_string(int p_axis) {
|
|
|
+String Input::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) {
|
|
|
+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;
|
|
@@ -1256,7 +1256,7 @@ int InputFilter::get_joy_axis_index_from_string(String p_axis) {
|
|
|
ERR_FAIL_V(-1);
|
|
|
}
|
|
|
|
|
|
-InputFilter::InputFilter() {
|
|
|
+Input::Input() {
|
|
|
|
|
|
singleton = this;
|
|
|
use_accumulated_input = true;
|