| 
40 | 40 | #include "core/os/thread.h"  | 
41 | 41 | #endif  | 
42 | 42 | 
 
  | 
 | 43 | +#include "drivers/sdl/joypad_sdl.h"  | 
 | 44 | + | 
43 | 45 | static const char *_joy_buttons[(size_t)JoyButton::SDL_MAX] = {  | 
44 | 46 | 	"a",  | 
45 | 47 | 	"b",  | 
@@ -145,10 +147,24 @@ void Input::_bind_methods() {  | 
145 | 147 | 	ClassDB::bind_method(D_METHOD("get_accelerometer"), &Input::get_accelerometer);  | 
146 | 148 | 	ClassDB::bind_method(D_METHOD("get_magnetometer"), &Input::get_magnetometer);  | 
147 | 149 | 	ClassDB::bind_method(D_METHOD("get_gyroscope"), &Input::get_gyroscope);  | 
 | 150 | +	ClassDB::bind_method(D_METHOD("get_joy_accelerometer_enabled", "device"), &Input::get_joy_accelerometer_enabled);  | 
 | 151 | +	ClassDB::bind_method(D_METHOD("get_joy_gyroscope_enabled", "device"), &Input::get_joy_gyroscope_enabled);  | 
 | 152 | +	ClassDB::bind_method(D_METHOD("get_joy_accelerometer", "device"), &Input::get_joy_accelerometer);  | 
 | 153 | +	ClassDB::bind_method(D_METHOD("get_joy_gyroscope", "device"), &Input::get_joy_gyroscope);  | 
 | 154 | +	ClassDB::bind_method(D_METHOD("get_joy_model", "device"), &Input::get_joy_model);  | 
 | 155 | +	ClassDB::bind_method(D_METHOD("get_joy_scheme", "device"), &Input::get_joy_scheme);  | 
 | 156 | +	ClassDB::bind_method(D_METHOD("get_joy_axis_string", "device", "axis"), &Input::get_joy_axis_string);  | 
 | 157 | +	ClassDB::bind_method(D_METHOD("get_joy_button_string", "device", "button"), &Input::get_joy_button_string);  | 
148 | 158 | 	ClassDB::bind_method(D_METHOD("set_gravity", "value"), &Input::set_gravity);  | 
149 | 159 | 	ClassDB::bind_method(D_METHOD("set_accelerometer", "value"), &Input::set_accelerometer);  | 
150 | 160 | 	ClassDB::bind_method(D_METHOD("set_magnetometer", "value"), &Input::set_magnetometer);  | 
151 | 161 | 	ClassDB::bind_method(D_METHOD("set_gyroscope", "value"), &Input::set_gyroscope);  | 
 | 162 | +	ClassDB::bind_method(D_METHOD("set_joy_light", "device", "color"), &Input::set_joy_light);  | 
 | 163 | +	ClassDB::bind_method(D_METHOD("set_joy_accelerometer_enabled", "device", "enable"), &Input::set_joy_accelerometer_enabled);  | 
 | 164 | +	ClassDB::bind_method(D_METHOD("set_joy_gyroscope_enabled", "device", "enable"), &Input::set_joy_gyroscope_enabled);  | 
 | 165 | +	ClassDB::bind_method(D_METHOD("has_joy_light", "device"), &Input::has_joy_light);  | 
 | 166 | +	ClassDB::bind_method(D_METHOD("has_joy_accelerometer", "device"), &Input::has_joy_accelerometer);  | 
 | 167 | +	ClassDB::bind_method(D_METHOD("has_joy_gyroscope", "device"), &Input::has_joy_gyroscope);  | 
152 | 168 | 	ClassDB::bind_method(D_METHOD("get_last_mouse_velocity"), &Input::get_last_mouse_velocity);  | 
153 | 169 | 	ClassDB::bind_method(D_METHOD("get_last_mouse_screen_velocity"), &Input::get_last_mouse_screen_velocity);  | 
154 | 170 | 	ClassDB::bind_method(D_METHOD("get_mouse_button_mask"), &Input::get_mouse_button_mask);  | 
@@ -661,6 +677,48 @@ Vector3 Input::get_gyroscope() const {  | 
661 | 677 | 	return gyroscope;  | 
662 | 678 | }  | 
663 | 679 | 
 
  | 
 | 680 | +bool Input::get_joy_accelerometer_enabled(int p_device) const {  | 
 | 681 | +	return JoypadSDL::get_singleton()->is_accelerometer_enabled(p_device);  | 
 | 682 | +}  | 
 | 683 | + | 
 | 684 | +bool Input::get_joy_gyroscope_enabled(int p_device) const {  | 
 | 685 | +	return JoypadSDL::get_singleton()->is_gyroscope_enabled(p_device);  | 
 | 686 | +}  | 
 | 687 | + | 
 | 688 | +Vector3 Input::get_joy_accelerometer(int p_device) const {  | 
 | 689 | +	_THREAD_SAFE_METHOD_  | 
 | 690 | +	if (joy_motion.has(p_device)) {  | 
 | 691 | +		return joy_motion[p_device].accelerometer;  | 
 | 692 | +	} else {  | 
 | 693 | +		return Vector3();  | 
 | 694 | +	}  | 
 | 695 | +}  | 
 | 696 | + | 
 | 697 | +Vector3 Input::get_joy_gyroscope(int p_device) const {  | 
 | 698 | +	_THREAD_SAFE_METHOD_  | 
 | 699 | +	if (joy_motion.has(p_device)) {  | 
 | 700 | +		return joy_motion[p_device].gyroscope;  | 
 | 701 | +	} else {  | 
 | 702 | +		return Vector3();  | 
 | 703 | +	}  | 
 | 704 | +}  | 
 | 705 | + | 
 | 706 | +JoyModel Input::get_joy_model(int p_device) const {  | 
 | 707 | +	return JoypadSDL::get_singleton()->get_model(p_device);  | 
 | 708 | +}  | 
 | 709 | + | 
 | 710 | +JoyScheme Input::get_joy_scheme(int p_device) const {  | 
 | 711 | +	return JoypadSDL::get_singleton()->get_scheme(p_device);  | 
 | 712 | +}  | 
 | 713 | + | 
 | 714 | +String Input::get_joy_axis_string(int p_device, JoyAxis p_axis) const {  | 
 | 715 | +	return JoypadSDL::get_singleton()->get_axis_string(p_device, p_axis);  | 
 | 716 | +}  | 
 | 717 | + | 
 | 718 | +String Input::get_joy_button_string(int p_device, JoyButton p_button) const {  | 
 | 719 | +	return JoypadSDL::get_singleton()->get_button_string(p_device, p_button);  | 
 | 720 | +}  | 
 | 721 | + | 
664 | 722 | void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated) {  | 
665 | 723 | 	// This function does the final delivery of the input event to user land.  | 
666 | 724 | 	// Regardless where the event came from originally, this has to happen on the main thread.  | 
@@ -914,6 +972,62 @@ void Input::set_joy_axis(int p_device, JoyAxis p_axis, float p_value) {  | 
914 | 972 | 	_joy_axis[c] = p_value;  | 
915 | 973 | }  | 
916 | 974 | 
 
  | 
 | 975 | +bool Input::set_joy_light(int p_device, Color p_color) {  | 
 | 976 | +	return JoypadSDL::get_singleton()->set_light(p_device, p_color);  | 
 | 977 | +}  | 
 | 978 | + | 
 | 979 | +bool Input::set_joy_accelerometer_enabled(int p_device, bool p_enable) {  | 
 | 980 | +	bool enabled = JoypadSDL::get_singleton()->enable_accelerometer(p_device, p_enable);  | 
 | 981 | +	if (enabled) {  | 
 | 982 | +		if (!joy_motion.has(p_device)) {  | 
 | 983 | +			joy_motion.insert(p_device, {});  | 
 | 984 | +		}  | 
 | 985 | +		joy_motion[p_device].accelerometer = Vector3();  | 
 | 986 | +	}  | 
 | 987 | +	return enabled;  | 
 | 988 | +}  | 
 | 989 | + | 
 | 990 | +bool Input::set_joy_gyroscope_enabled(int p_device, bool p_enable) {  | 
 | 991 | +	bool enabled = JoypadSDL::get_singleton()->enable_gyroscope(p_device, p_enable);  | 
 | 992 | +	if (enabled) {  | 
 | 993 | +		if (!joy_motion.has(p_device)) {  | 
 | 994 | +			joy_motion.insert(p_device, {});  | 
 | 995 | +		}  | 
 | 996 | +		joy_motion[p_device].gyroscope = Vector3();  | 
 | 997 | +	}  | 
 | 998 | +	return enabled;  | 
 | 999 | +}  | 
 | 1000 | + | 
 | 1001 | +void Input::set_joy_accelerometer(int p_device, const Vector3 &p_value) {  | 
 | 1002 | +	_THREAD_SAFE_METHOD_  | 
 | 1003 | +	if (!get_joy_accelerometer_enabled(p_device)) {  | 
 | 1004 | +		return;  | 
 | 1005 | +	}  | 
 | 1006 | + | 
 | 1007 | +	joy_motion[p_device].accelerometer = p_value;  | 
 | 1008 | +}  | 
 | 1009 | + | 
 | 1010 | +void Input::set_joy_gyroscope(int p_device, const Vector3 &p_value) {  | 
 | 1011 | +	_THREAD_SAFE_METHOD_  | 
 | 1012 | +	if (!get_joy_gyroscope_enabled(p_device)) {  | 
 | 1013 | +		return;  | 
 | 1014 | +	}  | 
 | 1015 | + | 
 | 1016 | +	joy_motion[p_device].gyroscope = p_value;  | 
 | 1017 | +}  | 
 | 1018 | + | 
 | 1019 | +bool Input::has_joy_light(int p_device) const {  | 
 | 1020 | +	return JoypadSDL::get_singleton()->has_light(p_device);  | 
 | 1021 | +}  | 
 | 1022 | + | 
 | 1023 | +bool Input::has_joy_accelerometer(int p_device) const {  | 
 | 1024 | +	return JoypadSDL::get_singleton()->has_accelerometer(p_device);  | 
 | 1025 | +}  | 
 | 1026 | + | 
 | 1027 | +bool Input::has_joy_gyroscope(int p_device) const {  | 
 | 1028 | +	return JoypadSDL::get_singleton()->has_gyroscope(p_device);  | 
 | 1029 | +}  | 
 | 1030 | + | 
917 | 1031 | void Input::start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration) {  | 
918 | 1032 | 	_THREAD_SAFE_METHOD_  | 
919 | 1033 | 	if (p_weak_magnitude < 0.f || p_weak_magnitude > 1.f || p_strong_magnitude < 0.f || p_strong_magnitude > 1.f) {  | 
 | 
0 commit comments