src/events/SDL_windowevents.c
author Sam Lantinga
Wed, 19 Jul 2006 04:24:41 +0000
changeset 1915 a228436a2404
parent 1895 c121d94672cb
child 1970 db3ba6c0d0df
permissions -rw-r--r--
Implemented multi-window OpenGL program with test framework.
     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         break;
    76     case SDL_WINDOWEVENT_MINIMIZED:
    77         if (window->flags & SDL_WINDOW_MINIMIZED) {
    78             return 0;
    79         }
    80         window->flags |= SDL_WINDOW_MINIMIZED;
    81         break;
    82     case SDL_WINDOWEVENT_MAXIMIZED:
    83         if (window->flags & SDL_WINDOW_MAXIMIZED) {
    84             return 0;
    85         }
    86         window->flags |= SDL_WINDOW_MAXIMIZED;
    87         break;
    88     case SDL_WINDOWEVENT_RESTORED:
    89         if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
    90             return 0;
    91         }
    92         window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
    93         break;
    94     case SDL_WINDOWEVENT_ENTER:
    95         if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
    96             return 0;
    97         }
    98         window->flags |= SDL_WINDOW_MOUSE_FOCUS;
    99         break;
   100     case SDL_WINDOWEVENT_LEAVE:
   101         if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
   102             return 0;
   103         }
   104         window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
   105         break;
   106     case SDL_WINDOWEVENT_FOCUS_GAINED:
   107         if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
   108             return 0;
   109         }
   110         window->flags |= SDL_WINDOW_INPUT_FOCUS;
   111         SDL_OnWindowFocusGained(window);
   112         break;
   113     case SDL_WINDOWEVENT_FOCUS_LOST:
   114         if (!(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
   115             return 0;
   116         }
   117         window->flags &= ~SDL_WINDOW_INPUT_FOCUS;
   118         SDL_OnWindowFocusLost(window);
   119         break;
   120     }
   121 
   122     /* Post the event, if desired */
   123     posted = 0;
   124     if (SDL_ProcessEvents[SDL_WINDOWEVENT] == SDL_ENABLE) {
   125         SDL_Event event;
   126         event.type = SDL_WINDOWEVENT;
   127         event.window.event = windowevent;
   128         event.window.data1 = data1;
   129         event.window.data2 = data2;
   130         event.window.windowID = windowID;
   131         posted = (SDL_PushEvent(&event) > 0);
   132     }
   133     return (posted);
   134 }
   135 
   136 /* vi: set ts=4 sw=4 expandtab: */