DrawContext.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. /// <summary>
  4. /// Tracks the region that has been drawn during <see cref="View.Draw(DrawContext?)"/>. This is primarily
  5. /// in support of <see cref="ViewportSettings.Transparent"/>.
  6. /// </summary>
  7. public class DrawContext
  8. {
  9. private readonly Region _drawnRegion = new Region ();
  10. /// <summary>
  11. /// Gets a copy of the region drawn so far in this context.
  12. /// </summary>
  13. public Region GetDrawnRegion () => _drawnRegion.Clone ();
  14. /// <summary>
  15. /// Reports that a rectangle has been drawn.
  16. /// </summary>
  17. /// <param name="rect">The rectangle that was drawn.</param>
  18. public void AddDrawnRectangle (Rectangle rect)
  19. {
  20. _drawnRegion.Combine (rect, RegionOp.Union);
  21. }
  22. /// <summary>
  23. /// Reports that a region has been drawn.
  24. /// </summary>
  25. /// <param name="region">The region that was drawn.</param>
  26. public void AddDrawnRegion (Region region)
  27. {
  28. _drawnRegion.Combine (region, RegionOp.Union);
  29. }
  30. /// <summary>
  31. /// Clips (intersects) the drawn region with the specified rectangle.
  32. /// This modifies the internal drawn region directly.
  33. /// </summary>
  34. /// <param name="clipRect">The clipping rectangle.</param>
  35. public void ClipDrawnRegion (Rectangle clipRect)
  36. {
  37. _drawnRegion.Intersect (clipRect);
  38. }
  39. /// <summary>
  40. /// Clips (intersects) the drawn region with the specified region.
  41. /// This modifies the internal drawn region directly.
  42. /// </summary>
  43. /// <param name="clipRegion">The clipping region.</param>
  44. public void ClipDrawnRegion (Region clipRegion)
  45. {
  46. _drawnRegion.Intersect (clipRegion);
  47. }
  48. }