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 | /// Rectangle tool |
||
8 | /// </summary> |
||
9 | internal class ToolText : ToolObject |
||
10 | { |
||
11 | public ToolText() |
||
12 | { |
||
13 | Cursor = new Cursor(GetType(), "Rectangle.cur"); |
||
14 | } |
||
15 | |||
16 | public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e) |
||
17 | { |
||
18 | TextDialog td = new TextDialog(); |
||
19 | td.TopLevel = true; |
||
20 | td.TopMost = true; |
||
21 | td.TheColor = drawArea.LineColor; |
||
22 | td.TheText = _lastText ?? ""; |
||
23 | td.TheFont = _lastFont ?? new Font(FontFamily.GenericSansSerif, 12, FontStyle.Regular); |
||
24 | td.Zoom = drawArea.Zoom; |
||
25 | td.StartPosition = FormStartPosition.Manual; |
||
26 | Point pnlLocationOnScreen = drawArea.MyParent.pnlDrawArea.PointToScreen(new Point(0, 0)); |
||
27 | Point pp = e.Location; |
||
28 | pp = new Point( |
||
29 | pnlLocationOnScreen.X+pp.X //hit point on screen |
||
30 | -18-SystemInformation.Border3DSize.Width-SystemInformation.SizingBorderWidth //-text box location |
||
31 | +drawArea.Left //+scroll amount |
||
32 | , |
||
33 | pnlLocationOnScreen.Y+pp.Y //hit point on screen |
||
34 | -18-SystemInformation.Border3DSize.Height-SystemInformation.SizingBorderWidth -SystemInformation.CaptionHeight //-text box location |
||
35 | +drawArea.Top //+scroll amount |
||
36 | ); |
||
37 | td.Location = pp; |
||
38 | if (td.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(td.Text)) |
||
39 | { |
||
40 | _lastText = td.TheText; |
||
41 | _lastFont = td.TheFont; |
||
42 | string t = td.TheText; |
||
43 | Color c = td.TheColor; |
||
44 | Font f = td.TheFont; |
||
45 | Point p = drawArea.MyParent.PointToClient(td.Location); |
||
46 | p = new Point(p.X+17-drawArea.Left,p.Y+15-drawArea.Top); |
||
47 | p = drawArea.BackTrackMouse(p); |
||
48 | AddNewObject(drawArea, new DrawText(p.X, p.Y, t, f, c)); |
||
49 | |||
50 | int al = drawArea.TheLayers.ActiveLayerIndex; |
||
51 | drawArea.AddCommandToHistory(new CommandAdd(drawArea.TheLayers[al].Graphics[0])); |
||
52 | |||
53 | drawArea.ActiveTool = DrawArea.DrawToolType.Pointer; |
||
54 | } |
||
55 | } |
||
56 | |||
57 | private static string _lastText; |
||
58 | private static Font _lastFont; |
||
59 | |||
60 | public override void OnMouseMove(DrawArea drawArea, MouseEventArgs e) |
||
61 | { |
||
62 | drawArea.Cursor = Cursor; |
||
63 | if (e.Button == MouseButtons.Left) |
||
64 | { |
||
65 | Point point = drawArea.BackTrackMouse(new Point(e.X, e.Y)); |
||
66 | int al = drawArea.TheLayers.ActiveLayerIndex; |
||
67 | drawArea.TheLayers[al].Graphics[0].MoveHandleTo(point, 5); |
||
68 | drawArea.Refresh(); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | #region Destruction |
||
73 | private bool _disposed = false; |
||
74 | |||
75 | protected override void Dispose(bool disposing) |
||
76 | { |
||
77 | if (!this._disposed) |
||
78 | { |
||
79 | if (disposing) |
||
80 | { |
||
81 | // Free any managed objects here. |
||
82 | if (_lastFont != null) |
||
83 | { |
||
84 | _lastFont.Dispose(); |
||
85 | _lastFont = null; |
||
86 | } |
||
87 | } |
||
88 | |||
89 | // Free any unmanaged objects here. |
||
90 | |||
91 | this._disposed = true; |
||
92 | } |
||
93 | base.Dispose(disposing); |
||
94 | } |
||
95 | |||
96 | ~ToolText() |
||
97 | { |
||
98 | this.Dispose(false); |
||
99 | } |
||
100 | #endregion |
||
101 | } |
||
102 | } |