forked from torum/Image-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathufullscreen.pas
1701 lines (1494 loc) · 40.2 KB
/
ufullscreen.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
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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit UFullscreen;
{$mode objfpc}{$H+}
{
Debug:
DEFINE MyDebug
}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
LclType, LclProc, LclIntf, Menus
{$ifdef MyDebug}, strutils{$endif}{$ifdef windows}, Windows{$endif};
type
{ TfrmFullscreen }
TfrmFullscreen = class(TForm)
IdleTimerMouseHide: TIdleTimer;
Image1: TImage;
MenuItemBorderForSOT: TMenuItem;
MenuItemStart: TMenuItem;
MenuItemStayOnTop: TMenuItem;
MenuItemRepeat: TMenuItem;
MenuItemRandom: TMenuItem;
MenuItemFit: TMenuItem;
MenuItemExpand: TMenuItem;
MenuItemStretchBoth: TMenuItem;
MenuItemMoniters: TMenuItem;
MenuItemFilterFileSize: TMenuItem;
MenuItemPlayback: TMenuItem;
MenuItemInterval: TMenuItem;
MenuItemFilter: TMenuItem;
MenuItemQuit: TMenuItem;
MenuItem5: TMenuItem;
MenuItemBack: TMenuItem;
MenuItemNext: TMenuItem;
MenuItemPause: TMenuItem;
MenuItemEffect: TMenuItem;
MenuItemStretch: TMenuItem;
PopupMenu1: TPopupMenu;
Separator1: TMenuItem;
TimerInterval: TTimer;
TimerFadeIn: TTimer;
TimerFadeOut: TTimer;
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure FormCreate(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormResize(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
procedure FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
MousePos: TPoint; var Handled: Boolean);
procedure IdleTimerMouseHideTimer(Sender: TObject);
procedure Image1DblClick(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure MenuItemStartClick(Sender: TObject);
procedure MenuItemStayOnTopClick(Sender: TObject);
procedure MenuItemExpandClick(Sender: TObject);
procedure MenuItemFitClick(Sender: TObject);
procedure MenuItemQuitClick(Sender: TObject);
procedure MenuItemBackClick(Sender: TObject);
procedure MenuItemNextClick(Sender: TObject);
procedure MenuItemPauseClick(Sender: TObject);
procedure MenuItemEffectClick(Sender: TObject);
procedure MenuItemRandomClick(Sender: TObject);
procedure MenuItemRepeatClick(Sender: TObject);
procedure MenuItemStretchBothClick(Sender: TObject);
procedure PopupMenu1Close(Sender: TObject);
procedure PopupMenu1Popup(Sender: TObject);
procedure TimerFadeInTimer(Sender: TObject);
procedure TimerFadeOutTimer(Sender: TObject);
procedure TimerIntervalTimer(Sender: TObject);
private
FFileList:TStringlist;
FiCurr:integer;
FstrCurr:string;
FInterval:integer;
FStretch:boolean;
FExpand:boolean;
FFit:boolean;
FEffect:boolean;
FMinimulFileSizeKiloByte:integer;
FManualTransition:boolean;
FRandom:boolean;
FRepeat:boolean;
FIsFullScreen: boolean;
FIsSlideshowPlaying:boolean;
FOrigBounds: TRect;
FOrigWndState: TWindowState;
FiStartWith:integer;
FOptIntMoniter:integer;
FisInFrame :boolean;
FisStartNormal:boolean;
FXPos, FYPos: Integer;
FisMoving: Boolean;
FisPopupMenuShowing:boolean;
procedure ShowFullScreen(blnOn: boolean);
procedure SetFullScreen_Universal(blnOn: boolean);
procedure SetFullScreen_Win32(blnOn: boolean);
procedure StartSlideshow(startIndex:integer);
{Starts slideshow begining of specified "starts" index.
}
function DisplayImage(id:integer):integer;
{Display an Image.
Takes an index of the playback list, return current index.
}
function ValidateFileIndex(id:integer):boolean;
{Validates if given int is in range of the list.
Returns true if id is in range of the playback list,
}
function ValideteFile(id:integer):integer;
{Validate Image file. It determines if it is exists.
Returns -1 if "not there", or return "FileSize".
}
procedure DisplayError(id:integer;message:string);
{Takes an index of the playback list,
Return current index.
}
function GetNextImageIndex(id:integer):integer;
{Takes current index, and returns next index of the playback list.
Returns -1 if there is no next or reached at the end of the list.
}
function GetPreviousImageIndex(id:integer):integer;
{Takes current index, and returns previous index of the playback list.
Returns -1 if there is no previous or reached at the beggining.
}
procedure ChangeMoniterClicked(Sender: TObject);
procedure ChangeIntervalClicked(Sender: TObject);
procedure ChangeMinFileSizeClicked(Sender: TObject);
procedure PlaybackRepeatStart();
procedure ResizeImage();
public
procedure PlaybackNext();
procedure PlaybackBack();
procedure PlaybackPause();
procedure PlaybackPlay(preLoad:boolean);
property Current: integer read FiCurr;
property StartWith: integer write FiStartWith;
end;
{$ifdef windows}
function SetThreadExecutionState(esFlags: DWORD): DWORD; stdcall external 'kernel32.dll';
{$endif}
var
frmFullscreen: TfrmFullscreen;
implementation
uses UMain;
{$R *.lfm}
const
ES_SYSTEM_REQUIRED = $00000001;
ES_DISPLAY_REQUIRED = $00000002;
ES_CONTINUOUS = $80000000;
procedure TfrmFullscreen.FormCreate(Sender: TObject);
var
i:integer;
childItem: TMenuItem;
begin
FiCurr:=-1;
{$ifdef windows}
TimerFadeIn.Interval:=1;
TimerFadeOut.Interval:=2;
{$else}
TimerFadeIn.Interval:=10;
TimerFadeOut.Interval:=12;
{$endif}
FFileList:=TStringlist.Create;
FFileList.Assign(frmMain.FileList);
FInterval:= frmMain.OptIntervalIntSeconds*1000;
TimerInterval.Interval:=FInterval;
TimerInterval.Enabled:=false;
FStretch:= frmMain.OptStretch;
FFit:=frmMain.OptFit;
FExpand:=frmMain.OptExpand;
FEffect:=frmMain.OptTransitEffect;
FMinimulFileSizeKiloByte:=frmMain.OptMinimulFileSizeKiloByte;
FManualTransition:=frmMain.IsManualTransition;
FRandom:= frmMain.OptRandom;
FRepeat:= frmMain.OptRepeat;
FOptIntMoniter:=frmMain.OptIntMoniter;
FisInFrame:=frmMain.IsInFrame;
FisStartNormal:=frmMain.IsStartNormal;
FiStartWith:=0;
Image1.Stretch:=false;
if FStretch or FFit then
Image1.StretchInEnabled:=true
else
Image1.StretchInEnabled:=false;
Image1.StretchOutEnabled:=true;
Image1.Proportional:=true;
Image1.Center:=true;
// i18n
MenuItemPlayback.Caption:=resstrPlayback;
MenuItemNext.Caption:=resstrPlaybackNext;
MenuItemBack.Caption:=resstrPlaybackPrevious;
MenuItemPause.Caption:=resstrPlaybackPause;
MenuItemInterval.Caption:=resstrInterval;
MenuItemRandom.Caption:=resstrRandom;
MenuItemRepeat.Caption:=resstrRepeat;
MenuItemEffect.Caption:=resstrEffect;
MenuItemStretch.Caption:=resstrStretch;
MenuItemFit.Caption:=resstrStretchIn;
MenuItemExpand.Caption:=resstrStretchOut;
MenuItemFilter.Caption:=resstrFilter;
MenuItemFilterFileSize.Caption:=resstrFilterFileSize;
MenuItemMoniters.Caption:=resstrMoniters;
MenuItemQuit.Caption:=resstrQuit;
MenuItemStayOnTop.Caption:=resstrStayOnTop;
// Popup Menues
childItem := TMenuItem.Create(PopupMenu1);
childItem.Caption := '[&1] ' + resstrSecond;
childItem.OnClick := @ChangeIntervalClicked;
childItem.Tag:=1;
MenuItemInterval.Add(childItem);
for i:=1 to 9 do begin
childItem := TMenuItem.Create(PopupMenu1);
childItem.Caption := '[&'+intToStr(i+1)+'] ' + resstrSeconds;
childItem.OnClick := @ChangeIntervalClicked;
childItem.Tag:=i+1;
MenuItemInterval.Add(childItem);
end;
childItem := TMenuItem.Create(PopupMenu1);
childItem.Caption := '[1] ' + resstrMinute;
childItem.OnClick := @ChangeIntervalClicked;
childItem.Tag:=60;
MenuItemInterval.Add(childItem);
childItem := TMenuItem.Create(PopupMenu1);
childItem.Caption := '[5] ' + resstrMinutes;
childItem.OnClick := @ChangeIntervalClicked;
childItem.Tag:=300;
MenuItemInterval.Add(childItem);
childItem := TMenuItem.Create(PopupMenu1);
childItem.Caption := '[10] ' + resstrMinutes;
childItem.OnClick := @ChangeIntervalClicked;
childItem.Tag:=600;
MenuItemInterval.Add(childItem);
childItem := TMenuItem.Create(PopupMenu1);
childItem.Caption := '[15] ' + resstrMinutes;
childItem.OnClick := @ChangeIntervalClicked;
childItem.Tag:=900;
MenuItemInterval.Add(childItem);
// Minimum file size
childItem := TMenuItem.Create(PopupMenu1);
childItem.Caption := '> [&'+intToStr(1)+'] KB';
childItem.OnClick := @ChangeMinFileSizeClicked;
childItem.Tag:=1;
MenuItemFilterFileSize.Add(childItem);
childItem := TMenuItem.Create(PopupMenu1);
childItem.Caption := '> [&'+intToStr(50)+'] KB';
childItem.OnClick := @ChangeMinFileSizeClicked;
childItem.Tag:=50;
MenuItemFilterFileSize.Add(childItem);
for i:=0 to 9 do
begin
childItem := TMenuItem.Create(PopupMenu1);
childItem.Caption := '> [&'+intToStr(i+1)+'00] KB';
childItem.OnClick := @ChangeMinFileSizeClicked;
childItem.Tag:=i*100;
MenuItemFilterFileSize.Add(childItem);
end;
// Moniters
for i:=0 to Screen.MonitorCount-1 do
begin
childItem := TMenuItem.Create(PopupMenu1);
childItem.Caption := resstrMoniter + ' [&'+intToStr(i+1)+']';
childItem.OnClick := @ChangeMoniterClicked;
childItem.Tag:=i;
MenuItemMoniters.Add(childItem);
end;
self.Visible:=false; // Don't set to true.
self.ShowInTaskBar:=stNever;
self.AlphaBlend:=true;
if FEffect then
begin
// do NOT ever set it to 0.
self.AlphaBlendValue := 1;
end else
begin
self.AlphaBlendValue := 255;
end;
// Important.
Randomize;
end;
procedure Shuffle(Strings: TStringList);
var
i: Integer;
begin
for i := Strings.Count-1 downto 1 do
Strings.Exchange(i, Random(i+1));
end;
procedure TfrmFullscreen.FormShow(Sender: TObject);
begin
// Changing moniter (show) cause slideshow to star over, so...
if FIsSlideshowPlaying then exit;
if FIsFullscreen then exit;
if (FFileList.Count > 0) then
begin
// Sets fullscreen and show.
if FisInFrame then
begin
self.BoundsRect := frmMain.ClientRect;
StartSlideshow(FiStartWith);
end else
begin
// Make it fullscreen.
ShowFullScreen(true);
// Start.
StartSlideshow(FiStartWith);
end;
end else begin
// No files are selected or to open. List empty.
// This should not happen.
end;
IdleTimerMouseHide.Enabled:=true;
end;
procedure TfrmFullscreen.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
if FisInFrame then
begin
TimerInterval.Enabled:=false;
TimerFadeOut.Enabled:=false;
TimerFadeIn.Enabled:=false;
end;
CanClose:=true;
end;
procedure TfrmFullscreen.FormClose(Sender: TObject;
var CloseAction: TCloseAction);
begin
CloseAction:= caFree;
TimerInterval.Enabled := false;
TimerFadeIn.Enabled := false;
TimerFadeOut.Enabled := false;
IdleTimerMouseHide.Enabled:=false;
Screen.Cursor:=crDefault;
Self.Cursor:=crDefault;
Image1.Cursor:=crDefault;
// Apply chagens in options.
frmMain.OptTransitEffect := FEffect;
frmMain.OptFit := FFit;
frmMain.OptExpand := FExpand;
frmMain.OptIntervalIntSeconds := FInterval div 1000;
frmMain.OptRandom := FRandom;
frmMain.OptRepeat := FRepeat;
if FisInFrame then
begin
frmMain.DoneInFrame(FstrCurr);
end else begin
frmMain.DoneFullscreen(FstrCurr);
end;
// Re-enabling the Screensaver
{$IFDEF Windows}
SetThreadExecutionState(ES_CONTINUOUS);
{$ENDIF}
//ShowFullScreen(false);
end;
procedure TfrmFullscreen.FormDestroy(Sender: TObject);
begin
FFileList.Free;
end;
procedure TfrmFullscreen.StartSlideshow(startIndex:integer);
begin
FIsSlideshowPlaying:=true;
if FRandom then begin
if startIndex > -1 then
begin
FstrCurr:= FFileList[startIndex];
// Randomize the file list.
Shuffle(FFileList);
// Specify index for display.
TimerInterval.tag:= FFileList.IndexOf(FstrCurr);
end else
begin
TimerInterval.tag:=0;
end;
end else
begin
// Specify index for display.
TimerInterval.tag:=startIndex;
end;
if (not frmMain.OptSlideshowAutoStart) or frmMain.IsSingleFileSelected then
begin
// Did not add files manually. started as single file. So,
FManualTransition:=true;
end else
begin
FManualTransition:=false;
end;
// Start slideshow.
PlaybackPlay(false);
end;
procedure TfrmFullscreen.PlaybackPlay(preLoad:boolean);
var
i,iNext:integer;
{$ifdef windows}
{$else}
MPos: TPoint;
{$endif}
begin
{$ifdef Mydebug}
OutputDebugString(PChar(TrimRight( 'PlaybackPlay:id '+ intToStr(TimerInterval.Tag) )));
{$endif}
// Disabling the Screensaver
{$IFDEF Windows}
SetThreadExecutionState(ES_DISPLAY_REQUIRED or ES_SYSTEM_REQUIRED or ES_CONTINUOUS);
{$ELSE}
// Couldn't find a better way.
// https://forum.lazarus.freepascal.org/index.php/topic,56671.0.html
MPos:=Mouse.CursorPos;
Mouse.CursorPos:=MPos;
{$ENDIF}
TimerInterval.Enabled:=false; //just in case.
i:=TimerInterval.Tag;
if ValidateFileIndex(i) then
begin
// Display image
FiCurr:=DisplayImage(i);
FstrCurr:=FFileList[FiCurr];
if FiCurr < 0 then
begin
//TODO:
// Skipping or error
//DisplayError(i,'file skipping. error .'+intToStr(i));
// If you set Repeat and FileSize Filter, it triggers infinite loop.
end else
begin
if FisInFrame then
begin
if (FFileList.Count = 1) then
begin
frmMain.SetCaption('InFrame Slideshow - ' + FFileList[FiCurr]);
end else
begin
frmMain.SetCaption('InFrame Slideshow: '+'['+intToStr(FiCurr+1)+'/'+ intToStr(FFileList.Count) +'] - ' + FFileList[FiCurr]);
end;
end;
end;
end else begin
DisplayError(i,'Display file index out of rainge.'+intToStr(i));
{$ifdef Mydebug}
OutputDebugString(PChar(TrimRight( 'Display file index out of rainge.'+intToStr(i) )));
{$endif}
exit;
end;
// Next cycle.
if FFileList.Count > 0 then
begin
// Tell Timer what to play.
iNext:=GetNextImageIndex(Current);
if (iNext > -1) then
begin
{$ifdef Mydebug}
OutputDebugString(PChar(TrimRight( 'PlaybackPlay: ->Next:'+ intToStr(iNext))));
{$endif}
// Set next
TimerInterval.tag:= iNext;
// Start timer
if FEffect then begin
TimerFadeIn.Enabled:=true;
end else begin
TimerInterval.Enabled:=true;
end;
end else
begin
// Next is the end of list.
{$ifdef Mydebug}
OutputDebugString(PChar(TrimRight( 'PlaybackPlay: ->PlaybackRepeatStart')));
{$endif}
if FEffect then begin
// It's the last but you need to fade in.
// TimerFadeIn checks repeat option.
TimerFadeIn.Enabled:=true;
end else begin
// Checking repeat option.
//PlaybackRepeatStart(); // Don't...?
end;
end;
end;
end;
procedure TfrmFullscreen.PlaybackRepeatStart();
begin
{$ifdef Mydebug}
OutputDebugString(PChar(TrimRight( 'PlaybackRepeatStart ')));
{$endif}
if FRepeat then begin
// Start from beggining.
// Clear
//FFileListRemaining.Clear;
//FFileListRemaining.Assign(FFileList);
// Reset next
//if FRandom then begin
// FiCurr:=-1;
// TimerInterval.tag:=GetNextRandomImageIndex();
//end else begin
// FiCurr:=0;
// TimerInterval.tag:=0;
//end;
FiCurr:=0;
TimerInterval.tag:=0;
{$ifdef Mydebug}
OutputDebugString(PChar(TrimRight( 'PlaybackRepeatStart '+ intToStr(TimerInterval.tag) )));
{$endif}
// Start timer
TimerInterval.Enabled:=true;
end else begin
//TODO: self terminate?
{$ifdef Mydebug}
OutputDebugString(PChar(TrimRight( 'PlaybackRepeatStart: No repeat.')));
{$endif}
end;
end;
procedure TfrmFullscreen.PlaybackPause();
begin
// Toggle playback pause/start
if FIsSlideshowPlaying then begin
// Re-enabling the Screensaver
{$IFDEF Windows}
SetThreadExecutionState(ES_CONTINUOUS);
{$ENDIF}
if FManualTransition then
begin
FManualTransition:=false;
if TimerFadeIn.Enabled then
begin
TimerInterval.Enabled:=true;
end else
begin
if FEffect then
begin
TimerFadeOut.Enabled:=true;
end else
begin
PlaybackPlay(false);
end;
end;
end else
begin
FManualTransition:=true;
TimerInterval.Enabled:=false;
TimerFadeIn.Enabled:=false;
TimerFadeOut.Enabled:=false;
self.AlphaBlendValue:=255;
end;
end;
end;
procedure TfrmFullscreen.PlaybackNext();
begin
if FFileList.Count > 1 then begin
TimerInterval.Enabled:=false;
if FEffect then begin
if TimerFadeIn.Enabled then
begin
// Fading IN. so just speed up.
self.AlphaBlendValue:=255;
TimerFadeInTimer(nil);
TimerFadeOut.Enabled:=true;
end else if TimerFadeOut.Enabled then
begin
// Fading OUT. so let's just speed up.
self.AlphaBlendValue:=1;
TimerFadeOutTimer(nil);
end else
begin
TimerFadeOut.Enabled:=true;
end;
end else begin
PlaybackPlay(false);
end;
end;
end;
procedure TfrmFullscreen.PlaybackBack();
var
iPrev:integer;
begin
if FFileList.Count > 1 then begin
iPrev:=GetPreviousImageIndex(Current);
if (iPrev > -1) then
begin
if FEffect then begin
if TimerFadeIn.Enabled then
begin
TimerFadeIn.Enabled:=false;
alphablendvalue:=255;
TimerInterval.Enabled:=false;
TimerInterval.Tag := iPrev;
PlaybackPlay(false);
end else if TimerFadeOut.Enabled then
begin
TimerFadeOut.Enabled:=false;
TimerInterval.Enabled:=false;
alphablendvalue:=255;
TimerInterval.Enabled:=true;
end else
begin
TimerInterval.Enabled:=false;
TimerInterval.Tag := iPrev;
alphablendvalue:=255;
TimerFadeOut.Enabled:=false;
TimerInterval.Enabled:=false;
PlaybackPlay(false);
end;
end else begin
TimerInterval.Enabled:=false;
TimerInterval.Tag := iPrev;
PlaybackPlay(false);
end;
end else
begin
end;
end;
end;
function TfrmFullscreen.ValidateFileIndex(id:integer):boolean;
begin
if (id > -1) and ((FFileList.Count-1) >= id) then
begin
result := true;
end else
begin
result := false;
//OutputDebugString(PChar(TrimRight( 'ValidateFileIndex '+ intToStr(id) )));
end;
end;
function TfrmFullscreen.ValideteFile(id:integer):integer;
begin
// FileExists?
result := FileSize(FFileList[id]);
end;
procedure TfrmFullscreen.ResizeImage();
var
curWidth,curHeight:integer;
begin
if FisInFrame then
begin
curWidth := self.Parent.ClientWidth;
curHeight:= self.Parent.ClientHeight;
end else
begin
curWidth := screen.Monitors[FOptIntMoniter].Width;
curHeight:= screen.Monitors[FOptIntMoniter].Height;
end;
if FStretch then begin
Image1.Stretch:=true;
end else begin
if FFit then begin
if ((Image1.Picture.Width > curWidth) or
(Image1.Picture.height > curHeight)) then begin
Image1.Stretch:=true;
Image1.StretchInEnabled:=true;
// Fit only when larger than screen size.
end else begin
Image1.Stretch:=false;
Image1.StretchInEnabled:=false;
end;
end else begin
Image1.Stretch:=false;
end;
if FExpand then begin
Image1.Stretch:=true;
end;
end;
end;
function TfrmFullscreen.DisplayImage(id:integer):integer;
var
f:integer;
begin
f:= ValideteFile(id);
if f >= (FMinimulFileSizeKiloByte * 1024) then
begin
Image1.Picture.Clear;
Image1.Stretch:=false;
Image1.StretchInEnabled:=false;
try
Image1.Picture.LoadFromFile(FFileList[id]);
ResizeImage();
Image1.Refresh;
result:=id;
except
On E :Exception do begin
Image1.Picture.Clear;
DisplayError(id,'DisplayImage@LoadFromFile - '+E.ClassName+' - '+E.Message);
// On error, stop.
//result:=-1;
// On error, keep going.
result:=id;
end;
end;
end else
begin
// File does not exists.
if (f < 0) then begin
Image1.Picture.Clear;
self.AlphaBlendValue:=255;
with image1.Canvas do
begin
Brush.Style := bsClear;
Font.Color := clWhite;
TextOut(24,24, 'File not found: '+FFileList[id]);
end;
Image1.Update;
result:=id;
end else begin
// File size just too small. File size became smaller during the slideshow.
self.AlphaBlendValue:=255;
Image1.Picture.Clear;
with image1.Canvas do
begin
Brush.Style := bsClear;
Font.Color := clWhite;
TextOut(24,24, 'File size is wrong: '+FFileList[id]);
end;
Image1.Update;
result:=id;
//TODO: getNext and continue?
//result:=-1;
end;
end;
end;
procedure TfrmFullscreen.DisplayError(id:integer;message:string);
var
strFilePath:string;
{$ifdef MyDebug} esl:TStringlist;
logFile:string; {$endif}
begin
if ValidateFileIndex(id) then
begin
strFilePath:=FFileList[id];
end;
Image1.Picture.Clear;
with image1.Canvas do
begin
Brush.Style := bsClear;
Font.Color := clWhite;
TextOut(24,24, 'File load error: ' + message);
TextOut(52,52, 'File: ' + strFilePath);
end;
Image1.Update;
{$ifdef MyDebug}
try
esl:=TStringlist.Create;
try
logFile:=ReplaceStr(ExtractFileName(ParamStr(0)),ExtractFileExt(ParamStr(0)),'.log');
if FileExists(logFile) then
begin
esl.LoadFromFile(logFile);
end;
esl.Add(DateTimeToStr(Now));
esl.Add('DisplayError: '+message);
esl.Add('FileIndex: '+intToStr(id));
esl.Add('File: '+strFilePath);
esl.SaveToFile(logFile);
finally
esl.Free;
end;
except
//
end;
{$endif}
end;
procedure TfrmFullscreen.TimerFadeInTimer(Sender: TObject);
var
iNext:integer;
begin
if FFileList.Count = 0 then
begin
TimerInterval.Enabled:=false;
self.AlphaBlendValue := 255;
//close;
exit;
end;
if self.AlphaBlendValue < 255 then
begin
if (self.AlphaBlendValue < 100 ) then begin
self.AlphaBlendValue := self.AlphaBlendValue + 10;
end else
begin
if (self.AlphaBlendValue +5 >= 255) then begin
self.AlphaBlendValue := 255;
end else begin
self.AlphaBlendValue := self.AlphaBlendValue + 4;
end;
end;
end else begin
TimerFadeIn.Enabled:=false;
iNext:=GetNextImageIndex(Current);
if (iNext > -1) then begin
// Start interval timer
TimerInterval.Enabled:=true;
end else begin
PlaybackRepeatStart();
end;
end;
end;
procedure TfrmFullscreen.TimerIntervalTimer(Sender: TObject);
begin
if FManualTransition then
begin
TimerInterval.Enabled:=false;
exit;
end;
if FEffect then begin
TimerFadeOut.Enabled:=true;
end else begin
PlaybackPlay(false);
end;
end;
procedure TfrmFullscreen.TimerFadeOutTimer(Sender: TObject);
begin
if FFileList.Count = 0 then
begin
TimerInterval.Enabled:=false;
TimerFadeOut.Enabled:=false;
//close;
exit;
end else if FFileList.Count = 1 then
begin
TimerInterval.Enabled:=false;
TimerFadeOut.Enabled:=false;
exit;
end;
TimerInterval.Enabled:=false;
if self.AlphaBlendValue > 1 then
begin
if (self.AlphaBlendValue > 128 ) then begin
self.AlphaBlendValue := self.AlphaBlendValue - 4;
end else
begin
if (self.AlphaBlendValue < 17) then begin
self.AlphaBlendValue := 1;
end else begin
self.AlphaBlendValue := self.AlphaBlendValue - 15;
end;
end;
end else begin
TimerFadeOut.Enabled:=false;
PlaybackPlay(false);
end;
end;
function TfrmFullscreen.GetNextImageIndex(id:integer):integer;
begin
if ValidateFileIndex(id) then begin
if (id = (FFileList.Count-1)) then
begin
// End of the list. There is no NEXT.
if FRepeat then
begin
result:=0;
end else begin
result:=-1;
end;
end else if (id > (FFileList.Count-1)) then
begin
//TODO: close? or ...
result:=-1;
end else begin
// Just next.
result:=id+1;
end;
end else
begin
// Something went wrong.
//OutputDebugString(PChar(TrimRight('GetNextImageIndex:(id): ValidateFileIndex FAILED: '+intToStr(id))));
result:=-1;
end;
end;
function TfrmFullscreen.GetPreviousImageIndex(id:integer):integer;
begin
if ValidateFileIndex(id) then begin
if (id <= 0) then
begin
// Beginning of the list. There is no PREVIOUS.
if FRepeat then
begin
result:=FFileList.Count-1;
//OutputDebugString(PChar(TrimRight('GetPreviousImageIndex:(id): '+intToStr(id))));