Debian Codegraph @

examples/user_interface/timer_test/timer_test.dpr

raw
1 {
2 Copyright 2016-2023 Michalis Kamburelis.
3
4 This file is part of "Castle Game Engine".
5
6 "Castle Game Engine" is free software; see the file COPYING.txt,
7 included in this distribution, for details about the copyright.
8
9 "Castle Game Engine" is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 ----------------------------------------------------------------------------
14 }
15
16 { Demo of TCastleTimer and TCastleFlashEffect. }
17 program timer_test;
18
19 {$ifdef MSWINDOWS} {$apptype GUI} {$endif}
20
21 uses Math,
22 CastleColors, CastleWindow, CastleControls, CastleFlashEffect;
23
24 var
25 Window: TCastleWindow;
26 Flash: array [0..2] of TCastleFlashEffect;
27 Timer: array [0..2] of TCastleTimer;
28
29 type
30 TEventHandler = class
31 class procedure Timer(Sender: TObject);
32 end;
33
34 class procedure TEventHandler.Timer(Sender: TObject);
35 begin
36 Flash[(Sender as TCastleTimer).Tag].Flash(White, false);
37 end;
38
39 var
40 I: Integer;
41 begin
42 Window := TCastleWindow.Create(Application);
43 Window.Width := 600;
44 Window.Height := 120;
45
46 for I := 0 to 2 do
47 begin
48 Timer[I] := TCastleTimer.Create(Application);
49 Timer[I].IntervalSeconds := Power(2, I - 1); //0.5, 1, 2, 4...
50 Timer[I].OnTimer := {$ifdef FPC}@{$endif}TEventHandler.Timer;
51 Timer[I].Tag := I;
52 // without this, timers will slightly desynchronize after a couple of seconds
53 Timer[I].CounteractDelays := true;
54 Window.Controls.InsertFront(Timer[I]);
55
56 Flash[I] := TCastleFlashEffect.Create(Application);
57 Flash[I].FullSize := false;
58 Flash[I].Left := I * 200 + 10;
59 Flash[I].Bottom := 10;
60 Flash[I].Width := 180;
61 Flash[I].Height := 100;
62 Window.Controls.InsertFront(Flash[I]);
63 end;
64
65 Window.OpenAndRun;
66 end.
67