src/events/SDL_windowevents.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 30 Jun 2006 08:18:44 +0000
branchSDL-1.3
changeset 1722 5daa04d862f1
parent 1668 4da1ee79c9af
child 1724 6c63fc2bd986
permissions -rw-r--r--
Added a userdata parameter for event filters.
Added a function to filter the existing queued events.
Added explicit support for relative mouse mode to the API.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 /* Window event handling code for SDL */
    25 
    26 #include "SDL_events.h"
    27 #include "SDL_events_c.h"
    28 #include "../video/SDL_sysvideo.h"
    29 
    30 int
    31 SDL_PrivateWindowEvent(SDL_WindowID windowID, Uint8 windowevent, int data1,
    32                        int data2)
    33 {
    34     int posted;
    35     SDL_Window *window;
    36 
    37     window = SDL_GetWindowFromID(windowID);
    38     if (!window) {
    39         return 0;
    40     }
    41     switch (windowevent) {
    42     case SDL_WINDOWEVENT_SHOWN:
    43         if (window->flags & SDL_WINDOW_SHOWN) {
    44             return 0;
    45         }
    46         window->flags |= SDL_WINDOW_SHOWN;
    47         break;
    48     case SDL_WINDOWEVENT_HIDDEN:
    49         if (!(window->flags & SDL_WINDOW_SHOWN)) {
    50             return 0;
    51         }
    52         window->flags &= ~SDL_WINDOW_SHOWN;
    53         break;
    54     case SDL_WINDOWEVENT_MINIMIZED:
    55         if (window->flags & SDL_WINDOW_MINIMIZED) {
    56             return 0;
    57         }
    58         window->flags |= SDL_WINDOW_MINIMIZED;
    59         break;
    60     case SDL_WINDOWEVENT_MAXIMIZED:
    61         if (window->flags & SDL_WINDOW_MAXIMIZED) {
    62             return 0;
    63         }
    64         window->flags |= SDL_WINDOW_MAXIMIZED;
    65         break;
    66     case SDL_WINDOWEVENT_RESTORED:
    67         if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
    68             return 0;
    69         }
    70         window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
    71         break;
    72     case SDL_WINDOWEVENT_ENTER:
    73         if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
    74             return 0;
    75         }
    76         window->flags |= SDL_WINDOW_MOUSE_FOCUS;
    77         break;
    78     case SDL_WINDOWEVENT_LEAVE:
    79         if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
    80             return 0;
    81         }
    82         window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
    83         break;
    84     case SDL_WINDOWEVENT_FOCUS_GAINED:
    85         if (window->flags & SDL_WINDOW_KEYBOARD_FOCUS) {
    86             return 0;
    87         }
    88         window->flags |= SDL_WINDOW_KEYBOARD_FOCUS;
    89         break;
    90     case SDL_WINDOWEVENT_FOCUS_LOST:
    91         if (!(window->flags & SDL_WINDOW_KEYBOARD_FOCUS)) {
    92             return 0;
    93         }
    94         window->flags &= ~SDL_WINDOW_KEYBOARD_FOCUS;
    95         break;
    96     }
    97 
    98     /* Post the event, if desired */
    99     posted = 0;
   100     if (SDL_ProcessEvents[SDL_WINDOWEVENT] == SDL_ENABLE) {
   101         SDL_Event event;
   102         event.type = SDL_WINDOWEVENT;
   103         event.window.event = windowevent;
   104         event.window.data1 = data1;
   105         event.window.data2 = data2;
   106         event.window.windowID = windowID;
   107         if ((SDL_EventOK == NULL)
   108             || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
   109             posted = 1;
   110             SDL_PushEvent(&event);
   111         }
   112     }
   113     return (posted);
   114 }
   115 
   116 /* vi: set ts=4 sw=4 expandtab: */