Debian Codegraph @

examples/mobile/on_screen_keyboard/code/gameviewmain.pas

raw
1 {
2 Copyright 2022 Andrzej Kilijanski, 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, CastleAds, CastleOpenDocument;
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 ButtonShow: TCastleButton;
33 ButtonHide: TCastleButton;
34 Edit1: TCastleEdit;
35 public
36 constructor Create(AOwner: TComponent); override;
37 procedure Start; override;
38 procedure Update(const SecondsPassed: Single; var HandleInput: Boolean); override;
39
40 procedure ButtonShowClick(Sender: TObject);
41 procedure ButtonHideClick(Sender: TObject);
42 end;
43
44 var
45 ViewMain: TViewMain;
46
47 implementation
48
49 uses SysUtils, CastleWindow;
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 ButtonShow.OnClick := {$ifdef FPC}@{$endif}ButtonShowClick;
63 ButtonHide.OnClick := {$ifdef FPC}@{$endif}ButtonHideClick;
64 end;
65
66 procedure TViewMain.Update(const SecondsPassed: Single; var HandleInput: Boolean);
67 begin
68 inherited;
69 { This virtual method is executed every frame.}
70 Assert(LabelFps <> nil, 'If you remove LabelFps from the design, remember to remove also the assignment "LabelFps.Caption := ..." from code');
71 LabelFps.Caption := 'FPS: ' + Container.Fps.ToString;
72 end;
73
74 procedure TViewMain.ButtonShowClick(Sender: TObject);
75 begin
76 Edit1.Focused := true;
77 end;
78
79 procedure TViewMain.ButtonHideClick(Sender: TObject);
80 begin
81 Edit1.Focused := false;
82 end;
83
84 end.