src/events/SDL_windowevents.c
author Sam Lantinga
Sat, 08 Jul 2006 20:07:08 +0000
branchSDL-1.3
changeset 1731 875c3cf1a12c
parent 1724 6c63fc2bd986
child 1733 0b1070f2f94d
permissions -rw-r--r--
SDL_PushEvent() calls the event filter code, and has a return value to tell
whether or not the event was actually pushed.
SDL_GetEventFilter() now returns an SDL_bool instead of the filter function.
     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_SendWindowEvent(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_MOVED:
    55         if (data1 == window->x && data2 == window->y) {
    56             return 0;
    57         }
    58         break;
    59     case SDL_WINDOWEVENT_RESIZED:
    60         if (data1 == window->w && data2 == window->h) {
    61             return 0;
    62         }
    63         break;
    64     case SDL_WINDOWEVENT_MINIMIZED:
    65         if (window->flags & SDL_WINDOW_MINIMIZED) {
    66             return 0;
    67         }
    68         window->flags |= SDL_WINDOW_MINIMIZED;
    69         break;
    70     case SDL_WINDOWEVENT_MAXIMIZED:
    71         if (window->flags & SDL_WINDOW_MAXIMIZED) {
    72             return 0;
    73         }
    74         window->flags |= SDL_WINDOW_MAXIMIZED;
    75         break;
    76     case SDL_WINDOWEVENT_RESTORED:
    77         if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
    78             return 0;
    79         }
    80         window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
    81         break;
    82     case SDL_WINDOWEVENT_ENTER:
    83         if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
    84             return 0;
    85         }
    86         window->flags |= SDL_WINDOW_MOUSE_FOCUS;
    87         break;
    88     case SDL_WINDOWEVENT_LEAVE:
    89         if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
    90             return 0;
    91         }
    92         window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
    93         break;
    94     case SDL_WINDOWEVENT_FOCUS_GAINED:
    95         if (window->flags & SDL_WINDOW_KEYBOARD_FOCUS) {
    96             return 0;
    97         }
    98         window->flags |= SDL_WINDOW_KEYBOARD_FOCUS;
    99         break;
   100     case SDL_WINDOWEVENT_FOCUS_LOST:
   101         if (!(window->flags & SDL_WINDOW_KEYBOARD_FOCUS)) {
   102             return 0;
   103         }
   104         window->flags &= ~SDL_WINDOW_KEYBOARD_FOCUS;
   105         break;
   106     }
   107 
   108     /* Post the event, if desired */
   109     posted = 0;
   110     if (SDL_ProcessEvents[SDL_WINDOWEVENT] == SDL_ENABLE) {
   111         SDL_Event event;
   112         event.type = SDL_WINDOWEVENT;
   113         event.window.event = windowevent;
   114         event.window.data1 = data1;
   115         event.window.data2 = data2;
   116         event.window.windowID = windowID;
   117         posted = (SDL_PushEvent(&event) > 0);
   118     }
   119     return (posted);
   120 }
   121 
   122 /* vi: set ts=4 sw=4 expandtab: */