From 7e1d6679ce1547afd8d682bbd1cda68eeba4526c Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Tue, 15 Oct 2024 19:43:08 +0200 Subject: [PATCH 1/2] add debug draw clear to game and editor panel --- Source/Editor/Viewport/EditorViewport.cs | 9 +++++++++ Source/Editor/Windows/GameWindow.cs | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/Source/Editor/Viewport/EditorViewport.cs b/Source/Editor/Viewport/EditorViewport.cs index edb3e0e39..619338fe7 100644 --- a/Source/Editor/Viewport/EditorViewport.cs +++ b/Source/Editor/Viewport/EditorViewport.cs @@ -973,6 +973,15 @@ namespace FlaxEditor.Viewport ViewWidgetButtonMenu.AddSeparator(); + // Clear Debug Draw + { + var button = ViewWidgetButtonMenu.AddButton("Clear Debug Draw"); + button.CloseMenuOnClick = false; + button.Clicked += () => DebugDraw.Clear(); + } + + ViewWidgetButtonMenu.AddSeparator(); + // Brightness { var brightness = ViewWidgetButtonMenu.AddButton("Brightness"); diff --git a/Source/Editor/Windows/GameWindow.cs b/Source/Editor/Windows/GameWindow.cs index 56e4c4380..ea6889cb7 100644 --- a/Source/Editor/Windows/GameWindow.cs +++ b/Source/Editor/Windows/GameWindow.cs @@ -596,6 +596,13 @@ namespace FlaxEditor.Windows checkbox.StateChanged += x => ShowDebugDraw = x.Checked; } + // Debug Draw Clear + { + var button = menu.AddButton("Clear Debug Draw"); + button.CloseMenuOnClick = false; + button.Clicked += () => DebugDraw.Clear(); + } + menu.MinimumWidth = 200; menu.AddSeparator(); } From 47b22b305d084cf9a25bab563dc365b8378d9d65 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 3 Mar 2025 09:51:05 +0100 Subject: [PATCH 2/2] Add conditional showing of `Clear Debug Draw` buttons only if there is anything to clear #2989 --- Source/Editor/Viewport/EditorViewport.cs | 3 +-- Source/Editor/Windows/GameWindow.cs | 16 ++++++++-------- Source/Engine/Debug/DebugDraw.cpp | 12 ++++++++++++ Source/Engine/Debug/DebugDraw.h | 7 +++++++ 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Source/Editor/Viewport/EditorViewport.cs b/Source/Editor/Viewport/EditorViewport.cs index 3ca66c343..e30e242e9 100644 --- a/Source/Editor/Viewport/EditorViewport.cs +++ b/Source/Editor/Viewport/EditorViewport.cs @@ -968,13 +968,12 @@ namespace FlaxEditor.Viewport debugView.VisibleChanged += WidgetViewModeShowHide; } - ViewWidgetButtonMenu.AddSeparator(); - // Clear Debug Draw { var button = ViewWidgetButtonMenu.AddButton("Clear Debug Draw"); button.CloseMenuOnClick = false; button.Clicked += () => DebugDraw.Clear(); + ViewWidgetButtonMenu.VisibleChanged += (Control cm) => { button.Visible = DebugDraw.CanClear(); }; } ViewWidgetButtonMenu.AddSeparator(); diff --git a/Source/Editor/Windows/GameWindow.cs b/Source/Editor/Windows/GameWindow.cs index b7a17214b..ebc64cbd8 100644 --- a/Source/Editor/Windows/GameWindow.cs +++ b/Source/Editor/Windows/GameWindow.cs @@ -117,7 +117,6 @@ namespace FlaxEditor.Windows { if (!AudioMuted) Audio.MasterVolume = value; - _audioVolume = value; } } @@ -677,6 +676,14 @@ namespace FlaxEditor.Windows checkbox.StateChanged += x => ShowDebugDraw = x.Checked; } + // Clear Debug Draw + if (DebugDraw.CanClear()) + { + var button = menu.AddButton("Clear Debug Draw"); + button.CloseMenuOnClick = false; + button.Clicked += () => DebugDraw.Clear(); + } + menu.AddSeparator(); // Mute Audio @@ -695,13 +702,6 @@ namespace FlaxEditor.Windows slider.ValueChanged += () => AudioVolume = slider.Value; } - // Debug Draw Clear - { - var button = menu.AddButton("Clear Debug Draw"); - button.CloseMenuOnClick = false; - button.Clicked += () => DebugDraw.Clear(); - } - menu.MinimumWidth = 200; menu.AddSeparator(); } diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index 4dacb95d6..6e2388ed2 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -347,6 +347,11 @@ struct DebugDrawContext DebugDrawData DebugDrawDepthTest; Float3 LastViewPos = Float3::Zero; Matrix LastViewProj = Matrix::Identity; + + inline int32 Count() const + { + return DebugDrawDefault.Count() + DebugDrawDepthTest.Count(); + } }; namespace @@ -739,6 +744,13 @@ void DebugDraw::SetContext(void* context) Context = context ? (DebugDrawContext*)context : &GlobalContext; } +bool DebugDraw::CanClear(void* context) +{ + if (!context) + context = &GlobalContext; + return ((DebugDrawContext*)context)->Count() != 0; +} + #endif Vector3 DebugDraw::GetViewPos() diff --git a/Source/Engine/Debug/DebugDraw.h b/Source/Engine/Debug/DebugDraw.h index 84e223434..4bea47118 100644 --- a/Source/Engine/Debug/DebugDraw.h +++ b/Source/Engine/Debug/DebugDraw.h @@ -62,6 +62,13 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw /// /// The context or null. API_FUNCTION() static void SetContext(void* context); + + /// + /// Checks if can clear all debug shapes displayed on screen. Can be used to disable this functionality when not needed for the user. + /// + /// The context. + /// True fi context can be cleared (has any shapes), otherwise false. + API_FUNCTION() static bool CanClear(void* context = nullptr); #endif // Gets the last view position when rendering the current context. Can be sued for custom culling or LODing when drawing more complex shapes.