Exemplo n.º 1
0
        /// <summary>
        /// Returns an array of events in the event queue.
        /// It does not remove them from the event queue.
        /// </summary>
        /// <param name="eventMask">Mask of events to find in queue</param>
        /// <param name="numberOfEvents">Number of events to find in queue</param>
        /// <returns>Array of events in queue.</returns>
        public static SdlEventArgs[] Peek(EventMask eventMask, int numberOfEvents)
        {
            Sdl.SDL_Event[] events = new Sdl.SDL_Event[numberOfEvents];
            Sdl.SDL_PumpEvents();
            int result =
                Sdl.SDL_PeepEvents(
                    events,
                    events.Length,
                    Sdl.SDL_PEEKEVENT,
                    (int)eventMask);

            if (result == (int)SdlFlag.Error)
            {
                throw SdlException.Generate();
            }
            SdlEventArgs[] eventsArray = new SdlEventArgs[result];
            for (int i = 0; i < eventsArray.Length; i++)
            {
                if (events[i].type == (byte)EventTypes.UserEvent)
                {
                    eventsArray[i] = (UserEventArgs)userEvents[events[i].user.code];
                }
                else
                {
                    eventsArray[i] = SdlEventArgs.CreateEventArgs(events[i]);
                }
            }
            return(eventsArray);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Checks the event queue, and processes
 /// any events it finds by invoking the event properties
 /// </summary>
 /// <returns>
 /// True if any events were in the queue, otherwise False
 /// </returns>
 public static bool Poll()
 {
     try
     {
         Sdl.SDL_Event ev;
         int           ret = Sdl.SDL_PollEvent(out ev);
         if (ret == (int)SdlFlag.Error)
         {
             throw SdlException.Generate();
         }
         if (ret == (int)SdlFlag.None)
         {
             return(false);
         }
         else
         {
             ProcessEvent(ev);
             return(true);
         }
     }
     catch (AccessViolationException)
     {
         return(false);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Checks the event queue, and waits until an event is available
 /// </summary>
 /// <remarks></remarks>
 public static void Wait()
 {
     Sdl.SDL_Event ev;
     if (Sdl.SDL_WaitEvent(out ev) == (int)SdlFlag.Error2)
     {
         throw SdlException.Generate();
     }
     ProcessEvent(ev);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initialize timer.
 /// </summary>
 public static bool Initialize()
 {
     if ((Sdl.SDL_WasInit(Sdl.SDL_INIT_TIMER))
         == (int)SdlFlag.FalseValue)
     {
         if (Sdl.SDL_Init(Sdl.SDL_INIT_TIMER) != (int)SdlFlag.Success)
         {
             throw SdlException.Generate();
         }
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Returns an array of events in the event queue.
        /// </summary>
        /// <param name="eventMask">Mask for event that will be removed from queue</param>
        /// <param name="numberOfEvents">Number of events to remove</param>
        public static void Remove(EventMask eventMask, int numberOfEvents)
        {
            Sdl.SDL_Event[] events = new Sdl.SDL_Event[numberOfEvents];
            Sdl.SDL_PumpEvents();
            int result =
                Sdl.SDL_PeepEvents(
                    events,
                    events.Length,
                    Sdl.SDL_GETEVENT,
                    (int)eventMask);

            if (result == (int)SdlFlag.Error)
            {
                throw SdlException.Generate();
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Polls and processes a given number of events before returning false
 /// </summary>
 /// <remarks>If the are no more events, the method will return false</remarks>
 /// <param name="numberOfEvents">
 /// Nunmber of events to process at a time at most
 /// </param>
 /// <returns>Returns false when done processing events</returns>
 public static bool Poll(int numberOfEvents)
 {
     Sdl.SDL_Event ev;
     for (int i = 0; i <= numberOfEvents; i++)
     {
         int ret = Sdl.SDL_PollEvent(out ev);
         if (ret == (int)SdlFlag.Error)
         {
             throw SdlException.Generate();
         }
         if (ret == (int)SdlFlag.None)
         {
             break;
         }
         else
         {
             ProcessEvent(ev);
         }
     }
     return(false);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Returns basic exception
 /// </summary>
 public SdlException()
 {
     SdlException.Generate();
 }