/******************************************************************************************** **********************File Name: GraElement.cs,Version 1.0,8 November 2004******************* **********************************Author: Mayank Bansal************************************** ** This class mainly defines graphical elements. GraElement class gets the type of ** ** GraElement to draw and it gets the mode of drawing and gets the existing path on ** ** the bitmap and updates the new path. GraEleWithPen, GraEleWithPenBrush are inherited ** ** from GraElement class. GraEleWithPen class is used to draw Graphical Elements with ** ** Pen (default C# drawing object) like Line. GraEleWithPenBrush is used to draw solid ** ** Graphical Elements like rectangle, ellipse etc which use both pen and brush properties. ** ** ** ** ** ********************************************************************************************/ /// using System; using System.Drawing; using System.Drawing.Drawing2D; using GraEditor.BaseDef; // Namespace Elements, include GraElemetn,GraEleWithPen,GraEleWithPenBrush,LineGra,LinesGra,RectGra,EllipseGra,TextGra,ImageGra, namespace GraEditor.Elements { [Flags] // Two drawing mode: frame and solid public enum GraDrawMode { Frame = 0x01, Fill = 0x02 } //6 types drawing element: Line,Lines,Rect,Ellipse,Text,Image. public enum GraEleType { Line, Lines, Rect, Ellipse, Text, Image } //Abstract class, which is defined for graph element. //The GraEleWithPen(), ImageGra() and GraEleWithPenBrush() will inherit from this class. public abstract class GraElement { public GraElement() { //public path variable of GraElement,which save the path of graphic element this.path = new GraphicsPath(); } protected GraDrawMode drawMode;//specify the draw mode: frame or fill //Draw Mode property of GraElement public GraDrawMode DrawMode { get { return drawMode; } set { drawMode = value; } } //specify the graph element type:Line or Line or Rect or Ellipse or Text or Image. public abstract GraEleType Type { get; } protected GraphicsPath path;//protected path variable of GraElement //Path property of GraElement public GraphicsPath Path { get { return path;} //return public path variable of GraElement } //Reset the path variable public virtual void UpdatePath() { this.path.Reset(); } //Draw function of GraElement public virtual void Draw(Graphics g) { if((this.drawMode & GraDrawMode.Fill) == GraDrawMode.Fill)//draw solid graph { Brush b = this.BrushExt.Brush;// define a new Brush b,sent the GraElement.BrushExt.Brush to b g.FillPath(b,this.path); //draw graph element with brush b } if((this.drawMode & GraDrawMode.Frame) == GraDrawMode.Frame)//draw frame graph { Pen p = this.PenExt.Pen;// define a new Pen,sent the GraElement.PenExt.Pen to p g.DrawPath(p,this.path); //draw graph element with pen p } } //Pen property of GraElement public virtual PenExt PenExt { get { return null;} set { } } //Brush property of GraElement public virtual BrushExt BrushExt { get { return null;} set { } } } // Abstract class inherit from GraElement(), which will used for drawing line, lines. //class LineGra() and LinesGra() inherit from it public abstract class GraEleWithPen :GraElement { public GraEleWithPen(Pen pen) //Set PenExt of GraEleWithPen :base() { this.penExt = new PenExt(); this.penExt.Pen = pen; this.drawMode = GraDrawMode.Frame; } private PenExt penExt; //Private PenExt varible of GraEleWithPen //Pen property of GraEleWithPen public override PenExt PenExt { get { return penExt; } set { penExt = value;} } } //Abstract class inherit from GraElement(), which will used for drawing rectangle, ellipse, text. //class RectGra(), EllipseGra and TextGra() inherit from it. public abstract class GraEleWithPenBrush : GraEleWithPen { //Construction Function of GraEleWithPenBrush.set BrushExt and PenExt of GraEleWithPen. //When we draw a solid graph, we will draw the frame of it and then fill the frame. public GraEleWithPenBrush(Pen pen, Brush brush,GraDrawMode drawMode) :base(pen) { this.brushExt = new BrushExt(); this.brushExt.Brush = brush; this.drawMode = drawMode; } protected BrushExt brushExt;//Private BrushExt varible of GraEleWithPen //Brush property of GraEleWithPenBrush public override BrushExt BrushExt { get { return brushExt; } set { brushExt = value;} } } }