src/events/SDL_windowevents.c
changeset 1895 c121d94672cb
child 1915 a228436a2404
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/events/SDL_windowevents.c	Mon Jul 10 21:04:37 2006 +0000
     1.3 @@ -0,0 +1,132 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997-2006 Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Lesser General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2.1 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Lesser General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Lesser General Public
    1.19 +    License along with this library; if not, write to the Free Software
    1.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +*/
    1.25 +#include "SDL_config.h"
    1.26 +
    1.27 +/* Window event handling code for SDL */
    1.28 +
    1.29 +#include "SDL_events.h"
    1.30 +#include "SDL_events_c.h"
    1.31 +#include "../video/SDL_sysvideo.h"
    1.32 +
    1.33 +int
    1.34 +SDL_SendWindowEvent(SDL_WindowID windowID, Uint8 windowevent, int data1,
    1.35 +                    int data2)
    1.36 +{
    1.37 +    int posted;
    1.38 +    SDL_Window *window;
    1.39 +
    1.40 +    window = SDL_GetWindowFromID(windowID);
    1.41 +    if (!window) {
    1.42 +        return 0;
    1.43 +    }
    1.44 +    switch (windowevent) {
    1.45 +    case SDL_WINDOWEVENT_SHOWN:
    1.46 +        if (window->flags & SDL_WINDOW_SHOWN) {
    1.47 +            return 0;
    1.48 +        }
    1.49 +        window->flags |= SDL_WINDOW_SHOWN;
    1.50 +        SDL_OnWindowShown(window);
    1.51 +        break;
    1.52 +    case SDL_WINDOWEVENT_HIDDEN:
    1.53 +        if (!(window->flags & SDL_WINDOW_SHOWN)) {
    1.54 +            return 0;
    1.55 +        }
    1.56 +        window->flags &= ~SDL_WINDOW_SHOWN;
    1.57 +        SDL_OnWindowHidden(window);
    1.58 +        break;
    1.59 +    case SDL_WINDOWEVENT_MOVED:
    1.60 +        if (window->flags & SDL_WINDOW_FULLSCREEN) {
    1.61 +            return 0;
    1.62 +        }
    1.63 +        if (data1 == window->x && data2 == window->y) {
    1.64 +            return 0;
    1.65 +        }
    1.66 +        break;
    1.67 +    case SDL_WINDOWEVENT_RESIZED:
    1.68 +        if (window->flags & SDL_WINDOW_FULLSCREEN) {
    1.69 +            return 0;
    1.70 +        }
    1.71 +        if (data1 == window->w && data2 == window->h) {
    1.72 +            return 0;
    1.73 +        }
    1.74 +        break;
    1.75 +    case SDL_WINDOWEVENT_MINIMIZED:
    1.76 +        if (window->flags & SDL_WINDOW_MINIMIZED) {
    1.77 +            return 0;
    1.78 +        }
    1.79 +        window->flags |= SDL_WINDOW_MINIMIZED;
    1.80 +        break;
    1.81 +    case SDL_WINDOWEVENT_MAXIMIZED:
    1.82 +        if (window->flags & SDL_WINDOW_MAXIMIZED) {
    1.83 +            return 0;
    1.84 +        }
    1.85 +        window->flags |= SDL_WINDOW_MAXIMIZED;
    1.86 +        break;
    1.87 +    case SDL_WINDOWEVENT_RESTORED:
    1.88 +        if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
    1.89 +            return 0;
    1.90 +        }
    1.91 +        window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
    1.92 +        break;
    1.93 +    case SDL_WINDOWEVENT_ENTER:
    1.94 +        if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
    1.95 +            return 0;
    1.96 +        }
    1.97 +        window->flags |= SDL_WINDOW_MOUSE_FOCUS;
    1.98 +        break;
    1.99 +    case SDL_WINDOWEVENT_LEAVE:
   1.100 +        if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
   1.101 +            return 0;
   1.102 +        }
   1.103 +        window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
   1.104 +        break;
   1.105 +    case SDL_WINDOWEVENT_FOCUS_GAINED:
   1.106 +        if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
   1.107 +            return 0;
   1.108 +        }
   1.109 +        window->flags |= SDL_WINDOW_INPUT_FOCUS;
   1.110 +        SDL_OnWindowFocusGained(window);
   1.111 +        break;
   1.112 +    case SDL_WINDOWEVENT_FOCUS_LOST:
   1.113 +        if (!(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
   1.114 +            return 0;
   1.115 +        }
   1.116 +        window->flags &= ~SDL_WINDOW_INPUT_FOCUS;
   1.117 +        SDL_OnWindowFocusLost(window);
   1.118 +        break;
   1.119 +    }
   1.120 +
   1.121 +    /* Post the event, if desired */
   1.122 +    posted = 0;
   1.123 +    if (SDL_ProcessEvents[SDL_WINDOWEVENT] == SDL_ENABLE) {
   1.124 +        SDL_Event event;
   1.125 +        event.type = SDL_WINDOWEVENT;
   1.126 +        event.window.event = windowevent;
   1.127 +        event.window.data1 = data1;
   1.128 +        event.window.data2 = data2;
   1.129 +        event.window.windowID = windowID;
   1.130 +        posted = (SDL_PushEvent(&event) > 0);
   1.131 +    }
   1.132 +    return (posted);
   1.133 +}
   1.134 +
   1.135 +/* vi: set ts=4 sw=4 expandtab: */