mage_0.6.1_e5032cff/src/mage-input.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
 99
100
101
102
103
with Ada.Containers.Ordered_Sets;

with SDL.Events.Keyboards;

package Mage.Input is

   package Keyboards renames SDL.Events.Keyboards;

   --  Inputs
   --
   --  Inputs are separated into actions and modifiers on those actions.
   --  Underneath they are mapped to any input device.

   type Action is
     (Up, Down, Left, Right, Turn_Left, Turn_Right, Strafe_Left, Strafe_Right,

      Jump, Crouch, Prone, Enter, Escape, Interact, Talk, Grab, Release, Push,
      Pull, Open, Close);

   subtype Absolute_Direction is Action range Up .. Right;
   subtype Relative_Direction is Action range Turn_Left .. Strafe_Right;
   subtype Posture is Action range Jump .. Prone;
   subtype Interaction is Action range Enter .. Close;

   type Modifier is (Any, None, Strong, Weak, Fast, Slow, High, Low, Super);

   subtype Configurable_Modifier is Modifier range None .. Modifier'Last;
   subtype Existing_Modifier is Modifier range Strong .. Modifier'Last;

   type Modifier_Flags is array (Existing_Modifier) of Boolean;

   type Mod_Key is (Shift, Ctrl, Alt);

   --------------
   -- Keyboard --
   --------------

   procedure Map_Keyboard
     (A           : Action; Pressed : Keyboards.Scan_Codes;
      Can_Be_Held : Boolean := True);

   procedure Map_Keyboard
     (A : Action; M : Configurable_Modifier; Pressed : Keyboards.Scan_Codes;
      Can_Be_Held : Boolean := True);

   procedure Map_Keyboard (M : Existing_Modifier; Held : Mod_Key);
   --  Map a modifier key to a modifier, will add the modifier to all actions
   --  that happen while the mod key is being pressed

   -------------
   -- General --
   -------------

   type Keyboard_Layouts is (Unknown, QWERTY, QWERTZ, AZERTY);

   function Keyboard return Keyboard_Layouts;

   procedure Keyboard (L : Keyboard_Layouts; Apply_Presets : Boolean := True);
   --  This is called at initialization

   procedure Clear (A : Action);

   procedure Clear (M : Modifier);

   procedure Clear_All;
   --  NB: Mage uses localized presets, this will clear them

   type Action_Set is tagged private;
   function Global_Actions return Action_Set;

   function Has_Action
     (E : Action_Set; A : Action; M : Modifier := Any) return Boolean;

private

   type Full_Action is record
      Act      : Action;
      Modifier : Modifier_Flags;
   end record;

   function Set_Ordering (A, B : Full_Action) return Boolean is
     (A.Act < B.Act);

   package Action_Sets_Pkg is new Ada.Containers.Ordered_Sets
     (Full_Action, "<" => Set_Ordering);

   type Action_Set is new Action_Sets_Pkg.Set with null record;

   function Is_Action
     (E : Full_Action; A : Action; M : Modifier := Any) return Boolean is
     (E.Act = A
      and then
      (if M /= Any then -- Any = accept all modifiers
         (if M /= None then E.Modifier (M) -- specified modifier must be set
          else
            (for all F of E.Modifier =>
               not F)))); -- None = no modifier must be set

   function Has_Action
     (E : Action_Set; A : Action; M : Modifier := Any) return Boolean is
     (for some V of E => Is_Action (V, A, M));

end Mage.Input;