/****************************************************************************************** *******************File Name:GerElement.cs,Version 1.0, 8 November 2004******************** *****************************Author: MingZhang*********************** **This class is written to implement various functions in our software like ** ** draw lines, draw rectangle, draw ellipse, insert text box and insert image. ** ** The classes defined here are: ** ** 1.Linegra: This class inherits from GraEleWithPen. ** ** This class will store the start and end points of a line. ** ** 2.RectGra: This class inherits from GraEleWithPenBrush; it stores ** ** the dimensions of rectangle. RectDrawTool inherits from this class. ** ** 3.EllipseGra: This class inherits from GraEleWithPenBrush. ** ** This class stores the dimensions of ellipse. ** ** EllipseDrawTool inherits from this class. ** 5. TextGra: This class inherits from GraEleWithPenBrush. It stores the insert text in this class. TextDrawTool inherits from this class. ** ** // ** ** ** ** /******************************************************************************************/ using System; using System.Drawing; using System.Drawing.Drawing2D; using GraEditor.BaseDef;//BaseDef include BrushExt,PenExt,FontData //Graph element includes Line,Lines,Rectangle,Ellipse,Text,Image namespace GraEditor.Elements { // Line graph element class. This class inherit from GraEleWithPen()t. // It will store the start and end point of this line in this class. LineDrawTool() inherit from it public class LineGra : GraEleWithPen { //Set start and end point public LineGra(Pen pen, Point pt1,Point pt2) :base(pen) { this.startPt = pt1;//Start point this.endPt = pt2; //End point UpdatePath(); //Store start and end point in to path } //Specify Line type public override GraEleType Type { get { return GraEleType.Line; } } private Point startPt;//Private start point variable of LineGra //Start point property of LinGra public Point StartPt { get { return startPt; } set { startPt = value; UpdatePath(); } } private Point endPt;//Private end point variable of LineGra //End point property of LinGra public Point EndPt { get { return endPt; } set { endPt = value; UpdatePath(); } } //Add start and end point of line into path public override void UpdatePath() { this.path.Reset();//clear GraElement.path this.path.AddLine(startPt,endPt);//Add line to GraElement.path } } //Lines graph element class. This class inherit from GraEleWithPen()t. //It will store the start and end point of this line in this class. LinesDrawTool() inherit from it. public class LinesGra : GraEleWithPen { //Set the key points of lines public LinesGra(Pen pen,Point[] pts) :base(pen) { this.pts = pts; UpdatePath(); //Save these points into path } //Specify Lines type public override GraEleType Type { get { return GraEleType.Lines; } } private Point[] pts;//Private key points varible //Points property of LinsGra public Point[] Pts { get { return pts; } set //Save key points of lines { pts = value; UpdatePath(); } } //Add key points of lines into path public override void UpdatePath() { base.UpdatePath(); this.path.AddLines(this.pts); } } public class EraseLinesGra : LinesGra { //Set the key points of lines public EraseLinesGra(Pen pen,Point[] pts) :base(pen,pts) { } } public class FreehandLinesGra : LinesGra { //Set the key points of lines public FreehandLinesGra(Pen pen,Point[] pts) :base(pen,pts) { } } //Rectangle draw element class. This class inherit from GraEleWithPenBrush() //It store the rectangle in this class. RectDrawTool() will inherit from it. public class RectGra : GraEleWithPenBrush { ////Set the size and position of rectangle public RectGra(Pen pen,Brush brush,GraDrawMode drawMode,Rectangle rect) :base(pen,brush,drawMode) { this.rect = rect; UpdatePath(); } //Specify the rectangle drawing element public override GraEleType Type { get { return GraEleType.Rect; } } private Rectangle rect;//Private rectangle variable //Rectangle property of RectGra public Rectangle Rect { get { return rect; } set { rect = value; UpdatePath(); } } //Add a rectangle into path public override void UpdatePath() { base.UpdatePath(); this.path.AddRectangle(this.rect); } } public class EraseRectGra : RectGra { public EraseRectGra(Pen pen,Brush brush,GraDrawMode drawMode,Rectangle rect) :base(pen,brush,drawMode,rect) { } } //Ellipse draw element class. This class inherit from GraEleWithPenBrush() //It store the ellipse in this class. EllipseDrawTool() will inherit from it. public class EllipseGra : GraEleWithPenBrush { //Set the size and position of ellipse public EllipseGra(Pen pen,Brush brush,GraDrawMode drawMode,Rectangle rect) :base(pen,brush,drawMode) { this.rect = rect; UpdatePath(); } //Specify the ellipse drawing element public override GraEleType Type { get { return GraEleType.Ellipse; } } //Private rectangle variable. We will use a rectangle to decide the position and size of an ellipse. //The ellipse is in-cut the rectangle private Rectangle rect; //Rectangle property of EllipseGra public Rectangle Rect { get { return rect; } set { rect = value; UpdatePath(); } } //Add ellipse(rectangle) into path public override void UpdatePath() { base.UpdatePath(); this.path.AddEllipse(this.rect); } } //Image draw element class. This class inherit from GraElelement() //It store the insert picture in this class. ImageDrawTool() inherit from it. public class ImageGra : GraElement { //Set the insert picture and its size and position to ImageGra public ImageGra(Image image, Rectangle rect) { this.image = image; //set insert picture to ImageGra this.rect = rect; //set the size and position of insert picture to ImageGra } //Specify the image drawing element public override GraEleType Type { get { return GraEleType.Image; } } private Image image;//Private image variable of ImageGra to save insert picture //Image property of ImageGra public Image Image { get { return image; } set { image = value; } } //Private rectangle variable of ImageGra to save the size and position of rectangle private Rectangle rect; //Rectangle property of ImageGra public Rectangle Rect { get { return rect; } set { rect = value; } } //Draw the insert picture public override void Draw(Graphics g) { if(this.image == null || this.rect.IsEmpty)//No image exist return; g.DrawImage(this.image,this.rect);// Draw the picture in the area of rect. } } //Text draw element class. This class inherit from GraEleWithPenBrush() //It store the insert text in this class. TextDrawTool() inherit from it. public class TextGra : GraEleWithPenBrush { //set the insert text and its font to TextGra public TextGra(string text,Font font,Brush brush,Rectangle rect) :base(null,brush,GraDrawMode.Fill) { this.fontData = new FontData(font); this.text = text; this.rect = rect; } //Specify the image drawing element public override GraEleType Type { get { return GraEleType.Text; } } private Rectangle rect;//private point variable to save the insert point of text //Position property of TextGra public Rectangle Rect { get { return rect; } set { rect = value; } } private string text; //private text variable to save the insert text //Text property of TextGra public string Text { get { return text;} set { text = value;} } private FontData fontData;//private font variable to save the font of the insert text //Font property of TextGra public FontData FontData { get { return fontData; } set { fontData = value; } } //Draw the insert text public override void Draw(Graphics g) { if(fontData.IsEmpty())//No font return; using(Font f = new Font(fontData.Name,fontData.Size,fontData.Style)) { g.DrawString(this.text,f,this.brushExt.Brush,this.rect); } } } }