| 1 |
{ |
| 2 |
Copyright 2020-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 |
CastleScene, CastleControls, |
| 23 |
CastleKeysMouse, CastleColors, CastleViewport, CastleUIControls, |
| 24 |
CastleActivityRecognition; |
| 25 |
|
| 26 |
type |
| 27 |
{ Main view, where most of the application logic takes place. } |
| 28 |
TViewMain = class(TCastleView) |
| 29 |
published |
| 30 |
{ Components designed using CGE editor. |
| 31 |
These fields will be automatically initialized at Start. } |
| 32 |
LabelStatus: TCastleLabel; |
| 33 |
ButtonStartListening: TCastleButton; |
| 34 |
ButtonStopListening: TCastleButton; |
| 35 |
private |
| 36 |
ActivityRecognition: TActivityRecognition; |
| 37 |
procedure ClickStartListening(Sender: TObject); |
| 38 |
procedure ClickStopListening(Sender: TObject); |
| 39 |
procedure ActivityRecognitionChange(Sender: TObject); |
| 40 |
procedure UpdateStatus; |
| 41 |
public |
| 42 |
constructor Create(AOwner: TComponent); override; |
| 43 |
procedure Start; override; |
| 44 |
end; |
| 45 |
|
| 46 |
var |
| 47 |
ViewMain: TViewMain; |
| 48 |
|
| 49 |
implementation |
| 50 |
|
| 51 |
uses SysUtils, |
| 52 |
CastleUtils, CastleComponentSerialize; |
| 53 |
|
| 54 |
{ TViewMain ----------------------------------------------------------------- } |
| 55 |
|
| 56 |
constructor TViewMain.Create(AOwner: TComponent); |
| 57 |
begin |
| 58 |
inherited; |
| 59 |
DesignUrl := 'castle-data:/gameviewmain.castle-user-interface'; |
| 60 |
end; |
| 61 |
|
| 62 |
procedure TViewMain.Start; |
| 63 |
begin |
| 64 |
inherited; |
| 65 |
|
| 66 |
ButtonStartListening.OnClick := {$ifdef FPC}@{$endif} ClickStartListening; |
| 67 |
ButtonStopListening.OnClick := {$ifdef FPC}@{$endif} ClickStopListening; |
| 68 |
|
| 69 |
ActivityRecognition := TActivityRecognition.Create(FreeAtStop); |
| 70 |
ActivityRecognition.OnChange := {$ifdef FPC}@{$endif} ActivityRecognitionChange; |
| 71 |
ActivityRecognition.Start; |
| 72 |
|
| 73 |
UpdateStatus; |
| 74 |
end; |
| 75 |
|
| 76 |
procedure TViewMain.UpdateStatus; |
| 77 |
var |
| 78 |
S: String; |
| 79 |
begin |
| 80 |
S := 'Started:' + BoolToStr(ActivityRecognition.Started, true) + NL + NL; |
| 81 |
if not ActivityRecognition.ActivityValid then |
| 82 |
S := S + 'Not yet detected anything.' + NL |
| 83 |
else |
| 84 |
S := S + 'Detected:' + NL + |
| 85 |
NL + |
| 86 |
'Possible Activities:' + NL + |
| 87 |
PossibleActivitiesToStr(ActivityRecognition.PossibleActivities, ',') + NL + |
| 88 |
NL + |
| 89 |
'Most Useful Activity' + NL + |
| 90 |
'(from the Possible set):' + NL + |
| 91 |
ActivityToStr(ActivityRecognition.Activity) + NL + |
| 92 |
NL + |
| 93 |
'Confidence:' + NL + |
| 94 |
ActivityConfidenceToStr(ActivityRecognition.ActivityConfidence) + NL + |
| 95 |
NL + |
| 96 |
'Changed at: ' + FormatDateTime('yyyy"-"mm"-"dd" "tt', ActivityRecognition.ActivityTime) + NL; |
| 97 |
LabelStatus.Caption := S; |
| 98 |
end; |
| 99 |
|
| 100 |
procedure TViewMain.ClickStartListening(Sender: TObject); |
| 101 |
begin |
| 102 |
ActivityRecognition.Start; |
| 103 |
UpdateStatus; |
| 104 |
end; |
| 105 |
|
| 106 |
procedure TViewMain.ClickStopListening(Sender: TObject); |
| 107 |
begin |
| 108 |
ActivityRecognition.Stop; |
| 109 |
UpdateStatus; |
| 110 |
end; |
| 111 |
|
| 112 |
procedure TViewMain.ActivityRecognitionChange(Sender: TObject); |
| 113 |
begin |
| 114 |
UpdateStatus; |
| 115 |
end; |
| 116 |
|
| 117 |
end. |