GraElement.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /********************************************************************************************
  2. **********************File Name: GraElement.cs,Version 1.0,8 November 2004*******************
  3. **********************************Author: Mayank Bansal**************************************
  4. ** This class mainly defines graphical elements. GraElement class gets the type of **
  5. ** GraElement to draw and it gets the mode of drawing and gets the existing path on **
  6. ** the bitmap and updates the new path. GraEleWithPen, GraEleWithPenBrush are inherited **
  7. ** from GraElement class. GraEleWithPen class is used to draw Graphical Elements with **
  8. ** Pen (default C# drawing object) like Line. GraEleWithPenBrush is used to draw solid **
  9. ** Graphical Elements like rectangle, ellipse etc which use both pen and brush properties. **
  10. ** **
  11. ** **
  12. ********************************************************************************************/
  13. ///
  14. using System;
  15. using System.Drawing;
  16. using System.Drawing.Drawing2D;
  17. using GraEditor.BaseDef;
  18. // Namespace Elements, include GraElemetn,GraEleWithPen,GraEleWithPenBrush,LineGra,LinesGra,RectGra,EllipseGra,TextGra,ImageGra,
  19. namespace GraEditor.Elements
  20. {
  21. [Flags]
  22. // Two drawing mode: frame and solid
  23. public enum GraDrawMode
  24. {
  25. Frame = 0x01,
  26. Fill = 0x02
  27. }
  28. //6 types drawing element: Line,Lines,Rect,Ellipse,Text,Image.
  29. public enum GraEleType
  30. {
  31. Line,
  32. Lines,
  33. Rect,
  34. Ellipse,
  35. Text,
  36. Image
  37. }
  38. //Abstract class, which is defined for graph element.
  39. //The GraEleWithPen(), ImageGra() and GraEleWithPenBrush() will inherit from this class.
  40. public abstract class GraElement
  41. {
  42. public GraElement()
  43. {
  44. //public path variable of GraElement,which save the path of graphic element
  45. this.path = new GraphicsPath();
  46. }
  47. protected GraDrawMode drawMode;//specify the draw mode: frame or fill
  48. //Draw Mode property of GraElement
  49. public GraDrawMode DrawMode
  50. {
  51. get { return drawMode; }
  52. set { drawMode = value; }
  53. }
  54. //specify the graph element type:Line or Line or Rect or Ellipse or Text or Image.
  55. public abstract GraEleType Type
  56. {
  57. get;
  58. }
  59. protected GraphicsPath path;//protected path variable of GraElement
  60. //Path property of GraElement
  61. public GraphicsPath Path
  62. {
  63. get { return path;} //return public path variable of GraElement
  64. }
  65. //Reset the path variable
  66. public virtual void UpdatePath()
  67. {
  68. this.path.Reset();
  69. }
  70. //Draw function of GraElement
  71. public virtual void Draw(Graphics g)
  72. {
  73. if((this.drawMode & GraDrawMode.Fill) == GraDrawMode.Fill)//draw solid graph
  74. {
  75. Brush b = this.BrushExt.Brush;// define a new Brush b,sent the GraElement.BrushExt.Brush to b
  76. g.FillPath(b,this.path); //draw graph element with brush b
  77. }
  78. if((this.drawMode & GraDrawMode.Frame) == GraDrawMode.Frame)//draw frame graph
  79. {
  80. Pen p = this.PenExt.Pen;// define a new Pen,sent the GraElement.PenExt.Pen to p
  81. g.DrawPath(p,this.path); //draw graph element with pen p
  82. }
  83. }
  84. //Pen property of GraElement
  85. public virtual PenExt PenExt
  86. {
  87. get { return null;}
  88. set { }
  89. }
  90. //Brush property of GraElement
  91. public virtual BrushExt BrushExt
  92. {
  93. get { return null;}
  94. set { }
  95. }
  96. }
  97. // Abstract class inherit from GraElement(), which will used for drawing line, lines.
  98. //class LineGra() and LinesGra() inherit from it
  99. public abstract class GraEleWithPen :GraElement
  100. {
  101. public GraEleWithPen(Pen pen) //Set PenExt of GraEleWithPen
  102. :base()
  103. {
  104. this.penExt = new PenExt();
  105. this.penExt.Pen = pen;
  106. this.drawMode = GraDrawMode.Frame;
  107. }
  108. private PenExt penExt; //Private PenExt varible of GraEleWithPen
  109. //Pen property of GraEleWithPen
  110. public override PenExt PenExt
  111. {
  112. get { return penExt; }
  113. set { penExt = value;}
  114. }
  115. }
  116. //Abstract class inherit from GraElement(), which will used for drawing rectangle, ellipse, text.
  117. //class RectGra(), EllipseGra and TextGra() inherit from it.
  118. public abstract class GraEleWithPenBrush : GraEleWithPen
  119. {
  120. //Construction Function of GraEleWithPenBrush.set BrushExt and PenExt of GraEleWithPen.
  121. //When we draw a solid graph, we will draw the frame of it and then fill the frame.
  122. public GraEleWithPenBrush(Pen pen, Brush brush,GraDrawMode drawMode)
  123. :base(pen)
  124. {
  125. this.brushExt = new BrushExt();
  126. this.brushExt.Brush = brush;
  127. this.drawMode = drawMode;
  128. }
  129. protected BrushExt brushExt;//Private BrushExt varible of GraEleWithPen
  130. //Brush property of GraEleWithPenBrush
  131. public override BrushExt BrushExt
  132. {
  133. get { return brushExt; }
  134. set { brushExt = value;}
  135. }
  136. }
  137. }