CanvasControl.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace PaintDotNet.Measurement
  5. {
  6. public abstract class CanvasControl : SurfaceBoxGraphicsRenderer
  7. {
  8. private PointF location;
  9. private SizeF size;
  10. private Cursor cursor;
  11. public event EventHandler CursorChanged;
  12. protected virtual void OnCursorChanged()
  13. {
  14. if (CursorChanged != null)
  15. {
  16. CursorChanged(this, EventArgs.Empty);
  17. }
  18. }
  19. public Cursor Cursor
  20. {
  21. get
  22. {
  23. return this.cursor;
  24. }
  25. set
  26. {
  27. if (this.cursor != value)
  28. {
  29. this.cursor = value;
  30. OnCursorChanged();
  31. }
  32. }
  33. }
  34. public event EventHandler LocationChanging;
  35. protected virtual void OnLocationChanging()
  36. {
  37. if (LocationChanging != null)
  38. {
  39. LocationChanging(this, EventArgs.Empty);
  40. }
  41. }
  42. public event EventHandler LocationChanged;
  43. protected virtual void OnLocationChanged()
  44. {
  45. if (LocationChanged != null)
  46. {
  47. LocationChanged(this, EventArgs.Empty);
  48. }
  49. }
  50. public PointF Location
  51. {
  52. get
  53. {
  54. return this.location;
  55. }
  56. set
  57. {
  58. if (this.location != value)
  59. {
  60. OnLocationChanging();
  61. this.location = value;
  62. OnLocationChanged();
  63. }
  64. }
  65. }
  66. public event EventHandler SizeChanging;
  67. protected virtual void OnSizeChanging()
  68. {
  69. if (SizeChanging != null)
  70. {
  71. SizeChanging(this, EventArgs.Empty);
  72. }
  73. }
  74. public event EventHandler SizeChanged;
  75. protected virtual void OnSizeChanged()
  76. {
  77. if (SizeChanged != null)
  78. {
  79. SizeChanged(this, EventArgs.Empty);
  80. }
  81. }
  82. public SizeF Size
  83. {
  84. get
  85. {
  86. return this.size;
  87. }
  88. set
  89. {
  90. if (this.size != value)
  91. {
  92. OnSizeChanging();
  93. this.size = value;
  94. OnSizeChanged();
  95. }
  96. }
  97. }
  98. public float Width
  99. {
  100. get
  101. {
  102. return Size.Width;
  103. }
  104. set
  105. {
  106. Size = new SizeF(value, Size.Height);
  107. }
  108. }
  109. public float Height
  110. {
  111. get
  112. {
  113. return Size.Height;
  114. }
  115. set
  116. {
  117. Size = new SizeF(Size.Width, value);
  118. }
  119. }
  120. public RectangleF Bounds
  121. {
  122. get
  123. {
  124. return new RectangleF(this.location, this.size);
  125. }
  126. set
  127. {
  128. Location = value.Location;
  129. Size = value.Size;
  130. }
  131. }
  132. public PointF CanvasPointToControlPoint(PointF canvasPtF)
  133. {
  134. return new PointF(canvasPtF.X - this.location.X, canvasPtF.Y - this.location.Y);
  135. }
  136. public PointF ControlPointToCanvasPoint(PointF controlPtF)
  137. {
  138. return new PointF(controlPtF.X + this.location.X, controlPtF.Y + this.location.Y);
  139. }
  140. public RectangleF CanvasRectToControlRect(RectangleF canvasRectF)
  141. {
  142. return new RectangleF(CanvasPointToControlPoint(canvasRectF.Location), canvasRectF.Size);
  143. }
  144. public RectangleF ControlRectToCanvasRect(RectangleF controlRectF)
  145. {
  146. return new RectangleF(ControlPointToCanvasPoint(controlRectF.Location), controlRectF.Size);
  147. }
  148. public void PerformMouseEnter()
  149. {
  150. MouseEnter();
  151. }
  152. private void MouseEnter()
  153. {
  154. OnMouseEnter();
  155. }
  156. protected virtual void OnMouseEnter()
  157. {
  158. }
  159. public void PerformMouseDown(MouseEventArgs e)
  160. {
  161. MouseDown(e);
  162. }
  163. private void MouseDown(MouseEventArgs e)
  164. {
  165. MouseDown(e);
  166. }
  167. protected virtual void OnMouseDown(MouseEventArgs e)
  168. {
  169. }
  170. public void PerformMouseUp(MouseEventArgs e)
  171. {
  172. MouseUp(e);
  173. }
  174. private void MouseUp(MouseEventArgs e)
  175. {
  176. OnMouseUp(e);
  177. }
  178. protected virtual void OnMouseUp(MouseEventArgs e)
  179. {
  180. }
  181. public void PerformMouseLeave()
  182. {
  183. MouseLeave();
  184. }
  185. private void MouseLeave()
  186. {
  187. OnMouseLeave();
  188. }
  189. protected virtual void OnMouseLeave()
  190. {
  191. }
  192. public void PerformPulse()
  193. {
  194. Pulse();
  195. }
  196. private void Pulse()
  197. {
  198. OnPulse();
  199. }
  200. protected virtual void OnPulse()
  201. {
  202. }
  203. public override sealed void RenderToGraphics(Graphics g, Point offset)
  204. {
  205. OnRender(g, offset);
  206. }
  207. protected virtual void OnRender(Graphics g, Point offset)
  208. {
  209. }
  210. protected CanvasControl(SurfaceBoxRendererList ownerList)
  211. : base(ownerList)
  212. {
  213. }
  214. }
  215. }