-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUNotifierPopUp.pas
404 lines (343 loc) · 9.81 KB
/
UNotifierPopUp.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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
unit UNotifierPopUp;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, StdCtrls, ExtCtrls;
type
{ TNotifierPopUpForm }
TNotifierPopUpForm = class(TForm)
private
lblTitle: TLabel;
lblText: TLabel;
imgIcon: TPicture;
Timer1 : TTimer;
Timer2 : TTimer;
Panel1 : TPanel;
procedure HideForm(Sender: TObject);
procedure HandleResize(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Show;
procedure Paint; override;
procedure SetText(Value: string);
procedure SetTitle(Value: string);
procedure SetColorTop(Value: TColor);
procedure SetColorBG(Value: TColor);
end;
{***************************************************************************
* Create global: NotifierPopUp - Lists of Notifier window self Hide by Interval
* Send info text to NotifierPopUp.AddNotifer(ATitle, AText: string);
* Set: Color, ColorTop, Icon, Interval ...
***************************************************************************}
TNotifierPopUp = class(TComponent)
private
fLista: TList; // lista TNofierPopUpForm
fColorTop: TColor;
fHeight: integer;
fInterval: integer;
fLeft: integer;
fColor: TColor;
fIcon: TPicture;
fOnClose: TCloseEvent;
fText: string;
fTitle: string;
fTop: integer;
fWidth: integer;
procedure SetColor(AValue: TColor);
procedure SetColorTop(AValue: TColor);
procedure SetHeight(AValue: integer);
procedure SetIcon(AValue: TPicture);
procedure SetInterval(AValue: integer);
procedure SetLeft(AValue: integer);
procedure SetOnClose(AValue: TCloseEvent);
procedure SetText(AValue: string);
procedure SetTitle(AValue: string);
procedure SetTop(AValue: integer);
procedure SetWidth(AValue: integer);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
Procedure AddNotifer(ATitle, AText: string);
published
property Top: integer read fTop write SetTop;
property Left: integer read fLeft write SetLeft;
property Height: integer read fHeight write SetHeight;
property Width: integer read fWidth write SetWidth;
property Color: TColor read fColor write SetColor;
property ColorTop: TColor read fColorTop write SetColorTop;
property Icon: TPicture read fIcon write SetIcon;
property Text: string read fText write SetText;
property Title: string read fTitle write SetTitle;
property Interval: integer read fInterval write SetInterval;
property OnClose: TCloseEvent read fOnClose write SetOnClose;
end;
{ TForm2 }
implementation
{*******************************************************************
* TNotifierPopUpForm
*******************************************************************}
constructor TNotifierPopUpForm.Create(AOwner: TComponent);
begin
inherited CreateNew(AOwner);
BorderStyle := bsNone;
FormStyle := fsStayOnTop;
AlphaBlend := true;
AlphaBlendValue:= 255;
ImgIcon := TPicture.Create;
Panel1:= TPanel.Create(Self);
Panel1.Parent:= Self;
Panel1.Align := alTop;
Panel1.Color := $00FF4242; // $005C5C5C;
Panel1.Height:= 5;
Panel1.BevelOuter:= bvNone;
lblTitle := TLabel.Create(Self);
lblTitle.Parent := Self;
lblTitle.AutoSize := False;
lblTitle.Transparent := True;
lblTitle.Font.Style := [FsBold];
lblTitle.Font.Color := $005C5C5C;
lblTitle.Caption := 'OTIS';
lblTitle.ParentColor := True;
lblTitle.OnClick := @HideForm;
lblText := TLabel.Create(Self);
lblText.Parent := Self;
lblText.AutoSize := False;
lblText.Transparent := True;
lblText.Caption := 'Text';
lblText.Font.Color := $005C5C5C;
lblText.WordWrap := True;
lblText.ParentColor := True;
lblText.OnClick := @HideForm;
Timer1:= TTimer.Create(Self);
Timer1.Interval := 3000;
Timer1.Enabled := false;
Timer1.OnTimer := @Timer1Timer;
Timer2:= TTimer.Create(Self);
Timer2.Interval := 100;
Timer2.Enabled := false;
Timer2.OnTimer := @Timer2Timer;
Color := $DCFFFF; // Kolor tła
HandleResize(Self);
// Connects the methods to events
OnClick := @HideForm;
OnShow := @HandleResize;
end;
destructor TNotifierPopUpForm.Destroy;
begin
ImgIcon.Free;
lblTitle.Free;
lblText.Free;
Timer1.Free;
Timer2.Free;
Panel1.Free;
inherited Destroy;
end;
procedure TNotifierPopUpForm.Show;
begin
Timer1.Enabled:= true;
inherited Show;
end;
procedure TNotifierPopUpForm.Paint;
begin
Canvas.Brush.Style := bsSolid;
Canvas.Brush.Color := Color;
Canvas.FillRect(Rect(0,0,width,height));
{ Paints the icon. We can't use a TImage because it's on ExtCtrls }
if Assigned(imgIcon.Bitmap) then Canvas.Draw(5, 10, imgIcon.Bitmap);
end;
procedure TNotifierPopUpForm.SetText(Value: string);
begin
lblText.Caption:= Value;
end;
procedure TNotifierPopUpForm.SetTitle(Value: string);
begin
lblTitle.Caption:= Value;
end;
procedure TNotifierPopUpForm.SetColorTop(Value: TColor);
begin
Panel1.Color:= Value;
end;
procedure TNotifierPopUpForm.SetColorBG(Value: TColor);
begin
Color:= Value;
end;
procedure TNotifierPopUpForm.HideForm(Sender: TObject);
Var NoValue :TCloseAction;
begin
if Assigned(OnClose) then
OnClose(Self,NoValue);
Hide;
end;
procedure TNotifierPopUpForm.HandleResize(Sender: TObject);
var
IconAdjust: Integer;
INT_NOTIFIER_SPACING: integer;
begin
INT_NOTIFIER_SPACING:= 5;
if (ImgIcon.Bitmap <> nil) then
IconAdjust := INT_NOTIFIER_SPACING + imgIcon.Bitmap.Width
else
IconAdjust := 0;
if (lblTitle <> nil) then
begin
lblTitle.Left := IconAdjust + INT_NOTIFIER_SPACING;
lblTitle.Top := INT_NOTIFIER_SPACING + 5;
lblTitle.Width := Width - (lblTitle.Left + INT_NOTIFIER_SPACING);
lblTitle.Height:= 20;
end;
if (lblText <> nil) then
begin
lblText.Left := IconAdjust + 20;
lblText.Top := LblTitle.Top + LblTitle.Height + INT_NOTIFIER_SPACING;
lblText.Width := Width - (lblText.Left + INT_NOTIFIER_SPACING);
lblText.Height := Height - (lblText.Top + INT_NOTIFIER_SPACING);
end;
end;
procedure TNotifierPopUpForm.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled:= false;
Timer2.Enabled:= true;
end;
procedure TNotifierPopUpForm.Timer2Timer(Sender: TObject);
begin
AlphaBlendValue:= AlphaBlendValue - 20;
if AlphaBlendValue <= 20 then close;
end;
{*********************************************************************************************************************
* TNotifierPopUp
**********************************************************************************************************************}
procedure TNotifierPopUp.SetColor(AValue: TColor);
begin
if fColor=AValue then Exit;
fColor:=AValue;
end;
procedure TNotifierPopUp.SetColorTop(AValue: TColor);
begin
if fColorTop=AValue then Exit;
fColorTop:=AValue;
end;
procedure TNotifierPopUp.SetHeight(AValue: integer);
begin
if fHeight=AValue then Exit;
fHeight:=AValue;
end;
procedure TNotifierPopUp.SetIcon(AValue: TPicture);
begin
if Assigned(AValue) then
fIcon.Assign(AValue);
end;
procedure TNotifierPopUp.SetInterval(AValue: integer);
begin
if fInterval=AValue then Exit;
fInterval:=AValue;
end;
procedure TNotifierPopUp.SetLeft(AValue: integer);
begin
if fLeft=AValue then Exit;
fLeft:=AValue;
end;
procedure TNotifierPopUp.SetOnClose(AValue: TCloseEvent);
begin
if fOnClose=AValue then Exit;
fOnClose:=AValue;
end;
procedure TNotifierPopUp.SetText(AValue: string);
begin
if fText=AValue then Exit;
fText:=AValue;
end;
procedure TNotifierPopUp.SetTitle(AValue: string);
begin
if fTitle=AValue then Exit;
fTitle:=AValue;
end;
procedure TNotifierPopUp.SetTop(AValue: integer);
begin
if fTop=AValue then Exit;
fTop:=AValue;
end;
procedure TNotifierPopUp.SetWidth(AValue: integer);
begin
if fWidth=AValue then Exit;
fWidth:=AValue;
end;
constructor TNotifierPopUp.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fLista:= TList.Create;
fLeft := 0;
fTop := 0;
fWidth := 350;
fHeight := 80;
fInterval:= 3000; // czas wygaśnięcia okienka
fIcon := TPicture.Create;
fColorTop:= clBlack;
fColor := $DCFFFF;
end;
destructor TNotifierPopUp.Destroy;
var i: integer;
frm: TNotifierPopUpForm;
begin
for i:=0 to fLista.Count-1 do
begin
frm:= TNotifierPopUpForm(fLista[i]);
FreeAndNil(frm);
end;
fLista.Clear;
FreeAndNil(fLista);
FreeAndNil(fIcon);
inherited Destroy;
end;
procedure TNotifierPopUp.AddNotifer(ATitle, AText: string);
var frm : TNotifierPopUpForm;
posindex: integer;
i : integer;
isAnyVisible: Boolean;
begin
// Sprawdzamy czy są widoczne komunikaty
isAnyVisible:= false;
for i:=0 to fLista.Count-1 do
begin
frm:= TNotifierPopUpForm(fLista[i]);
if Assigned(frm)and(frm.Visible) then
begin
isAnyVisible:= true;
Break;
end;
end;
// jeśli nie ma widocznych to czyścimy listę
if not isAnyVisible then
begin
for i:=0 to fLista.Count-1 do
begin
frm:= TNotifierPopUpForm(fLista[i]);
FreeAndNil(frm);
end;
fLista.Clear;
end;
// CREATE
frm:= TNotifierPopUpForm.Create(Self);
posindex:= fLista.Add(frm);
posindex:= posindex mod 8; // jednocześnie osiem komunikatów na ekran, jeden pod drugim, następne od nowa
with frm do
begin
Height:= fHeight;
Width := fWidth;
Left:= Screen.Width-Width-10;
Top := 20+posindex * (Height+2);
if AText='' then AText := fText;
if ATitle='' then ATitle:= fTitle;
SetText(AText);
SetTitle(ATitle);
SetColorTop(fColorTop);
SetColorBG(fColor);
if Assigned(fIcon) then
imgIcon.Assign(fIcon);
Timer1.Interval:= fInterval;
Show;
end;
end;
end.