Debian Codegraph @

src/ui/castleuicontrols_inputinspector.inc

raw
1 {%MainUnit castleuicontrols.pas}
2 {
3 Copyright 2010-2021 Michalis Kamburelis.
4
5 This file is part of "Castle Game Engine".
6
7 "Castle Game Engine" is free software; see the file COPYING.txt,
8 included in this distribution, for details about the copyright.
9
10 "Castle Game Engine" is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 ----------------------------------------------------------------------------
15 }
16
17 {$ifdef read_interface}
18
19 //type
20
21 { How to invoke the inspector, see @link(TCastleContainer.InputInspector). }
22 TInputInspector = class(TComponent)
23 strict private
24 Pressed: TFloatTime;
25 private
26 { Does this TInputPressRelease should toggle the inspector. }
27 function IsEvent(const Event: TInputPressRelease): Boolean;
28
29 { Track should we trigger inspector toggle because of PressFingers/PressTime. }
30 function IsPressed(const Container: TCastleContainer; const SecondsPassed: Single): Boolean;
31 public
32 { Key to activate the inspector (set to keyNone to disable).
33 By default this is keyF8 in debug builds, and keyNone in release. }
34 Key: TKey;
35
36 { Required modifiers to be pressed together with @link(Key).
37 This is [] by default (no modifiers).
38 Ignored when @link(Key) is keyNone. }
39 KeyModifiers: TModifierKeys;
40
41 { Number of fingers necessary to be pressed on a touch device to activate the inspector
42 (set to 0 to disable).
43 By default this is 3 in debug builds, 0 in release.
44 On multi-touch devices (typical mobile devices) this determines
45 the number of fingers you need to press. }
46 PressFingers: Cardinal;
47
48 { How long do the fingers mentioned in @link(PressFingers) have to be pressed.
49 Ignored when @link(PressFingers) is 0. }
50 PressTime: TFloatTime;
51
52 { Describe current TInputInspector state. }
53 function ToString: String; override;
54 end;
55
56 {$endif read_interface}
57
58 {$ifdef read_implementation}
59
60 { TInputInspector ------------------------------------------------------------ }
61
62 function TInputInspector.IsEvent(const Event: TInputPressRelease): Boolean;
63 begin
64 Result := Event.IsKey(Key) and (Event.ModifiersDown = KeyModifiers);
65 end;
66
67 function TInputInspector.IsPressed(const Container: TCastleContainer; const SecondsPassed: Single): Boolean;
68 var
69 PressedNow: Boolean;
70 begin
71 Result := false;
72 // PressFingers checked first, as it will be false in most release builds
73 PressedNow := (PressFingers <> 0) and
74 ApplicationProperties.TouchDevice and
75 (Container.TouchesCount >= PressFingers);
76 if PressedNow then
77 begin
78 Pressed := Pressed + SecondsPassed;
79 if Pressed >= PressTime then
80 begin
81 Result := true;
82 Pressed := 0;
83 end;
84 end else
85 Pressed := 0;
86 end;
87
88 function TInputInspector.ToString: String;
89 var
90 MK: TModifierKey;
91 begin
92 Result := '';
93
94 if Key <> keyNone then
95 begin
96 for MK in KeyModifiers do
97 Result := Result + KeyToStr(ModifierKeyToKey[MK]) + '+';
98 Result := Result + KeyToStr(Key);
99 end;
100
101 if PressFingers <> 0 then
102 begin
103 Result := SAppendPart(Result, ' / ', Format('Press %d fingers', [PressFingers]));
104 end;
105 end;
106
107 {$endif read_implementation}