src/events/SDL_windowevents.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 27 Nov 2008 21:53:18 +0000
changeset 2794 f7872b7a8732
parent 1970 db3ba6c0d0df
child 2849 523b10db69f8
permissions -rw-r--r--
Fixed mouse coordinate range on Mac OS X
     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 "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         SDL_SetMouseFocusSize(windowID, window->w, window->h);
    78         break;
    79     case SDL_WINDOWEVENT_MINIMIZED:
    80         if (window->flags & SDL_WINDOW_MINIMIZED) {
    81             return 0;
    82         }
    83         window->flags |= SDL_WINDOW_MINIMIZED;
    84         break;
    85     case SDL_WINDOWEVENT_MAXIMIZED:
    86         if (window->flags & SDL_WINDOW_MAXIMIZED) {
    87             return 0;
    88         }
    89         window->flags |= SDL_WINDOW_MAXIMIZED;
    90         break;
    91     case SDL_WINDOWEVENT_RESTORED:
    92         if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
    93             return 0;
    94         }
    95         window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
    96         break;
    97     case SDL_WINDOWEVENT_ENTER:
    98         if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
    99             return 0;
   100         }
   101         window->flags |= SDL_WINDOW_MOUSE_FOCUS;
   102         break;
   103     case SDL_WINDOWEVENT_LEAVE:
   104         if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
   105             return 0;
   106         }
   107         window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
   108         break;
   109     case SDL_WINDOWEVENT_FOCUS_GAINED:
   110         if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
   111             return 0;
   112         }
   113         window->flags |= SDL_WINDOW_INPUT_FOCUS;
   114         SDL_OnWindowFocusGained(window);
   115         break;
   116     case SDL_WINDOWEVENT_FOCUS_LOST:
   117         if (!(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
   118             return 0;
   119         }
   120         window->flags &= ~SDL_WINDOW_INPUT_FOCUS;
   121         SDL_OnWindowFocusLost(window);
   122         break;
   123     }
   124 
   125     /* Post the event, if desired */
   126     posted = 0;
   127     if (SDL_ProcessEvents[SDL_WINDOWEVENT] == SDL_ENABLE) {
   128         SDL_Event event;
   129         event.type = SDL_WINDOWEVENT;
   130         event.window.event = windowevent;
   131         event.window.data1 = data1;
   132         event.window.data2 = data2;
   133         event.window.windowID = windowID;
   134         posted = (SDL_PushEvent(&event) > 0);
   135     }
   136     return (posted);
   137 }
   138 
   139 /* vi: set ts=4 sw=4 expandtab: */