-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathbctoolbar.pas
183 lines (157 loc) · 5.1 KB
/
bctoolbar.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
// SPDX-License-Identifier: LGPL-3.0-linking-exception
{
Created by BGRA Controls Team
Dibo, Circular, lainz (007) and contributors.
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
}
{******************************* CONTRIBUTOR(S) ******************************
- Edivando S. Santos Brasil | [email protected]
(Compatibility with delphi VCL 11/2018)
***************************** END CONTRIBUTOR(S) *****************************}
unit BCToolBar;
{$I bgracontrols.inc}
interface
uses
Classes, {$IFDEF FPC}LResources,{$ELSE}types, BGRAGraphics, GraphType, FPImage,{$ENDIF}
Forms, Controls, Graphics, Dialogs, ComCtrls,
BGRABitmap, BGRABitmapTypes, BGRAGradients, BCTypes;
type
{ TBCToolBar }
TBCToolBar = class(TToolBar)
private
FLimitMemoryUsage: boolean;
{ Private declarations }
FOnRedraw: TBGRARedrawEvent;
FBGRA: TBGRABitmap;
procedure SetLimitMemoryUsage(AValue: boolean);
protected
{ Protected declarations }
{$IFDEF FPC}
procedure Paint; override;
{$ELSE}
procedure Paint; virtual;
procedure PaintWindow(DC: HDC); override;
{$ENDIF}
procedure CheckMemoryUsage; virtual;
public
{ Public declarations }
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property OnRedraw: TBGRARedrawEvent read FOnRedraw write FOnRedraw;
property LimitMemoryUsage: boolean read FLimitMemoryUsage write SetLimitMemoryUsage;
end;
procedure DrawWindows7ToolBar(Bitmap: TBGRABitmap; AColor: TColor = clDefault);
{$IFDEF FPC}procedure Register;{$ENDIF}
implementation
function SetHue(AColor: TBGRAPixel; g_hue: integer): TBGRAPixel;
var hsla: THSLAPixel;
begin
if g_hue = -1 then result := AColor else
begin
hsla := BGRAToHSLA(AColor);
hsla.hue := g_hue;
result := GSBAToBGRA(hsla);
end;
end;
procedure DrawWindows7ToolBar(Bitmap: TBGRABitmap; AColor: TColor = clDefault);
var
c1, c2, c3, c4: TBGRAPixel;
ARect, ARect2: TRect;
g_hue: integer;
begin
if AColor = clDefault then
g_hue := -1
else
g_hue := BGRAToGSBA(AColor).hue;
ARect := Rect(0, 0, Bitmap.Width, Bitmap.Height);
// Font: RGBToColor(30,57,91)
Bitmap.HorizLine(ARect.Left, ARect.Top, ARect.Right-1, SetHue(BGRA(169, 191, 214), g_hue), dmSet);
Bitmap.HorizLine(ARect.Left, ARect.Top + 1, ARect.Right-1, SetHue(BGRA(250, 252, 253), g_hue), dmSet);
Bitmap.HorizLine(ARect.Left, ARect.Top + 2, ARect.Right-1, SetHue(BGRA(253, 254, 255), g_hue), dmSet);
c1 := SetHue(BGRA(252, 254, 255), g_hue);
c2 := SetHue(BGRA(243, 248, 253), g_hue);
c3 := SetHue(BGRA(238, 243, 250), g_hue);
c4 := SetHue(BGRA(238, 244, 251), g_hue);
ARect2 := Rect(ARect.Left, ARect.Top + 3, ARect.Right, ARect.Bottom - 3);
DoubleGradientAlphaFill(Bitmap, ARect2, c1, c2, c3, c4, gdVertical,
gdVertical, gdVertical, 0.5);
c1 := SetHue(BGRA(249, 252, 255), g_hue);
c2 := SetHue(BGRA(230, 240, 250), g_hue);
c3 := SetHue(BGRA(220, 230, 244), g_hue);
c4 := SetHue(BGRA(221, 233, 247), g_hue);
ARect2 := Rect(ARect.Left + 1, ARect.Top + 3, ARect.Right - 1, ARect.Bottom - 3);
DoubleGradientAlphaFill(Bitmap, ARect2, c1, c2, c3, c4, gdVertical,
gdVertical, gdVertical, 0.5);
Bitmap.HorizLine(ARect.Left, ARect.Bottom - 3, ARect.Right-1, SetHue(BGRA(228, 239, 251), g_hue), dmSet);
Bitmap.HorizLine(ARect.Left, ARect.Bottom - 2, ARect.Right-1, SetHue(BGRA(205, 218, 234), g_hue), dmSet);
Bitmap.HorizLine(ARect.Left, ARect.Bottom - 1, ARect.Right-1, SetHue(BGRA(160, 175, 195), g_hue), dmSet);
end;
{$IFDEF FPC}
procedure Register;
begin
RegisterComponents('BGRA Controls', [TBCToolBar]);
end;
{$ENDIF}
{ TBCToolBar }
constructor TBCToolBar.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
FBGRA := TBGRABitmap.Create;
end;
destructor TBCToolBar.Destroy;
begin
FBGRA.Free;
inherited Destroy;
end;
procedure TBCToolBar.SetLimitMemoryUsage(AValue: boolean);
begin
if FLimitMemoryUsage=AValue then Exit;
FLimitMemoryUsage:=AValue;
CheckMemoryUsage;
end;
{$IFNDEF FPC}
procedure TBCToolBar.PaintWindow(DC: HDC);
begin
Canvas.Lock;
try
Canvas.Handle := DC;
try
TControlCanvas(Canvas).UpdateTextFlags;
Paint;
finally
Canvas.Handle := 0;
end;
finally
Canvas.Unlock;
end;
end;
{$ENDIF}
procedure TBCToolBar.Paint;
begin
if (FBGRA.Width <> Width) or (FBGRA.Height <> Height) then
begin
FBGRA.SetSize(Width, Height);
if Assigned(FOnRedraw) then
{ Draw using event }
FOnRedraw(self, FBGRA)
else
{ Draw this default }
DrawWindows7ToolBar(FBGRA, Color);
end;
FBGRA.Draw(Canvas, 0, 0);
CheckMemoryUsage;
end;
procedure TBCToolBar.CheckMemoryUsage;
begin
if FLimitMemoryUsage then
begin
if FBGRA.NbPixels <> 0 then
FBGRA.SetSize(0,0);
end;
end;
end.