GraElement.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. Arrow,
  33. Lines,
  34. Rect,
  35. Ellipse,
  36. Text,
  37. Image
  38. }
  39. //Abstract class, which is defined for graph element.
  40. //The GraEleWithPen(), ImageGra() and GraEleWithPenBrush() will inherit from this class.
  41. public abstract class GraElement
  42. {
  43. public GraElement()
  44. {
  45. //public path variable of GraElement,which save the path of graphic element
  46. this.path = new GraphicsPath();
  47. }
  48. protected GraDrawMode drawMode;//specify the draw mode: frame or fill
  49. //Draw Mode property of GraElement
  50. public GraDrawMode DrawMode
  51. {
  52. get { return drawMode; }
  53. set { drawMode = value; }
  54. }
  55. //specify the graph element type:Line or Line or Rect or Ellipse or Text or Image.
  56. public abstract GraEleType Type
  57. {
  58. get;
  59. }
  60. protected GraphicsPath path;//protected path variable of GraElement
  61. //Path property of GraElement
  62. public GraphicsPath Path
  63. {
  64. get { return path;} //return public path variable of GraElement
  65. }
  66. //Reset the path variable
  67. public virtual void UpdatePath()
  68. {
  69. this.path.Reset();
  70. }
  71. //Draw function of GraElement
  72. public virtual void Draw(Graphics g)
  73. {
  74. if((this.drawMode & GraDrawMode.Fill) == GraDrawMode.Fill)//draw solid graph
  75. {
  76. Brush b = this.BrushExt.Brush;// define a new Brush b,sent the GraElement.BrushExt.Brush to b
  77. g.FillPath(b,this.path); //draw graph element with brush b
  78. }
  79. if((this.drawMode & GraDrawMode.Frame) == GraDrawMode.Frame)//draw frame graph
  80. {
  81. Pen p = this.PenExt.Pen;// define a new Pen,sent the GraElement.PenExt.Pen to p
  82. g.DrawPath(p,this.path); //draw graph element with pen p
  83. }
  84. }
  85. //Pen property of GraElement
  86. public virtual PenExt PenExt
  87. {
  88. get { return null;}
  89. set { }
  90. }
  91. //Brush property of GraElement
  92. public virtual BrushExt BrushExt
  93. {
  94. get { return null;}
  95. set { }
  96. }
  97. }
  98. // Abstract class inherit from GraElement(), which will used for drawing line, lines.
  99. //class LineGra() and LinesGra() inherit from it
  100. public abstract class GraEleWithPen :GraElement
  101. {
  102. public GraEleWithPen(Pen pen) //Set PenExt of GraEleWithPen
  103. :base()
  104. {
  105. this.penExt = new PenExt();
  106. this.penExt.Pen = pen;
  107. this.drawMode = GraDrawMode.Frame;
  108. }
  109. private PenExt penExt; //Private PenExt varible of GraEleWithPen
  110. //Pen property of GraEleWithPen
  111. public override PenExt PenExt
  112. {
  113. get { return penExt; }
  114. set { penExt = value;}
  115. }
  116. }
  117. //Abstract class inherit from GraElement(), which will used for drawing rectangle, ellipse, text.
  118. //class RectGra(), EllipseGra and TextGra() inherit from it.
  119. public abstract class GraEleWithPenBrush : GraEleWithPen
  120. {
  121. //Construction Function of GraEleWithPenBrush.set BrushExt and PenExt of GraEleWithPen.
  122. //When we draw a solid graph, we will draw the frame of it and then fill the frame.
  123. public GraEleWithPenBrush(Pen pen, Brush brush,GraDrawMode drawMode)
  124. :base(pen)
  125. {
  126. this.brushExt = new BrushExt();
  127. this.brushExt.Brush = brush;
  128. this.drawMode = drawMode;
  129. }
  130. protected BrushExt brushExt;//Private BrushExt varible of GraEleWithPen
  131. //Brush property of GraEleWithPenBrush
  132. public override BrushExt BrushExt
  133. {
  134. get { return brushExt; }
  135. set { brushExt = value;}
  136. }
  137. }
  138. }