namespace Terminal.Gui.ViewBase; /// /// Tracks the region that has been drawn during . This is primarily /// in support of . /// /// /// /// When a has set, the /// is used to track exactly which areas of the screen have been drawn to. After drawing is complete, these drawn /// regions are excluded from the clip region, allowing views beneath the transparent view to show through in /// the areas that were not drawn. /// /// /// All coordinates tracked by are in screen-relative coordinates. When reporting /// drawn areas from within , use /// or to convert viewport-relative or content-relative coordinates to /// screen-relative coordinates before calling or . /// /// /// Example of reporting a non-rectangular drawn region for transparency: /// /// /// protected override bool OnDrawingContent (DrawContext? context) /// { /// // Draw some content in viewport-relative coordinates /// Rectangle rect1 = new Rectangle (5, 5, 10, 3); /// Rectangle rect2 = new Rectangle (8, 8, 4, 7); /// FillRect (rect1, Glyphs.BlackCircle); /// FillRect (rect2, Glyphs.BlackCircle); /// /// // Report the drawn region in screen-relative coordinates /// Region drawnRegion = new Region (ViewportToScreen (rect1)); /// drawnRegion.Union (ViewportToScreen (rect2)); /// context?.AddDrawnRegion (drawnRegion); /// /// return true; /// } /// /// public class DrawContext { private readonly Region _drawnRegion = new Region (); /// /// Gets a copy of the region drawn so far in this context. /// /// /// The returned region contains all areas that have been reported as drawn via /// or , in screen-relative coordinates. /// public Region GetDrawnRegion () => _drawnRegion.Clone (); /// /// Reports that a rectangle has been drawn. /// /// The rectangle that was drawn, in screen-relative coordinates. /// /// When called from within , ensure the rectangle is in /// screen-relative coordinates by using or similar methods. /// public void AddDrawnRectangle (Rectangle rect) { _drawnRegion.Combine (rect, RegionOp.Union); } /// /// Reports that a region has been drawn. /// /// The region that was drawn, in screen-relative coordinates. /// /// /// This method is useful for reporting non-rectangular drawn areas, which is important for /// proper transparency support with . /// /// /// When called from within , ensure the region is in /// screen-relative coordinates by using to convert each /// rectangle in the region. /// /// public void AddDrawnRegion (Region region) { _drawnRegion.Combine (region, RegionOp.Union); } /// /// Clips (intersects) the drawn region with the specified rectangle. /// This modifies the internal drawn region directly. /// /// The clipping rectangle, in screen-relative coordinates. public void ClipDrawnRegion (Rectangle clipRect) { _drawnRegion.Intersect (clipRect); } /// /// Clips (intersects) the drawn region with the specified region. /// This modifies the internal drawn region directly. /// /// The clipping region, in screen-relative coordinates. public void ClipDrawnRegion (Region clipRegion) { _drawnRegion.Intersect (clipRegion); } }