From 5af3a22fd01f4b32809cfbf5690992a8388edfec Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Wed, 17 Mar 2021 20:22:06 +0100 Subject: [PATCH 1/3] Add DrawSelf. --- Source/Engine/UI/GUI/ContainerControl.cs | 43 ++++++++++++++---------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/Source/Engine/UI/GUI/ContainerControl.cs b/Source/Engine/UI/GUI/ContainerControl.cs index 817bc28a5..8e046ecde 100644 --- a/Source/Engine/UI/GUI/ContainerControl.cs +++ b/Source/Engine/UI/GUI/ContainerControl.cs @@ -616,32 +616,35 @@ namespace FlaxEngine.GUI } } - /// + /// + /// Draw the control and the children. + /// public override void Draw() { - base.Draw(); + DrawSelf(); + DrawChildren(); + } + /// + /// Draws the control. + /// + public virtual void DrawSelf() + { + base.Draw(); + } + + /// + /// Draws the children. Can be overridden to provide some customizations. Draw is performed with applied clipping mask for the client area. + /// + protected virtual void DrawChildren() + { // Push clipping mask if (ClipChildren) { GetDesireClientArea(out var clientArea); Render2D.PushClip(ref clientArea); } - - DrawChildren(); - - // Pop clipping mask - if (ClipChildren) - { - Render2D.PopClip(); - } - } - - /// - /// Draws the children. Can be overridden to provide some customizations. Draw is performed with applied clipping mask for the client area. - /// - protected virtual void DrawChildren() - { + // Draw all visible child controls if (CullChildren) { @@ -676,6 +679,12 @@ namespace FlaxEngine.GUI } } } + + // Pop clipping mask + if (ClipChildren) + { + Render2D.PopClip(); + } } /// From fb70368c8d94b07d233caa243ae24aee97d78878 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Wed, 17 Mar 2021 20:22:27 +0100 Subject: [PATCH 2/3] Fix image ordering. --- Source/Engine/UI/GUI/Common/Image.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Engine/UI/GUI/Common/Image.cs b/Source/Engine/UI/GUI/Common/Image.cs index b94b285b6..adeddce6b 100644 --- a/Source/Engine/UI/GUI/Common/Image.cs +++ b/Source/Engine/UI/GUI/Common/Image.cs @@ -80,10 +80,10 @@ namespace FlaxEngine.GUI } /// - public override void Draw() + public override void DrawSelf() { - base.Draw(); - + base.DrawSelf(); + if (Brush == null) return; From c8b57d417c9dc3ffd5b5fc43ca8105b9115a5f36 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Wed, 17 Mar 2021 20:53:42 +0100 Subject: [PATCH 3/3] Convert Control to ContainerControl. --- Source/Engine/UI/GUI/Common/Border.cs | 6 +++--- Source/Engine/UI/GUI/Common/Button.cs | 4 ++-- Source/Engine/UI/GUI/Common/ProgressBar.cs | 6 +++--- Source/Engine/UI/GUI/Common/RenderToTextureControl.cs | 4 ++-- Source/Engine/UI/GUI/Common/RichTextBoxBase.cs | 2 +- Source/Engine/UI/GUI/Common/TextBox.cs | 2 +- Source/Engine/UI/GUI/Common/TextBoxBase.cs | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Source/Engine/UI/GUI/Common/Border.cs b/Source/Engine/UI/GUI/Common/Border.cs index 543735e99..fb699b132 100644 --- a/Source/Engine/UI/GUI/Common/Border.cs +++ b/Source/Engine/UI/GUI/Common/Border.cs @@ -5,7 +5,7 @@ namespace FlaxEngine.GUI /// /// Border control that draws the border around the control edges (inner and outer sides). /// - public class Border : Control + public class Border : ContainerControl { /// /// Gets or sets the color used to draw border lines. @@ -30,9 +30,9 @@ namespace FlaxEngine.GUI } /// - public override void Draw() + public override void DrawSelf() { - base.Draw(); + base.DrawSelf(); Render2D.DrawRectangle(new Rectangle(Vector2.Zero, Size), BorderColor, BorderWidth); } diff --git a/Source/Engine/UI/GUI/Common/Button.cs b/Source/Engine/UI/GUI/Common/Button.cs index 9d56a4a36..639552ec3 100644 --- a/Source/Engine/UI/GUI/Common/Button.cs +++ b/Source/Engine/UI/GUI/Common/Button.cs @@ -7,7 +7,7 @@ namespace FlaxEngine.GUI /// /// Button control /// - public class Button : Control + public class Button : ContainerControl { /// /// The default height fro the buttons. @@ -171,7 +171,7 @@ namespace FlaxEngine.GUI } /// - public override void Draw() + public override void DrawSelf() { // Cache data Rectangle clientRect = new Rectangle(Vector2.Zero, Size); diff --git a/Source/Engine/UI/GUI/Common/ProgressBar.cs b/Source/Engine/UI/GUI/Common/ProgressBar.cs index f68336d24..21cce7faa 100644 --- a/Source/Engine/UI/GUI/Common/ProgressBar.cs +++ b/Source/Engine/UI/GUI/Common/ProgressBar.cs @@ -8,7 +8,7 @@ namespace FlaxEngine.GUI /// Progress bar control shows visual progress of the action or set of actions. /// /// - public class ProgressBar : Control + public class ProgressBar : ContainerControl { /// /// The value. @@ -160,9 +160,9 @@ namespace FlaxEngine.GUI } /// - public override void Draw() + public override void DrawSelf() { - base.Draw(); + base.DrawSelf(); float progressNormalized = (_current - _minimum) / _maximum; if (progressNormalized > 0.001f) diff --git a/Source/Engine/UI/GUI/Common/RenderToTextureControl.cs b/Source/Engine/UI/GUI/Common/RenderToTextureControl.cs index 526390dac..3894c3027 100644 --- a/Source/Engine/UI/GUI/Common/RenderToTextureControl.cs +++ b/Source/Engine/UI/GUI/Common/RenderToTextureControl.cs @@ -105,7 +105,7 @@ namespace FlaxEngine.GUI } /// - public override void Draw() + public override void DrawSelf() { // Draw cached texture if (_texture && !_invalid && !_isDuringTextureDraw) @@ -119,7 +119,7 @@ namespace FlaxEngine.GUI } // Draw default UI directly - base.Draw(); + base.DrawSelf(); } /// diff --git a/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs b/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs index 0ef44594b..1a57061e1 100644 --- a/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs +++ b/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs @@ -220,7 +220,7 @@ namespace FlaxEngine.GUI } /// - public override void Draw() + public override void DrawSelf() { // Cache data var rect = new Rectangle(Vector2.Zero, Size); diff --git a/Source/Engine/UI/GUI/Common/TextBox.cs b/Source/Engine/UI/GUI/Common/TextBox.cs index 0a6f11660..0ed5c731c 100644 --- a/Source/Engine/UI/GUI/Common/TextBox.cs +++ b/Source/Engine/UI/GUI/Common/TextBox.cs @@ -132,7 +132,7 @@ namespace FlaxEngine.GUI } /// - public override void Draw() + public override void DrawSelf() { // Cache data var rect = new Rectangle(Vector2.Zero, Size); diff --git a/Source/Engine/UI/GUI/Common/TextBoxBase.cs b/Source/Engine/UI/GUI/Common/TextBoxBase.cs index 1df079b48..c05790308 100644 --- a/Source/Engine/UI/GUI/Common/TextBoxBase.cs +++ b/Source/Engine/UI/GUI/Common/TextBoxBase.cs @@ -9,7 +9,7 @@ namespace FlaxEngine.GUI /// /// Base class for all text box controls which can gather text input from the user. /// - public abstract class TextBoxBase : Control + public abstract class TextBoxBase : ContainerControl { /// /// The text separators (used for words skipping).