mage_0.6.1_e5032cff/src/mage-event.adb

 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
with Ada.Containers.Vectors;

package body Mage.Event is

   App_Killed : Boolean := False;

   function Is_Killed return Boolean is (App_Killed);

   use all type Keyboard_Event;
   package Keyboard_Event_Vector_Pkg
      is new Ada.Containers.Vectors (Positive, Keyboard_Event);
   subtype Keyboard_Event_Vector is Keyboard_Event_Vector_Pkg.Vector;

   Keyboard_Events : Keyboard_Event_Vector;
   procedure Handle_Events (Window : Mage.Draw.Window_ID) is
      Ev : Event;
   begin
      while Events.Poll (Ev) loop
         case Ev.Common.Event_Type is
            when SDL.Events.Quit =>
               App_Killed := True;
            when SDL.Events.Keyboards.Key_Down | SDL.Events.Keyboards.Key_Up =>
               Keyboard_Events.Append (Ev.Keyboard);
            when others =>
               null;
         end case;
      end loop;

      Mage.Draw.Swap_Buffers (Window);
   end Handle_Events;

   function Poll_Keyboard (Evt : out Keyboard_Event) return Boolean is
   begin
      if not Keyboard_Events.Is_Empty then
         Evt := Keyboard_Events.First_Element;
         Keyboard_Events.Delete_First;
         return True;
      else
         return False;
      end if;
   end Poll_Keyboard;

end Mage.Event;