Skip to content

Commit

Permalink
feat: window background transparency (#2373)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
lodicolo authored Aug 7, 2024
1 parent c348a01 commit b7b7f88
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
19 changes: 18 additions & 1 deletion Intersect.Client.Framework/Gwen/Control/WindowControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,15 @@ public override bool IsOnTop
get { return Parent.Children.Where(x => x is WindowControl).Last() == this; }
}

/// <summary>
/// If the shadow under the window should be drawn.
/// </summary>
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));
Expand All @@ -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(
Expand Down Expand Up @@ -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()
Expand Down
14 changes: 10 additions & 4 deletions Intersect.Client.Framework/Gwen/Skin/Intersect2021.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -193,19 +192,26 @@ 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,
windowControl.TitleBar.Bottom,
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
Expand Down

0 comments on commit b7b7f88

Please sign in to comment.