@@ -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