Debian Codegraph @

src/ui/castleinternaljoysticksexplicit.pas

raw
1 {
2 Copyright 2019-2019 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 { Joystick backend getting notified about joystick state by external API. }
17 unit CastleInternalJoysticksExplicit;
18
19 interface
20
21 uses CastleJoysticks, CastleVectors;
22
23 type
24 TExplicitJoystickBackend = class(TJoysticksBackend)
25 procedure Initialize(const List: TJoystickList); override;
26 procedure Poll(const List: TJoystickList;
27 const EventContainer: TJoysticks); override;
28 procedure SetJoystickCount(const List: TJoystickList; const NewJoystickCount: Integer);
29 procedure SetJoystickAxis(const List: TJoystickList; const JoystickIndex: Integer; const Axis: TVector2);
30 end;
31
32 implementation
33
34 uses CastleUtils, CastleLog;
35
36 procedure TExplicitJoystickBackend.Initialize(const List: TJoystickList);
37 begin
38 end;
39
40 procedure TExplicitJoystickBackend.Poll(const List: TJoystickList;
41 const EventContainer: TJoysticks);
42 begin
43 end;
44
45 procedure TExplicitJoystickBackend.SetJoystickCount(const List: TJoystickList; const NewJoystickCount: Integer);
46 var
47 I: Integer;
48 begin
49 List.Clear;
50 for I := 0 to NewJoystickCount - 1 do
51 List.Add(TJoystick.Create);
52 end;
53
54 procedure TExplicitJoystickBackend.SetJoystickAxis(const List: TJoystickList; const JoystickIndex: Integer; const Axis: TVector2);
55 var
56 Joystick: TJoystick;
57 begin
58 if Between(JoystickIndex, 0, List.Count - 1) then
59 begin
60 Joystick := List[JoystickIndex];
61 Joystick.State.Axis[JOY_AXIS_X] := Axis.X;
62 Joystick.State.Axis[JOY_AXIS_Y] := Axis.Y;
63 end else
64 WriteLnWarning('Joystick index %d given to CGEApp_JoystickAxis is incorrect. Current joystick count (given to CGEApp_JoystickCount) is %d.', [
65 JoystickIndex,
66 List.Count
67 ]);
68 end;
69
70 end.