forked from bgrabitmap/bgracontrols
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dtthemedgauge.pp
249 lines (191 loc) · 7.12 KB
/
dtthemedgauge.pp
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
// SPDX-License-Identifier: LGPL-3.0-linking-exception
{
Part of BGRA Controls. Made by third party.
For detailed information see readme.txt
Site: https://sourceforge.net/p/bgra-controls/
Wiki: http://wiki.lazarus.freepascal.org/BGRAControls
Forum: http://forum.lazarus.freepascal.org/index.php/board,46.0.html
}
unit dtthemedgauge;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, DTAnalogCommon,
BGRABitmap, BGRABitmapTypes;
type
{ TDTCustomThemedGauge }
TDTCustomThemedGauge = class(TDTBaseAnalogDevice)
private
FPointerCapSettings: TDTPointerCapSettings;
FPointerSettings: TDTPointerSettings;
FScaleBitmap: TBGRABitmap;
FPointerBitmap: TBGRABitmap;
FPosition: integer;
procedure SetPointerCapSettings(AValue: TDTPointerCapSettings);
procedure SetPointerSettings(AValue: TDTPointerSettings);
procedure SetPosition(AValue: integer);
{ Private declarations }
protected
{ Protected declarations }
property PointerSettings: TDTPointerSettings read FPointerSettings write SetPointerSettings;
property PointerCapSettings: TDTPointerCapSettings read FPointerCapSettings write SetPointerCapSettings;
property Position: integer read FPosition write SetPosition;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Paint; override;
procedure DrawScale;
procedure DrawPointer;
end;
{ TDTThemedGauge }
TDTThemedGauge = class(TDTCustomThemedGauge)
private
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
property FaceSettings;
property ScaleSettings;
property PointerSettings;
property PointerCapSettings;
property Position;
end;
procedure Register;
implementation
procedure Register;
begin
//{$I icons\dtthemedgauge_icon.lrs}
RegisterComponents('BGRA Controls', [TDTThemedGauge]);
end;
{ TDTCustomThemedGauge }
//procedure TDTCustomThemedGauge.SetNeedleSettings(AValue: TDTNeedleSettings);
//begin
// if FNeedleSettings = AValue then
// Exit;
// FNeedleSettings := AValue;
//
// DoChange(self);
//end;
//
procedure TDTCustomThemedGauge.SetPointerCapSettings(AValue: TDTPointerCapSettings);
begin
if FPointerCapSettings = AValue then
Exit;
FPointerCapSettings := AValue;
DoChange(self);
end;
procedure TDTCustomThemedGauge.SetPointerSettings(AValue: TDTPointerSettings);
begin
if FPointerSettings = AValue then
Exit;
FPointerSettings := AValue;
DoChange(self);
end;
procedure TDTCustomThemedGauge.SetPosition(AValue: integer);
begin
if FPosition = AValue then
Exit;
FPosition := AValue;
DoChange(self);
end;
constructor TDTCustomThemedGauge.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FPointerSettings := TDTPointerSettings.Create;
FPointerSettings.OnChange := @DoChange;
FPointerSettings.Color := BGRA(255, 81, 81);
FPointerCapSettings := TDTPointerCapSettings.Create;
FPointerCapSettings.OnChange := @DoChange;
FScaleBitmap := TBGRABitmap.Create;
FPointerBitmap := TBGRABitmap.Create;
end;
destructor TDTCustomThemedGauge.Destroy;
begin
FPointerCapSettings.OnChange:=nil;
FPointerCapSettings.Free;
FPointerSettings.OnChange:=nil;
FPointerSettings.Free;
FScaleBitmap.Free;
FPointerBitmap.Free;
inherited Destroy;
end;
procedure TDTCustomThemedGauge.Paint;
begin
inherited Paint;
DrawScale;
DrawPointer;
FGaugeBitmap.BlendImage(0, 0, FScaleBitmap, boLinearBlend);
FGaugeBitmap.BlendImage(0, 0, FPointerBitmap, boLinearBlend);
FGaugeBitmap.Draw(Canvas, 0, 0, False);
end;
procedure TDTCustomThemedGauge.DrawScale;
var
Origin: TDTOrigin;
r, i, n, x, y, xt, yt: integer;
j: single;
begin
Origin := Initializebitmap(FScaleBitmap, Width, Height);
r := round(Origin.Radius * 0.85);
//j := (180 - ScaleSettings.Angle) / 2;
j := (180 - 270) / 2;
// Draw SubTicks
if ScaleSettings.EnableSubTicks then
begin
n := ScaleSettings.MainTickCount * ScaleSettings.SubTickCount;
for i := 0 to n do
begin
// Calculate draw from point
X := Origin.CenterPoint.x - Round(r * cos((j + i * 270 / n) * Pi / 180));
Y := Origin.CenterPoint.y - Round(r * sin((j + i * 270 / n) * Pi / 180));
// Calculate draw to point
Xt := Origin.CenterPoint.x - Round((r - ScaleSettings.LengthSubTick) * cos((j + i * 270 / n) * Pi / 180));
Yt := Origin.CenterPoint.y - Round((r - ScaleSettings.LengthSubTick) * sin((j + i * 270 / n) * Pi / 180));
FScaleBitmap.DrawLineAntialias(x, y, xt, yt, ScaleSettings.TickColor, ScaleSettings.ThicknessSubTick);
end;
end;
if ScaleSettings.EnableMainTicks then
begin
FScaleBitmap.FontName := ScaleSettings.TextFont;
FScaleBitmap.FontHeight := ScaleSettings.TextSize;
FScaleBitmap.FontQuality := fqFineAntialiasing;
n := ScaleSettings.MainTickCount;
for i := 0 to n do
begin
// Draw main ticks
// Calculate draw from point
X := Origin.CenterPoint.x - Round(r * cos((j + i * 270 / n) * Pi / 180));
Y := Origin.CenterPoint.y - Round(r * sin((j + i * 270 / n) * Pi / 180));
// Calculate draw to point
Xt := Origin.CenterPoint.x - Round((r - ScaleSettings.LengthMainTick) * cos((j + i * 270 / n) * Pi / 180));
Yt := Origin.CenterPoint.y - Round((r - ScaleSettings.LengthMainTick) * sin((j + i * 270 / n) * Pi / 180));
FScaleBitmap.DrawLineAntialias(x, y, xt, yt, ScaleSettings.TickColor, ScaleSettings.ThicknessMainTick);
if ScaleSettings.EnableScaleText then
begin
// Draw text for main ticks
Xt := Origin.CenterPoint.x - Round(ScaleSettings.TextRadius * cos((j + i * 270 / n) * Pi / 180));
Yt := Origin.CenterPoint.y - Round(ScaleSettings.TextRadius * sin((j + i * 270 / n) * Pi / 180));
FScaleBitmap.TextOut(Xt, Yt - (FScaleBitmap.FontHeight / 1.7), IntToStr(i * ScaleSettings.Maximum div ScaleSettings.MainTickCount), ScaleSettings.TextColor, taCenter);
end;
end;
end;
end;
procedure TDTCustomThemedGauge.DrawPointer;
var
Origin: TDTOrigin;
{%H-}r, x, y: integer;
j: single;
begin
Origin := Initializebitmap(FPointerBitmap, Width, Height);
r := round(Origin.Radius * 0.85);
j := (180 - 270) / 2;
X := origin.CenterPoint.x - Round(PointerSettings.Length * cos((j + Position * 270 / ScaleSettings.Maximum) * Pi / 180));
Y := origin.CenterPoint.y - Round(PointerSettings.Length * sin((j + Position * 270 / ScaleSettings.Maximum) * Pi / 180));
FPointerBitmap.DrawLineAntialias(origin.CenterPoint.y, origin.CenterPoint.y, x, y, PointerSettings.Color, PointerSettings.Thickness);
// Draw cap over needle
FPointerBitmap.EllipseAntialias(origin.CenterPoint.x, origin.CenterPoint.y, PointerCapSettings.Radius, PointerCapSettings.Radius, PointerCapSettings.EdgeColor, 2, ColorToBGRA(PointerCapSettings.FillColor));
end;
end.