Debian Codegraph @

examples/user_interface/ui_batching/code/gameviewmain.pas

raw
1 {
2 Copyright 2024-2024 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 LabelStats: TCastleLabel;
33 CheckboxBatchUi: TCastleCheckbox;
34 private
35 procedure CheckboxBatchUiChange(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 CastleGLImages, CastleLog;
49
50 { TViewMain ----------------------------------------------------------------- }
51
52 constructor TViewMain.Create(AOwner: TComponent);
53 begin
54 inherited;
55 DesignUrl := 'castle-data:/gameviewmain.castle-user-interface';
56 end;
57
58 procedure TViewMain.Start;
59 begin
60 inherited;
61
62 { Make initial state of UserInterfaceBatching
63 matching CheckboxBatchUi.Checked initially. }
64 Container.UserInterfaceBatching := CheckboxBatchUi.Checked;
65
66 CheckboxBatchUi.OnChange := {$ifdef FPC}@{$endif} CheckboxBatchUiChange;
67 end;
68
69 procedure TViewMain.CheckboxBatchUiChange(Sender: TObject);
70 begin
71 Container.UserInterfaceBatching := CheckboxBatchUi.Checked;
72 end;
73
74 procedure TViewMain.Update(const SecondsPassed: Single; var HandleInput: Boolean);
75 begin
76 inherited;
77 Assert(LabelFps <> nil, 'If you remove LabelFps from the design, remember to remove also the assignment "LabelFps.Caption := ..." from code');
78 LabelFps.Caption := 'FPS: ' + Container.Fps.ToString;
79 LabelStats.Caption := 'TDrawableImage.Statistics: ' + TDrawableImage.Statistics.ToString;
80 end;
81
82 end.