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
| unit PngButton;
interface
uses
Forms,Windows,Messages,Graphics,
ExtCtrls,Classes,SysUtils,Variants,Dialogs,Controls,StdCtrls,Pngimage;
type
TPngButton = class(TCustomControl)
private
FLeaveBackground: TPngImage;
FEnterBackground: TPngImage;
FInterval: Integer;
FText: String;
FFont: TFont;
MouseEnter: Boolean;
procedure SetLeaveBackground(Value: TPngImage);
procedure SetEnterBackground(Value: TPngImage);
procedure SetFont(Value: TFont);
procedure SetInterval(Value: Integer);
procedure SetText(Value: String);
procedure WMLeave(var Message: TMessage); message CM_MOUSELEAVE;
procedure WMEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure Morphing(Png,Png1,Png2: TPNGimage);
public
procedure Paint; override;
constructor Create(AOWner: TComponent); override;
destructor Destroy; override;
published
property onClick;
property Font;
property Caption: String read FText write SetText;
property LeaveImage: TPngImage read FLeaveBackground write SetLeaveBackground;
property EnterImage: TPngImage read FEnterBackground write SetEnterBackground;
property Interval: Integer read FInterval write SetInterval;
property ShowHint;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('zloY_comp',[TPngButton]);
end;
procedure TPngButton.SetFont(Value: TFont);
begin
FFont.Assign(Value);
end;
procedure TPngButton.SetLeaveBackground(Value: TPngImage);
begin
FLeaveBackground.Assign(Value);
Invalidate;
end;
procedure TPngButton.SetEnterBackground(Value: TPngImage);
begin
FEnterBackground.Assign(Value);
Invalidate;
end;
procedure TPngButton.SetInterval(Value: Integer);
begin
if Value < 0 then Value:= 0;
FInterval:= Value;
end;
procedure TPngButton.SetText(Value: String);
begin
FText:= Value;
end;
constructor TPngButton.Create(AOWner: TComponent);
begin
inherited;
FLeaveBackground:= TPngImage.Create;
FEnterBackground:= TPngImage.Create;
Parent:= TForm(AOWner);
Parent.DoubleBuffered:= True;
FInterval:= 300;
end;
destructor TPngButton.Destroy;
begin
inherited;
FLeaveBackground.Destroy;
FEnterBackground.Destroy;
end;
procedure TPngButton.Morphing(Png,Png1,Png2: TPNGimage);
var
i: integer;
x, y: integer;
p1, p2, p: PByteArray;
c: integer;
k: integer;
begin
Png := Tpngimage.Create;
if Png1.Height < Png2.Height then
begin
Png.Height:= Png1.Height;
Png2.Height:= Png2.Height;
end
else
begin
Png.Height := Png2.Height;
Png1.Height := Png2.Height;
end;
if Png1.Width < Png2.Width then
begin
Png.Width := Png1.Width;
Png2.Width := Png1.Width;
end
else
begin
Png.Width := Png2.Width;
Png1.Width := Png2.Width;
end;
Canvas.Draw(0,0,Png1);
SetBkMode(Canvas.Handle,TRANSPARENT);
Canvas.TextOut((Width div 2) - (Canvas.TextWidth(FText) div 2),(Height div 2) - (Canvas.TextHeight(FText) div 2),FText);
SetBkMode(Canvas.Handle,OPAQUE);
for i := 1 to FInterval - 1 do
begin
for y := 0 to Png.Height - 1 do
begin
p := Png.ScanLine[y];
p1 := Png1.ScanLine[y];
p2 := Png2.ScanLine[y];
for x := 0 to Png.Width * 3 - 1 do
p^[x] := round((p1^[x] * (FInterval - i) + p2^[x] * i) / FInterval);
end;
Canvas.Draw(0,0,Png);
SetBkMode(Canvas.Handle,TRANSPARENT);
Canvas.TextOut((Width div 2) - (Canvas.TextWidth(FText) div 2),(Height div 2) - (Canvas.TextHeight(FText) div 2),FText);
SetBkMode(Canvas.Handle,OPAQUE);
Application.ProcessMessages;
if Application.Terminated then
break;
end;
Canvas.Draw(0,0,Png2);
SetBkMode(Canvas.Handle,TRANSPARENT);
Canvas.TextOut((Width div 2) - (Canvas.TextWidth(FText) div 2),(Height div 2) - (Canvas.TextHeight(FText) div 2),FText);
SetBkMode(Canvas.Handle,OPAQUE);
Png.Destroy;
end;
procedure TPngButton.WMLeave(var Message: TMessage);
begin
inherited;
if FEnterBackground.PngImage.Handle = 0 then Exit;
Morphing(FEnterBackground.PngImage,FLeaveBackground.PngImage);
end;
procedure TPngButton.WMEnter(var Message: TMessage);
begin
if FEnterBackground.PngImage.Handle = 0 then Exit;
Morphing(FLeaveBackground.PngImage,FEnterBackground.PngImage);
end;
procedure TPngButton.Paint;
begin
inherited;
Canvas.Font:= Font;
SetBkMode(Canvas.Handle,TRANSPARENT);
Canvas.TextOut((Width div 2) - (Canvas.TextWidth(FText) div 2),(Height div 2) - (Canvas.TextHeight(FText) div 2),FText);
SetBkMode(Canvas.Handle,OPAQUE);
if FLeaveBackground.PngImage.Handle = 0 then Exit;
Canvas.Draw(0,0,FLeaveBackground.PngImage);
SetBkMode(Canvas.Handle,TRANSPARENT);
Canvas.TextOut((Width div 2) - (Canvas.TextWidth(FText) div 2),(Height div 2) - (Canvas.TextHeight(FText) div 2),FText);
SetBkMode(Canvas.Handle,OPAQUE);
end;
end. |