SurfaceBoxRenderer.cs 3.7 KB

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