-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathbgracolortheme.pas
233 lines (204 loc) · 6.67 KB
/
bgracolortheme.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// SPDX-License-Identifier: LGPL-3.0-linking-exception
unit BGRAColorTheme;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, BGRATheme,
BGRABitmap, BGRABitmapTypes, BGRASVGImageList;
type
{ TBGRAColorTheme }
TBGRAColorTheme = class(TBGRATheme)
private
FColorActive: TColor;
FColorDisabled: TColor;
FColorFocused: TColor;
FColorHover: TColor;
FColorNormal: TColor;
FColorText: TColor;
procedure SetFColorActive(AValue: TColor);
procedure SetFColorDisabled(AValue: TColor);
procedure SetFColorFocused(AValue: TColor);
procedure SetFColorHover(AValue: TColor);
procedure SetFColorNormal(AValue: TColor);
procedure SetFColorText(AValue: TColor);
protected
public
procedure DrawButton(Caption: string; State: TBGRAThemeButtonState;
Focused: boolean; ARect: TRect; ASurface: TBGRAThemeSurface; AImageIndex: Integer = -1; AImageList: TBGRASVGImageList = nil); override;
procedure DrawRadioButton(Caption: string; State: TBGRAThemeButtonState;
{%H-}Focused: boolean; Checked: boolean; ARect: TRect; ASurface: TBGRAThemeSurface); override;
procedure DrawCheckBox(Caption: string; State: TBGRAThemeButtonState;
{%H-}Focused: boolean; Checked: boolean; ARect: TRect; ASurface: TBGRAThemeSurface); override;
published
property ColorNormal: TColor read FColorNormal write SetFColorNormal;
property ColorHover: TColor read FColorHover write SetFColorHover;
property ColorActive: TColor read FColorActive write SetFColorActive;
property ColorDisabled: TColor read FColorDisabled write SetFColorDisabled;
property ColorFocused: TColor read FColorFocused write SetFColorFocused;
property ColorText: TColor read FColorText write SetFColorText;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('BGRA Themes', [TBGRAColorTheme]);
end;
{ TBGRAColorTheme }
procedure TBGRAColorTheme.SetFColorActive(AValue: TColor);
begin
if FColorActive = AValue then
Exit;
FColorActive := AValue;
end;
procedure TBGRAColorTheme.SetFColorDisabled(AValue: TColor);
begin
if FColorDisabled = AValue then
Exit;
FColorDisabled := AValue;
end;
procedure TBGRAColorTheme.SetFColorFocused(AValue: TColor);
begin
if FColorFocused = AValue then
Exit;
FColorFocused := AValue;
end;
procedure TBGRAColorTheme.SetFColorHover(AValue: TColor);
begin
if FColorHover = AValue then
Exit;
FColorHover := AValue;
end;
procedure TBGRAColorTheme.SetFColorNormal(AValue: TColor);
begin
if FColorNormal = AValue then
Exit;
FColorNormal := AValue;
end;
procedure TBGRAColorTheme.SetFColorText(AValue: TColor);
begin
if FColorText = AValue then
Exit;
FColorText := AValue;
end;
procedure TBGRAColorTheme.DrawButton(Caption: string;
State: TBGRAThemeButtonState; Focused: boolean; ARect: TRect;
ASurface: TBGRAThemeSurface; AImageIndex: Integer;
AImageList: TBGRASVGImageList);
var
Style: TTextStyle;
begin
with ASurface do
begin
case State of
btbsNormal: DestCanvas.Brush.Color := ColorNormal;
btbsHover: DestCanvas.Brush.Color := ColorHover;
btbsActive: DestCanvas.Brush.Color := ColorActive;
btbsDisabled: DestCanvas.Brush.Color := ColorDisabled;
end;
DestCanvas.Pen.Color := DestCanvas.Brush.Color;
DestCanvas.Rectangle(ARect);
if Focused then
begin
DestCanvas.Pen.Color := ColorFocused;
DestCanvas.Rectangle(ARect);
end;
if Caption <> '' then
begin
fillchar(Style, sizeof(Style), 0);
Style.Alignment := taCenter;
Style.Layout := tlCenter;
Style.Wordbreak := True;
if ColorText <> clDefault then
DestCanvas.Font.Color := ColorText;
DestCanvas.TextRect(ARect, 0, 0, Caption, Style);
end;
end;
end;
procedure TBGRAColorTheme.DrawRadioButton(Caption: string;
State: TBGRAThemeButtonState; Focused: boolean; Checked: boolean;
ARect: TRect; ASurface: TBGRAThemeSurface);
var
Style: TTextStyle;
Color: TBGRAPixel;
begin
with ASurface do
begin
DestCanvas.Font.Color := ColorText;
case State of
btbsHover: Color := ColorHover;
btbsActive: Color := ColorActive;
btbsDisabled:
begin
DestCanvas.Font.Color := ColorDisabled;
Color := ColorDisabled;
end;
else {btbsNormal}
Color := ColorNormal;
end;
BitmapRect := RectWithSize(ARect.Left, ARect.Top, ARect.Height, ARect.Height);
Bitmap.FillEllipseAntialias(Bitmap.Height / 2, Bitmap.Height / 2,
Bitmap.Height / 2 - 2, Bitmap.Height / 2 - 2, BGRAWhite);
Bitmap.EllipseAntialias(Bitmap.Height / 2, Bitmap.Height / 2,
Bitmap.Height / 2 - 2, Bitmap.Height / 2 - 2, Color{%H-}, 1);
if Checked then
Bitmap.FillEllipseAntialias(Bitmap.Height / 2, Bitmap.Height /
2, Bitmap.Height / 4, Bitmap.Height / 4, Color);
DrawBitmap;
if Caption <> '' then
begin
fillchar(Style, sizeof(Style), 0);
Style.Alignment := taLeftJustify;
Style.Layout := tlCenter;
Style.Wordbreak := True;
DestCanvas.TextRect(Rect(Arect.Height, 0, ARect.Right, ARect.Bottom),
ARect.Height, 0, Caption, Style);
end;
end;
end;
procedure TBGRAColorTheme.DrawCheckBox(Caption: string;
State: TBGRAThemeButtonState; Focused: boolean; Checked: boolean;
ARect: TRect; ASurface: TBGRAThemeSurface);
var
Style: TTextStyle;
Color: TBGRAPixel;
aleft, atop, aright, abottom: integer;
begin
with ASurface do
begin
DestCanvas.Font.Color := ColorText;
case State of
btbsHover: Color := ColorHover;
btbsActive: Color := ColorActive;
btbsDisabled:
begin
DestCanvas.Font.Color := ColorDisabled;
Color := ColorDisabled;
end;
else {btbsNormal}
Color := ColorNormal;
end;
BitmapRect := RectWithSize(ARect.Left, ARect.Top, ARect.Height, ARect.Height);
Bitmap.Rectangle(0, 0, Bitmap.Height, Bitmap.Height, Color, BGRAWhite);
aleft := 0;
aright := Bitmap.Height;
atop := 0;
abottom := Bitmap.Height;
if Checked then
Bitmap.DrawPolyLineAntialias(Bitmap.ComputeBezierSpline(
[BezierCurve(pointF(aleft + 2, atop + 3), PointF((aleft + aright - 1) / 2, abottom - 3)),
BezierCurve(PointF((aleft + aright - 1) / 2, abottom - 3), PointF(
(aleft + aright - 1) / 2, (atop * 2 + abottom - 1) / 3), PointF(aright - 2, atop - 2))]),
Color, 1.5);
DrawBitmap;
if Caption <> '' then
begin
fillchar(Style, sizeof(Style), 0);
Style.Alignment := taLeftJustify;
Style.Layout := tlCenter;
Style.Wordbreak := True;
DestCanvas.TextRect(Rect(Arect.Height, 0, ARect.Right, ARect.Bottom),
ARect.Height, 0, Caption, Style);
end;
end;
end;
end.