From 942b6d99389657f19972307924d2e05dfb54f706 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 28 Jul 2022 18:54:48 +0200 Subject: [PATCH] Ported: Make Input mouse_mode and use_accumulated_input properties - fire-forge, timothyqiu https://github.com/godotengine/godot/commit/53c01540d917384ac3addb9ea4938c37a10cd043 --- core/os/input.cpp | 4 ++++ core/os/input.h | 3 ++- doc/classes/Input.xml | 32 +++++++++------------------ doc/classes/InputEventMouseMotion.xml | 2 +- main/input_default.cpp | 4 ++++ main/input_default.h | 1 + 6 files changed, 22 insertions(+), 24 deletions(-) diff --git a/core/os/input.cpp b/core/os/input.cpp index 2467d8938..187a7400c 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -103,8 +103,12 @@ void Input::_bind_methods() { ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor", "image", "shape", "hotspot"), &Input::set_custom_mouse_cursor, DEFVAL(CURSOR_ARROW), DEFVAL(Vector2())); ClassDB::bind_method(D_METHOD("parse_input_event", "event"), &Input::parse_input_event); ClassDB::bind_method(D_METHOD("set_use_accumulated_input", "enable"), &Input::set_use_accumulated_input); + ClassDB::bind_method(D_METHOD("is_using_accumulated_input"), &Input::is_using_accumulated_input); ClassDB::bind_method(D_METHOD("flush_buffered_events"), &Input::flush_buffered_events); + ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_mode"), "set_mouse_mode", "get_mouse_mode"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_accumulated_input"), "set_use_accumulated_input", "is_using_accumulated_input"); + BIND_ENUM_CONSTANT(MOUSE_MODE_VISIBLE); BIND_ENUM_CONSTANT(MOUSE_MODE_HIDDEN); BIND_ENUM_CONSTANT(MOUSE_MODE_CAPTURED); diff --git a/core/os/input.h b/core/os/input.h index 9eeccd1be..ddfdc4201 100644 --- a/core/os/input.h +++ b/core/os/input.h @@ -30,10 +30,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#include "core/math/vector2i.h" #include "core/object.h" #include "core/os/main_loop.h" #include "core/os/thread_safe.h" -#include "core/math/vector2i.h" class Input : public Object { GDCLASS(Input, Object); @@ -144,6 +144,7 @@ public: virtual void flush_buffered_events() = 0; virtual bool is_using_input_buffering() = 0; virtual void set_use_input_buffering(bool p_enable) = 0; + virtual bool is_using_accumulated_input() = 0; virtual void set_use_accumulated_input(bool p_enable) = 0; Input(); diff --git a/doc/classes/Input.xml b/doc/classes/Input.xml index 6db3bf6ca..f2a05b6b9 100644 --- a/doc/classes/Input.xml +++ b/doc/classes/Input.xml @@ -36,7 +36,7 @@ - Sends all input events which are in the current buffer to the game loop. These events may have been buffered as a result of accumulated input ([method set_use_accumulated_input]) or agile input flushing ([member ProjectSettings.input_devices/buffering/agile_event_flushing]). + Sends all input events which are in the current buffer to the game loop. These events may have been buffered as a result of accumulated input ([member use_accumulated_input]) or agile input flushing ([member ProjectSettings.input_devices/buffering/agile_event_flushing]). The engine will already do this itself at key execution points (at least once per frame). However, this can be useful in advanced cases where you want precise control over the timing of event handling. @@ -178,12 +178,6 @@ Returns mouse buttons as a bitmask. If multiple mouse buttons are pressed at the same time, the bits are added together. - - - - Returns the mouse mode. See the constants for more information. - - @@ -341,21 +335,6 @@ [b]Note:[/b] This value can be immediately overwritten by the hardware sensor value on Android and iOS. - - - - - Sets the mouse mode. See the constants for more information. - - - - - - - Enables or disables the accumulation of similar input events sent by the operating system. When input accumulation is enabled, all input events generated during a frame will be merged and emitted when the frame is done rendering. Therefore, this limits the number of input method calls per second to the rendering FPS. - Input accumulation is enabled by default. It can be disabled to get slightly more precise/reactive input at the cost of increased CPU usage. In applications where drawing freehand lines is required, input accumulation should generally be disabled while the user is drawing the line to get results that closely follow the actual input. - - @@ -401,6 +380,15 @@ + + + Controls the mouse mode. See [enum MouseMode] for more information. + + + If [code]true[/code], similar input events sent by the operating system are accumulated. When input accumulation is enabled, all input events generated during a frame will be merged and emitted when the frame is done rendering. Therefore, this limits the number of input method calls per second to the rendering FPS. + Input accumulation can be disabled to get slightly more precise/reactive input at the cost of increased CPU usage. In applications where drawing freehand lines is required, input accumulation should generally be disabled while the user is drawing the line to get results that closely follow the actual input. + + Makes the mouse cursor visible if it is hidden. diff --git a/doc/classes/InputEventMouseMotion.xml b/doc/classes/InputEventMouseMotion.xml index 7064d6a87..9193e14c8 100644 --- a/doc/classes/InputEventMouseMotion.xml +++ b/doc/classes/InputEventMouseMotion.xml @@ -5,7 +5,7 @@ Contains mouse and pen motion information. Supports relative, absolute positions and speed. See [method Node._input]. - [b]Note:[/b] By default, this event is only emitted once per frame rendered at most. If you need more precise input reporting, call [method Input.set_use_accumulated_input] with [code]false[/code] to make events emitted as often as possible. If you use InputEventMouseMotion to draw lines, consider implementing [url=https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm]Bresenham's line algorithm[/url] as well to avoid visible gaps in lines if the user is moving the mouse quickly. + [b]Note:[/b] By default, this event is only emitted once per frame rendered at most. If you need more precise input reporting, set [member Input.use_accumulated_input] to [code]false[/code] to make events emitted as often as possible. If you use InputEventMouseMotion to draw lines, consider implementing [url=https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm]Bresenham's line algorithm[/url] as well to avoid visible gaps in lines if the user is moving the mouse quickly. $DOCS_URL/tutorials/inputs/mouse_and_input_coordinates.html diff --git a/main/input_default.cpp b/main/input_default.cpp index df229c2ed..d622d0165 100644 --- a/main/input_default.cpp +++ b/main/input_default.cpp @@ -723,6 +723,10 @@ void InputDefault::set_use_input_buffering(bool p_enable) { use_input_buffering = p_enable; } +bool InputDefault::is_using_accumulated_input() { + return use_accumulated_input; +} + void InputDefault::set_use_accumulated_input(bool p_enable) { use_accumulated_input = p_enable; } diff --git a/main/input_default.h b/main/input_default.h index 245bb5bc9..ec42ad470 100644 --- a/main/input_default.h +++ b/main/input_default.h @@ -300,6 +300,7 @@ public: virtual void flush_buffered_events(); virtual bool is_using_input_buffering(); virtual void set_use_input_buffering(bool p_enable); + virtual bool is_using_accumulated_input(); virtual void set_use_accumulated_input(bool p_enable); virtual void release_pressed_events();