2014-02-09 22:10:30 -03:00
/**************************************************************************/
/* input_event.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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. */
/**************************************************************************/
2018-01-05 00:50:27 +01:00
2014-02-09 22:10:30 -03:00
# include "input_event.h"
2017-08-27 21:07:15 +02:00
2020-03-01 19:14:37 -03:00
# include "core/input/input_map.h"
2021-08-22 12:37:22 -03:00
# include "core/input/shortcut.h"
2018-09-11 18:13:45 +02:00
# include "core/os/keyboard.h"
2022-11-14 16:27:26 +02:00
# include "core/os/os.h"
2014-02-09 22:10:30 -03:00
2017-05-20 12:38:03 -03:00
void InputEvent : : set_device ( int p_device ) {
device = p_device ;
2021-06-28 00:15:56 +10:00
emit_changed ( ) ;
2017-05-20 12:38:03 -03:00
}
int InputEvent : : get_device ( ) const {
return device ;
2014-02-09 22:10:30 -03:00
}
2020-12-14 00:22:42 +10:00
bool InputEvent : : is_action ( const StringName & p_action , bool p_exact_match ) const {
2022-04-05 13:40:26 +03:00
return InputMap : : get_singleton ( ) - > event_is_action ( Ref < InputEvent > ( const_cast < InputEvent * > ( this ) ) , p_action , p_exact_match ) ;
2017-05-20 12:38:03 -03:00
}
2020-12-14 00:22:42 +10:00
bool InputEvent : : is_action_pressed ( const StringName & p_action , bool p_allow_echo , bool p_exact_match ) const {
2023-05-03 17:57:13 -07:00
bool pressed_state ;
bool valid = InputMap : : get_singleton ( ) - > event_get_action_status ( Ref < InputEvent > ( const_cast < InputEvent * > ( this ) ) , p_action , p_exact_match , & pressed_state , nullptr , nullptr ) ;
return valid & & pressed_state & & ( p_allow_echo | | ! is_echo ( ) ) ;
2017-05-20 12:38:03 -03:00
}
2018-02-21 22:06:34 +01:00
2020-12-14 00:22:42 +10:00
bool InputEvent : : is_action_released ( const StringName & p_action , bool p_exact_match ) const {
2023-05-03 17:57:13 -07:00
bool pressed_state ;
bool valid = InputMap : : get_singleton ( ) - > event_get_action_status ( Ref < InputEvent > ( const_cast < InputEvent * > ( this ) ) , p_action , p_exact_match , & pressed_state , nullptr , nullptr ) ;
return valid & & ! pressed_state ;
2018-02-21 22:06:34 +01:00
}
2020-12-14 00:22:42 +10:00
float InputEvent : : get_action_strength ( const StringName & p_action , bool p_exact_match ) const {
2018-02-21 22:06:34 +01:00
float strength ;
2022-04-05 13:40:26 +03:00
bool valid = InputMap : : get_singleton ( ) - > event_get_action_status ( Ref < InputEvent > ( const_cast < InputEvent * > ( this ) ) , p_action , p_exact_match , nullptr , & strength , nullptr ) ;
2018-02-21 22:06:34 +01:00
return valid ? strength : 0.0f ;
}
2020-12-14 00:22:42 +10:00
float InputEvent : : get_action_raw_strength ( const StringName & p_action , bool p_exact_match ) const {
2020-10-24 05:22:35 -04:00
float raw_strength ;
2022-04-05 13:40:26 +03:00
bool valid = InputMap : : get_singleton ( ) - > event_get_action_status ( Ref < InputEvent > ( const_cast < InputEvent * > ( this ) ) , p_action , p_exact_match , nullptr , nullptr , & raw_strength ) ;
2020-10-24 05:22:35 -04:00
return valid ? raw_strength : 0.0f ;
}
2023-05-03 17:57:13 -07:00
bool InputEvent : : is_canceled ( ) const {
return canceled ;
}
2018-02-21 22:06:34 +01:00
bool InputEvent : : is_pressed ( ) const {
2023-05-03 17:57:13 -07:00
return pressed & & ! canceled ;
}
bool InputEvent : : is_released ( ) const {
return ! pressed & & ! canceled ;
2014-02-09 22:10:30 -03:00
}
bool InputEvent : : is_echo ( ) const {
2017-05-20 12:38:03 -03:00
return false ;
2014-02-09 22:10:30 -03:00
}
2017-05-20 12:38:03 -03:00
Ref < InputEvent > InputEvent : : xformed_by ( const Transform2D & p_xform , const Vector2 & p_local_ofs ) const {
2022-04-05 13:40:26 +03:00
return Ref < InputEvent > ( const_cast < InputEvent * > ( this ) ) ;
2014-02-09 22:10:30 -03:00
}
2021-10-23 22:38:32 -05:00
bool InputEvent : : action_match ( const Ref < InputEvent > & p_event , bool p_exact_match , float p_deadzone , bool * r_pressed , float * r_strength , float * r_raw_strength ) const {
2017-05-20 12:38:03 -03:00
return false ;
}
2021-05-13 18:13:24 +01:00
bool InputEvent : : is_match ( const Ref < InputEvent > & p_event , bool p_exact_match ) const {
2017-06-22 19:57:59 -03:00
return false ;
}
2017-05-20 12:38:03 -03:00
bool InputEvent : : is_action_type ( ) const {
return false ;
}
void InputEvent : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_device " , " device " ) , & InputEvent : : set_device ) ;
ClassDB : : bind_method ( D_METHOD ( " get_device " ) , & InputEvent : : get_device ) ;
2020-12-14 00:22:42 +10:00
ClassDB : : bind_method ( D_METHOD ( " is_action " , " action " , " exact_match " ) , & InputEvent : : is_action , DEFVAL ( false ) ) ;
ClassDB : : bind_method ( D_METHOD ( " is_action_pressed " , " action " , " allow_echo " , " exact_match " ) , & InputEvent : : is_action_pressed , DEFVAL ( false ) , DEFVAL ( false ) ) ;
ClassDB : : bind_method ( D_METHOD ( " is_action_released " , " action " , " exact_match " ) , & InputEvent : : is_action_released , DEFVAL ( false ) ) ;
ClassDB : : bind_method ( D_METHOD ( " get_action_strength " , " action " , " exact_match " ) , & InputEvent : : get_action_strength , DEFVAL ( false ) ) ;
2018-02-21 22:06:34 +01:00
2023-05-03 17:57:13 -07:00
ClassDB : : bind_method ( D_METHOD ( " is_canceled " ) , & InputEvent : : is_canceled ) ;
2018-02-21 22:06:34 +01:00
ClassDB : : bind_method ( D_METHOD ( " is_pressed " ) , & InputEvent : : is_pressed ) ;
2023-05-03 17:57:13 -07:00
ClassDB : : bind_method ( D_METHOD ( " is_released " ) , & InputEvent : : is_released ) ;
2017-05-20 12:38:03 -03:00
ClassDB : : bind_method ( D_METHOD ( " is_echo " ) , & InputEvent : : is_echo ) ;
ClassDB : : bind_method ( D_METHOD ( " as_text " ) , & InputEvent : : as_text ) ;
2021-05-13 18:13:24 +01:00
ClassDB : : bind_method ( D_METHOD ( " is_match " , " event " , " exact_match " ) , & InputEvent : : is_match , DEFVAL ( true ) ) ;
2017-05-20 12:38:03 -03:00
ClassDB : : bind_method ( D_METHOD ( " is_action_type " ) , & InputEvent : : is_action_type ) ;
2019-03-03 19:52:18 -03:00
ClassDB : : bind_method ( D_METHOD ( " accumulate " , " with_event " ) , & InputEvent : : accumulate ) ;
2017-08-09 13:19:41 +02:00
ClassDB : : bind_method ( D_METHOD ( " xformed_by " , " xform " , " local_ofs " ) , & InputEvent : : xformed_by , DEFVAL ( Vector2 ( ) ) ) ;
2017-06-24 16:28:19 +03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " device " ) , " set_device " , " get_device " ) ;
2024-03-15 18:10:41 +01:00
2024-01-27 02:46:08 +01:00
ClassDB : : bind_method ( D_METHOD ( " get_timestamp " ) , & InputEvent : : get_timestamp ) ;
ClassDB : : bind_method ( D_METHOD ( " set_timestamp " , " timestamp " ) , & InputEvent : : set_timestamp ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " timestamp " ) , " set_timestamp " , " get_timestamp " ) ;
2024-03-15 18:10:41 +01:00
BIND_CONSTANT ( DEVICE_ID_EMULATION ) ;
2017-05-20 12:38:03 -03:00
}
2020-05-12 17:01:17 +02:00
///////////////////////////////////
2020-03-01 19:14:37 -03:00
void InputEventFromWindow : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_window_id " , " id " ) , & InputEventFromWindow : : set_window_id ) ;
ClassDB : : bind_method ( D_METHOD ( " get_window_id " ) , & InputEventFromWindow : : get_window_id ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " window_id " ) , " set_window_id " , " get_window_id " ) ;
}
void InputEventFromWindow : : set_window_id ( int64_t p_id ) {
window_id = p_id ;
2021-06-28 00:15:56 +10:00
emit_changed ( ) ;
2020-03-01 19:14:37 -03:00
}
2020-05-14 14:29:06 +02:00
2020-03-01 19:14:37 -03:00
int64_t InputEventFromWindow : : get_window_id ( ) const {
return window_id ;
}
2020-05-12 17:01:17 +02:00
///////////////////////////////////
2017-05-20 12:38:03 -03:00
2022-09-02 12:37:48 +03:00
void InputEventWithModifiers : : set_command_or_control_autoremap ( bool p_enabled ) {
command_or_control_autoremap = p_enabled ;
if ( command_or_control_autoremap ) {
2022-11-14 16:27:26 +02:00
if ( OS : : get_singleton ( ) - > has_feature ( " macos " ) | | OS : : get_singleton ( ) - > has_feature ( " web_macos " ) | | OS : : get_singleton ( ) - > has_feature ( " web_ios " ) ) {
ctrl_pressed = false ;
meta_pressed = true ;
} else {
ctrl_pressed = true ;
meta_pressed = false ;
}
2022-09-02 12:37:48 +03:00
} else {
ctrl_pressed = false ;
meta_pressed = false ;
}
2021-06-28 00:15:56 +10:00
emit_changed ( ) ;
2020-09-29 00:23:51 +10:00
}
2022-09-02 12:37:48 +03:00
bool InputEventWithModifiers : : is_command_or_control_autoremap ( ) const {
return command_or_control_autoremap ;
}
bool InputEventWithModifiers : : is_command_or_control_pressed ( ) const {
2022-11-14 16:27:26 +02:00
if ( OS : : get_singleton ( ) - > has_feature ( " macos " ) | | OS : : get_singleton ( ) - > has_feature ( " web_macos " ) | | OS : : get_singleton ( ) - > has_feature ( " web_ios " ) ) {
return meta_pressed ;
} else {
return ctrl_pressed ;
}
2020-09-29 00:23:51 +10:00
}
2021-04-24 14:33:50 -06:00
void InputEventWithModifiers : : set_shift_pressed ( bool p_enabled ) {
shift_pressed = p_enabled ;
2021-06-28 00:15:56 +10:00
emit_changed ( ) ;
2017-05-20 12:38:03 -03:00
}
2021-04-24 14:33:50 -06:00
bool InputEventWithModifiers : : is_shift_pressed ( ) const {
return shift_pressed ;
2017-05-20 12:38:03 -03:00
}
2021-04-24 14:33:50 -06:00
void InputEventWithModifiers : : set_alt_pressed ( bool p_enabled ) {
alt_pressed = p_enabled ;
2021-06-28 00:15:56 +10:00
emit_changed ( ) ;
2017-05-20 12:38:03 -03:00
}
2020-05-14 14:29:06 +02:00
2021-04-24 14:33:50 -06:00
bool InputEventWithModifiers : : is_alt_pressed ( ) const {
return alt_pressed ;
2017-05-20 12:38:03 -03:00
}
2021-04-24 14:33:50 -06:00
void InputEventWithModifiers : : set_ctrl_pressed ( bool p_enabled ) {
2023-03-28 16:48:18 -07:00
ERR_FAIL_COND_MSG ( command_or_control_autoremap , " Command or Control autoremapping is enabled, cannot set Control directly! " ) ;
2021-04-24 14:33:50 -06:00
ctrl_pressed = p_enabled ;
2021-06-28 00:15:56 +10:00
emit_changed ( ) ;
2017-05-20 12:38:03 -03:00
}
2020-05-14 14:29:06 +02:00
2021-04-24 14:33:50 -06:00
bool InputEventWithModifiers : : is_ctrl_pressed ( ) const {
return ctrl_pressed ;
2017-05-20 12:38:03 -03:00
}
2021-04-24 14:33:50 -06:00
void InputEventWithModifiers : : set_meta_pressed ( bool p_enabled ) {
2023-03-28 16:48:18 -07:00
ERR_FAIL_COND_MSG ( command_or_control_autoremap , " Command or Control autoremapping is enabled, cannot set Meta directly! " ) ;
2021-04-24 14:33:50 -06:00
meta_pressed = p_enabled ;
2021-06-28 00:15:56 +10:00
emit_changed ( ) ;
2017-05-20 12:38:03 -03:00
}
2020-05-14 14:29:06 +02:00
2021-04-24 14:33:50 -06:00
bool InputEventWithModifiers : : is_meta_pressed ( ) const {
return meta_pressed ;
2017-05-20 12:38:03 -03:00
}
2017-11-01 21:49:39 +01:00
void InputEventWithModifiers : : set_modifiers_from_event ( const InputEventWithModifiers * event ) {
2021-04-24 14:33:50 -06:00
set_alt_pressed ( event - > is_alt_pressed ( ) ) ;
set_shift_pressed ( event - > is_shift_pressed ( ) ) ;
set_ctrl_pressed ( event - > is_ctrl_pressed ( ) ) ;
set_meta_pressed ( event - > is_meta_pressed ( ) ) ;
2017-11-01 21:49:39 +01:00
}
2023-01-08 00:55:54 +01:00
BitField < KeyModifierMask > InputEventWithModifiers : : get_modifiers_mask ( ) const {
BitField < KeyModifierMask > mask ;
2021-05-13 18:13:24 +01:00
if ( is_ctrl_pressed ( ) ) {
2023-01-08 00:55:54 +01:00
mask . set_flag ( KeyModifierMask : : CTRL ) ;
2021-05-13 18:13:24 +01:00
}
if ( is_shift_pressed ( ) ) {
2023-01-08 00:55:54 +01:00
mask . set_flag ( KeyModifierMask : : SHIFT ) ;
2021-05-13 18:13:24 +01:00
}
if ( is_alt_pressed ( ) ) {
2023-01-08 00:55:54 +01:00
mask . set_flag ( KeyModifierMask : : ALT ) ;
2021-05-13 18:13:24 +01:00
}
if ( is_meta_pressed ( ) ) {
2023-01-08 00:55:54 +01:00
mask . set_flag ( KeyModifierMask : : META ) ;
2021-05-13 18:13:24 +01:00
}
2022-09-02 12:37:48 +03:00
if ( is_command_or_control_autoremap ( ) ) {
2022-11-14 16:27:26 +02:00
if ( OS : : get_singleton ( ) - > has_feature ( " macos " ) | | OS : : get_singleton ( ) - > has_feature ( " web_macos " ) | | OS : : get_singleton ( ) - > has_feature ( " web_ios " ) ) {
mask . set_flag ( KeyModifierMask : : META ) ;
} else {
mask . set_flag ( KeyModifierMask : : CTRL ) ;
}
2022-09-02 12:37:48 +03:00
}
2021-05-13 18:13:24 +01:00
return mask ;
}
2020-10-01 22:55:23 +10:00
String InputEventWithModifiers : : as_text ( ) const {
Vector < String > mod_names ;
2021-04-24 14:33:50 -06:00
if ( is_ctrl_pressed ( ) ) {
2021-08-13 16:31:57 -05:00
mod_names . push_back ( find_keycode_name ( Key : : CTRL ) ) ;
2020-10-01 22:55:23 +10:00
}
2021-04-24 14:33:50 -06:00
if ( is_shift_pressed ( ) ) {
2021-08-13 16:31:57 -05:00
mod_names . push_back ( find_keycode_name ( Key : : SHIFT ) ) ;
2020-10-01 22:55:23 +10:00
}
2021-04-24 14:33:50 -06:00
if ( is_alt_pressed ( ) ) {
2021-08-13 16:31:57 -05:00
mod_names . push_back ( find_keycode_name ( Key : : ALT ) ) ;
2020-10-01 22:55:23 +10:00
}
2021-04-24 14:33:50 -06:00
if ( is_meta_pressed ( ) ) {
2021-08-13 16:31:57 -05:00
mod_names . push_back ( find_keycode_name ( Key : : META ) ) ;
2020-10-01 22:55:23 +10:00
}
2020-12-15 12:04:21 +00:00
if ( ! mod_names . is_empty ( ) ) {
2020-10-01 22:55:23 +10:00
return String ( " + " ) . join ( mod_names ) ;
} else {
2020-12-14 12:42:42 +10:00
return " " ;
2020-10-01 22:55:23 +10:00
}
}
String InputEventWithModifiers : : to_string ( ) {
return as_text ( ) ;
}
2017-05-20 12:38:03 -03:00
void InputEventWithModifiers : : _bind_methods ( ) {
2022-09-02 12:37:48 +03:00
ClassDB : : bind_method ( D_METHOD ( " set_command_or_control_autoremap " , " enable " ) , & InputEventWithModifiers : : set_command_or_control_autoremap ) ;
ClassDB : : bind_method ( D_METHOD ( " is_command_or_control_autoremap " ) , & InputEventWithModifiers : : is_command_or_control_autoremap ) ;
ClassDB : : bind_method ( D_METHOD ( " is_command_or_control_pressed " ) , & InputEventWithModifiers : : is_command_or_control_pressed ) ;
2020-09-29 00:23:51 +10:00
2021-04-24 14:33:50 -06:00
ClassDB : : bind_method ( D_METHOD ( " set_alt_pressed " , " pressed " ) , & InputEventWithModifiers : : set_alt_pressed ) ;
ClassDB : : bind_method ( D_METHOD ( " is_alt_pressed " ) , & InputEventWithModifiers : : is_alt_pressed ) ;
2017-05-20 12:38:03 -03:00
2021-04-24 14:33:50 -06:00
ClassDB : : bind_method ( D_METHOD ( " set_shift_pressed " , " pressed " ) , & InputEventWithModifiers : : set_shift_pressed ) ;
ClassDB : : bind_method ( D_METHOD ( " is_shift_pressed " ) , & InputEventWithModifiers : : is_shift_pressed ) ;
2017-05-20 12:38:03 -03:00
2021-04-24 14:33:50 -06:00
ClassDB : : bind_method ( D_METHOD ( " set_ctrl_pressed " , " pressed " ) , & InputEventWithModifiers : : set_ctrl_pressed ) ;
ClassDB : : bind_method ( D_METHOD ( " is_ctrl_pressed " ) , & InputEventWithModifiers : : is_ctrl_pressed ) ;
2017-05-20 12:38:03 -03:00
2021-04-24 14:33:50 -06:00
ClassDB : : bind_method ( D_METHOD ( " set_meta_pressed " , " pressed " ) , & InputEventWithModifiers : : set_meta_pressed ) ;
ClassDB : : bind_method ( D_METHOD ( " is_meta_pressed " ) , & InputEventWithModifiers : : is_meta_pressed ) ;
2017-05-20 12:38:03 -03:00
2022-12-11 01:21:22 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_modifiers_mask " ) , & InputEventWithModifiers : : get_modifiers_mask ) ;
2022-09-02 12:37:48 +03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " command_or_control_autoremap " ) , " set_command_or_control_autoremap " , " is_command_or_control_autoremap " ) ;
2021-04-24 14:33:50 -06:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " alt_pressed " ) , " set_alt_pressed " , " is_alt_pressed " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " shift_pressed " ) , " set_shift_pressed " , " is_shift_pressed " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " ctrl_pressed " ) , " set_ctrl_pressed " , " is_ctrl_pressed " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " meta_pressed " ) , " set_meta_pressed " , " is_meta_pressed " ) ;
2017-05-20 12:38:03 -03:00
}
2022-08-12 23:57:11 +03:00
void InputEventWithModifiers : : _validate_property ( PropertyInfo & p_property ) const {
2022-09-02 12:37:48 +03:00
if ( command_or_control_autoremap ) {
// Cannot be used with Meta/Command or Control!
2022-08-12 23:57:11 +03:00
if ( p_property . name = = " meta_pressed " ) {
p_property . usage ^ = PROPERTY_USAGE_STORAGE ;
2020-09-29 00:23:51 +10:00
}
2022-08-12 23:57:11 +03:00
if ( p_property . name = = " ctrl_pressed " ) {
p_property . usage ^ = PROPERTY_USAGE_STORAGE ;
2020-09-29 00:23:51 +10:00
}
} else {
2022-09-02 12:37:48 +03:00
if ( p_property . name = = " command_or_control_autoremap " ) {
2022-08-12 23:57:11 +03:00
p_property . usage ^ = PROPERTY_USAGE_STORAGE ;
2020-09-29 00:23:51 +10:00
}
}
}
2020-05-12 17:01:17 +02:00
///////////////////////////////////
2017-05-20 12:38:03 -03:00
void InputEventKey : : set_pressed ( bool p_pressed ) {
pressed = p_pressed ;
2021-06-28 00:15:56 +10:00
emit_changed ( ) ;
2017-05-20 12:38:03 -03:00
}
2021-06-20 13:12:33 -04:00
void InputEventKey : : set_keycode ( Key p_keycode ) {
2018-04-05 20:59:35 +03:00
keycode = p_keycode ;
2021-06-28 00:15:56 +10:00
emit_changed ( ) ;
2017-05-20 12:38:03 -03:00
}
2021-06-20 13:12:33 -04:00
Key InputEventKey : : get_keycode ( ) const {
2018-04-05 20:59:35 +03:00
return keycode ;
}
2022-12-11 01:21:22 +02:00
void InputEventKey : : set_key_label ( Key p_key_label ) {
key_label = p_key_label ;
emit_changed ( ) ;
}
Key InputEventKey : : get_key_label ( ) const {
return key_label ;
}
2021-06-20 13:12:33 -04:00
void InputEventKey : : set_physical_keycode ( Key p_keycode ) {
2018-04-05 20:59:35 +03:00
physical_keycode = p_keycode ;
2021-06-28 00:15:56 +10:00
emit_changed ( ) ;
2018-04-05 20:59:35 +03:00
}
2021-06-20 13:12:33 -04:00
Key InputEventKey : : get_physical_keycode ( ) const {
2018-04-05 20:59:35 +03:00
return physical_keycode ;
2017-05-20 12:38:03 -03:00
}
2021-08-13 16:31:57 -05:00
void InputEventKey : : set_unicode ( char32_t p_unicode ) {
2017-05-20 12:38:03 -03:00
unicode = p_unicode ;
2021-06-28 00:15:56 +10:00
emit_changed ( ) ;
2017-05-20 12:38:03 -03:00
}
2018-04-05 20:59:35 +03:00
2021-08-13 16:31:57 -05:00
char32_t InputEventKey : : get_unicode ( ) const {
2017-05-20 12:38:03 -03:00
return unicode ;
}
2023-08-03 15:18:26 +02:00
void InputEventKey : : set_location ( KeyLocation p_key_location ) {
location = p_key_location ;
emit_changed ( ) ;
}
KeyLocation InputEventKey : : get_location ( ) const {
return location ;
}
2017-05-20 12:38:03 -03:00
void InputEventKey : : set_echo ( bool p_enable ) {
echo = p_enable ;
2021-06-28 00:15:56 +10:00
emit_changed ( ) ;
2017-05-20 12:38:03 -03:00
}
2018-04-05 20:59:35 +03:00
2017-05-20 12:38:03 -03:00
bool InputEventKey : : is_echo ( ) const {
return echo ;
2015-06-23 16:24:48 -04:00
}
2021-08-13 16:31:57 -05:00
Key InputEventKey : : get_keycode_with_modifiers ( ) const {
2023-01-08 00:55:54 +01:00
return keycode | ( int64_t ) get_modifiers_mask ( ) ;
2018-04-05 20:59:35 +03:00
}
2021-08-13 16:31:57 -05:00
Key InputEventKey : : get_physical_keycode_with_modifiers ( ) const {
2023-01-08 00:55:54 +01:00
return physical_keycode | ( int64_t ) get_modifiers_mask ( ) ;
2014-02-09 22:10:30 -03:00
}
2016-06-27 09:59:43 -03:00
2022-12-11 01:21:22 +02:00
Key InputEventKey : : get_key_label_with_modifiers ( ) const {
return key_label | get_modifiers_mask ( ) ;
}
String InputEventKey : : as_text_physical_keycode ( ) const {
String kc ;
if ( physical_keycode ! = Key : : NONE ) {
kc = keycode_get_string ( physical_keycode ) ;
} else {
kc = " ( " + RTR ( " Unset " ) + " ) " ;
}
if ( kc . is_empty ( ) ) {
return kc ;
}
String mods_text = InputEventWithModifiers : : as_text ( ) ;
return mods_text . is_empty ( ) ? kc : mods_text + " + " + kc ;
}
String InputEventKey : : as_text_keycode ( ) const {
String kc ;
if ( keycode ! = Key : : NONE ) {
kc = keycode_get_string ( keycode ) ;
} else {
kc = " ( " + RTR ( " Unset " ) + " ) " ;
}
if ( kc . is_empty ( ) ) {
return kc ;
}
String mods_text = InputEventWithModifiers : : as_text ( ) ;
return mods_text . is_empty ( ) ? kc : mods_text + " + " + kc ;
}
String InputEventKey : : as_text_key_label ( ) const {
String kc ;
if ( key_label ! = Key : : NONE ) {
kc = keycode_get_string ( key_label ) ;
} else {
kc = " ( " + RTR ( " Unset " ) + " ) " ;
}
if ( kc . is_empty ( ) ) {
return kc ;
}
String mods_text = InputEventWithModifiers : : as_text ( ) ;
return mods_text . is_empty ( ) ? kc : mods_text + " + " + kc ;
}
2023-08-03 15:18:26 +02:00
String InputEventKey : : as_text_location ( ) const {
String loc ;
switch ( location ) {
case KeyLocation : : LEFT :
loc = " left " ;
break ;
case KeyLocation : : RIGHT :
loc = " right " ;
break ;
default :
break ;
}
return loc ;
}
2017-06-22 19:57:59 -03:00
String InputEventKey : : as_text ( ) const {
2020-10-01 22:55:23 +10:00
String kc ;
2022-12-11 01:21:22 +02:00
if ( keycode = = Key : : NONE & & physical_keycode = = Key : : NONE & & key_label ! = Key : : NONE ) {
kc = keycode_get_string ( key_label ) + " (Unicode) " ;
} else if ( keycode ! = Key : : NONE ) {
kc = keycode_get_string ( keycode ) ;
} else if ( physical_keycode ! = Key : : NONE ) {
2020-10-01 22:55:23 +10:00
kc = keycode_get_string ( physical_keycode ) + " ( " + RTR ( " Physical " ) + " ) " ;
} else {
2022-12-11 01:21:22 +02:00
kc = " ( " + RTR ( " Unset " ) + " ) " ;
2020-10-01 22:55:23 +10:00
}
2021-12-09 03:42:46 -06:00
if ( kc . is_empty ( ) ) {
2017-06-22 19:57:59 -03:00
return kc ;
2020-05-14 16:41:43 +02:00
}
2017-06-22 19:57:59 -03:00
2020-10-01 22:55:23 +10:00
String mods_text = InputEventWithModifiers : : as_text ( ) ;
2021-12-09 03:42:46 -06:00
return mods_text . is_empty ( ) ? kc : mods_text + " + " + kc ;
2020-10-01 22:55:23 +10:00
}
String InputEventKey : : to_string ( ) {
String p = is_pressed ( ) ? " true " : " false " ;
String e = is_echo ( ) ? " true " : " false " ;
2020-12-14 12:42:42 +10:00
String kc = " " ;
String physical = " false " ;
2022-12-11 01:21:22 +02:00
2023-08-03 15:18:26 +02:00
String loc = as_text_location ( ) ;
if ( loc . is_empty ( ) ) {
loc = " unspecified " ;
}
2022-12-11 01:21:22 +02:00
if ( keycode = = Key : : NONE & & physical_keycode = = Key : : NONE & & unicode ! = 0 ) {
kc = " U+ " + String : : num_uint64 ( unicode , 16 ) + " ( " + String : : chr ( unicode ) + " ) " ;
} else if ( keycode ! = Key : : NONE ) {
kc = itos ( ( int64_t ) keycode ) + " ( " + keycode_get_string ( keycode ) + " ) " ;
} else if ( physical_keycode ! = Key : : NONE ) {
2021-08-13 16:31:57 -05:00
kc = itos ( ( int64_t ) physical_keycode ) + " ( " + keycode_get_string ( physical_keycode ) + " ) " ;
2020-12-14 12:42:42 +10:00
physical = " true " ;
2020-10-01 22:55:23 +10:00
} else {
2022-12-11 01:21:22 +02:00
kc = " ( " + RTR ( " Unset " ) + " ) " ;
2017-06-22 19:57:59 -03:00
}
2020-12-14 12:42:42 +10:00
String mods = InputEventWithModifiers : : as_text ( ) ;
2022-03-28 15:24:14 +02:00
mods = mods . is_empty ( ) ? " none " : mods ;
2020-12-14 12:42:42 +10:00
2023-08-03 15:18:26 +02:00
return vformat ( " InputEventKey: keycode=%s, mods=%s, physical=%s, location=%s, pressed=%s, echo=%s " , kc , mods , physical , loc , p , e ) ;
2017-06-22 19:57:59 -03:00
}
2023-02-20 23:11:57 +01:00
Ref < InputEventKey > InputEventKey : : create_reference ( Key p_keycode , bool p_physical ) {
2020-12-07 21:31:25 +10:00
Ref < InputEventKey > ie ;
2021-06-17 16:03:09 -06:00
ie . instantiate ( ) ;
2023-02-20 23:11:57 +01:00
if ( p_physical ) {
ie - > set_physical_keycode ( p_keycode & KeyModifierMask : : CODE_MASK ) ;
} else {
ie - > set_keycode ( p_keycode & KeyModifierMask : : CODE_MASK ) ;
}
2023-05-09 15:50:48 +02:00
char32_t ch = char32_t ( p_keycode & KeyModifierMask : : CODE_MASK ) ;
if ( ch < 0xd800 | | ( ch > 0xdfff & & ch < = 0x10ffff ) ) {
ie - > set_unicode ( ch ) ;
}
2020-12-07 21:31:25 +10:00
2021-08-13 16:31:57 -05:00
if ( ( p_keycode & KeyModifierMask : : SHIFT ) ! = Key : : NONE ) {
2021-04-24 14:33:50 -06:00
ie - > set_shift_pressed ( true ) ;
2020-12-07 21:31:25 +10:00
}
2021-08-13 16:31:57 -05:00
if ( ( p_keycode & KeyModifierMask : : ALT ) ! = Key : : NONE ) {
2021-04-24 14:33:50 -06:00
ie - > set_alt_pressed ( true ) ;
2020-12-07 21:31:25 +10:00
}
2022-09-02 12:37:48 +03:00
if ( ( p_keycode & KeyModifierMask : : CMD_OR_CTRL ) ! = Key : : NONE ) {
ie - > set_command_or_control_autoremap ( true ) ;
if ( ( p_keycode & KeyModifierMask : : CTRL ) ! = Key : : NONE | | ( p_keycode & KeyModifierMask : : META ) ! = Key : : NONE ) {
WARN_PRINT ( " Invalid Key Modifiers: Command or Control autoremapping is enabled, Meta and Control values are ignored! " ) ;
}
} else {
if ( ( p_keycode & KeyModifierMask : : CTRL ) ! = Key : : NONE ) {
ie - > set_ctrl_pressed ( true ) ;
}
if ( ( p_keycode & KeyModifierMask : : META ) ! = Key : : NONE ) {
ie - > set_meta_pressed ( true ) ;
}
2020-12-07 21:31:25 +10:00
}
return ie ;
}
2021-10-23 22:38:32 -05:00
bool InputEventKey : : action_match ( const Ref < InputEvent > & p_event , bool p_exact_match , float p_deadzone , bool * r_pressed , float * r_strength , float * r_raw_strength ) const {
2017-05-20 12:38:03 -03:00
Ref < InputEventKey > key = p_event ;
2020-05-14 16:41:43 +02:00
if ( key . is_null ( ) ) {
2017-05-20 12:38:03 -03:00
return false ;
2020-05-14 16:41:43 +02:00
}
2016-06-27 09:59:43 -03:00
2021-10-23 22:38:32 -05:00
bool match ;
2022-12-11 01:21:22 +02:00
if ( keycode = = Key : : NONE & & physical_keycode = = Key : : NONE & & key_label ! = Key : : NONE ) {
match = key_label = = key - > key_label ;
} else if ( keycode ! = Key : : NONE ) {
2021-10-23 22:38:32 -05:00
match = keycode = = key - > keycode ;
2022-12-11 01:21:22 +02:00
} else if ( physical_keycode ! = Key : : NONE ) {
match = physical_keycode = = key - > physical_keycode ;
2023-08-03 15:18:26 +02:00
if ( location ! = KeyLocation : : UNSPECIFIED ) {
match & = location = = key - > location ;
}
2018-04-05 20:59:35 +03:00
} else {
2022-12-11 01:21:22 +02:00
match = false ;
2021-10-23 22:38:32 -05:00
}
2022-12-11 01:21:22 +02:00
2023-01-08 00:55:54 +01:00
Key action_mask = ( Key ) ( int64_t ) get_modifiers_mask ( ) ;
Key key_mask = ( Key ) ( int64_t ) key - > get_modifiers_mask ( ) ;
2022-03-20 06:57:28 +00:00
if ( key - > is_pressed ( ) ) {
match & = ( action_mask & key_mask ) = = action_mask ;
}
2021-10-23 22:38:32 -05:00
if ( p_exact_match ) {
2022-03-20 06:57:28 +00:00
match & = action_mask = = key_mask ;
2018-04-05 20:59:35 +03:00
}
2018-02-21 22:06:34 +01:00
if ( match ) {
2022-09-29 12:53:28 +03:00
bool key_pressed = key - > is_pressed ( ) ;
2021-10-23 22:38:32 -05:00
if ( r_pressed ! = nullptr ) {
2022-09-29 12:53:28 +03:00
* r_pressed = key_pressed ;
2020-05-14 16:41:43 +02:00
}
2022-09-29 12:53:28 +03:00
float strength = key_pressed ? 1.0f : 0.0f ;
2021-10-23 22:38:32 -05:00
if ( r_strength ! = nullptr ) {
* r_strength = strength ;
2020-10-24 05:22:35 -04:00
}
2021-10-23 22:38:32 -05:00
if ( r_raw_strength ! = nullptr ) {
* r_raw_strength = strength ;
2020-05-14 16:41:43 +02:00
}
2018-02-21 22:06:34 +01:00
}
return match ;
2017-05-20 12:38:03 -03:00
}
2021-05-13 18:13:24 +01:00
bool InputEventKey : : is_match ( const Ref < InputEvent > & p_event , bool p_exact_match ) const {
2017-06-22 19:57:59 -03:00
Ref < InputEventKey > key = p_event ;
2020-05-14 16:41:43 +02:00
if ( key . is_null ( ) ) {
2017-06-22 19:57:59 -03:00
return false ;
2020-05-14 16:41:43 +02:00
}
2017-06-22 19:57:59 -03:00
2022-12-11 01:21:22 +02:00
if ( keycode = = Key : : NONE & & physical_keycode = = Key : : NONE & & key_label ! = Key : : NONE ) {
return ( key_label = = key - > key_label ) & &
( ! p_exact_match | | get_modifiers_mask ( ) = = key - > get_modifiers_mask ( ) ) ;
} else if ( keycode ! = Key : : NONE ) {
return ( keycode = = key - > keycode ) & &
( ! p_exact_match | | get_modifiers_mask ( ) = = key - > get_modifiers_mask ( ) ) ;
} else if ( physical_keycode ! = Key : : NONE ) {
2023-08-03 15:18:26 +02:00
if ( location ! = KeyLocation : : UNSPECIFIED & & location ! = key - > location ) {
return false ;
}
2022-12-11 01:21:22 +02:00
return ( physical_keycode = = key - > physical_keycode ) & &
2021-10-28 15:19:35 +02:00
( ! p_exact_match | | get_modifiers_mask ( ) = = key - > get_modifiers_mask ( ) ) ;
2021-10-19 22:19:41 +03:00
} else {
2022-12-11 01:21:22 +02:00
return false ;
2021-10-19 22:19:41 +03:00
}
2017-06-22 19:57:59 -03:00
}
2017-05-20 12:38:03 -03:00
void InputEventKey : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_pressed " , " pressed " ) , & InputEventKey : : set_pressed ) ;
2018-04-05 20:59:35 +03:00
ClassDB : : bind_method ( D_METHOD ( " set_keycode " , " keycode " ) , & InputEventKey : : set_keycode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_keycode " ) , & InputEventKey : : get_keycode ) ;
ClassDB : : bind_method ( D_METHOD ( " set_physical_keycode " , " physical_keycode " ) , & InputEventKey : : set_physical_keycode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_physical_keycode " ) , & InputEventKey : : get_physical_keycode ) ;
2017-05-20 12:38:03 -03:00
2022-12-11 01:21:22 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_key_label " , " key_label " ) , & InputEventKey : : set_key_label ) ;
ClassDB : : bind_method ( D_METHOD ( " get_key_label " ) , & InputEventKey : : get_key_label ) ;
2017-05-20 12:38:03 -03:00
ClassDB : : bind_method ( D_METHOD ( " set_unicode " , " unicode " ) , & InputEventKey : : set_unicode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_unicode " ) , & InputEventKey : : get_unicode ) ;
2023-08-03 15:18:26 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_location " , " location " ) , & InputEventKey : : set_location ) ;
ClassDB : : bind_method ( D_METHOD ( " get_location " ) , & InputEventKey : : get_location ) ;
2017-05-20 12:38:03 -03:00
ClassDB : : bind_method ( D_METHOD ( " set_echo " , " echo " ) , & InputEventKey : : set_echo ) ;
2018-04-05 20:59:35 +03:00
ClassDB : : bind_method ( D_METHOD ( " get_keycode_with_modifiers " ) , & InputEventKey : : get_keycode_with_modifiers ) ;
ClassDB : : bind_method ( D_METHOD ( " get_physical_keycode_with_modifiers " ) , & InputEventKey : : get_physical_keycode_with_modifiers ) ;
2022-12-11 01:21:22 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_key_label_with_modifiers " ) , & InputEventKey : : get_key_label_with_modifiers ) ;
ClassDB : : bind_method ( D_METHOD ( " as_text_keycode " ) , & InputEventKey : : as_text_keycode ) ;
ClassDB : : bind_method ( D_METHOD ( " as_text_physical_keycode " ) , & InputEventKey : : as_text_physical_keycode ) ;
ClassDB : : bind_method ( D_METHOD ( " as_text_key_label " ) , & InputEventKey : : as_text_key_label ) ;
2023-08-03 15:18:26 +02:00
ClassDB : : bind_method ( D_METHOD ( " as_text_location " ) , & InputEventKey : : as_text_location ) ;
2017-05-20 12:38:03 -03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " pressed " ) , " set_pressed " , " is_pressed " ) ;
2018-04-05 20:59:35 +03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " keycode " ) , " set_keycode " , " get_keycode " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " physical_keycode " ) , " set_physical_keycode " , " get_physical_keycode " ) ;
2022-12-11 01:21:22 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " key_label " ) , " set_key_label " , " get_key_label " ) ;
2017-05-20 12:38:03 -03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " unicode " ) , " set_unicode " , " get_unicode " ) ;
2023-08-03 15:18:26 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " location " , PROPERTY_HINT_ENUM , " Unspecified,Left,Right " ) , " set_location " , " get_location " ) ;
2020-03-01 09:52:37 +03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " echo " ) , " set_echo " , " is_echo " ) ;
2017-05-20 12:38:03 -03:00
}
2020-05-12 17:01:17 +02:00
///////////////////////////////////
2017-05-20 12:38:03 -03:00
2023-01-08 00:55:54 +01:00
void InputEventMouse : : set_button_mask ( BitField < MouseButtonMask > p_mask ) {
2017-05-20 12:38:03 -03:00
button_mask = p_mask ;
2021-06-28 00:15:56 +10:00
emit_changed ( ) ;
2017-05-20 12:38:03 -03:00
}
2020-05-14 14:29:06 +02:00
2023-01-08 00:55:54 +01:00
BitField < MouseButtonMask > InputEventMouse : : get_button_mask ( ) const {
2017-05-20 12:38:03 -03:00
return button_mask ;
}
2017-06-03 10:54:24 +02:00
void InputEventMouse : : set_position ( const Vector2 & p_pos ) {
2017-05-20 12:38:03 -03:00
pos = p_pos ;
}
2020-05-14 14:29:06 +02:00
2017-06-03 10:54:24 +02:00
Vector2 InputEventMouse : : get_position ( ) const {
2017-05-20 12:38:03 -03:00
return pos ;
}
2017-06-03 10:54:24 +02:00
void InputEventMouse : : set_global_position ( const Vector2 & p_global_pos ) {
2017-05-20 12:38:03 -03:00
global_pos = p_global_pos ;
}
2020-05-14 14:29:06 +02:00
2017-06-03 10:54:24 +02:00
Vector2 InputEventMouse : : get_global_position ( ) const {
2017-05-20 12:38:03 -03:00
return global_pos ;
}
void InputEventMouse : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_button_mask " , " button_mask " ) , & InputEventMouse : : set_button_mask ) ;
ClassDB : : bind_method ( D_METHOD ( " get_button_mask " ) , & InputEventMouse : : get_button_mask ) ;
2017-06-03 10:54:24 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_position " , " position " ) , & InputEventMouse : : set_position ) ;
ClassDB : : bind_method ( D_METHOD ( " get_position " ) , & InputEventMouse : : get_position ) ;
2017-05-20 12:38:03 -03:00
2017-06-03 10:54:24 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_global_position " , " global_position " ) , & InputEventMouse : : set_global_position ) ;
ClassDB : : bind_method ( D_METHOD ( " get_global_position " ) , & InputEventMouse : : get_global_position ) ;
2017-05-20 12:38:03 -03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " button_mask " ) , " set_button_mask " , " get_button_mask " ) ;
2022-05-20 00:24:41 -05:00
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR2 , " position " , PROPERTY_HINT_NONE , " suffix:px " ) , " set_position " , " get_position " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR2 , " global_position " , PROPERTY_HINT_NONE , " suffix:px " ) , " set_global_position " , " get_global_position " ) ;
2017-05-20 12:38:03 -03:00
}
2020-05-12 17:01:17 +02:00
///////////////////////////////////
2017-05-20 12:38:03 -03:00
void InputEventMouseButton : : set_factor ( float p_factor ) {
factor = p_factor ;
}
2020-04-25 13:25:00 +02:00
float InputEventMouseButton : : get_factor ( ) const {
2017-05-20 12:38:03 -03:00
return factor ;
}
2021-03-25 16:56:12 -04:00
void InputEventMouseButton : : set_button_index ( MouseButton p_index ) {
2017-05-20 12:38:03 -03:00
button_index = p_index ;
2021-06-28 00:15:56 +10:00
emit_changed ( ) ;
2017-05-20 12:38:03 -03:00
}
2020-05-14 14:29:06 +02:00
2021-03-25 16:56:12 -04:00
MouseButton InputEventMouseButton : : get_button_index ( ) const {
2017-05-20 12:38:03 -03:00
return button_index ;
}
void InputEventMouseButton : : set_pressed ( bool p_pressed ) {
pressed = p_pressed ;
}
2020-05-14 14:29:06 +02:00
2023-05-03 17:57:13 -07:00
void InputEventMouseButton : : set_canceled ( bool p_canceled ) {
canceled = p_canceled ;
2017-05-20 12:38:03 -03:00
}
2021-04-13 04:25:44 -04:00
void InputEventMouseButton : : set_double_click ( bool p_double_click ) {
double_click = p_double_click ;
2017-05-20 12:38:03 -03:00
}
2020-05-14 14:29:06 +02:00
2021-04-13 04:25:44 -04:00
bool InputEventMouseButton : : is_double_click ( ) const {
return double_click ;
2017-05-20 12:38:03 -03:00
}
Ref < InputEvent > InputEventMouseButton : : xformed_by ( const Transform2D & p_xform , const Vector2 & p_local_ofs ) const {
2019-09-03 00:58:10 +02:00
Vector2 g = get_global_position ( ) ;
2017-06-03 10:54:24 +02:00
Vector2 l = p_xform . xform ( get_position ( ) + p_local_ofs ) ;
2017-05-20 12:38:03 -03:00
Ref < InputEventMouseButton > mb ;
2021-06-17 16:03:09 -06:00
mb . instantiate ( ) ;
2017-05-20 12:38:03 -03:00
mb - > set_device ( get_device ( ) ) ;
2020-03-01 19:14:37 -03:00
mb - > set_window_id ( get_window_id ( ) ) ;
2017-11-01 21:49:39 +01:00
mb - > set_modifiers_from_event ( this ) ;
2017-05-20 12:38:03 -03:00
2017-06-03 10:54:24 +02:00
mb - > set_position ( l ) ;
mb - > set_global_position ( g ) ;
2017-05-20 12:38:03 -03:00
mb - > set_button_mask ( get_button_mask ( ) ) ;
mb - > set_pressed ( pressed ) ;
2023-05-03 17:57:13 -07:00
mb - > set_canceled ( canceled ) ;
2021-04-13 04:25:44 -04:00
mb - > set_double_click ( double_click ) ;
2017-05-20 12:38:03 -03:00
mb - > set_factor ( factor ) ;
mb - > set_button_index ( button_index ) ;
return mb ;
}
2021-10-23 22:38:32 -05:00
bool InputEventMouseButton : : action_match ( const Ref < InputEvent > & p_event , bool p_exact_match , float p_deadzone , bool * r_pressed , float * r_strength , float * r_raw_strength ) const {
2017-05-20 12:38:03 -03:00
Ref < InputEventMouseButton > mb = p_event ;
2020-05-14 16:41:43 +02:00
if ( mb . is_null ( ) ) {
2017-05-20 12:38:03 -03:00
return false ;
2020-05-14 16:41:43 +02:00
}
2017-05-20 12:38:03 -03:00
2021-10-23 22:38:32 -05:00
bool match = button_index = = mb - > button_index ;
2023-01-08 00:55:54 +01:00
Key action_modifiers_mask = ( Key ) ( int64_t ) get_modifiers_mask ( ) ;
Key button_modifiers_mask = ( Key ) ( int64_t ) mb - > get_modifiers_mask ( ) ;
2022-03-20 06:57:28 +00:00
if ( mb - > is_pressed ( ) ) {
2022-09-29 12:53:28 +03:00
match & = ( action_modifiers_mask & button_modifiers_mask ) = = action_modifiers_mask ;
2022-03-20 06:57:28 +00:00
}
2021-10-23 22:38:32 -05:00
if ( p_exact_match ) {
2022-09-29 12:53:28 +03:00
match & = action_modifiers_mask = = button_modifiers_mask ;
2021-10-23 22:38:32 -05:00
}
2018-02-21 22:06:34 +01:00
if ( match ) {
2022-09-29 12:53:28 +03:00
bool mb_pressed = mb - > is_pressed ( ) ;
2021-10-23 22:38:32 -05:00
if ( r_pressed ! = nullptr ) {
2022-09-29 12:53:28 +03:00
* r_pressed = mb_pressed ;
2020-05-14 16:41:43 +02:00
}
2022-09-29 12:53:28 +03:00
float strength = mb_pressed ? 1.0f : 0.0f ;
2021-10-23 22:38:32 -05:00
if ( r_strength ! = nullptr ) {
* r_strength = strength ;
2020-10-24 05:22:35 -04:00
}
2021-10-23 22:38:32 -05:00
if ( r_raw_strength ! = nullptr ) {
* r_raw_strength = strength ;
2020-05-14 16:41:43 +02:00
}
2018-02-21 22:06:34 +01:00
}
return match ;
2017-05-20 12:38:03 -03:00
}
2021-05-13 18:13:24 +01:00
bool InputEventMouseButton : : is_match ( const Ref < InputEvent > & p_event , bool p_exact_match ) const {
Ref < InputEventMouseButton > mb = p_event ;
if ( mb . is_null ( ) ) {
return false ;
}
return button_index = = mb - > button_index & &
2021-10-28 15:19:35 +02:00
( ! p_exact_match | | get_modifiers_mask ( ) = = mb - > get_modifiers_mask ( ) ) ;
2021-05-13 18:13:24 +01:00
}
2020-10-01 22:55:23 +10:00
static const char * _mouse_button_descriptions [ 9 ] = {
TTRC ( " Left Mouse Button " ) ,
TTRC ( " Right Mouse Button " ) ,
TTRC ( " Middle Mouse Button " ) ,
TTRC ( " Mouse Wheel Up " ) ,
TTRC ( " Mouse Wheel Down " ) ,
TTRC ( " Mouse Wheel Left " ) ,
TTRC ( " Mouse Wheel Right " ) ,
TTRC ( " Mouse Thumb Button 1 " ) ,
TTRC ( " Mouse Thumb Button 2 " )
} ;
2017-08-25 01:14:36 +09:00
String InputEventMouseButton : : as_text ( ) const {
2020-10-01 22:55:23 +10:00
// Modifiers
String mods_text = InputEventWithModifiers : : as_text ( ) ;
2021-12-09 03:42:46 -06:00
String full_string = mods_text . is_empty ( ) ? " " : mods_text + " + " ;
2020-10-01 22:55:23 +10:00
// Button
2021-08-13 16:31:57 -05:00
MouseButton idx = get_button_index ( ) ;
2020-10-01 22:55:23 +10:00
switch ( idx ) {
2021-08-13 16:31:57 -05:00
case MouseButton : : LEFT :
case MouseButton : : RIGHT :
case MouseButton : : MIDDLE :
case MouseButton : : WHEEL_UP :
case MouseButton : : WHEEL_DOWN :
case MouseButton : : WHEEL_LEFT :
case MouseButton : : WHEEL_RIGHT :
case MouseButton : : MB_XBUTTON1 :
case MouseButton : : MB_XBUTTON2 :
full_string + = RTR ( _mouse_button_descriptions [ ( size_t ) idx - 1 ] ) ; // button index starts from 1, array index starts from 0, so subtract 1
2018-07-05 17:50:30 +03:00
break ;
2017-08-25 01:14:36 +09:00
default :
2021-08-13 16:31:57 -05:00
full_string + = RTR ( " Button " ) + " # " + itos ( ( int64_t ) idx ) ;
2017-08-25 01:14:36 +09:00
break ;
}
2020-10-01 22:55:23 +10:00
// Double Click
2021-04-13 04:25:44 -04:00
if ( double_click ) {
2020-10-01 22:55:23 +10:00
full_string + = " ( " + RTR ( " Double Click " ) + " ) " ;
}
return full_string ;
}
String InputEventMouseButton : : to_string ( ) {
String p = is_pressed ( ) ? " true " : " false " ;
2023-05-03 17:57:13 -07:00
String canceled_state = is_canceled ( ) ? " true " : " false " ;
2021-04-13 04:25:44 -04:00
String d = double_click ? " true " : " false " ;
2020-10-01 22:55:23 +10:00
2021-08-13 16:31:57 -05:00
MouseButton idx = get_button_index ( ) ;
String button_string = itos ( ( int64_t ) idx ) ;
2020-10-01 22:55:23 +10:00
switch ( idx ) {
2021-08-13 16:31:57 -05:00
case MouseButton : : LEFT :
case MouseButton : : RIGHT :
case MouseButton : : MIDDLE :
case MouseButton : : WHEEL_UP :
case MouseButton : : WHEEL_DOWN :
case MouseButton : : WHEEL_LEFT :
case MouseButton : : WHEEL_RIGHT :
case MouseButton : : MB_XBUTTON1 :
case MouseButton : : MB_XBUTTON2 :
2022-03-28 15:24:14 +02:00
button_string + = vformat ( " (%s) " , TTRGET ( _mouse_button_descriptions [ ( size_t ) idx - 1 ] ) ) ; // button index starts from 1, array index starts from 0, so subtract 1
2020-10-01 22:55:23 +10:00
break ;
default :
break ;
}
2020-12-14 12:42:42 +10:00
String mods = InputEventWithModifiers : : as_text ( ) ;
2022-03-28 15:24:14 +02:00
mods = mods . is_empty ( ) ? " none " : mods ;
2020-12-14 12:42:42 +10:00
// Work around the fact vformat can only take 5 substitutions but 6 need to be passed.
2021-05-15 10:06:15 +01:00
String index_and_mods = vformat ( " button_index=%s, mods=%s " , button_index , mods ) ;
2023-05-03 17:57:13 -07:00
return vformat ( " InputEventMouseButton: %s, pressed=%s, canceled=%s, position=(%s) , button_mask = % d , double_click = % s " , index_and_mods, p, canceled_state, String(get_position()), get_button_mask(), d) ;
2017-08-25 01:14:36 +09:00
}
2017-05-20 12:38:03 -03:00
void InputEventMouseButton : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_factor " , " factor " ) , & InputEventMouseButton : : set_factor ) ;
ClassDB : : bind_method ( D_METHOD ( " get_factor " ) , & InputEventMouseButton : : get_factor ) ;
ClassDB : : bind_method ( D_METHOD ( " set_button_index " , " button_index " ) , & InputEventMouseButton : : set_button_index ) ;
ClassDB : : bind_method ( D_METHOD ( " get_button_index " ) , & InputEventMouseButton : : get_button_index ) ;
ClassDB : : bind_method ( D_METHOD ( " set_pressed " , " pressed " ) , & InputEventMouseButton : : set_pressed ) ;
2023-05-03 17:57:13 -07:00
ClassDB : : bind_method ( D_METHOD ( " set_canceled " , " canceled " ) , & InputEventMouseButton : : set_canceled ) ;
2017-05-20 12:38:03 -03:00
2021-04-13 04:25:44 -04:00
ClassDB : : bind_method ( D_METHOD ( " set_double_click " , " double_click " ) , & InputEventMouseButton : : set_double_click ) ;
ClassDB : : bind_method ( D_METHOD ( " is_double_click " ) , & InputEventMouseButton : : is_double_click ) ;
2017-05-20 12:38:03 -03:00
2020-02-24 15:20:53 -03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " factor " ) , " set_factor " , " get_factor " ) ;
2017-05-20 12:38:03 -03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " button_index " ) , " set_button_index " , " get_button_index " ) ;
2023-05-03 17:57:13 -07:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " canceled " ) , " set_canceled " , " is_canceled " ) ;
2017-05-20 12:38:03 -03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " pressed " ) , " set_pressed " , " is_pressed " ) ;
2021-04-13 04:25:44 -04:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " double_click " ) , " set_double_click " , " is_double_click " ) ;
2017-05-20 12:38:03 -03:00
}
2020-05-12 17:01:17 +02:00
///////////////////////////////////
2017-05-20 12:38:03 -03:00
2018-12-13 22:32:11 +02:00
void InputEventMouseMotion : : set_tilt ( const Vector2 & p_tilt ) {
tilt = p_tilt ;
}
Vector2 InputEventMouseMotion : : get_tilt ( ) const {
return tilt ;
}
void InputEventMouseMotion : : set_pressure ( float p_pressure ) {
pressure = p_pressure ;
}
float InputEventMouseMotion : : get_pressure ( ) const {
return pressure ;
}
2022-06-19 02:58:24 -07:00
void InputEventMouseMotion : : set_pen_inverted ( bool p_inverted ) {
pen_inverted = p_inverted ;
}
bool InputEventMouseMotion : : get_pen_inverted ( ) const {
return pen_inverted ;
}
2017-05-20 12:38:03 -03:00
void InputEventMouseMotion : : set_relative ( const Vector2 & p_relative ) {
relative = p_relative ;
}
2018-12-13 22:32:11 +02:00
2017-05-20 12:38:03 -03:00
Vector2 InputEventMouseMotion : : get_relative ( ) const {
return relative ;
}
2023-10-04 19:20:01 +02:00
void InputEventMouseMotion : : set_relative_screen_position ( const Vector2 & p_relative ) {
screen_relative = p_relative ;
}
Vector2 InputEventMouseMotion : : get_relative_screen_position ( ) const {
return screen_relative ;
}
2021-12-29 13:22:22 +00:00
void InputEventMouseMotion : : set_velocity ( const Vector2 & p_velocity ) {
velocity = p_velocity ;
2017-05-20 12:38:03 -03:00
}
2018-12-13 22:32:11 +02:00
2021-12-29 13:22:22 +00:00
Vector2 InputEventMouseMotion : : get_velocity ( ) const {
return velocity ;
2017-05-20 12:38:03 -03:00
}
2023-10-04 19:20:01 +02:00
void InputEventMouseMotion : : set_screen_velocity ( const Vector2 & p_velocity ) {
screen_velocity = p_velocity ;
}
Vector2 InputEventMouseMotion : : get_screen_velocity ( ) const {
return screen_velocity ;
}
2017-05-20 12:38:03 -03:00
Ref < InputEvent > InputEventMouseMotion : : xformed_by ( const Transform2D & p_xform , const Vector2 & p_local_ofs ) const {
Ref < InputEventMouseMotion > mm ;
2021-06-17 16:03:09 -06:00
mm . instantiate ( ) ;
2017-05-20 12:38:03 -03:00
mm - > set_device ( get_device ( ) ) ;
2020-03-01 19:14:37 -03:00
mm - > set_window_id ( get_window_id ( ) ) ;
2017-05-20 12:38:03 -03:00
2017-11-01 21:49:39 +01:00
mm - > set_modifiers_from_event ( this ) ;
2017-05-20 12:38:03 -03:00
2021-12-29 13:22:22 +00:00
mm - > set_position ( p_xform . xform ( get_position ( ) + p_local_ofs ) ) ;
2018-12-13 22:32:11 +02:00
mm - > set_pressure ( get_pressure ( ) ) ;
2022-06-19 02:58:24 -07:00
mm - > set_pen_inverted ( get_pen_inverted ( ) ) ;
2018-12-13 22:32:11 +02:00
mm - > set_tilt ( get_tilt ( ) ) ;
2021-12-29 13:22:22 +00:00
mm - > set_global_position ( get_global_position ( ) ) ;
2017-05-20 12:38:03 -03:00
mm - > set_button_mask ( get_button_mask ( ) ) ;
2021-12-29 13:22:22 +00:00
mm - > set_relative ( p_xform . basis_xform ( get_relative ( ) ) ) ;
2023-10-04 19:20:01 +02:00
mm - > set_relative_screen_position ( get_relative_screen_position ( ) ) ;
2021-12-29 13:22:22 +00:00
mm - > set_velocity ( p_xform . basis_xform ( get_velocity ( ) ) ) ;
2023-10-04 19:20:01 +02:00
mm - > set_screen_velocity ( get_screen_velocity ( ) ) ;
2017-05-20 12:38:03 -03:00
return mm ;
}
2017-08-25 01:14:36 +09:00
String InputEventMouseMotion : : as_text ( ) const {
2021-12-29 13:22:22 +00:00
return vformat ( RTR ( " Mouse motion at position (%s) with velocity ( % s ) " ), String(get_position()), String(get_velocity())) ;
2020-10-01 22:55:23 +10:00
}
String InputEventMouseMotion : : to_string ( ) {
2023-01-08 00:55:54 +01:00
BitField < MouseButtonMask > mouse_button_mask = get_button_mask ( ) ;
2022-09-29 12:53:28 +03:00
String button_mask_string = itos ( ( int64_t ) mouse_button_mask ) ;
2023-01-08 00:55:54 +01:00
if ( mouse_button_mask . has_flag ( MouseButtonMask : : LEFT ) ) {
button_mask_string + = vformat ( " (%s) " , TTRGET ( _mouse_button_descriptions [ ( size_t ) MouseButton : : LEFT - 1 ] ) ) ;
}
if ( mouse_button_mask . has_flag ( MouseButtonMask : : MIDDLE ) ) {
button_mask_string + = vformat ( " (%s) " , TTRGET ( _mouse_button_descriptions [ ( size_t ) MouseButton : : MIDDLE - 1 ] ) ) ;
}
if ( mouse_button_mask . has_flag ( MouseButtonMask : : RIGHT ) ) {
button_mask_string + = vformat ( " (%s) " , TTRGET ( _mouse_button_descriptions [ ( size_t ) MouseButton : : RIGHT - 1 ] ) ) ;
}
if ( mouse_button_mask . has_flag ( MouseButtonMask : : MB_XBUTTON1 ) ) {
button_mask_string + = vformat ( " (%s) " , TTRGET ( _mouse_button_descriptions [ ( size_t ) MouseButton : : MB_XBUTTON1 - 1 ] ) ) ;
}
if ( mouse_button_mask . has_flag ( MouseButtonMask : : MB_XBUTTON2 ) ) {
button_mask_string + = vformat ( " (%s) " , TTRGET ( _mouse_button_descriptions [ ( size_t ) MouseButton : : MB_XBUTTON2 - 1 ] ) ) ;
2017-08-25 01:14:36 +09:00
}
2020-10-01 22:55:23 +10:00
2022-06-19 02:58:24 -07:00
// Work around the fact vformat can only take 5 substitutions but 7 need to be passed.
String mask_and_position_and_relative = vformat ( " button_mask=%s, position=(%s), relative=(%s) " , button_mask_string , String ( get_position ( ) ) , String ( get_relative ( ) ) ) ;
2022-08-07 09:57:09 +08:00
return vformat ( " InputEventMouseMotion: %s, velocity=(%s) , pressure = % .2f , tilt = ( % s ) , pen_inverted = ( % s ) " , mask_and_position_and_relative, String(get_velocity()), get_pressure(), String(get_tilt()), get_pen_inverted()) ;
2017-08-25 01:14:36 +09:00
}
2019-03-03 19:52:18 -03:00
bool InputEventMouseMotion : : accumulate ( const Ref < InputEvent > & p_event ) {
Ref < InputEventMouseMotion > motion = p_event ;
2020-05-14 16:41:43 +02:00
if ( motion . is_null ( ) ) {
2019-03-03 19:52:18 -03:00
return false ;
2020-05-14 16:41:43 +02:00
}
2019-03-03 19:52:18 -03:00
2020-03-01 19:14:37 -03:00
if ( get_window_id ( ) ! = motion - > get_window_id ( ) ) {
return false ;
}
2023-05-03 17:57:13 -07:00
if ( is_canceled ( ) ! = motion - > is_canceled ( ) ) {
return false ;
}
2019-03-03 19:52:18 -03:00
if ( is_pressed ( ) ! = motion - > is_pressed ( ) ) {
return false ;
}
if ( get_button_mask ( ) ! = motion - > get_button_mask ( ) ) {
return false ;
}
2021-04-24 14:33:50 -06:00
if ( is_shift_pressed ( ) ! = motion - > is_shift_pressed ( ) ) {
2019-03-03 19:52:18 -03:00
return false ;
}
2021-04-24 14:33:50 -06:00
if ( is_ctrl_pressed ( ) ! = motion - > is_ctrl_pressed ( ) ) {
2019-03-03 19:52:18 -03:00
return false ;
}
2021-04-24 14:33:50 -06:00
if ( is_alt_pressed ( ) ! = motion - > is_alt_pressed ( ) ) {
2019-03-03 19:52:18 -03:00
return false ;
}
2021-04-24 14:33:50 -06:00
if ( is_meta_pressed ( ) ! = motion - > is_meta_pressed ( ) ) {
2019-03-03 19:52:18 -03:00
return false ;
}
set_position ( motion - > get_position ( ) ) ;
set_global_position ( motion - > get_global_position ( ) ) ;
2021-12-29 13:22:22 +00:00
set_velocity ( motion - > get_velocity ( ) ) ;
2023-10-04 19:20:01 +02:00
set_screen_velocity ( motion - > get_screen_velocity ( ) ) ;
2019-03-03 19:52:18 -03:00
relative + = motion - > get_relative ( ) ;
2023-10-04 19:20:01 +02:00
screen_relative + = motion - > get_relative_screen_position ( ) ;
2019-03-03 19:52:18 -03:00
return true ;
}
2017-05-20 12:38:03 -03:00
void InputEventMouseMotion : : _bind_methods ( ) {
2018-12-13 22:32:11 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_tilt " , " tilt " ) , & InputEventMouseMotion : : set_tilt ) ;
ClassDB : : bind_method ( D_METHOD ( " get_tilt " ) , & InputEventMouseMotion : : get_tilt ) ;
ClassDB : : bind_method ( D_METHOD ( " set_pressure " , " pressure " ) , & InputEventMouseMotion : : set_pressure ) ;
ClassDB : : bind_method ( D_METHOD ( " get_pressure " ) , & InputEventMouseMotion : : get_pressure ) ;
2022-06-19 02:58:24 -07:00
ClassDB : : bind_method ( D_METHOD ( " set_pen_inverted " , " pen_inverted " ) , & InputEventMouseMotion : : set_pen_inverted ) ;
ClassDB : : bind_method ( D_METHOD ( " get_pen_inverted " ) , & InputEventMouseMotion : : get_pen_inverted ) ;
2017-05-20 12:38:03 -03:00
ClassDB : : bind_method ( D_METHOD ( " set_relative " , " relative " ) , & InputEventMouseMotion : : set_relative ) ;
ClassDB : : bind_method ( D_METHOD ( " get_relative " ) , & InputEventMouseMotion : : get_relative ) ;
2023-10-04 19:20:01 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_screen_relative " , " relative " ) , & InputEventMouseMotion : : set_relative_screen_position ) ;
ClassDB : : bind_method ( D_METHOD ( " get_screen_relative " ) , & InputEventMouseMotion : : get_relative_screen_position ) ;
2021-12-29 13:22:22 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_velocity " , " velocity " ) , & InputEventMouseMotion : : set_velocity ) ;
ClassDB : : bind_method ( D_METHOD ( " get_velocity " ) , & InputEventMouseMotion : : get_velocity ) ;
2017-05-20 12:38:03 -03:00
2023-10-04 19:20:01 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_screen_velocity " , " velocity " ) , & InputEventMouseMotion : : set_screen_velocity ) ;
ClassDB : : bind_method ( D_METHOD ( " get_screen_velocity " ) , & InputEventMouseMotion : : get_screen_velocity ) ;
2018-12-13 22:32:11 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR2 , " tilt " ) , " set_tilt " , " get_tilt " ) ;
2020-02-24 15:20:53 -03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " pressure " ) , " set_pressure " , " get_pressure " ) ;
2022-06-19 02:58:24 -07:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " pen_inverted " ) , " set_pen_inverted " , " get_pen_inverted " ) ;
2022-05-20 00:24:41 -05:00
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR2 , " relative " , PROPERTY_HINT_NONE , " suffix:px " ) , " set_relative " , " get_relative " ) ;
2023-10-04 19:20:01 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR2 , " screen_relative " , PROPERTY_HINT_NONE , " suffix:px " ) , " set_screen_relative " , " get_screen_relative " ) ;
2022-05-20 00:24:41 -05:00
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR2 , " velocity " , PROPERTY_HINT_NONE , " suffix:px/s " ) , " set_velocity " , " get_velocity " ) ;
2023-10-04 19:20:01 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR2 , " screen_velocity " , PROPERTY_HINT_NONE , " suffix:px/s " ) , " set_screen_velocity " , " get_screen_velocity " ) ;
2017-05-20 12:38:03 -03:00
}
2020-05-12 17:01:17 +02:00
///////////////////////////////////
2017-05-20 12:38:03 -03:00
2021-03-25 16:56:12 -04:00
void InputEventJoypadMotion : : set_axis ( JoyAxis p_axis ) {
2024-09-16 12:12:27 +02:00
ERR_FAIL_COND ( p_axis < JoyAxis : : INVALID | | p_axis > JoyAxis : : MAX ) ;
2021-09-30 19:32:21 +09:00
2017-05-20 12:38:03 -03:00
axis = p_axis ;
2021-06-28 00:15:56 +10:00
emit_changed ( ) ;
2017-05-20 12:38:03 -03:00
}
2021-03-25 16:56:12 -04:00
JoyAxis InputEventJoypadMotion : : get_axis ( ) const {
2017-05-20 12:38:03 -03:00
return axis ;
}
void InputEventJoypadMotion : : set_axis_value ( float p_value ) {
axis_value = p_value ;
2023-05-03 17:57:13 -07:00
pressed = Math : : abs ( axis_value ) > = 0.5f ;
2021-06-28 00:15:56 +10:00
emit_changed ( ) ;
2017-05-20 12:38:03 -03:00
}
2018-02-21 22:06:34 +01:00
2017-05-20 12:38:03 -03:00
float InputEventJoypadMotion : : get_axis_value ( ) const {
return axis_value ;
}
2021-10-23 22:38:32 -05:00
bool InputEventJoypadMotion : : action_match ( const Ref < InputEvent > & p_event , bool p_exact_match , float p_deadzone , bool * r_pressed , float * r_strength , float * r_raw_strength ) const {
2017-05-20 12:38:03 -03:00
Ref < InputEventJoypadMotion > jm = p_event ;
2020-05-14 16:41:43 +02:00
if ( jm . is_null ( ) ) {
2017-05-20 12:38:03 -03:00
return false ;
2020-05-14 16:41:43 +02:00
}
2017-05-20 12:38:03 -03:00
2021-10-23 22:38:32 -05:00
// Matches even if not in the same direction, but returns a "not pressed" event.
bool match = axis = = jm - > axis ;
if ( p_exact_match ) {
match & = ( axis_value < 0 ) = = ( jm - > axis_value < 0 ) ;
}
2018-02-21 22:06:34 +01:00
if ( match ) {
2020-10-24 05:22:35 -04:00
float jm_abs_axis_value = Math : : abs ( jm - > get_axis_value ( ) ) ;
2018-04-25 22:29:39 +02:00
bool same_direction = ( ( ( axis_value < 0 ) = = ( jm - > axis_value < 0 ) ) | | jm - > axis_value = = 0 ) ;
2023-05-03 17:57:13 -07:00
bool pressed_state = same_direction & & jm_abs_axis_value > = p_deadzone ;
2021-10-23 22:38:32 -05:00
if ( r_pressed ! = nullptr ) {
2023-05-03 17:57:13 -07:00
* r_pressed = pressed_state ;
2020-05-14 16:41:43 +02:00
}
2021-10-23 22:38:32 -05:00
if ( r_strength ! = nullptr ) {
2023-05-03 17:57:13 -07:00
if ( pressed_state ) {
2019-05-15 11:21:10 +02:00
if ( p_deadzone = = 1.0f ) {
2021-10-23 22:38:32 -05:00
* r_strength = 1.0f ;
2019-05-15 11:21:10 +02:00
} else {
2021-10-23 22:38:32 -05:00
* r_strength = CLAMP ( Math : : inverse_lerp ( p_deadzone , 1.0f , jm_abs_axis_value ) , 0.0f , 1.0f ) ;
2019-05-15 11:21:10 +02:00
}
} else {
2021-10-23 22:38:32 -05:00
* r_strength = 0.0f ;
2019-05-15 11:21:10 +02:00
}
}
2021-10-23 22:38:32 -05:00
if ( r_raw_strength ! = nullptr ) {
2020-10-24 05:22:35 -04:00
if ( same_direction ) { // NOT pressed, because we want to ignore the deadzone.
2021-10-23 22:38:32 -05:00
* r_raw_strength = jm_abs_axis_value ;
2020-10-24 05:22:35 -04:00
} else {
2021-10-23 22:38:32 -05:00
* r_raw_strength = 0.0f ;
2020-10-24 05:22:35 -04:00
}
}
2018-02-21 22:06:34 +01:00
}
return match ;
2017-05-20 12:38:03 -03:00
}
2021-05-13 18:13:24 +01:00
bool InputEventJoypadMotion : : is_match ( const Ref < InputEvent > & p_event , bool p_exact_match ) const {
Ref < InputEventJoypadMotion > jm = p_event ;
if ( jm . is_null ( ) ) {
return false ;
}
return axis = = jm - > axis & &
2021-10-28 15:19:35 +02:00
( ! p_exact_match | | ( ( axis_value < 0 ) = = ( jm - > axis_value < 0 ) ) ) ;
2021-05-13 18:13:24 +01:00
}
2021-08-13 16:31:57 -05:00
static const char * _joy_axis_descriptions [ ( size_t ) JoyAxis : : MAX ] = {
2020-10-01 22:55:23 +10:00
TTRC ( " Left Stick X-Axis, Joystick 0 X-Axis " ) ,
TTRC ( " Left Stick Y-Axis, Joystick 0 Y-Axis " ) ,
TTRC ( " Right Stick X-Axis, Joystick 1 X-Axis " ) ,
TTRC ( " Right Stick Y-Axis, Joystick 1 Y-Axis " ) ,
TTRC ( " Joystick 2 X-Axis, Left Trigger, Sony L2, Xbox LT " ) ,
TTRC ( " Joystick 2 Y-Axis, Right Trigger, Sony R2, Xbox RT " ) ,
TTRC ( " Joystick 3 X-Axis " ) ,
TTRC ( " Joystick 3 Y-Axis " ) ,
TTRC ( " Joystick 4 X-Axis " ) ,
TTRC ( " Joystick 4 Y-Axis " ) ,
} ;
2017-08-25 01:14:36 +09:00
String InputEventJoypadMotion : : as_text ( ) const {
2022-03-28 15:24:14 +02:00
String desc = axis < JoyAxis : : MAX ? TTRGET ( _joy_axis_descriptions [ ( size_t ) axis ] ) : RTR ( " Unknown Joypad Axis " ) ;
2020-10-01 22:55:23 +10:00
2022-03-28 15:24:14 +02:00
return vformat ( RTR ( " Joypad Motion on Axis %d (%s) with Value % .2f " ), axis, desc, axis_value) ;
2020-10-01 22:55:23 +10:00
}
String InputEventJoypadMotion : : to_string ( ) {
2021-05-15 10:06:15 +01:00
return vformat ( " InputEventJoypadMotion: axis=%d, axis_value=%.2f " , axis , axis_value ) ;
2017-08-25 01:14:36 +09:00
}
2023-02-09 11:25:56 -05:00
Ref < InputEventJoypadMotion > InputEventJoypadMotion : : create_reference ( JoyAxis p_axis , float p_value ) {
Ref < InputEventJoypadMotion > ie ;
ie . instantiate ( ) ;
ie - > set_axis ( p_axis ) ;
ie - > set_axis_value ( p_value ) ;
return ie ;
}
2017-05-20 12:38:03 -03:00
void InputEventJoypadMotion : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_axis " , " axis " ) , & InputEventJoypadMotion : : set_axis ) ;
ClassDB : : bind_method ( D_METHOD ( " get_axis " ) , & InputEventJoypadMotion : : get_axis ) ;
ClassDB : : bind_method ( D_METHOD ( " set_axis_value " , " axis_value " ) , & InputEventJoypadMotion : : set_axis_value ) ;
ClassDB : : bind_method ( D_METHOD ( " get_axis_value " ) , & InputEventJoypadMotion : : get_axis_value ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " axis " ) , " set_axis " , " get_axis " ) ;
2020-02-24 15:20:53 -03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " axis_value " ) , " set_axis_value " , " get_axis_value " ) ;
2017-05-20 12:38:03 -03:00
}
2020-05-12 17:01:17 +02:00
///////////////////////////////////
2017-05-20 12:38:03 -03:00
2021-03-25 16:56:12 -04:00
void InputEventJoypadButton : : set_button_index ( JoyButton p_index ) {
2017-05-20 12:38:03 -03:00
button_index = p_index ;
2021-06-28 00:15:56 +10:00
emit_changed ( ) ;
2017-05-20 12:38:03 -03:00
}
2021-03-25 16:56:12 -04:00
JoyButton InputEventJoypadButton : : get_button_index ( ) const {
2017-05-20 12:38:03 -03:00
return button_index ;
}
void InputEventJoypadButton : : set_pressed ( bool p_pressed ) {
pressed = p_pressed ;
}
2020-05-14 14:29:06 +02:00
2017-05-20 12:38:03 -03:00
void InputEventJoypadButton : : set_pressure ( float p_pressure ) {
pressure = p_pressure ;
}
2020-05-14 14:29:06 +02:00
2017-05-20 12:38:03 -03:00
float InputEventJoypadButton : : get_pressure ( ) const {
return pressure ;
}
2021-10-23 22:38:32 -05:00
bool InputEventJoypadButton : : action_match ( const Ref < InputEvent > & p_event , bool p_exact_match , float p_deadzone , bool * r_pressed , float * r_strength , float * r_raw_strength ) const {
2017-05-20 12:38:03 -03:00
Ref < InputEventJoypadButton > jb = p_event ;
2020-05-14 16:41:43 +02:00
if ( jb . is_null ( ) ) {
2017-05-20 12:38:03 -03:00
return false ;
2020-05-14 16:41:43 +02:00
}
2017-05-20 12:38:03 -03:00
2018-02-21 22:06:34 +01:00
bool match = button_index = = jb - > button_index ;
if ( match ) {
2022-09-29 12:53:28 +03:00
bool jb_pressed = jb - > is_pressed ( ) ;
2021-10-23 22:38:32 -05:00
if ( r_pressed ! = nullptr ) {
2022-09-29 12:53:28 +03:00
* r_pressed = jb_pressed ;
2020-05-14 16:41:43 +02:00
}
2022-09-29 12:53:28 +03:00
float strength = jb_pressed ? 1.0f : 0.0f ;
2021-10-23 22:38:32 -05:00
if ( r_strength ! = nullptr ) {
* r_strength = strength ;
2020-10-24 05:22:35 -04:00
}
2021-10-23 22:38:32 -05:00
if ( r_raw_strength ! = nullptr ) {
* r_raw_strength = strength ;
2020-05-14 16:41:43 +02:00
}
2018-02-21 22:06:34 +01:00
}
return match ;
2017-05-20 12:38:03 -03:00
}
2021-05-13 18:13:24 +01:00
bool InputEventJoypadButton : : is_match ( const Ref < InputEvent > & p_event , bool p_exact_match ) const {
2019-02-16 00:26:07 +01:00
Ref < InputEventJoypadButton > button = p_event ;
2020-05-14 16:41:43 +02:00
if ( button . is_null ( ) ) {
2019-02-16 00:26:07 +01:00
return false ;
2020-05-14 16:41:43 +02:00
}
2019-02-16 00:26:07 +01:00
return button_index = = button - > button_index ;
}
2021-08-13 16:31:57 -05:00
static const char * _joy_button_descriptions [ ( size_t ) JoyButton : : SDL_MAX ] = {
2020-10-01 22:55:23 +10:00
TTRC ( " Bottom Action, Sony Cross, Xbox A, Nintendo B " ) ,
TTRC ( " Right Action, Sony Circle, Xbox B, Nintendo A " ) ,
TTRC ( " Left Action, Sony Square, Xbox X, Nintendo Y " ) ,
TTRC ( " Top Action, Sony Triangle, Xbox Y, Nintendo X " ) ,
TTRC ( " Back, Sony Select, Xbox Back, Nintendo - " ) ,
TTRC ( " Guide, Sony PS, Xbox Home " ) ,
2023-06-26 09:14:26 +02:00
TTRC ( " Start, Xbox Menu, Nintendo + " ) ,
2020-10-01 22:55:23 +10:00
TTRC ( " Left Stick, Sony L3, Xbox L/LS " ) ,
TTRC ( " Right Stick, Sony R3, Xbox R/RS " ) ,
TTRC ( " Left Shoulder, Sony L1, Xbox LB " ) ,
TTRC ( " Right Shoulder, Sony R1, Xbox RB " ) ,
TTRC ( " D-pad Up " ) ,
TTRC ( " D-pad Down " ) ,
TTRC ( " D-pad Left " ) ,
TTRC ( " D-pad Right " ) ,
2021-02-07 13:52:38 +00:00
TTRC ( " Xbox Share, PS5 Microphone, Nintendo Capture " ) ,
TTRC ( " Xbox Paddle 1 " ) ,
TTRC ( " Xbox Paddle 2 " ) ,
TTRC ( " Xbox Paddle 3 " ) ,
TTRC ( " Xbox Paddle 4 " ) ,
TTRC ( " PS4/5 Touchpad " ) ,
2020-10-01 22:55:23 +10:00
} ;
2017-08-25 01:14:36 +09:00
String InputEventJoypadButton : : as_text ( ) const {
2023-02-10 00:24:52 +08:00
String text = vformat ( RTR ( " Joypad Button %d " ) , ( int64_t ) button_index ) ;
2020-10-01 22:55:23 +10:00
2021-08-13 16:31:57 -05:00
if ( button_index > JoyButton : : INVALID & & button_index < JoyButton : : SDL_MAX ) {
2023-02-10 00:24:52 +08:00
text + = vformat ( " (%s) " , TTRGET ( _joy_button_descriptions [ ( size_t ) button_index ] ) ) ;
2020-10-01 22:55:23 +10:00
}
if ( pressure ! = 0 ) {
2023-02-10 00:24:52 +08:00
text + = " , " + RTR ( " Pressure: " ) + " " + String ( Variant ( pressure ) ) ;
2020-10-01 22:55:23 +10:00
}
return text ;
}
String InputEventJoypadButton : : to_string ( ) {
2023-05-03 17:57:13 -07:00
String p = is_pressed ( ) ? " true " : " false " ;
2021-05-15 10:06:15 +01:00
return vformat ( " InputEventJoypadButton: button_index=%d, pressed=%s, pressure=%.2f " , button_index , p , pressure ) ;
2017-08-25 01:14:36 +09:00
}
2021-03-25 16:56:12 -04:00
Ref < InputEventJoypadButton > InputEventJoypadButton : : create_reference ( JoyButton p_btn_index ) {
2020-12-07 21:31:25 +10:00
Ref < InputEventJoypadButton > ie ;
2021-06-17 16:03:09 -06:00
ie . instantiate ( ) ;
2020-12-07 21:31:25 +10:00
ie - > set_button_index ( p_btn_index ) ;
return ie ;
}
2017-05-20 12:38:03 -03:00
void InputEventJoypadButton : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_button_index " , " button_index " ) , & InputEventJoypadButton : : set_button_index ) ;
ClassDB : : bind_method ( D_METHOD ( " get_button_index " ) , & InputEventJoypadButton : : get_button_index ) ;
ClassDB : : bind_method ( D_METHOD ( " set_pressure " , " pressure " ) , & InputEventJoypadButton : : set_pressure ) ;
ClassDB : : bind_method ( D_METHOD ( " get_pressure " ) , & InputEventJoypadButton : : get_pressure ) ;
ClassDB : : bind_method ( D_METHOD ( " set_pressed " , " pressed " ) , & InputEventJoypadButton : : set_pressed ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " button_index " ) , " set_button_index " , " get_button_index " ) ;
2020-02-24 15:20:53 -03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " pressure " ) , " set_pressure " , " get_pressure " ) ;
2017-05-20 12:38:03 -03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " pressed " ) , " set_pressed " , " is_pressed " ) ;
}
2020-05-12 17:01:17 +02:00
///////////////////////////////////
2017-05-20 12:38:03 -03:00
void InputEventScreenTouch : : set_index ( int p_index ) {
index = p_index ;
}
2020-05-14 14:29:06 +02:00
2017-05-20 12:38:03 -03:00
int InputEventScreenTouch : : get_index ( ) const {
return index ;
}
2017-06-03 10:54:24 +02:00
void InputEventScreenTouch : : set_position ( const Vector2 & p_pos ) {
2017-05-20 12:38:03 -03:00
pos = p_pos ;
}
2020-05-14 14:29:06 +02:00
2017-06-03 10:54:24 +02:00
Vector2 InputEventScreenTouch : : get_position ( ) const {
2017-05-20 12:38:03 -03:00
return pos ;
}
void InputEventScreenTouch : : set_pressed ( bool p_pressed ) {
pressed = p_pressed ;
}
2020-05-14 14:29:06 +02:00
2023-05-03 17:57:13 -07:00
void InputEventScreenTouch : : set_canceled ( bool p_canceled ) {
canceled = p_canceled ;
2017-05-20 12:38:03 -03:00
}
2022-10-22 07:30:46 -07:00
void InputEventScreenTouch : : set_double_tap ( bool p_double_tap ) {
double_tap = p_double_tap ;
}
bool InputEventScreenTouch : : is_double_tap ( ) const {
return double_tap ;
}
2017-05-20 12:38:03 -03:00
Ref < InputEvent > InputEventScreenTouch : : xformed_by ( const Transform2D & p_xform , const Vector2 & p_local_ofs ) const {
Ref < InputEventScreenTouch > st ;
2021-06-17 16:03:09 -06:00
st . instantiate ( ) ;
2017-05-20 12:38:03 -03:00
st - > set_device ( get_device ( ) ) ;
2020-03-01 19:14:37 -03:00
st - > set_window_id ( get_window_id ( ) ) ;
2017-05-20 12:38:03 -03:00
st - > set_index ( index ) ;
2017-06-03 10:54:24 +02:00
st - > set_position ( p_xform . xform ( pos + p_local_ofs ) ) ;
2017-05-20 12:38:03 -03:00
st - > set_pressed ( pressed ) ;
2023-05-03 17:57:13 -07:00
st - > set_canceled ( canceled ) ;
2022-10-22 07:30:46 -07:00
st - > set_double_tap ( double_tap ) ;
2017-05-20 12:38:03 -03:00
return st ;
}
2017-08-25 01:14:36 +09:00
String InputEventScreenTouch : : as_text ( ) const {
2023-05-03 17:57:13 -07:00
String status = canceled ? RTR ( " canceled " ) : ( pressed ? RTR ( " touched " ) : RTR ( " released " ) ) ;
2020-10-01 22:55:23 +10:00
return vformat ( RTR ( " Screen %s at (%s) with % s touch points " ), status, String(get_position()), itos(index)) ;
}
String InputEventScreenTouch : : to_string ( ) {
2021-05-15 10:06:15 +01:00
String p = pressed ? " true " : " false " ;
2023-05-03 17:57:13 -07:00
String canceled_state = canceled ? " true " : " false " ;
2022-10-22 07:30:46 -07:00
String double_tap_string = double_tap ? " true " : " false " ;
2023-05-03 17:57:13 -07:00
return vformat ( " InputEventScreenTouch: index=%d, pressed=%s, canceled=%s, position=(%s) , double_tap = % s " , index, p, canceled_state, String(get_position()), double_tap_string) ;
2017-08-25 01:14:36 +09:00
}
2017-05-20 12:38:03 -03:00
void InputEventScreenTouch : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_index " , " index " ) , & InputEventScreenTouch : : set_index ) ;
ClassDB : : bind_method ( D_METHOD ( " get_index " ) , & InputEventScreenTouch : : get_index ) ;
2017-09-10 15:37:49 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_position " , " position " ) , & InputEventScreenTouch : : set_position ) ;
2017-06-03 10:54:24 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_position " ) , & InputEventScreenTouch : : get_position ) ;
2017-05-20 12:38:03 -03:00
ClassDB : : bind_method ( D_METHOD ( " set_pressed " , " pressed " ) , & InputEventScreenTouch : : set_pressed ) ;
2023-05-03 17:57:13 -07:00
ClassDB : : bind_method ( D_METHOD ( " set_canceled " , " canceled " ) , & InputEventScreenTouch : : set_canceled ) ;
2017-05-20 12:38:03 -03:00
2022-10-22 07:30:46 -07:00
ClassDB : : bind_method ( D_METHOD ( " set_double_tap " , " double_tap " ) , & InputEventScreenTouch : : set_double_tap ) ;
ClassDB : : bind_method ( D_METHOD ( " is_double_tap " ) , & InputEventScreenTouch : : is_double_tap ) ;
2017-05-20 12:38:03 -03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " index " ) , " set_index " , " get_index " ) ;
2022-05-20 00:24:41 -05:00
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR2 , " position " , PROPERTY_HINT_NONE , " suffix:px " ) , " set_position " , " get_position " ) ;
2023-05-03 17:57:13 -07:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " canceled " ) , " set_canceled " , " is_canceled " ) ;
2017-05-20 12:38:03 -03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " pressed " ) , " set_pressed " , " is_pressed " ) ;
2022-10-22 07:30:46 -07:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " double_tap " ) , " set_double_tap " , " is_double_tap " ) ;
2017-05-20 12:38:03 -03:00
}
2020-05-12 17:01:17 +02:00
///////////////////////////////////
2017-05-20 12:38:03 -03:00
void InputEventScreenDrag : : set_index ( int p_index ) {
index = p_index ;
}
int InputEventScreenDrag : : get_index ( ) const {
return index ;
}
2022-12-23 17:37:45 +02:00
void InputEventScreenDrag : : set_tilt ( const Vector2 & p_tilt ) {
tilt = p_tilt ;
}
Vector2 InputEventScreenDrag : : get_tilt ( ) const {
return tilt ;
}
void InputEventScreenDrag : : set_pressure ( float p_pressure ) {
pressure = p_pressure ;
}
float InputEventScreenDrag : : get_pressure ( ) const {
return pressure ;
}
void InputEventScreenDrag : : set_pen_inverted ( bool p_inverted ) {
pen_inverted = p_inverted ;
}
bool InputEventScreenDrag : : get_pen_inverted ( ) const {
return pen_inverted ;
}
2017-06-03 10:54:24 +02:00
void InputEventScreenDrag : : set_position ( const Vector2 & p_pos ) {
2017-05-20 12:38:03 -03:00
pos = p_pos ;
}
2020-05-14 14:29:06 +02:00
2017-06-03 10:54:24 +02:00
Vector2 InputEventScreenDrag : : get_position ( ) const {
2017-05-20 12:38:03 -03:00
return pos ;
}
void InputEventScreenDrag : : set_relative ( const Vector2 & p_relative ) {
relative = p_relative ;
}
2020-05-14 14:29:06 +02:00
2017-05-20 12:38:03 -03:00
Vector2 InputEventScreenDrag : : get_relative ( ) const {
return relative ;
}
2023-10-04 19:20:01 +02:00
void InputEventScreenDrag : : set_relative_screen_position ( const Vector2 & p_relative ) {
screen_relative = p_relative ;
}
Vector2 InputEventScreenDrag : : get_relative_screen_position ( ) const {
return screen_relative ;
}
2021-12-29 13:22:22 +00:00
void InputEventScreenDrag : : set_velocity ( const Vector2 & p_velocity ) {
velocity = p_velocity ;
2017-05-20 12:38:03 -03:00
}
2020-05-14 14:29:06 +02:00
2021-12-29 13:22:22 +00:00
Vector2 InputEventScreenDrag : : get_velocity ( ) const {
return velocity ;
2017-05-20 12:38:03 -03:00
}
2023-10-04 19:20:01 +02:00
void InputEventScreenDrag : : set_screen_velocity ( const Vector2 & p_velocity ) {
screen_velocity = p_velocity ;
}
Vector2 InputEventScreenDrag : : get_screen_velocity ( ) const {
return screen_velocity ;
}
2017-05-20 12:38:03 -03:00
Ref < InputEvent > InputEventScreenDrag : : xformed_by ( const Transform2D & p_xform , const Vector2 & p_local_ofs ) const {
Ref < InputEventScreenDrag > sd ;
2021-06-17 16:03:09 -06:00
sd . instantiate ( ) ;
2017-05-20 12:38:03 -03:00
sd - > set_device ( get_device ( ) ) ;
2020-03-01 19:14:37 -03:00
sd - > set_window_id ( get_window_id ( ) ) ;
2017-05-20 12:38:03 -03:00
sd - > set_index ( index ) ;
2022-12-23 17:37:45 +02:00
sd - > set_pressure ( get_pressure ( ) ) ;
sd - > set_pen_inverted ( get_pen_inverted ( ) ) ;
sd - > set_tilt ( get_tilt ( ) ) ;
2017-06-03 10:54:24 +02:00
sd - > set_position ( p_xform . xform ( pos + p_local_ofs ) ) ;
2017-05-20 12:38:03 -03:00
sd - > set_relative ( p_xform . basis_xform ( relative ) ) ;
2023-10-04 19:20:01 +02:00
sd - > set_relative_screen_position ( get_relative_screen_position ( ) ) ;
2021-12-29 13:22:22 +00:00
sd - > set_velocity ( p_xform . basis_xform ( velocity ) ) ;
2023-10-04 19:20:01 +02:00
sd - > set_screen_velocity ( get_screen_velocity ( ) ) ;
2017-05-20 12:38:03 -03:00
return sd ;
}
2017-08-25 01:14:36 +09:00
String InputEventScreenDrag : : as_text ( ) const {
2021-12-29 13:22:22 +00:00
return vformat ( RTR ( " Screen dragged with %s touch points at position (%s) with velocity of ( % s ) " ), itos(index), String(get_position()), String(get_velocity())) ;
2020-10-01 22:55:23 +10:00
}
String InputEventScreenDrag : : to_string ( ) {
2022-12-23 17:37:45 +02:00
return vformat ( " InputEventScreenDrag: index=%d, position=(%s) , relative = ( % s ) , velocity = ( % s ) , pressure = % .2f , tilt = ( % s ) , pen_inverted = ( % s ) " , index, String(get_position()), String(get_relative()), String(get_velocity()), get_pressure(), String(get_tilt()), get_pen_inverted()) ;
2017-08-25 01:14:36 +09:00
}
2021-08-13 00:31:16 +02:00
bool InputEventScreenDrag : : accumulate ( const Ref < InputEvent > & p_event ) {
Ref < InputEventScreenDrag > drag = p_event ;
2022-01-27 10:34:33 -06:00
if ( drag . is_null ( ) ) {
2021-08-13 00:31:16 +02:00
return false ;
2022-01-27 10:34:33 -06:00
}
2021-08-13 00:31:16 +02:00
if ( get_index ( ) ! = drag - > get_index ( ) ) {
return false ;
}
set_position ( drag - > get_position ( ) ) ;
2021-12-29 13:22:22 +00:00
set_velocity ( drag - > get_velocity ( ) ) ;
2023-10-04 19:20:01 +02:00
set_screen_velocity ( drag - > get_screen_velocity ( ) ) ;
2021-08-13 00:31:16 +02:00
relative + = drag - > get_relative ( ) ;
2023-10-04 19:20:01 +02:00
screen_relative + = drag - > get_relative_screen_position ( ) ;
2021-08-13 00:31:16 +02:00
return true ;
}
2017-05-20 12:38:03 -03:00
void InputEventScreenDrag : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_index " , " index " ) , & InputEventScreenDrag : : set_index ) ;
ClassDB : : bind_method ( D_METHOD ( " get_index " ) , & InputEventScreenDrag : : get_index ) ;
2022-12-23 17:37:45 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_tilt " , " tilt " ) , & InputEventScreenDrag : : set_tilt ) ;
ClassDB : : bind_method ( D_METHOD ( " get_tilt " ) , & InputEventScreenDrag : : get_tilt ) ;
ClassDB : : bind_method ( D_METHOD ( " set_pressure " , " pressure " ) , & InputEventScreenDrag : : set_pressure ) ;
ClassDB : : bind_method ( D_METHOD ( " get_pressure " ) , & InputEventScreenDrag : : get_pressure ) ;
ClassDB : : bind_method ( D_METHOD ( " set_pen_inverted " , " pen_inverted " ) , & InputEventScreenDrag : : set_pen_inverted ) ;
ClassDB : : bind_method ( D_METHOD ( " get_pen_inverted " ) , & InputEventScreenDrag : : get_pen_inverted ) ;
2017-06-03 10:54:24 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_position " , " position " ) , & InputEventScreenDrag : : set_position ) ;
ClassDB : : bind_method ( D_METHOD ( " get_position " ) , & InputEventScreenDrag : : get_position ) ;
2017-05-20 12:38:03 -03:00
ClassDB : : bind_method ( D_METHOD ( " set_relative " , " relative " ) , & InputEventScreenDrag : : set_relative ) ;
ClassDB : : bind_method ( D_METHOD ( " get_relative " ) , & InputEventScreenDrag : : get_relative ) ;
2023-10-04 19:20:01 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_screen_relative " , " relative " ) , & InputEventScreenDrag : : set_relative_screen_position ) ;
ClassDB : : bind_method ( D_METHOD ( " get_screen_relative " ) , & InputEventScreenDrag : : get_relative_screen_position ) ;
2021-12-29 13:22:22 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_velocity " , " velocity " ) , & InputEventScreenDrag : : set_velocity ) ;
ClassDB : : bind_method ( D_METHOD ( " get_velocity " ) , & InputEventScreenDrag : : get_velocity ) ;
2017-05-20 12:38:03 -03:00
2023-10-04 19:20:01 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_screen_velocity " , " velocity " ) , & InputEventScreenDrag : : set_screen_velocity ) ;
ClassDB : : bind_method ( D_METHOD ( " get_screen_velocity " ) , & InputEventScreenDrag : : get_screen_velocity ) ;
2017-05-20 12:38:03 -03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " index " ) , " set_index " , " get_index " ) ;
2022-12-23 17:37:45 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR2 , " tilt " ) , " set_tilt " , " get_tilt " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " pressure " ) , " set_pressure " , " get_pressure " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " pen_inverted " ) , " set_pen_inverted " , " get_pen_inverted " ) ;
2022-05-20 00:24:41 -05:00
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR2 , " position " , PROPERTY_HINT_NONE , " suffix:px " ) , " set_position " , " get_position " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR2 , " relative " , PROPERTY_HINT_NONE , " suffix:px " ) , " set_relative " , " get_relative " ) ;
2023-10-04 19:20:01 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR2 , " screen_relative " , PROPERTY_HINT_NONE , " suffix:px " ) , " set_screen_relative " , " get_screen_relative " ) ;
2022-05-20 00:24:41 -05:00
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR2 , " velocity " , PROPERTY_HINT_NONE , " suffix:px/s " ) , " set_velocity " , " get_velocity " ) ;
2023-10-04 19:20:01 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR2 , " screen_velocity " , PROPERTY_HINT_NONE , " suffix:px/s " ) , " set_screen_velocity " , " get_screen_velocity " ) ;
2017-05-20 12:38:03 -03:00
}
2020-05-12 17:01:17 +02:00
///////////////////////////////////
2017-05-20 12:38:03 -03:00
void InputEventAction : : set_action ( const StringName & p_action ) {
action = p_action ;
}
2020-05-14 14:29:06 +02:00
2017-05-20 12:38:03 -03:00
StringName InputEventAction : : get_action ( ) const {
return action ;
}
void InputEventAction : : set_pressed ( bool p_pressed ) {
pressed = p_pressed ;
}
2020-05-14 14:29:06 +02:00
2019-06-01 15:31:47 +02:00
void InputEventAction : : set_strength ( float p_strength ) {
strength = CLAMP ( p_strength , 0.0f , 1.0f ) ;
}
float InputEventAction : : get_strength ( ) const {
return strength ;
}
2023-12-10 19:23:29 +01:00
void InputEventAction : : set_event_index ( int p_index ) {
event_index = p_index ;
}
int InputEventAction : : get_event_index ( ) const {
return event_index ;
}
2021-05-13 18:13:24 +01:00
bool InputEventAction : : is_match ( const Ref < InputEvent > & p_event , bool p_exact_match ) const {
2020-05-14 16:41:43 +02:00
if ( p_event . is_null ( ) ) {
2018-07-27 14:02:30 +03:00
return false ;
2020-05-14 16:41:43 +02:00
}
2018-07-27 14:02:30 +03:00
2022-07-17 17:20:37 +03:00
return p_event - > is_action ( action , p_exact_match ) ;
2018-07-27 14:02:30 +03:00
}
2017-05-20 12:38:03 -03:00
bool InputEventAction : : is_action ( const StringName & p_action ) const {
return action = = p_action ;
}
2021-10-23 22:38:32 -05:00
bool InputEventAction : : action_match ( const Ref < InputEvent > & p_event , bool p_exact_match , float p_deadzone , bool * r_pressed , float * r_strength , float * r_raw_strength ) const {
2018-09-10 15:15:06 -04:00
Ref < InputEventAction > act = p_event ;
2020-05-14 16:41:43 +02:00
if ( act . is_null ( ) ) {
2018-09-10 15:15:06 -04:00
return false ;
2020-05-14 16:41:43 +02:00
}
2018-09-10 15:15:06 -04:00
bool match = action = = act - > action ;
if ( match ) {
2023-05-03 17:57:13 -07:00
bool act_pressed = act - > is_pressed ( ) ;
2021-10-23 22:38:32 -05:00
if ( r_pressed ! = nullptr ) {
2022-09-29 12:53:28 +03:00
* r_pressed = act_pressed ;
2020-05-14 16:41:43 +02:00
}
2022-09-29 12:53:28 +03:00
float act_strength = act_pressed ? 1.0f : 0.0f ;
2021-10-23 22:38:32 -05:00
if ( r_strength ! = nullptr ) {
2022-09-29 12:53:28 +03:00
* r_strength = act_strength ;
2020-10-24 05:22:35 -04:00
}
2021-10-23 22:38:32 -05:00
if ( r_raw_strength ! = nullptr ) {
2022-09-29 12:53:28 +03:00
* r_raw_strength = act_strength ;
2020-05-14 16:41:43 +02:00
}
2018-09-10 15:15:06 -04:00
}
return match ;
}
2017-08-25 01:14:36 +09:00
String InputEventAction : : as_text ( ) const {
2022-10-23 17:08:47 +10:00
const List < Ref < InputEvent > > * events = InputMap : : get_singleton ( ) - > action_get_events ( action ) ;
if ( ! events ) {
return String ( ) ;
}
for ( const Ref < InputEvent > & E : * events ) {
if ( E . is_valid ( ) ) {
return E - > as_text ( ) ;
}
}
return String ( ) ;
2020-10-01 22:55:23 +10:00
}
String InputEventAction : : to_string ( ) {
2023-05-03 17:57:13 -07:00
String p = is_pressed ( ) ? " true " : " false " ;
2021-05-15 10:06:15 +01:00
return vformat ( " InputEventAction: action= \" %s \" , pressed=%s " , action , p ) ;
2017-08-25 01:14:36 +09:00
}
2017-05-20 12:38:03 -03:00
void InputEventAction : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_action " , " action " ) , & InputEventAction : : set_action ) ;
ClassDB : : bind_method ( D_METHOD ( " get_action " ) , & InputEventAction : : get_action ) ;
ClassDB : : bind_method ( D_METHOD ( " set_pressed " , " pressed " ) , & InputEventAction : : set_pressed ) ;
2019-06-01 15:31:47 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_strength " , " strength " ) , & InputEventAction : : set_strength ) ;
ClassDB : : bind_method ( D_METHOD ( " get_strength " ) , & InputEventAction : : get_strength ) ;
2023-12-10 19:23:29 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_event_index " , " index " ) , & InputEventAction : : set_event_index ) ;
ClassDB : : bind_method ( D_METHOD ( " get_event_index " ) , & InputEventAction : : get_event_index ) ;
2020-02-20 18:58:05 -03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING_NAME , " action " ) , " set_action " , " get_action " ) ;
2017-05-20 12:38:03 -03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " pressed " ) , " set_pressed " , " is_pressed " ) ;
2020-02-24 15:20:53 -03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " strength " , PROPERTY_HINT_RANGE , " 0,1,0.01 " ) , " set_strength " , " get_strength " ) ;
2023-12-10 19:23:29 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " event_index " , PROPERTY_HINT_RANGE , " -1,31,1 " ) , " set_event_index " , " get_event_index " ) ; // The max value equals to Input::MAX_EVENT - 1.
2017-05-20 12:38:03 -03:00
}
2020-05-12 17:01:17 +02:00
///////////////////////////////////
2017-11-01 21:49:39 +01:00
void InputEventGesture : : set_position ( const Vector2 & p_pos ) {
pos = p_pos ;
}
2017-11-24 19:22:33 +01:00
void InputEventGesture : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_position " , " position " ) , & InputEventGesture : : set_position ) ;
ClassDB : : bind_method ( D_METHOD ( " get_position " ) , & InputEventGesture : : get_position ) ;
2022-05-20 00:24:41 -05:00
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR2 , " position " , PROPERTY_HINT_NONE , " suffix:px " ) , " set_position " , " get_position " ) ;
2017-11-24 19:22:33 +01:00
}
2017-11-01 21:49:39 +01:00
Vector2 InputEventGesture : : get_position ( ) const {
return pos ;
}
2020-05-12 17:01:17 +02:00
///////////////////////////////////
2017-11-01 21:49:39 +01:00
void InputEventMagnifyGesture : : set_factor ( real_t p_factor ) {
factor = p_factor ;
}
real_t InputEventMagnifyGesture : : get_factor ( ) const {
return factor ;
}
Ref < InputEvent > InputEventMagnifyGesture : : xformed_by ( const Transform2D & p_xform , const Vector2 & p_local_ofs ) const {
Ref < InputEventMagnifyGesture > ev ;
2021-06-17 16:03:09 -06:00
ev . instantiate ( ) ;
2017-11-01 21:49:39 +01:00
ev - > set_device ( get_device ( ) ) ;
2020-03-01 19:14:37 -03:00
ev - > set_window_id ( get_window_id ( ) ) ;
2017-11-01 21:49:39 +01:00
ev - > set_modifiers_from_event ( this ) ;
ev - > set_position ( p_xform . xform ( get_position ( ) + p_local_ofs ) ) ;
ev - > set_factor ( get_factor ( ) ) ;
return ev ;
}
2018-02-24 10:25:50 +07:00
String InputEventMagnifyGesture : : as_text ( ) const {
2020-10-01 22:55:23 +10:00
return vformat ( RTR ( " Magnify Gesture at (%s) with factor % s " ), String(get_position()), rtos(get_factor())) ;
}
String InputEventMagnifyGesture : : to_string ( ) {
2021-05-15 10:06:15 +01:00
return vformat ( " InputEventMagnifyGesture: factor=%.2f, position=(%s) " , factor, String(get_position())) ;
2018-02-24 10:25:50 +07:00
}
2017-11-24 19:22:33 +01:00
void InputEventMagnifyGesture : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_factor " , " factor " ) , & InputEventMagnifyGesture : : set_factor ) ;
ClassDB : : bind_method ( D_METHOD ( " get_factor " ) , & InputEventMagnifyGesture : : get_factor ) ;
2020-02-24 15:20:53 -03:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " factor " ) , " set_factor " , " get_factor " ) ;
2017-11-24 19:22:33 +01:00
}
2020-05-12 17:01:17 +02:00
///////////////////////////////////
2017-11-01 21:49:39 +01:00
void InputEventPanGesture : : set_delta ( const Vector2 & p_delta ) {
delta = p_delta ;
}
Vector2 InputEventPanGesture : : get_delta ( ) const {
return delta ;
}
Ref < InputEvent > InputEventPanGesture : : xformed_by ( const Transform2D & p_xform , const Vector2 & p_local_ofs ) const {
Ref < InputEventPanGesture > ev ;
2021-06-17 16:03:09 -06:00
ev . instantiate ( ) ;
2017-11-01 21:49:39 +01:00
ev - > set_device ( get_device ( ) ) ;
2020-03-01 19:14:37 -03:00
ev - > set_window_id ( get_window_id ( ) ) ;
2017-11-01 21:49:39 +01:00
ev - > set_modifiers_from_event ( this ) ;
ev - > set_position ( p_xform . xform ( get_position ( ) + p_local_ofs ) ) ;
ev - > set_delta ( get_delta ( ) ) ;
return ev ;
}
2018-02-24 10:25:50 +07:00
String InputEventPanGesture : : as_text ( ) const {
2020-10-01 22:55:23 +10:00
return vformat ( RTR ( " Pan Gesture at (%s) with delta ( % s ) " ), String(get_position()), String(get_delta())) ;
}
String InputEventPanGesture : : to_string ( ) {
2021-05-15 10:06:15 +01:00
return vformat ( " InputEventPanGesture: delta=(%s) , position = ( % s ) " , String(get_delta()), String(get_position())) ;
2018-02-24 10:25:50 +07:00
}
2017-11-24 19:22:33 +01:00
void InputEventPanGesture : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_delta " , " delta " ) , & InputEventPanGesture : : set_delta ) ;
ClassDB : : bind_method ( D_METHOD ( " get_delta " ) , & InputEventPanGesture : : get_delta ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR2 , " delta " ) , " set_delta " , " get_delta " ) ;
}
2020-05-12 17:01:17 +02:00
///////////////////////////////////
2018-07-14 09:11:28 -03:00
void InputEventMIDI : : set_channel ( const int p_channel ) {
channel = p_channel ;
}
int InputEventMIDI : : get_channel ( ) const {
return channel ;
}
2021-03-25 16:56:12 -04:00
void InputEventMIDI : : set_message ( const MIDIMessage p_message ) {
2018-07-14 09:11:28 -03:00
message = p_message ;
}
2021-03-25 16:56:12 -04:00
MIDIMessage InputEventMIDI : : get_message ( ) const {
2018-07-14 09:11:28 -03:00
return message ;
}
void InputEventMIDI : : set_pitch ( const int p_pitch ) {
pitch = p_pitch ;
}
int InputEventMIDI : : get_pitch ( ) const {
return pitch ;
}
void InputEventMIDI : : set_velocity ( const int p_velocity ) {
velocity = p_velocity ;
}
int InputEventMIDI : : get_velocity ( ) const {
return velocity ;
}
void InputEventMIDI : : set_instrument ( const int p_instrument ) {
instrument = p_instrument ;
}
int InputEventMIDI : : get_instrument ( ) const {
return instrument ;
}
void InputEventMIDI : : set_pressure ( const int p_pressure ) {
pressure = p_pressure ;
}
int InputEventMIDI : : get_pressure ( ) const {
return pressure ;
}
void InputEventMIDI : : set_controller_number ( const int p_controller_number ) {
controller_number = p_controller_number ;
}
int InputEventMIDI : : get_controller_number ( ) const {
return controller_number ;
}
void InputEventMIDI : : set_controller_value ( const int p_controller_value ) {
controller_value = p_controller_value ;
}
int InputEventMIDI : : get_controller_value ( ) const {
return controller_value ;
}
String InputEventMIDI : : as_text ( ) const {
2021-08-13 16:31:57 -05:00
return vformat ( RTR ( " MIDI Input on Channel=%s Message=%s " ) , itos ( channel ) , itos ( ( int64_t ) message ) ) ;
2020-10-01 22:55:23 +10:00
}
String InputEventMIDI : : to_string ( ) {
2022-11-18 18:34:26 +10:30
String ret ;
switch ( message ) {
case MIDIMessage : : NOTE_ON :
ret = vformat ( " Note On: channel=%d, pitch=%d, velocity=%d " , channel , pitch , velocity ) ;
break ;
case MIDIMessage : : NOTE_OFF :
ret = vformat ( " Note Off: channel=%d, pitch=%d, velocity=%d " , channel , pitch , velocity ) ;
break ;
case MIDIMessage : : PITCH_BEND :
ret = vformat ( " Pitch Bend: channel=%d, pitch=%d " , channel , pitch ) ;
break ;
case MIDIMessage : : CHANNEL_PRESSURE :
ret = vformat ( " Channel Pressure: channel=%d, pressure=%d " , channel , pressure ) ;
break ;
case MIDIMessage : : CONTROL_CHANGE :
ret = vformat ( " Control Change: channel=%d, controller_number=%d, controller_value=%d " , channel , controller_number , controller_value ) ;
break ;
default :
ret = vformat ( " channel=%d, message=%d, pitch=%d, velocity=%d, pressure=%d, controller_number=%d, controller_value=%d, instrument=%d " , channel , message , pitch , velocity , pressure , controller_number , controller_value , instrument ) ;
}
return " InputEventMIDI: " + ret ;
2018-07-14 09:11:28 -03:00
}
void InputEventMIDI : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_channel " , " channel " ) , & InputEventMIDI : : set_channel ) ;
ClassDB : : bind_method ( D_METHOD ( " get_channel " ) , & InputEventMIDI : : get_channel ) ;
ClassDB : : bind_method ( D_METHOD ( " set_message " , " message " ) , & InputEventMIDI : : set_message ) ;
ClassDB : : bind_method ( D_METHOD ( " get_message " ) , & InputEventMIDI : : get_message ) ;
ClassDB : : bind_method ( D_METHOD ( " set_pitch " , " pitch " ) , & InputEventMIDI : : set_pitch ) ;
ClassDB : : bind_method ( D_METHOD ( " get_pitch " ) , & InputEventMIDI : : get_pitch ) ;
ClassDB : : bind_method ( D_METHOD ( " set_velocity " , " velocity " ) , & InputEventMIDI : : set_velocity ) ;
ClassDB : : bind_method ( D_METHOD ( " get_velocity " ) , & InputEventMIDI : : get_velocity ) ;
ClassDB : : bind_method ( D_METHOD ( " set_instrument " , " instrument " ) , & InputEventMIDI : : set_instrument ) ;
ClassDB : : bind_method ( D_METHOD ( " get_instrument " ) , & InputEventMIDI : : get_instrument ) ;
ClassDB : : bind_method ( D_METHOD ( " set_pressure " , " pressure " ) , & InputEventMIDI : : set_pressure ) ;
ClassDB : : bind_method ( D_METHOD ( " get_pressure " ) , & InputEventMIDI : : get_pressure ) ;
ClassDB : : bind_method ( D_METHOD ( " set_controller_number " , " controller_number " ) , & InputEventMIDI : : set_controller_number ) ;
ClassDB : : bind_method ( D_METHOD ( " get_controller_number " ) , & InputEventMIDI : : get_controller_number ) ;
ClassDB : : bind_method ( D_METHOD ( " set_controller_value " , " controller_value " ) , & InputEventMIDI : : set_controller_value ) ;
ClassDB : : bind_method ( D_METHOD ( " get_controller_value " ) , & InputEventMIDI : : get_controller_value ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " channel " ) , " set_channel " , " get_channel " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " message " ) , " set_message " , " get_message " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " pitch " ) , " set_pitch " , " get_pitch " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " velocity " ) , " set_velocity " , " get_velocity " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " instrument " ) , " set_instrument " , " get_instrument " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " pressure " ) , " set_pressure " , " get_pressure " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " controller_number " ) , " set_controller_number " , " get_controller_number " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " controller_value " ) , " set_controller_value " , " get_controller_value " ) ;
}
2021-05-29 18:58:16 +05:30
///////////////////////////////////
void InputEventShortcut : : set_shortcut ( Ref < Shortcut > p_shortcut ) {
shortcut = p_shortcut ;
emit_changed ( ) ;
}
Ref < Shortcut > InputEventShortcut : : get_shortcut ( ) {
return shortcut ;
}
2021-08-22 12:37:22 -03:00
void InputEventShortcut : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_shortcut " , " shortcut " ) , & InputEventShortcut : : set_shortcut ) ;
ClassDB : : bind_method ( D_METHOD ( " get_shortcut " ) , & InputEventShortcut : : get_shortcut ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : OBJECT , " shortcut " , PROPERTY_HINT_RESOURCE_TYPE , " Shortcut " ) , " set_shortcut " , " get_shortcut " ) ;
}
2021-05-29 18:58:16 +05:30
String InputEventShortcut : : as_text ( ) const {
2021-09-25 23:44:42 +09:00
ERR_FAIL_COND_V ( shortcut . is_null ( ) , " None " ) ;
2021-05-29 18:58:16 +05:30
return vformat ( RTR ( " Input Event with Shortcut=%s " ) , shortcut - > get_as_text ( ) ) ;
}
String InputEventShortcut : : to_string ( ) {
2021-09-25 23:44:42 +09:00
ERR_FAIL_COND_V ( shortcut . is_null ( ) , " None " ) ;
2021-05-29 18:58:16 +05:30
return vformat ( " InputEventShortcut: shortcut=%s " , shortcut - > get_as_text ( ) ) ;
}
2023-09-23 19:43:07 +02:00
InputEventShortcut : : InputEventShortcut ( ) {
pressed = true ;
}