Debian Codegraph @

examples/images_videos/image_display/code/gameviewmain.pas

raw
1 {
2 Copyright 2021-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 { Main view, where most of the application logic takes place. }
17 unit GameViewMain;
18
19 interface
20
21 uses Classes,
22 CastleVectors, CastleComponentSerialize,
23 CastleUIControls, CastleControls, CastleKeysMouse;
24
25 type
26 { Main view, where most of the application logic takes place. }
27 TViewMain = class(TCastleView)
28 published
29 { Components designed using CGE editor.
30 These fields will be automatically initialized at Start. }
31 LabelFps: TCastleLabel;
32 ButtonQuit, ButtonGoSpeedTest: TCastleButton;
33 private
34 procedure ClickQuit(Sender: TObject);
35 procedure ClickGoSpeedTest(Sender: TObject);
36 public
37 constructor Create(AOwner: TComponent); override;
38 procedure Start; override;
39 procedure Update(const SecondsPassed: Single; var HandleInput: Boolean); override;
40 end;
41
42 var
43 ViewMain: TViewMain;
44
45 implementation
46
47 uses SysUtils,
48 CastleApplicationProperties, CastleWindow,
49 GameViewSpeedTest;
50
51 { TViewMain ----------------------------------------------------------------- }
52
53 constructor TViewMain.Create(AOwner: TComponent);
54 begin
55 inherited;
56 DesignUrl := 'castle-data:/gameviewmain.castle-user-interface';
57 end;
58
59 procedure TViewMain.Start;
60 begin
61 inherited;
62
63 // on some platforms, showing "Quit" button in applications is unusual
64 ButtonQuit.Exists := ApplicationProperties.ShowUserInterfaceToQuit;
65
66 ButtonQuit.OnClick := {$ifdef FPC}@{$endif} ClickQuit;
67 ButtonGoSpeedTest.OnClick := {$ifdef FPC}@{$endif} ClickGoSpeedTest;
68 end;
69
70 procedure TViewMain.Update(const SecondsPassed: Single; var HandleInput: Boolean);
71 begin
72 inherited;
73 { This virtual method is executed every frame (many times per second). }
74 LabelFps.Caption := 'FPS: ' + Container.Fps.ToString;
75 end;
76
77 procedure TViewMain.ClickQuit(Sender: TObject);
78 begin
79 Application.Terminate;
80 end;
81
82 procedure TViewMain.ClickGoSpeedTest(Sender: TObject);
83 begin
84 Container.View := ViewSpeedTest;
85 end;
86
87 end.