forked from ArduPilot/MissionPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDistanceBar.cs
172 lines (132 loc) · 4.85 KB
/
DistanceBar.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace MissionPlanner.Controls
{
public partial class DistanceBar : UserControl
{
private readonly Brush _brushbar = new SolidBrush(Color.FromArgb(50, Color.White));
private readonly Bitmap icon = global::MissionPlanner.Properties.Resources.marker_05;
private float _traveleddist = 0;
public float totaldist { get; set; }
public float traveleddist
{
get { return _traveleddist; }
set
{
_traveleddist = value;
this.Invalidate();
}
}
private object locker = new object();
private List<float> wpdist = new List<float>();
Bitmap buffer = new Bitmap(640, 480);
public void AddWPDist(float dist)
{
lock (locker)
{
wpdist.Add(dist);
totaldist = wpdist.Sum();
}
}
public void ClearWPDist()
{
lock (locker)
{
wpdist.Clear();
wpdist.Add(0);
}
}
protected override CreateParams CreateParams
{
get
{
CreateParams parms = base.CreateParams;
//parms.ExStyle |= 0x20;
return parms;
}
}
public DistanceBar()
{
//SetStyle(ControlStyles.SupportsTransparentBackColor, true);
//SetStyle(ControlStyles.Opaque, true);
this.DoubleBuffered = false;
InitializeComponent();
totaldist = 100;
//this.BackColor = Color.Transparent;
ClearWPDist();
}
public void DoPaintRemote(PaintEventArgs e)
{
var matrix = new System.Drawing.Drawing2D.Matrix();
matrix.Translate(this.Left, this.Top);
e.Graphics.Transform = matrix;
OnPaint(e);
e.Graphics.ResetTransform();
}
protected override void OnPaint(PaintEventArgs e)
{
//base.OnPaint(e);
if (this.Parent != null)
{
//Parent.Invalidate(this.Bounds, true);
}
try
{
using (Graphics etemp = Graphics.FromImage(buffer))
{
if (totaldist <= 0)
totaldist = 100;
// bar
RectangleF bar = new RectangleF(4, 4, this.Width - 8, this.Height - 8);
etemp.Clear(Color.Transparent);
etemp.FillRectangle(_brushbar, bar);
// draw bar traveled
RectangleF bartrav = new RectangleF(bar.X, bar.Y, bar.Width * (traveleddist / totaldist), bar.Height);
etemp.FillRectangle(_brushbar, bartrav);
etemp.FillRectangle(_brushbar, bartrav);
etemp.FillRectangle(_brushbar, bartrav);
etemp.FillRectangle(_brushbar, bartrav);
etemp.FillRectangle(_brushbar, bartrav);
// draw wp dist
lock (locker)
{
float iconwidth = this.Height / 4.0f;
float trav = 0;
foreach (var disttrav in wpdist)
{
trav += disttrav;
if (trav > totaldist)
trav = totaldist;
etemp.FillPie(Brushes.Yellow, (bar.X + bar.Width * (trav / totaldist)) - iconwidth / 2, bar.Top,
bar.Height / 2, bar.Height, 0, 360);
//e.Graphics.DrawImage(icon, (bar.X + bar.Width * (trav / totaldist)) - iconwidth / 2, 1, iconwidth, bar.Height);
}
}
// draw dist traveled
string dist = traveleddist.ToString("0");
etemp.DrawString(dist, this.Font, new SolidBrush(this.ForeColor), bartrav.Right,
bartrav.Bottom - FontHeight);
e.Graphics.DrawImageUnscaled(buffer, 0, 0);
}
}
catch (Exception)
{
}
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
if (this.Width == 0 || this.Height == 0)
return;
buffer = new Bitmap(this.Width, this.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
}
protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
// base.OnParentBackColorChanged(e);
}
}
}