Class DrawContext
Tracks the region that has been drawn during Draw(DrawContext?). This is primarily in support of Transparent.
public class DrawContext
- Inheritance
-
DrawContext
- Inherited Members
Remarks
When a View has Transparent set, the DrawContext 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 DrawContext are in screen-relative coordinates. When reporting drawn areas from within OnDrawingContent(DrawContext?), use ViewportToScreen(in Rectangle) or ContentToScreen(in Point) to convert viewport-relative or content-relative coordinates to screen-relative coordinates before calling AddDrawnRectangle(Rectangle) or AddDrawnRegion(Region).
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;
}
Methods
- AddDrawnRectangle(Rectangle)
Reports that a rectangle has been drawn.
- AddDrawnRegion(Region)
Reports that a region has been drawn.
- ClipDrawnRegion(Rectangle)
Clips (intersects) the drawn region with the specified rectangle. This modifies the internal drawn region directly.
- ClipDrawnRegion(Region)
Clips (intersects) the drawn region with the specified region. This modifies the internal drawn region directly.
- GetDrawnRegion()
Gets a copy of the region drawn so far in this context.