sdlada_2.5.20_cd53c280/src/inputs/sdl-inputs-joysticks.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
--------------------------------------------------------------------------------------------------------------------
--  This source code is subject to the Zlib license, see the LICENCE file in the root of this directory.
--------------------------------------------------------------------------------------------------------------------
--  SDL.Inputs.Joysticks
--------------------------------------------------------------------------------------------------------------------
with Ada.Finalization;
private with SDL.C_Pointers;
with SDL.Events.Joysticks;

package SDL.Inputs.Joysticks is
   pragma Preelaborate;

   Joystick_Error : exception;

   --  Use to determine whether there are no joysticks.
   type All_Devices is range 0 .. 2 ** 31 - 1 with
     Convention => C,
     Size       => 32;

   --  This range is the range of all connected joysticks.
   subtype Devices is All_Devices range All_Devices'First + 1 .. All_Devices'Last;

   --  SDL_Joystick_ID = instance ID.
   type Instances is range 0 .. 2 ** 31 - 1 with
     Convention => C,
     Size       => 32;

   type GUID_Element is range 0 .. 255 with
     convention => C,
     Size       => 8;

   type GUID_Array is array (1 .. 16) of aliased GUID_Element with
     Convention => C;
   --     Pack       => True;

   type GUIDs is
      record
         Data : GUID_Array;
      end record with
     Convention => C_Pass_By_Copy;

   --  Device specific information.
   function Total return All_Devices;
   function Name (Device : in Devices) return String;
   function GUID (Device : in Devices) return GUIDs;

   --  GUID utilities.
   function Image (GUID : in GUIDs) return String;
   function Value (GUID : in String) return GUIDs;

   --  Joysticks.
   type Joystick is new Ada.Finalization.Limited_Controlled with private;

   Null_Joystick : constant Joystick;

   function "=" (Left, Right : in Joystick) return Boolean with
     Inline => True;

   procedure Close (Self : in out Joystick);

   --  Information.
   function Axes (Self : in Joystick) return SDL.Events.Joysticks.Axes;
   function Balls (Self : in Joystick) return SDL.Events.Joysticks.Balls;
   function Buttons (Self : in Joystick) return SDL.Events.Joysticks.Buttons;
   function Hats (Self : in Joystick) return SDL.Events.Joysticks.Hats;
   function Name (Self : in Joystick) return String;
   function Is_Haptic (Self : in Joystick) return Boolean;

   function Is_Attached (Self : in Joystick) return Boolean with
     Inline => True;

   function GUID (Self : in Joystick) return GUIDs with
     Inline => True;

   function Instance (Self : in Joystick) return Instances;

   --  Data.
   function Axis_Value (Self : in Joystick;
                        Axis : in SDL.Events.Joysticks.Axes) return SDL.Events.Joysticks.Axes_Values;

   procedure Ball_Value (Self             : in Joystick;
                         Ball             : in SDL.Events.Joysticks.Balls;
                         Delta_X, Delta_Y : out SDL.Events.Joysticks.Ball_Values);

   function Hat_Value (Self : in Joystick;
                       Hat  : in SDL.Events.Joysticks.Hats) return SDL.Events.Joysticks.Hat_Positions;

   function Is_Button_Pressed (Self : in Joystick; Button : in SDL.Events.Joysticks.Buttons)
                               return SDL.Events.Button_State;
private
   type Joystick is new Ada.Finalization.Limited_Controlled with
      record
         Internal : SDL.C_Pointers.Joystick_Pointer := null;
         Owns     : Boolean                         := True;
      end record;

   Null_Joystick : constant Joystick := (Ada.Finalization.Limited_Controlled with Internal => null, Owns => True);
end SDL.Inputs.Joysticks;