CraftSynth.ImageEditor – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using System.Drawing; |
2 | using System.Windows.Forms; |
||
3 | |||
4 | namespace CraftSynth.ImageEditor |
||
5 | { |
||
6 | /// <summary> |
||
7 | /// PolyLine tool (a PolyLine is a series of connected straight lines where each line is drawn individually) |
||
8 | /// </summary> |
||
9 | internal class ToolPolyLine : ToolObject |
||
10 | { |
||
11 | public ToolPolyLine() |
||
12 | { |
||
13 | Cursor = new Cursor(GetType(), "Pencil.cur"); |
||
14 | } |
||
15 | |||
16 | private DrawPolyLine newPolyLine; |
||
17 | private bool _drawingInProcess = false; // Set to true when drawing |
||
18 | |||
19 | /// <summary> |
||
20 | /// Left nouse button is pressed |
||
21 | /// </summary> |
||
22 | /// <param name="drawArea"></param> |
||
23 | /// <param name="e"></param> |
||
24 | public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e) |
||
25 | { |
||
26 | if (e.Button == |
||
27 | MouseButtons.Right) |
||
28 | { |
||
29 | _drawingInProcess = false; |
||
30 | newPolyLine = null; |
||
31 | } |
||
32 | else |
||
33 | { |
||
34 | Point p = drawArea.BackTrackMouse(new Point(e.X, e.Y)); |
||
35 | |||
36 | if (_drawingInProcess == false) |
||
37 | { |
||
38 | newPolyLine = new DrawPolyLine(p.X, p.Y, p.X + 1, p.Y + 1, drawArea.LineColor, drawArea.LineWidth, drawArea.PenType); |
||
39 | newPolyLine.EndPoint = new Point(p.X + 1, p.Y + 1); |
||
40 | AddNewObject(drawArea, newPolyLine); |
||
41 | _drawingInProcess = true; |
||
42 | } |
||
43 | else |
||
44 | { |
||
45 | // Drawing is in process, so simply add a new point |
||
46 | newPolyLine.AddPoint(p); |
||
47 | newPolyLine.EndPoint = p; |
||
48 | } |
||
49 | |||
50 | } |
||
51 | } |
||
52 | |||
53 | /// <summary> |
||
54 | /// Mouse move - resize new polygon |
||
55 | /// </summary> |
||
56 | /// <param name="drawArea"></param> |
||
57 | /// <param name="e"></param> |
||
58 | public override void OnMouseMove(DrawArea drawArea, MouseEventArgs e) |
||
59 | { |
||
60 | drawArea.Cursor = Cursor; |
||
61 | |||
62 | if (e.Button != |
||
63 | MouseButtons.Left) |
||
64 | return; |
||
65 | |||
66 | if (newPolyLine == null) |
||
67 | return; // precaution |
||
68 | |||
69 | Point point = drawArea.BackTrackMouse(new Point(e.X, e.Y)); |
||
70 | // move last point |
||
71 | newPolyLine.MoveHandleTo(point, newPolyLine.HandleCount); |
||
72 | drawArea.Refresh(); |
||
73 | } |
||
74 | |||
75 | #region Destruction |
||
76 | private bool _disposed = false; |
||
77 | |||
78 | protected override void Dispose(bool disposing) |
||
79 | { |
||
80 | if (!this._disposed) |
||
81 | { |
||
82 | if (disposing) |
||
83 | { |
||
84 | // Free any managed objects here. |
||
85 | if (this.newPolyLine != null) |
||
86 | { |
||
87 | this.newPolyLine.Dispose(); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | // Free any unmanaged objects here. |
||
92 | |||
93 | this._disposed = true; |
||
94 | } |
||
95 | base.Dispose(disposing); |
||
96 | } |
||
97 | |||
98 | ~ToolPolyLine() |
||
99 | { |
||
100 | this.Dispose(false); |
||
101 | } |
||
102 | #endregion |
||
103 | } |
||
104 | } |