-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMaxLogic.VCL.PageControlTransitionEffects.pas
More file actions
448 lines (352 loc) · 10 KB
/
Copy pathMaxLogic.VCL.PageControlTransitionEffects.pas
File metadata and controls
448 lines (352 loc) · 10 KB
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
Unit MaxLogic.VCL.PageControlTransitionEffects;
{
requires PicShow: http://www.delphiarea.com/products/delphi-components/picshow/
}
Interface
Uses
windows, classes, sysUtils, VCL.ComCtrls, forms, graphics, controls, ExtCtrls, messages,
PicShow, PSEffect, diagnostics, OverlayForm;
Type
// forward declaration
TOverlayForm = Class;
TTransition = Class(TComponent)
Private
fOverlay: TOverlayFrm;
PicShow: TPicShow;
fTabIndices: Array [0 .. 1] Of integer;
fBmp: TBitmap;
FPageControl: TPageControl;
fOrgPageControlChange: TNotifyEvent;
fOrgPageChanging: TTabChangingEvent;
fStyle: integer;
FDuration: word;
fStyleBack: integer;
FOnTransitionStart: TNotifyEvent;
FOnTransitionCompleted: TNotifyEvent;
FEnabled: Boolean;
Procedure PageControlChanging(Sender: TObject; Var AllowChange: Boolean);
Procedure PageControlChange(Sender: TObject);
Function SelectStyleBasedOnTabDirection: integer;
// events
Procedure PicShowStart(Sender: TObject; Picture, Screen: TBitmap);
Procedure PicShowProgress(Sender: TObject);
Procedure PicShowStop(Sender: TObject);
Procedure PicShowComplete(Sender: TObject);
Procedure ShowOverlay;
Procedure PreparePicShow;
Procedure ApplyDurationToPicShow;
Function GetParentForm: TForm;
Procedure RestoreOrgState;
Procedure TakeScreenofCurTabSheet;
Procedure initOverlay;
Procedure initPicShow;
// property setters
Procedure SetPageControl(Const Value: TPageControl);
Procedure SetStyle(Const Value: integer);
Procedure SetDuration(Const Value: word);
Procedure SetStyleBack(Const Value: integer);
Procedure SetOnTransitionCompleted(Const Value: TNotifyEvent);
Procedure SetOnTransitionStart(Const Value: TNotifyEvent);
procedure SetEnabled(const Value: Boolean);
Public
Constructor Create(aOwner: TComponent);
Destructor destroy; Override;
Procedure GetStyleNames(Names: TStrings);
Property PageControl: TPageControl Read FPageControl Write SetPageControl;
// NOTE: is 1 based!
// Style is using when the from tab is positioned left to the target tab
Property Style: integer Read fStyle Write SetStyle;
// Style Back is used when the start tab is positioned right to the target tab
Property StyleBack: integer Read fStyleBack Write SetStyleBack;
// the duration of the transition effect
Property Duration: word Read FDuration Write SetDuration;
Property OnTransitionCompleted: TNotifyEvent Read FOnTransitionCompleted Write SetOnTransitionCompleted;
Property OnTransitionStart: TNotifyEvent Read FOnTransitionStart Write SetOnTransitionStart;
property Enabled: Boolean read FEnabled write SetEnabled;
End;
TOverlayForm = Class(TForm)
Private
fTransition: TTransition;
Protected
Procedure CreateParams(Var Params: TCreateParams); Override;
Procedure WMNCHitTest(Var Msg: TWMNCHitTest); Message wm_NCHitTest;
Public
Destructor destroy; Override;
End;
Implementation
{ Uses
pawel1; }
{$R *.dfm}
{ TTransition }
Procedure TTransition.ApplyDurationToPicShow;
Var
f: double;
i: integer;
Begin
// try to use 30fps if possible
i := 1;
Repeat
f := FDuration / (101 / i);
// this is the minimum steps neccessary for any half way decent showing...
If i >= 20 Then
break;
// it is quite possible, that we will not be able to display that fast...
If f < 30 Then
inc(i)
Else
break;
Until false;
// step is from 1..100, the percent to go
PicShow.Step := i;
// delay is the time between the steps I suppose?
PicShow.Delay := round(f);
End;
Constructor TTransition.Create(aOwner: TComponent);
Begin
Inherited;
FEnabled := True;
fBmp := TBitmap.Create;
FDuration := 1000;
fStyle := 131;
fStyleBack := 130;
End;
Destructor TTransition.destroy;
Begin
RestoreOrgState;
fBmp.free;
If assigned(fOverlay) Then
If GetParentForm <> Nil Then
Begin
// ??? fOverlay.fTransition := nil;
fOverlay.free;
End;
Inherited;
End;
Procedure TTransition.initOverlay;
Begin
freeAndNil(fOverlay);
fOverlay := TOverlayFrm.Create(GetParentForm);
fOverlay.BorderStyle := bsNone;
// must be set because without it the position will be resetted to poDefault when setting visible to true
fOverlay.Position := poDesigned;
fOverlay.AlphaBlend := True; // ensure the underlying controls are still painted
fOverlay.DoubleBuffered := True;
fOverlay.Visible := false;
End;
Procedure TTransition.initPicShow;
Begin
PicShow := TPicShow.Create(fOverlay);
PicShow.parent := fOverlay;
PicShow.Align := alClient;
PicShow.FrameWidth := 0;
PicShow.Style := fStyle;
PicShow.BgMode := bmTiled;
PicShow.Proportional := True;
PicShow.Stretch := false;
PicShow.FrameColor := fOverlay.Color;
PicShow.Threaded := True;
PicShow.ExactTiming := True;
PicShow.OnStart := PicShowStart;
PicShow.OnProgress := PicShowProgress;
PicShow.OnStop := PicShowStop;
PicShow.OnComplete := PicShowComplete;
PicShow.Manual := false;
PicShow.Visible := True;
End;
Function TTransition.GetParentForm: TForm;
Var
c: TWinControl;
Begin
result := Nil;
c := self.FPageControl.parent;
While c <> Nil Do
Begin
If c Is TForm Then
exit(c As TForm);
c := c.parent;
End;
End;
Procedure TTransition.GetStyleNames(Names: TStrings);
Var
x: integer;
Begin
Names.BeginUpdate;
Try
For x := 0 To PSEffects.Count - 1 Do
Begin
Names.Add('#' + IntToStr(x) + ' ' + PSEffects[x].Name);
End;
Finally
Names.EndUpdate;
End;
End;
Procedure TTransition.PageControlChange(Sender: TObject);
Begin
If assigned(fOrgPageControlChange) Then
fOrgPageControlChange(Sender);
fTabIndices[1] := FPageControl.ActivePageIndex;
if not FEnabled then
exit;
FPageControl.Update;
TakeScreenofCurTabSheet;
PicShow.Picture.assign(fBmp);
PicShow.Style := SelectStyleBasedOnTabDirection;
PicShow.Execute;
End;
Procedure TTransition.PageControlChanging(Sender: TObject; Var AllowChange: Boolean);
Begin
If assigned(fOrgPageChanging) Then
fOrgPageChanging(Sender, AllowChange);
If Not AllowChange Then
exit;
if not FEnabled then
exit;
fTabIndices[0] := FPageControl.ActivePageIndex;
TakeScreenofCurTabSheet;
ShowOverlay;
End;
Procedure TTransition.PicShowComplete(Sender: TObject);
Begin
fOverlay.Visible := false;
If assigned(self.FOnTransitionCompleted) Then
FOnTransitionCompleted(self);
End;
Procedure TTransition.PicShowProgress(Sender: TObject);
Begin
End;
Procedure TTransition.PicShowStart(Sender: TObject; Picture, Screen: TBitmap);
Begin
If assigned(self.FOnTransitionStart) Then
FOnTransitionStart(self);
fOverlay.TransparentColor := false;
End;
Procedure TTransition.PicShowStop(Sender: TObject);
Begin
End;
Procedure TTransition.PreparePicShow;
Begin
// if PicShow is playing, stops it
If PicShow.Busy Then
PicShow.Stop;
ApplyDurationToPicShow;
PicShow.Clear;
PicShow.BgPicture.assign(fBmp);
End;
Procedure TTransition.RestoreOrgState;
Begin
If Not assigned(FPageControl) Then
exit;
FPageControl.onchange := fOrgPageControlChange;
FPageControl.Onchanging := fOrgPageChanging;
End;
Function TTransition.SelectStyleBasedOnTabDirection: integer;
Begin
// are moving from left to right?
If fTabIndices[0] < fTabIndices[1] Then
result := fStyle
Else
result := fStyleBack;
End;
Procedure TTransition.SetDuration(Const Value: word);
Begin
FDuration := Value;
If assigned(PicShow) Then
ApplyDurationToPicShow;
End;
procedure TTransition.SetEnabled(const Value: Boolean);
begin
FEnabled := Value;
end;
Procedure TTransition.SetOnTransitionCompleted(Const Value: TNotifyEvent);
Begin
FOnTransitionCompleted := Value;
End;
Procedure TTransition.SetOnTransitionStart(Const Value: TNotifyEvent);
Begin
FOnTransitionStart := Value;
End;
Procedure TTransition.SetPageControl(Const Value: TPageControl);
Begin
If FPageControl = Value Then
exit;
RestoreOrgState;
FPageControl := Value;
// FPageControl.DoubleBuffered := True;
// FPageControl.parent.DoubleBuffered := True;
fOrgPageControlChange := FPageControl.onchange;
fOrgPageChanging := FPageControl.Onchanging;
FPageControl.onchange := PageControlChange;
FPageControl.Onchanging := PageControlChanging;
initOverlay;
fOverlay.parent := FPageControl.parent;
fOverlay.handleNeeded;
initPicShow;
PicShow.handleNeeded;
// GetParentForm.AlphaBlend:=true;
End;
Procedure TTransition.SetStyle(Const Value: integer);
Begin
fStyle := Value;
End;
Procedure TTransition.SetStyleBack(Const Value: integer);
Begin
fStyleBack := Value;
End;
Procedure TTransition.ShowOverlay;
Var
tsPos, parentPos: TPoint;
r: TRect;
Begin
tsPos := FPageControl.ActivePage.ClientToScreen(point(0, 0));
parentPos := FPageControl.parent.ClientToScreen(point(0, 0));
fOverlay.SetBounds(
(tsPos.x - parentPos.x),
(tsPos.y - parentPos.y),
FPageControl.ActivePage.width,
FPageControl.ActivePage.height);
PreparePicShow;
// PicShow.Update;
fOverlay.AlphaBlendValue := 0;
ShowWindow(fOverlay.Handle, SW_SHOWNOACTIVATE);
fOverlay.AlphaBlendValue := $FF;
fOverlay.Visible := True;
fOverlay.BringToFront; // ensure the form is over the controls
fOverlay.Update;
End;
Procedure TTransition.TakeScreenofCurTabSheet;
Var
dc: hDc;
b: TBitmap;
ts: TTabSheet;
Begin
b := fBmp;
ts := FPageControl.ActivePage;
if (b.width <> ts.width) or (b.height <> ts.height) then
b.SetSize(ts.width, ts.height);
dc := GetDC(ts.Handle);
try
BitBlt(b.Canvas.Handle, 0, 0, b.width, b.height, dc, 0, 0, SRCCOPY);
finally
ReleaseDC(ts.Handle, dc);
end;
End;
{ TOverlayForm }
Procedure TOverlayForm.CreateParams(Var Params: TCreateParams);
Begin
Inherited;
Params.Exstyle := Params.Exstyle Or WS_EX_NOACTIVATE;
End;
Destructor TOverlayForm.destroy;
Begin
If fTransition <> Nil Then
Begin
fTransition.fOverlay := Nil;
fTransition.PicShow := Nil;
End;
Inherited;
End;
Procedure TOverlayForm.WMNCHitTest(Var Msg: TWMNCHitTest);
Begin
Msg.result := HTTRANSPARENT;
End;
End.