src/events/SDL_windowevents.c
author Edgar Simo <bobbens@gmail.com>
Mon, 28 Jul 2008 10:26:21 +0000
branchgsoc2008_force_feedback
changeset 2549 491e43f427ee
parent 1970 db3ba6c0d0df
child 2794 f7872b7a8732
permissions -rw-r--r--
Put haptic defines in SDL_configs, patch by Alam.
     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         SDL_OnWindowShown(window);
    48         break;
    49     case SDL_WINDOWEVENT_HIDDEN:
    50         if (!(window->flags & SDL_WINDOW_SHOWN)) {
    51             return 0;
    52         }
    53         window->flags &= ~SDL_WINDOW_SHOWN;
    54         SDL_OnWindowHidden(window);
    55         break;
    56     case SDL_WINDOWEVENT_MOVED:
    57         if (window->flags & SDL_WINDOW_FULLSCREEN) {
    58             return 0;
    59         }
    60         if (data1 == window->x && data2 == window->y) {
    61             return 0;
    62         }
    63         window->x = data1;
    64         window->y = data2;
    65         break;
    66     case SDL_WINDOWEVENT_RESIZED:
    67         if (window->flags & SDL_WINDOW_FULLSCREEN) {
    68             return 0;
    69         }
    70         if (data1 == window->w && data2 == window->h) {
    71             return 0;
    72         }
    73         window->w = data1;
    74         window->h = data2;
    75         SDL_OnWindowResized(window);
    76         break;
    77     case SDL_WINDOWEVENT_MINIMIZED:
    78         if (window->flags & SDL_WINDOW_MINIMIZED) {
    79             return 0;
    80         }
    81         window->flags |= SDL_WINDOW_MINIMIZED;
    82         break;
    83     case SDL_WINDOWEVENT_MAXIMIZED:
    84         if (window->flags & SDL_WINDOW_MAXIMIZED) {
    85             return 0;
    86         }
    87         window->flags |= SDL_WINDOW_MAXIMIZED;
    88         break;
    89     case SDL_WINDOWEVENT_RESTORED:
    90         if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
    91             return 0;
    92         }
    93         window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
    94         break;
    95     case SDL_WINDOWEVENT_ENTER:
    96         if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
    97             return 0;
    98         }
    99         window->flags |= SDL_WINDOW_MOUSE_FOCUS;
   100         break;
   101     case SDL_WINDOWEVENT_LEAVE:
   102         if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
   103             return 0;
   104         }
   105         window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
   106         break;
   107     case SDL_WINDOWEVENT_FOCUS_GAINED:
   108         if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
   109             return 0;
   110         }
   111         window->flags |= SDL_WINDOW_INPUT_FOCUS;
   112         SDL_OnWindowFocusGained(window);
   113         break;
   114     case SDL_WINDOWEVENT_FOCUS_LOST:
   115         if (!(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
   116             return 0;
   117         }
   118         window->flags &= ~SDL_WINDOW_INPUT_FOCUS;
   119         SDL_OnWindowFocusLost(window);
   120         break;
   121     }
   122 
   123     /* Post the event, if desired */
   124     posted = 0;
   125     if (SDL_ProcessEvents[SDL_WINDOWEVENT] == SDL_ENABLE) {
   126         SDL_Event event;
   127         event.type = SDL_WINDOWEVENT;
   128         event.window.event = windowevent;
   129         event.window.data1 = data1;
   130         event.window.data2 = data2;
   131         event.window.windowID = windowID;
   132         posted = (SDL_PushEvent(&event) > 0);
   133     }
   134     return (posted);
   135 }
   136 
   137 /* vi: set ts=4 sw=4 expandtab: */