diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index cd30a323d2a..66d5c9e58b4 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -1712,6 +1712,7 @@ ProjectSettings::ProjectSettings() { GLOBAL_DEF("gui/timers/tooltip_delay_sec.editor_hint", 0.5); #endif + GLOBAL_DEF("gui/common/drag_threshold", 10); GLOBAL_DEF_BASIC("gui/common/snap_controls_to_pixels", true); GLOBAL_DEF(PropertyInfo(Variant::INT, "gui/common/show_focus_state_on_pointer_event", PROPERTY_HINT_ENUM, "Never,Control Supports Keyboard Input,Always"), 1); GLOBAL_DEF_BASIC("gui/fonts/dynamic_fonts/use_oversampling", true); diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index fa97e33012f..647aa20b992 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -1189,6 +1189,9 @@ Default value for [member ScrollContainer.scroll_deadzone], which will be used for all [ScrollContainer]s unless overridden. + + The minimum distance the mouse cursor must move while pressed before a drag operation begins in the default viewport. For custom viewports see [member Viewport.gui_drag_threshold]. + Determines whether a [Control] should visually indicate focus when said focus is gained using a mouse or touch input. - [b]Never[/b] ([code]0[/code]) show the focused state for mouse/touch input. diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index 8cdc3775216..7832cc844c8 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -353,6 +353,9 @@ If [code]true[/code], the viewport will not receive input events. + + The minimum distance the mouse cursor must move while pressed before a drag operation begins. + If [code]true[/code], sub-windows (popups and dialogs) will be embedded inside application window as control-like nodes. If [code]false[/code], they will appear as separate windows handled by the operating system. diff --git a/main/main.cpp b/main/main.cpp index 1b4098e5cf1..d95a9a95931 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -4414,6 +4414,9 @@ int Main::start() { bool snap_controls = GLOBAL_GET("gui/common/snap_controls_to_pixels"); sml->get_root()->set_snap_controls_to_pixels(snap_controls); + int drag_threshold = GLOBAL_GET("gui/common/drag_threshold"); + sml->get_root()->set_drag_threshold(drag_threshold); + bool font_oversampling = GLOBAL_GET("gui/fonts/dynamic_fonts/use_oversampling"); sml->get_root()->set_use_oversampling(font_oversampling); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 972f20a50de..0415d43c161 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2016,7 +2016,7 @@ void Viewport::_gui_input_event(Ref p_event) { if (!gui.drag_attempted && gui.mouse_focus && section_root && !section_root->gui.global_dragging && (mm->get_button_mask().has_flag(MouseButtonMask::LEFT))) { gui.drag_accum += mm->get_relative(); float len = gui.drag_accum.length(); - if (len > 10) { + if (len > gui.drag_threshold) { { // Attempt grab, try parent controls too. CanvasItem *ci = gui.mouse_focus; while (ci) { @@ -4136,6 +4136,16 @@ TypedArray Viewport::get_embedded_subwindows() const { return windows; } +void Viewport::set_drag_threshold(int p_threshold) { + ERR_MAIN_THREAD_GUARD + gui.drag_threshold = p_threshold; +} + +int Viewport::get_drag_threshold() const { + ERR_READ_THREAD_GUARD_V(10); + return gui.drag_threshold; +} + void Viewport::subwindow_set_popup_safe_rect(Window *p_window, const Rect2i &p_rect) { int index = _sub_window_find(p_window); ERR_FAIL_COND(index == -1); @@ -5033,6 +5043,9 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("is_embedding_subwindows"), &Viewport::is_embedding_subwindows); ClassDB::bind_method(D_METHOD("get_embedded_subwindows"), &Viewport::get_embedded_subwindows); + ClassDB::bind_method(D_METHOD("set_drag_threshold", "threshold"), &Viewport::set_drag_threshold); + ClassDB::bind_method(D_METHOD("get_drag_threshold"), &Viewport::get_drag_threshold); + ClassDB::bind_method(D_METHOD("set_canvas_cull_mask", "mask"), &Viewport::set_canvas_cull_mask); ClassDB::bind_method(D_METHOD("get_canvas_cull_mask"), &Viewport::get_canvas_cull_mask); @@ -5158,6 +5171,7 @@ void Viewport::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_disable_input"), "set_disable_input", "is_input_disabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_snap_controls_to_pixels"), "set_snap_controls_to_pixels", "is_snap_controls_to_pixels_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_embed_subwindows"), "set_embedding_subwindows", "is_embedding_subwindows"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "gui_drag_threshold"), "set_drag_threshold", "get_drag_threshold"); ADD_GROUP("SDF", "sdf_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "sdf_oversize", PROPERTY_HINT_ENUM, "100%,120%,150%,200%"), "set_sdf_oversize", "get_sdf_oversize"); ADD_PROPERTY(PropertyInfo(Variant::INT, "sdf_scale", PROPERTY_HINT_ENUM, "100%,50%,25%"), "set_sdf_scale", "get_sdf_scale"); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 85c6003986e..cf1d14383ef 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -401,6 +401,7 @@ private: bool drag_successful = false; Control *target_control = nullptr; // Control that the mouse is over in the innermost nested Viewport. Only used in root-Viewport and SubViewports, that are not children of a SubViewportContainer. bool embed_subwindows_hint = false; + int drag_threshold = 10; Window *subwindow_focused = nullptr; Window *currently_dragged_subwindow = nullptr; @@ -706,6 +707,9 @@ public: void subwindow_set_popup_safe_rect(Window *p_window, const Rect2i &p_rect); Rect2i subwindow_get_popup_safe_rect(Window *p_window) const; + void set_drag_threshold(int p_threshold); + int get_drag_threshold() const; + Viewport *get_parent_viewport() const; Window *get_base_window();