From b7b7f885f32252ae8e6d446c8ea607d0cfbb85a2 Mon Sep 17 00:00:00 2001 From: lodicolo Date: Wed, 7 Aug 2024 12:27:23 -0400 Subject: [PATCH] feat: window background transparency (#2373) - Add DrawShadow property (default true) to control drawing the backdrop shadow - DrawBackground of the window now controls if the "frame" (the background, minus the titlebar) is visible - DrawBackground of the Titlebar node now controls if the "titlebar" image is drawn --- .../Gwen/Control/WindowControl.cs | 19 ++++++++++++++++++- .../Gwen/Skin/Intersect2021.cs | 14 ++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Intersect.Client.Framework/Gwen/Control/WindowControl.cs b/Intersect.Client.Framework/Gwen/Control/WindowControl.cs index 058061305..520b57dd1 100644 --- a/Intersect.Client.Framework/Gwen/Control/WindowControl.cs +++ b/Intersect.Client.Framework/Gwen/Control/WindowControl.cs @@ -163,9 +163,15 @@ public override bool IsOnTop get { return Parent.Children.Where(x => x is WindowControl).Last() == this; } } + /// + /// If the shadow under the window should be drawn. + /// + public bool DrawShadow { get; set; } = true; + public override JObject GetJson(bool isRoot = default) { var obj = base.GetJson(isRoot); + obj.Add(nameof(DrawShadow), DrawShadow); obj.Add("ActiveImage", GetImageFilename(ControlState.Active)); obj.Add("InactiveImage", GetImageFilename(ControlState.Inactive)); obj.Add("ActiveColor", Color.ToString(mActiveColor)); @@ -182,6 +188,13 @@ public override JObject GetJson(bool isRoot = default) public override void LoadJson(JToken obj, bool isRoot = default) { base.LoadJson(obj); + + var tokenDrawShadow = obj[nameof(DrawShadow)]; + if (tokenDrawShadow != null) + { + DrawShadow = (bool)tokenDrawShadow; + } + if (obj["ActiveImage"] != null) { SetImage( @@ -333,7 +346,11 @@ protected override void Render(Skin.Base skin) protected override void RenderUnder(Skin.Base skin) { base.RenderUnder(skin); - skin.DrawShadow(this); + + if (DrawShadow) + { + skin.DrawShadow(this); + } } public override void Touch() diff --git a/Intersect.Client.Framework/Gwen/Skin/Intersect2021.cs b/Intersect.Client.Framework/Gwen/Skin/Intersect2021.cs index 8986ba789..ef0d388f6 100644 --- a/Intersect.Client.Framework/Gwen/Skin/Intersect2021.cs +++ b/Intersect.Client.Framework/Gwen/Skin/Intersect2021.cs @@ -158,7 +158,6 @@ public override void DrawWindow(Control.Base control, int topHeight, bool inFocu return; } - GameTexture? renderTexture = null; if (windowControl.TryGetTexture(WindowControl.ControlState.Active, out var activeTexture)) { @@ -193,7 +192,8 @@ public override void DrawWindow(Control.Base control, int topHeight, bool inFocu Rectangle frameBounds = windowControl.RenderBounds; - if (titleBar != default) + var shouldDrawTitlebarBackground = titleBar != default && windowControl.TitleBar.ShouldDrawBackground; + if (shouldDrawTitlebarBackground) { frameBounds = new Rectangle( 0, @@ -201,11 +201,17 @@ public override void DrawWindow(Control.Base control, int topHeight, bool inFocu control.RenderBounds.Width, control.RenderBounds.Height ); + } - titleBar.Draw(Renderer, windowControl.TitleBar.Bounds, windowControl.RenderColor); + if (frame != default && windowControl.ShouldDrawBackground) + { + frame.Draw(Renderer, frameBounds, windowControl.RenderColor); } - frame.Draw(Renderer, frameBounds, windowControl.RenderColor); + if (shouldDrawTitlebarBackground) + { + titleBar.Draw(Renderer, windowControl.TitleBar.Bounds, windowControl.RenderColor); + } } #endregion