SurfaceBoxRenderer.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace SmartCoalApplication.Core
  8. {
  9. public abstract class SurfaceBoxRenderer : 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()
  102. {
  103. Invalidate(Rectangle.FromLTRB(MinXCoordinate, MinYCoordinate, MaxXCoordinate + 1, MaxYCoordinate + 1));
  104. }
  105. public SurfaceBoxRenderer(SurfaceBoxRendererList ownerList)
  106. {
  107. this.ownerList = ownerList;
  108. this.visible = true;
  109. }
  110. ~SurfaceBoxRenderer()
  111. {
  112. this.Dispose(false);
  113. }
  114. public void Dispose()
  115. {
  116. this.Dispose(true);
  117. GC.SuppressFinalize(this);
  118. }
  119. protected virtual void Dispose(bool disposing)
  120. {
  121. this.disposed = true;
  122. }
  123. }
  124. }