-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathuNonVisual.pas
114 lines (87 loc) · 2.27 KB
/
uNonVisual.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
unit uNonVisual;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TNonVisual = class(TScrollBox)
private
{ Private declarations }
FLabel: TLabel;
FPanel: TScrollBox;
FImage: TImage;
FCaption: string;
procedure updatePos;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure WMMove(var Message: TWMMove); message WM_MOVE;
procedure SetCaption(const Value: string);
public
{ Public declarations }
constructor Create(AComponent: TComponent);
procedure loadFromFile(fName: string);
procedure Clear();
published
property Caption: string read FCaption write SetCaption;
end;
implementation
{ TNonVisual }
procedure TNonVisual.Clear;
begin
FImage.Picture.Bitmap := nil;
end;
constructor TNonVisual.Create(AComponent: TComponent);
begin
inherited;
BevelKind := bkFlat;
BorderStyle := bsNone;
Width := 25;
Height := 25;
Constraints.MaxHeight := 25;
Constraints.MaxWidth := 25;
Constraints.MinHeight := 25;
Constraints.MinWidth := 25;
BevelWidth := 2;
FImage := TImage.Create(AComponent);
FImage.Transparent := True;
FImage.Parent := Self;
FPanel := TScrollBox.Create(AComponent);
FPanel.Parent := TWinControl(AComponent);
FPanel.BevelKind := bkFlat;
FPanel.BorderStyle := bsNone;
FPanel.BevelWidth := 2;
FLabel := TLabel.Create(AComponent);
FLabel.Font.Name := 'Tahoma';
FLabel.Font.Size := 8;
FLabel.ParentFont := False;
FLabel.Alignment := taCenter;
FLabel.Parent := FPanel;
Caption := 'SkinManager';
FPanel.AutoSize := True;
updatePos();
end;
procedure TNonVisual.loadFromFile(fName: string);
begin
FImage.Picture.LoadFromFile(fName);
end;
procedure TNonVisual.SetCaption(const Value: string);
begin
FCaption := Value;
if Length(Value) > 15 then
FCaption := copy(Value, 1, 15) + #13 + copy(Value, 16, length(Value) - 15);
FLabel.Caption := FCaption;
updatePos();
end;
procedure TNonVisual.updatePos;
begin
FPanel.Top := Self.Top + Self.Height + 5;
FPanel.Left := Self.Left - trunc(FLabel.Width / 2) + 9;
end;
procedure TNonVisual.WMMove(var Message: TWMMove);
begin
updatePos();
end;
procedure TNonVisual.WMSize(var Message: TWMSize);
begin
updatePos();
end;
end.