| 1 |
{ |
| 2 |
Copyright 2022-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 |
ButtonAnimatedCursor: TCastleButton; |
| 33 |
ButtonImageCursor: TCastleButton; |
| 34 |
ButtonDefaultCursor: TCastleButton; |
| 35 |
private |
| 36 |
procedure ClickAnimatedCursor(Sender: TObject); |
| 37 |
procedure ClickImageCursor(Sender: TObject); |
| 38 |
procedure ClickDefaultCursor(Sender: TObject); |
| 39 |
public |
| 40 |
constructor Create(AOwner: TComponent); override; |
| 41 |
procedure Start; override; |
| 42 |
procedure Update(const SecondsPassed: Single; var HandleInput: Boolean); override; |
| 43 |
end; |
| 44 |
|
| 45 |
var |
| 46 |
ViewMain: TViewMain; |
| 47 |
|
| 48 |
implementation |
| 49 |
|
| 50 |
uses SysUtils, |
| 51 |
GameCustomCursor; |
| 52 |
|
| 53 |
{ TViewMain ----------------------------------------------------------------- } |
| 54 |
|
| 55 |
constructor TViewMain.Create(AOwner: TComponent); |
| 56 |
begin |
| 57 |
inherited; |
| 58 |
DesignUrl := 'castle-data:/gameviewmain.castle-user-interface'; |
| 59 |
end; |
| 60 |
|
| 61 |
procedure TViewMain.Start; |
| 62 |
begin |
| 63 |
inherited; |
| 64 |
|
| 65 |
ButtonAnimatedCursor.OnClick := {$ifdef FPC}@{$endif} ClickAnimatedCursor; |
| 66 |
ButtonImageCursor.OnClick := {$ifdef FPC}@{$endif} ClickImageCursor; |
| 67 |
ButtonDefaultCursor.OnClick := {$ifdef FPC}@{$endif} ClickDefaultCursor; |
| 68 |
|
| 69 |
{ by default, initialize csAnimated, and hide system cursor. } |
| 70 |
ClickAnimatedCursor(nil); |
| 71 |
end; |
| 72 |
|
| 73 |
procedure TViewMain.Update(const SecondsPassed: Single; var HandleInput: Boolean); |
| 74 |
begin |
| 75 |
inherited; |
| 76 |
{ This virtual method is executed every frame (many times per second). } |
| 77 |
LabelFps.Caption := 'FPS: ' + Container.Fps.ToString; |
| 78 |
end; |
| 79 |
|
| 80 |
procedure TViewMain.ClickAnimatedCursor(Sender: TObject); |
| 81 |
begin |
| 82 |
Cursor := mcForceNone; |
| 83 |
CustomCursor.Exists := true; |
| 84 |
CustomCursor.Style := csAnimated; |
| 85 |
end; |
| 86 |
|
| 87 |
procedure TViewMain.ClickImageCursor(Sender: TObject); |
| 88 |
begin |
| 89 |
Cursor := mcForceNone; |
| 90 |
CustomCursor.Exists := true; |
| 91 |
CustomCursor.Style := csImage; |
| 92 |
end; |
| 93 |
|
| 94 |
procedure TViewMain.ClickDefaultCursor(Sender: TObject); |
| 95 |
begin |
| 96 |
Cursor := mcDefault; |
| 97 |
CustomCursor.Exists := false; |
| 98 |
end; |
| 99 |
|
| 100 |
end. |