-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
bgraimagetheme.pas
106 lines (85 loc) · 2.52 KB
/
bgraimagetheme.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
// SPDX-License-Identifier: LGPL-3.0-linking-exception
unit BGRAImageTheme;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, BGRATheme,
BGRASliceScaling, BGRABitmap, BGRABitmapTypes, BGRASVGImageList;
type
{ TBGRAImageTheme }
TBGRAImageTheme = class(TBGRATheme)
private
FBackgroundColor: TColor;
FSliceScalingButton: TBGRAMultiSliceScaling;
procedure SetFBackgroundColor(AValue: TColor);
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure LoadResources(AFileName: string);
procedure DrawButton(Caption: string; State: TBGRAThemeButtonState;
Focused: boolean; ARect: TRect; ASurface: TBGRAThemeSurface; AImageIndex: Integer = -1; AImageList: TBGRASVGImageList = nil); override;
published
property BackgroundColor: TColor read FBackgroundColor
write SetFBackgroundColor default clForm;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('BGRA Themes', [TBGRAImageTheme]);
end;
{ TBGRAImageTheme }
procedure TBGRAImageTheme.SetFBackgroundColor(AValue: TColor);
begin
if FBackgroundColor = AValue then
Exit;
FBackgroundColor := AValue;
end;
constructor TBGRAImageTheme.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
BackgroundColor := clForm;
end;
destructor TBGRAImageTheme.Destroy;
begin
FSliceScalingButton.Free;
inherited Destroy;
end;
procedure TBGRAImageTheme.LoadResources(AFileName: string);
begin
FreeAndNil(FSliceScalingButton);
FSliceScalingButton := TBGRAMultiSliceScaling.Create(AFileName, 'Button');
end;
procedure TBGRAImageTheme.DrawButton(Caption: string;
State: TBGRAThemeButtonState; Focused: boolean; ARect: TRect;
ASurface: TBGRAThemeSurface; AImageIndex: Integer;
AImageList: TBGRASVGImageList);
var
Style: TTextStyle;
ImageIndex: integer;
begin
With ASurface do
begin
case State of
btbsHover: ImageIndex := 1;
btbsActive: ImageIndex := 2;
btbsDisabled: ImageIndex := 3;
else {btbsNormal}
ImageIndex := 0;
end;
Bitmap.Fill(BackgroundColor);
if Assigned(FSliceScalingButton) then
FSliceScalingButton.Draw(ImageIndex, Bitmap, 0, 0, Bitmap.Width, Bitmap.Height);
DrawBitmap;
if Caption <> '' then
begin
fillchar(Style, sizeof(Style), 0);
Style.Alignment := taCenter;
Style.Layout := tlCenter;
Style.Wordbreak := True;
DestCanvas.TextRect(ARect, 0, 0, Caption, Style);
end;
end;
end;
end.