-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
bcleaengrave.pas
272 lines (242 loc) · 7.38 KB
/
bcleaengrave.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
{
*****************************************************************************
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
Author: Boban Spasic
}
unit BCLeaEngrave;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Controls, Graphics, ExtCtrls, LResources,
BGRABitmapTypes, BGRABitmap, BGRATextFX, BGRATransform;
type
TBCLeaEngrave = class(TCustomControl)
private
FBitmap: TBGRABitmap;
FFontShadowColor: TColor;
FFontShadowOffsetX: integer;
FFontShadowOffsetY: integer;
FFontShadowRadius: integer;
FLayerZoom: integer;
FLayerOffsetX: integer;
FLayerOffsetY: integer;
FBlendOperation: TBlendOperation;
FInvBlending: boolean;
FLayerColor: TColor;
FAngle: integer;
procedure SetFFontShadowColor(AValue: TColor);
procedure SetFFontShadowOffsetX(AValue: integer);
procedure SetFFontShadowOffsetY(AValue: integer);
procedure SetFFontShadowRadius(AValue: integer);
procedure SetLayerZoom(AValue: integer);
procedure SetBlendOperation(AValue: TBlendOperation);
procedure SetInvBlending(AValue: boolean);
procedure SetLayerColor(AValue: TColor);
procedure SetLayerOffsetX(AValue: integer);
procedure SetLayerOffsetY(AValue: integer);
procedure SetAngle(AValue: integer);
protected
procedure SetVisible(Value: boolean); override;
procedure Paint; override;
procedure Redraw;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Align;
property Caption;
property Color default clBtnFace;
property Cursor;
property Font;
property ParentShowHint;
property ShowHint;
property Anchors;
property Constraints;
property Visible;
property FontShadowColor: TColor read FFontShadowColor write SetFFontShadowColor default clBlack;
property FontShadowOffsetX: integer read FFontShadowOffsetX write SetFFontShadowOffsetX default 2;
property FontShadowOffsetY: integer read FFontShadowOffsetY write SetFFontShadowOffsetY default 2;
property FontShadowRadius: integer read FFontSHadowRadius write SetFFontShadowRadius default 4;
property BlendOperation: TBlendOperation read FBlendOperation write SetBlendOperation default boSubtractInverse;
property LayerZoom: integer read FLayerZoom write SetLayerZoom default 102;
property InverseBlending: boolean read FInvBlending write SetInvBlending default False;
property LayerColor: TColor read FLayerColor write SetLayerColor default clBlack;
property LayerOffsetX: integer read FLayerOffsetX write SetLayerOffsetX default 0;
property LayerOffsetY: integer read FLayerOffsetY write SetLayerOffsetY default 0;
property Angle: integer read FAngle write SetAngle default 0;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('BGRA Controls', [TBCLeaEngrave]);
end;
constructor TBCLeaEngrave.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
with GetControlClassDefaultSize do
SetInitialBounds(0, 0, 100, 100);
Font.Color := clBlack;
Font.Height := 20;
FLayerZoom := 102;
FBlendOperation := boSubtractInverse;
FFontShadowRadius := 4;
FFontShadowOffsetX := 2;
FFontShadowOffsetY := 2;
FFontShadowColor := clBlack;
Color := clBtnFace;
FLayerColor := clBlack;
FLayerOffsetX := 0;
FLayerOffsetY := 0;
FAngle := 0;
FInvBlending := False;
FBitmap := TBGRABitmap.Create(Width, Height, Color);
end;
destructor TBCLeaEngrave.Destroy;
begin
FreeAndNil(FBitmap);
inherited Destroy;
end;
procedure TBCLeaEngrave.SetVisible(Value: boolean);
begin
inherited SetVisible(Value);
Invalidate;
end;
procedure TBCLeaEngrave.Paint;
begin
inherited Paint;
Redraw;
end;
procedure TBCLeaEngrave.Redraw;
var
TextBmp, LayerTextBmp: TBGRABitmap;
Zoom, UnZoom, RotBmp: TBGRABitmap;
CopyRect: TRect;
ZFactor: single;
Rad: single;
Affine: TBGRAAffineBitmapTransform;
begin
ZFactor := FLayerZoom / 100;
FBitmap.SetSize(Width, Height);
FBitmap.Fill(Color);
TextBmp := TextShadow(Width, Height, Caption, Font.Height,
Font.Color, FontShadowColor, FontShadowOFfsetX,
FontShadowOffsetY, FontShadowRadius, Font.Style, Font.Name) as TBGRABitmap;
LayerTextBmp := TextShadow(Width, Height, Caption, Font.Height,
LayerColor, FontShadowColor, FontShadowOFfsetX,
FontShadowOffsetY, FontShadowRadius, Font.Style, Font.Name) as TBGRABitmap;
Zoom := LayerTextBmp.Resample(round(Width * ZFactor), round(Height * ZFactor)) as TBGRABitmap;
CopyRect.Left := (Zoom.Width - Width) div 2 + FLayerOffsetX;
CopyRect.Right := CopyRect.Left + Width + FLayerOffsetX;
CopyRect.Top := (Zoom.Height - Height) div 2 + FLayerOffsetY;
CopyRect.Bottom := CopyRect.Top + Height + FLayerOffsetY;
UnZoom := Zoom.GetPart(CopyRect) as TBGRABitmap;
if FInvBlending then
begin
FBitmap.PutImage(0, 0, UnZoom, dmDrawWithTransparency);
FBitmap.BlendImageOver(0, 0, TextBmp, FBlendOperation);
end
else
begin
FBitmap.PutImage(0, 0, TextBmp, dmDrawWithTransparency);
FBitmap.BlendImageOver(0, 0, UnZoom, FBlendOperation);
end;
if FAngle <> 0 then
begin
RotBmp := TBGRABitmap.Create(Width, Height, Color);
Affine := TBGRAAffineBitmapTransform.Create(FBitmap);
Affine.Translate(-FBitmap.Width div 2, -FBitmap.Height div 2);
Affine.RotateDeg(FAngle);
Affine.Translate(FBitmap.Width div 2, FBitmap.Height div 2);
RotBmp.Fill(Affine);
FBitmap.Fill(Color);
FBitmap.PutImage(0, 0, RotBmp, dmDrawWithTransparency);
Affine.Free;
RotBmp.Free;
end;
if Visible then
FBitmap.Draw(Canvas, 0, 0, True);
TextBmp.Free;
Zoom.Free;
UnZoom.Free;
end;
procedure TBCLeaEngrave.SetFFontShadowColor(AValue: TColor);
begin
if FFontShadowColor = AValue then
Exit;
FFontShadowColor := AValue;
Invalidate;
end;
procedure TBCLeaEngrave.SetFFontShadowOffsetX(AValue: integer);
begin
if FFontShadowOffsetX = AValue then
Exit;
FFontShadowOffsetX := AValue;
Invalidate;
end;
procedure TBCLeaEngrave.SetFFontShadowOffsetY(AValue: integer);
begin
if FFontShadowOffsetY = AValue then
Exit;
FFontShadowOffsetY := AValue;
Invalidate;
end;
procedure TBCLeaEngrave.SetFFontShadowRadius(AValue: integer);
begin
if FFontSHadowRadius = AValue then
Exit;
FFontSHadowRadius := AValue;
Invalidate;
end;
procedure TBCLeaEngrave.SetBlendOperation(AValue: TBlendOperation);
begin
if FBlendOperation = AValue then
Exit;
FBlendOperation := AValue;
Invalidate;
end;
procedure TBCLeaEngrave.SetLayerZoom(AValue: integer);
begin
if FLayerZoom = AValue then
Exit;
FLayerZoom := AValue;
Invalidate;
end;
procedure TBCLeaEngrave.SetInvBlending(AValue: boolean);
begin
if FInvBlending = AValue then
Exit;
FInvBlending := AValue;
Invalidate;
end;
procedure TBCLeaEngrave.SetLayerColor(AValue: TColor);
begin
if FLayerColor = AValue then
Exit;
FLayerColor := AValue;
Invalidate;
end;
procedure TBCLeaEngrave.SetLayerOffsetX(AValue: integer);
begin
if FLayerOffsetX = AValue then
Exit;
FLayerOffsetX := AValue;
Invalidate;
end;
procedure TBCLeaEngrave.SetLayerOffsetY(AValue: integer);
begin
if FLayerOffsetY = AValue then
Exit;
FLayerOffsetY := AValue;
Invalidate;
end;
procedure TBCLeaEngrave.SetAngle(AValue: integer);
begin
if FAngle = AValue then
Exit;
FAngle := AValue;
Invalidate;
end;
end.