Skip to content

Commit 56aec53

Browse files
Fix draw clipping for projecting containers
1 parent 1e18ae8 commit 56aec53

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Wobble/Graphics/Container.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public class Container : Drawable
2020
/// </summary>
2121
public RenderTargetOptions RenderTargetOptions { get; } = new RenderTargetOptions();
2222

23+
protected override RectangleF ChildDrawRectangleMask =>
24+
RenderTargetOptions.RenderTarget.Value?.Bounds
25+
?? base.ChildDrawRectangleMask;
26+
2327
/// <summary>
2428
/// A projection sprite that has the same dimension, position, rotation and parent as the container.
2529
/// It shows <see cref="RenderTarget"/>, which the container can render its entire content to

Wobble/Graphics/Drawable.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ public Drawable Parent
7676
/// </summary>
7777
public RectangleF ScreenRectangle { get; private set; } = new RectangleF();
7878

79+
/// <summary>
80+
/// If outside this region, this will not be drawed.
81+
/// </summary>
82+
private RectangleF DrawRectangleMask { get; set; } =
83+
new RectangleF(0, 0, WindowManager.Width, WindowManager.Height);
84+
85+
/// <summary>
86+
/// Clipping region for children. Useful to RenderTargets
87+
/// </summary>
88+
protected virtual RectangleF ChildDrawRectangleMask =>
89+
Parent?.ChildDrawRectangleMask
90+
?? new RectangleF(0, 0, WindowManager.Width, WindowManager.Height);
91+
7992
/// <summary>
8093
/// The bounding box of the drawable relative to the entire screen.
8194
/// </summary>
@@ -503,7 +516,7 @@ public virtual void Draw(GameTime gameTime)
503516
if (!Visible)
504517
return;
505518

506-
if (!RectangleF.Intersects(ScreenMinimumBoundingRectangle, new RectangleF(0, 0, WindowManager.Width, WindowManager.Height)) && !DrawIfOffScreen)
519+
if (!RectangleF.Intersects(ScreenMinimumBoundingRectangle, DrawRectangleMask) && !DrawIfOffScreen)
507520
return;
508521

509522
// Draw the children and set their order.
@@ -584,6 +597,8 @@ protected void RecalculateRectangles()
584597
// Update AbsoluteRotation
585598
AbsoluteRotation = (Parent?.AbsoluteRotation ?? 0) + Rotation;
586599
AbsoluteScale = (Parent?.AbsoluteScale ?? Vector2.One) * Scale;
600+
DrawRectangleMask = Parent?.ChildDrawRectangleMask
601+
?? new RectangleF(0, 0, WindowManager.Width, WindowManager.Height);
587602

588603
// Make it relative to the parent.
589604
var width = RelativeWidth;

0 commit comments

Comments
 (0)