SurfaceBoxRenderer.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System;
  2. using System.Drawing;
  3. namespace PaintDotNet
  4. {
  5. /// <summary>
  6. /// This class handles rendering something to a SurfaceBox.
  7. /// </summary>
  8. public abstract class SurfaceBoxRenderer
  9. : IDisposable
  10. {
  11. private bool disposed = false;
  12. private SurfaceBoxRendererList ownerList;
  13. private bool visible;
  14. public const int MinXCoordinate = -131072;
  15. public const int MaxXCoordinate = +131072;
  16. public const int MinYCoordinate = -131072;
  17. public const int MaxYCoordinate = +131072;
  18. public bool IsDisposed
  19. {
  20. get
  21. {
  22. return this.disposed;
  23. }
  24. }
  25. public static Rectangle MaxBounds
  26. {
  27. get
  28. {
  29. return Rectangle.FromLTRB(MinXCoordinate, MinYCoordinate, MaxXCoordinate + 1, MaxYCoordinate + 1);
  30. }
  31. }
  32. protected object SyncRoot
  33. {
  34. get
  35. {
  36. return OwnerList.SyncRoot;
  37. }
  38. }
  39. protected SurfaceBoxRendererList OwnerList
  40. {
  41. get
  42. {
  43. return this.ownerList;
  44. }
  45. }
  46. public virtual void OnSourceSizeChanged()
  47. {
  48. }
  49. public virtual void OnDestinationSizeChanged()
  50. {
  51. }
  52. public Size SourceSize
  53. {
  54. get
  55. {
  56. return this.OwnerList.SourceSize;
  57. }
  58. }
  59. public Size DestinationSize
  60. {
  61. get
  62. {
  63. return this.OwnerList.DestinationSize;
  64. }
  65. }
  66. protected virtual void OnVisibleChanging()
  67. {
  68. }
  69. protected abstract void OnVisibleChanged();
  70. public bool Visible
  71. {
  72. get
  73. {
  74. return this.visible;
  75. }
  76. set
  77. {
  78. if (this.visible != value)
  79. {
  80. OnVisibleChanging();
  81. this.visible = value;
  82. OnVisibleChanged();
  83. }
  84. }
  85. }
  86. protected delegate void RenderDelegate(Surface dst, Point offset);
  87. /// <summary>
  88. /// Renders, at the appropriate scale, the layer's imagery.
  89. /// </summary>
  90. /// <param name="dst">The Surface to render to.</param>
  91. /// <param name="dstTranslation">The (x,y) location of the upper-left corner of dst within DestinationSize.</param>
  92. public abstract void Render(Surface dst, Point offset);
  93. protected virtual void OnInvalidate(Rectangle rect)
  94. {
  95. this.OwnerList.Invalidate(rect);
  96. }
  97. public void Invalidate(Rectangle rect)
  98. {
  99. OnInvalidate(rect);
  100. }
  101. public void Invalidate(RectangleF rectF)
  102. {
  103. Rectangle rect = Utility.RoundRectangle(rectF);
  104. Invalidate(rect);
  105. }
  106. public void Invalidate(PdnRegion region)
  107. {
  108. foreach (Rectangle rect in region.GetRegionScansReadOnlyInt())
  109. {
  110. Invalidate(rect);
  111. }
  112. }
  113. public void Invalidate()
  114. {
  115. Invalidate(Rectangle.FromLTRB(MinXCoordinate, MinYCoordinate, MaxXCoordinate + 1, MaxYCoordinate + 1));
  116. }
  117. public SurfaceBoxRenderer(SurfaceBoxRendererList ownerList)
  118. {
  119. this.ownerList = ownerList;
  120. this.visible = true;
  121. }
  122. ~SurfaceBoxRenderer()
  123. {
  124. this.Dispose(false);
  125. }
  126. public void Dispose()
  127. {
  128. this.Dispose(true);
  129. GC.SuppressFinalize(this);
  130. }
  131. protected virtual void Dispose(bool disposing)
  132. {
  133. this.disposed = true;
  134. }
  135. }
  136. }