-
Notifications
You must be signed in to change notification settings - Fork 1
/
LineLengthLabel.cs
131 lines (103 loc) · 3.55 KB
/
LineLengthLabel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using CodeImp.DoomBuilder.Windows;
using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Rendering;
using CodeImp.DoomBuilder.Geometry;
using System.Drawing;
using CodeImp.DoomBuilder.Editing;
using CodeImp.DoomBuilder;
#endregion
namespace TriDelta.DrawTextMode
{
public class LineLengthLabel : IDisposable {
#region ================== Constants
private const int TEXT_CAPACITY = 15;
private const float TEXT_SCALE = 14f;
private const string VALUE_FORMAT = "0";
#endregion
#region ================== Variables
protected TextLabel label;
protected Vector2D start;
protected Vector2D end;
private bool showAngle; //mxd
#endregion
#region ================== Properties
public TextLabel TextLabel { get { return label; } }
public Vector2D Start { get { return start; } set { start = value; Update(); } }
public Vector2D End { get { return end; } set { end = value; Update(); } }
#endregion
#region ================== Constructor / Disposer
// Constructor
public LineLengthLabel(bool showAngle) {
this.showAngle = showAngle; //mxd
// Initialize
Initialize();
}
// Constructor
public LineLengthLabel(Vector2D start, Vector2D end) {
// Initialize
Initialize();
Move(start, end);
}
// Initialization
protected virtual void Initialize() {
label = new TextLabel(TEXT_CAPACITY);
label.AlignX = TextAlignmentX.Center;
label.AlignY = TextAlignmentY.Middle;
label.Color = General.Colors.Highlight;
label.Backcolor = General.Colors.Background;
label.Scale = TEXT_SCALE;
label.TransformCoords = true;
}
// Disposer
public void Dispose() {
label.Dispose();
}
#endregion
#region ================== Methods
// This updates the text
protected virtual void Update() {
Vector2D delta = end - start;
float length = delta.GetLength();
//mxd
if (showAngle) {
float rads = (float)Math.Atan2(-(start.y - end.y), -(start.x - end.x));
if (rads < 0)
rads += (float)(Math.PI * 2);
int angle = (int)Math.Round(rads * 180 / Math.PI);
label.Text = "l:" + length.ToString(VALUE_FORMAT) + "; a:" + angle;
} else {
label.Text = length.ToString(VALUE_FORMAT);
}
label.Rectangle = new RectangleF(start.x + delta.x * 0.5f, start.y + delta.y * 0.5f, 0f, 0f);
}
// This moves the label
public void Move(Vector2D start, Vector2D end) {
this.start = start;
this.end = end;
Update();
}
#endregion
}
}