-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfxstyle.pas
218 lines (194 loc) Β· 5.23 KB
/
fxstyle.pas
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
unit fxstyle;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, BGRABitmap, BGRABitmapTypes, Graphics;
type
{ TFXStyle }
TFXStyle = class(TPersistent)
private
FBorderColor: TColor;
FBorderWidth: single;
FColor: TColor;
FEllipse: boolean;
FHeight: integer;
FLeft: integer;
FOnChange: TNotifyEvent;
FRoundOptions: TRoundRectangleOptions;
FRoundX: single;
FRoundY: single;
FTop: integer;
FWidth: integer;
procedure SetFBorderColor(AValue: TColor);
procedure SetFBorderWidth(AValue: single);
procedure SetFColor(AValue: TColor);
procedure SetFEllipse(AValue: boolean);
procedure SetFHeight(AValue: integer);
procedure SetFLeft(AValue: integer);
procedure SetFRoundOptions(AValue: TRoundRectangleOptions);
procedure SetFRoundX(AValue: single);
procedure SetFRoundY(AValue: single);
procedure SetFTop(AValue: integer);
procedure SetFWidth(AValue: integer);
protected
procedure Change;
public
procedure Draw(ABitmap: TBGRABitmap);
constructor Create;
published
property Ellipse: boolean read FEllipse write SetFEllipse;
property BorderWidth: single read FBorderWidth write SetFBorderWidth;
property BorderColor: TColor read FBorderColor write SetFBorderColor;
property Color: TColor read FColor write SetFColor;
property Left: integer read FLeft write SetFLeft;
property Top: integer read FTop write SetFTop;
property Width: integer read FWidth write SetFWidth;
property Height: integer read FHeight write SetFHeight;
property RoundX: single read FRoundX write SetFRoundX;
property RoundY: single read FRoundY write SetFRoundY;
property RoundOptions: TRoundRectangleOptions
read FRoundOptions write SetFRoundOptions;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
end;
implementation
{ TFXStyle }
procedure TFXStyle.SetFLeft(AValue: integer);
begin
if FLeft = AValue then
Exit;
FLeft := AValue;
Change;
end;
procedure TFXStyle.SetFRoundOptions(AValue: TRoundRectangleOptions);
begin
if FRoundOptions = AValue then
Exit;
FRoundOptions := AValue;
Change;
end;
procedure TFXStyle.SetFHeight(AValue: integer);
begin
if FHeight = AValue then
Exit;
FHeight := AValue;
Change;
end;
procedure TFXStyle.SetFColor(AValue: TColor);
begin
if FColor = AValue then
Exit;
FColor := AValue;
Change;
end;
procedure TFXStyle.SetFEllipse(AValue: boolean);
begin
if FEllipse = AValue then
Exit;
FEllipse := AValue;
Change;
end;
procedure TFXStyle.SetFBorderColor(AValue: TColor);
begin
if FBorderColor = AValue then
Exit;
FBorderColor := AValue;
Change;
end;
procedure TFXStyle.SetFBorderWidth(AValue: single);
begin
if FBorderWidth = AValue then
Exit;
FBorderWidth := AValue;
Change;
end;
procedure TFXStyle.SetFRoundX(AValue: single);
begin
if FRoundX = AValue then
Exit;
FRoundX := AValue;
Change;
end;
procedure TFXStyle.SetFRoundY(AValue: single);
begin
if FRoundY = AValue then
Exit;
FRoundY := AValue;
Change;
end;
procedure TFXStyle.SetFTop(AValue: integer);
begin
if FTop = AValue then
Exit;
FTop := AValue;
Change;
end;
procedure TFXStyle.SetFWidth(AValue: integer);
begin
if FWidth = AValue then
Exit;
FWidth := AValue;
Change;
end;
procedure TFXStyle.Change;
begin
if Assigned(OnChange) then
OnChange(Self);
end;
procedure TFXStyle.Draw(ABitmap: TBGRABitmap);
begin
// If there's nothing to draw exit
if (Width < Left) or (Height < Top) then
exit;
// If must draw an ellipse
if Ellipse then
begin
// If there's no border make it thin and the same color of filling
if BorderWidth = 0 then
ABitmap.EllipseAntialias(Left + (Width-Left) div 2, Top + (Height-Top) div 2, (Width-Left) div 2, (Height-Top) div 2, Color, 0.1, Color)
// Else draw an antialiased border and ellipse
else
ABitmap.EllipseAntialias(Left + (Width-Left) div 2, Top + (Height-Top) div 2, (Width-Left) div 2, (Height-Top) div 2, BorderColor, BorderWidth, Color);
end
else
begin
// If there's no rounding
if (RoundX = 0) and (RoundY = 0) then
begin
// If there's no border, draw perfect pixel square
if (BorderWidth = 0) then
ABitmap.Rectangle(Left, Top, Width, Height, Color, Color, dmDrawWithTransparency)
// If there's 1 px border, draw perfect pixel square and border
else if (BorderWidth = 1) then
ABitmap.Rectangle(Left, Top, Width, Height, BorderColor, Color,
dmDrawWithTransparency)
// Else draw antialiased border and square
else
ABitmap.RectangleAntialias(Left, Top, Width, Height, BorderColor,
BorderWidth, Color);
end
else
begin
// If there's not enough space to draw
if (RoundX * 2 > Width - Left) or (RoundY * 2 > Height - Top) then
exit;
// Else draw antialiased border and square
ABitmap.RoundRectAntialias(Left, Top, Width, Height, RoundX,
RoundY, BorderColor, BorderWidth, Color, RoundOptions);
end;
end;
end;
constructor TFXStyle.Create;
begin
inherited Create;
Left := 0;
Top := 0;
Width := 100;
Height := 100;
RoundX := 0;
RoundY := 0;
BorderColor := clBlack;
Color := clWhite;
BorderWidth := 0;
RoundOptions := [];
end;
end.