CraftSynth.ImageEditor – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using System; |
2 | using System.Drawing; |
||
3 | using System.Drawing.Drawing2D; |
||
4 | |||
5 | namespace CraftSynth.ImageEditor |
||
6 | { |
||
7 | /// <summary> |
||
8 | /// Ellipse graphic object |
||
9 | /// </summary> |
||
10 | [Serializable] |
||
11 | public class DrawEllipse : DrawRectangle |
||
12 | { |
||
13 | public DrawEllipse() |
||
14 | { |
||
15 | SetRectangle(0, 0, 1, 1); |
||
16 | Initialize(); |
||
17 | } |
||
18 | |||
19 | /// <summary> |
||
20 | /// Clone this instance |
||
21 | /// </summary> |
||
22 | public override DrawObject Clone() |
||
23 | { |
||
24 | DrawEllipse drawEllipse = new DrawEllipse(); |
||
25 | drawEllipse.Rectangle = Rectangle; |
||
26 | |||
27 | FillDrawObjectFields(drawEllipse); |
||
28 | return drawEllipse; |
||
29 | } |
||
30 | |||
31 | public DrawEllipse(int x, int y, int width, int height, Color lineColor, Color fillColor, bool filled, int lineWidth, DrawingPens.PenType penType, LineCap endCap) |
||
32 | { |
||
33 | Rectangle = new Rectangle(x, y, width, height); |
||
34 | Center = new Point(x + (width / 2), y + (height / 2)); |
||
35 | TipText = String.Format("Ellipse Center @ {0}, {1}", Center.X, Center.Y); |
||
36 | Color = lineColor; |
||
37 | FillColor = fillColor; |
||
38 | Filled = filled; |
||
39 | PenWidth = lineWidth; |
||
40 | PenType = penType; |
||
41 | EndCap = endCap; |
||
42 | Initialize(); |
||
43 | } |
||
44 | |||
45 | public override void Draw(Graphics g) |
||
46 | { |
||
47 | Pen pen; |
||
48 | Brush b = new SolidBrush(FillColor); |
||
49 | |||
50 | if (DrawPen == null) |
||
51 | { |
||
52 | pen = new Pen(Color, PenWidth); |
||
53 | DrawingPens.SetCurrentPen(ref pen, PenType, EndCap); |
||
54 | } |
||
55 | else |
||
56 | pen = (Pen) DrawPen.Clone(); |
||
57 | GraphicsPath gp = new GraphicsPath(); |
||
58 | gp.AddEllipse(GetNormalizedRectangle(Rectangle)); |
||
59 | // Rotate the path about it's center if necessary |
||
60 | if (Rotation != 0) |
||
61 | { |
||
62 | RectangleF pathBounds = gp.GetBounds(); |
||
63 | Matrix m = new Matrix(); |
||
64 | m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append); |
||
65 | gp.Transform(m); |
||
66 | } |
||
67 | |||
68 | if (Filled) g.FillPath(b, gp); |
||
69 | g.DrawPath(pen, gp); |
||
70 | |||
71 | gp.Dispose(); |
||
72 | pen.Dispose(); |
||
73 | b.Dispose(); |
||
74 | } |
||
75 | } |
||
76 | } |