src/events/SDL_windowevents.c
author Sam Lantinga
Mon, 08 Dec 2008 00:27:32 +0000
changeset 2859 99210400e8b9
parent 2849 523b10db69f8
child 2875 91a7e08cd238
permissions -rw-r--r--
Updated copyright date
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2009 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 "SDL_mouse_c.h"
    29 #include "../video/SDL_sysvideo.h"
    30 
    31 int
    32 SDL_SendWindowEvent(SDL_WindowID windowID, Uint8 windowevent, int data1,
    33                     int data2)
    34 {
    35     int posted;
    36     SDL_Window *window;
    37 
    38     window = SDL_GetWindowFromID(windowID);
    39     if (!window) {
    40         return 0;
    41     }
    42     switch (windowevent) {
    43     case SDL_WINDOWEVENT_SHOWN:
    44         if (window->flags & SDL_WINDOW_SHOWN) {
    45             return 0;
    46         }
    47         window->flags |= SDL_WINDOW_SHOWN;
    48         SDL_OnWindowShown(window);
    49         break;
    50     case SDL_WINDOWEVENT_HIDDEN:
    51         if (!(window->flags & SDL_WINDOW_SHOWN)) {
    52             return 0;
    53         }
    54         window->flags &= ~SDL_WINDOW_SHOWN;
    55         SDL_OnWindowHidden(window);
    56         break;
    57     case SDL_WINDOWEVENT_MOVED:
    58         if (window->flags & SDL_WINDOW_FULLSCREEN) {
    59             return 0;
    60         }
    61         if (data1 == window->x && data2 == window->y) {
    62             return 0;
    63         }
    64         window->x = data1;
    65         window->y = data2;
    66         break;
    67     case SDL_WINDOWEVENT_RESIZED:
    68         if (window->flags & SDL_WINDOW_FULLSCREEN) {
    69             return 0;
    70         }
    71         if (data1 == window->w && data2 == window->h) {
    72             return 0;
    73         }
    74         window->w = data1;
    75         window->h = data2;
    76         SDL_OnWindowResized(window);
    77         break;
    78     case SDL_WINDOWEVENT_MINIMIZED:
    79         if (window->flags & SDL_WINDOW_MINIMIZED) {
    80             return 0;
    81         }
    82         window->flags |= SDL_WINDOW_MINIMIZED;
    83         break;
    84     case SDL_WINDOWEVENT_MAXIMIZED:
    85         if (window->flags & SDL_WINDOW_MAXIMIZED) {
    86             return 0;
    87         }
    88         window->flags |= SDL_WINDOW_MAXIMIZED;
    89         break;
    90     case SDL_WINDOWEVENT_RESTORED:
    91         if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
    92             return 0;
    93         }
    94         window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
    95         break;
    96     case SDL_WINDOWEVENT_ENTER:
    97         if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
    98             return 0;
    99         }
   100         window->flags |= SDL_WINDOW_MOUSE_FOCUS;
   101         break;
   102     case SDL_WINDOWEVENT_LEAVE:
   103         if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
   104             return 0;
   105         }
   106         window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
   107         break;
   108     case SDL_WINDOWEVENT_FOCUS_GAINED:
   109         if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
   110             return 0;
   111         }
   112         window->flags |= SDL_WINDOW_INPUT_FOCUS;
   113         SDL_OnWindowFocusGained(window);
   114         break;
   115     case SDL_WINDOWEVENT_FOCUS_LOST:
   116         if (!(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
   117             return 0;
   118         }
   119         window->flags &= ~SDL_WINDOW_INPUT_FOCUS;
   120         SDL_OnWindowFocusLost(window);
   121         break;
   122     }
   123 
   124     /* Post the event, if desired */
   125     posted = 0;
   126     if (SDL_ProcessEvents[SDL_WINDOWEVENT] == SDL_ENABLE) {
   127         SDL_Event event;
   128         event.type = SDL_WINDOWEVENT;
   129         event.window.event = windowevent;
   130         event.window.data1 = data1;
   131         event.window.data2 = data2;
   132         event.window.windowID = windowID;
   133         posted = (SDL_PushEvent(&event) > 0);
   134     }
   135     return (posted);
   136 }
   137 
   138 /* vi: set ts=4 sw=4 expandtab: */