src/events/SDL_windowevents.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 08 Jul 2006 20:07:08 +0000
branchSDL-1.3
changeset 1731 875c3cf1a12c
parent 1724 6c63fc2bd986
child 1733 0b1070f2f94d
permissions -rw-r--r--
SDL_PushEvent() calls the event filter code, and has a return value to tell
whether or not the event was actually pushed.
SDL_GetEventFilter() now returns an SDL_bool instead of the filter function.
slouken@1662
     1
/*
slouken@1662
     2
    SDL - Simple DirectMedia Layer
slouken@1662
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@1662
     4
slouken@1662
     5
    This library is free software; you can redistribute it and/or
slouken@1662
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1662
     7
    License as published by the Free Software Foundation; either
slouken@1662
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1662
     9
slouken@1662
    10
    This library is distributed in the hope that it will be useful,
slouken@1662
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1662
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1662
    13
    Lesser General Public License for more details.
slouken@1662
    14
slouken@1662
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1662
    16
    License along with this library; if not, write to the Free Software
slouken@1662
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1662
    18
slouken@1662
    19
    Sam Lantinga
slouken@1662
    20
    slouken@libsdl.org
slouken@1662
    21
*/
slouken@1662
    22
#include "SDL_config.h"
slouken@1662
    23
slouken@1662
    24
/* Window event handling code for SDL */
slouken@1662
    25
slouken@1662
    26
#include "SDL_events.h"
slouken@1662
    27
#include "SDL_events_c.h"
slouken@1722
    28
#include "../video/SDL_sysvideo.h"
slouken@1662
    29
slouken@1662
    30
int
slouken@1724
    31
SDL_SendWindowEvent(SDL_WindowID windowID, Uint8 windowevent, int data1,
slouken@1724
    32
                    int data2)
slouken@1662
    33
{
slouken@1662
    34
    int posted;
slouken@1722
    35
    SDL_Window *window;
slouken@1722
    36
slouken@1722
    37
    window = SDL_GetWindowFromID(windowID);
slouken@1722
    38
    if (!window) {
slouken@1722
    39
        return 0;
slouken@1722
    40
    }
slouken@1722
    41
    switch (windowevent) {
slouken@1722
    42
    case SDL_WINDOWEVENT_SHOWN:
slouken@1722
    43
        if (window->flags & SDL_WINDOW_SHOWN) {
slouken@1722
    44
            return 0;
slouken@1722
    45
        }
slouken@1722
    46
        window->flags |= SDL_WINDOW_SHOWN;
slouken@1722
    47
        break;
slouken@1722
    48
    case SDL_WINDOWEVENT_HIDDEN:
slouken@1722
    49
        if (!(window->flags & SDL_WINDOW_SHOWN)) {
slouken@1722
    50
            return 0;
slouken@1722
    51
        }
slouken@1722
    52
        window->flags &= ~SDL_WINDOW_SHOWN;
slouken@1722
    53
        break;
slouken@1724
    54
    case SDL_WINDOWEVENT_MOVED:
slouken@1724
    55
        if (data1 == window->x && data2 == window->y) {
slouken@1724
    56
            return 0;
slouken@1724
    57
        }
slouken@1724
    58
        break;
slouken@1724
    59
    case SDL_WINDOWEVENT_RESIZED:
slouken@1724
    60
        if (data1 == window->w && data2 == window->h) {
slouken@1724
    61
            return 0;
slouken@1724
    62
        }
slouken@1724
    63
        break;
slouken@1722
    64
    case SDL_WINDOWEVENT_MINIMIZED:
slouken@1722
    65
        if (window->flags & SDL_WINDOW_MINIMIZED) {
slouken@1722
    66
            return 0;
slouken@1722
    67
        }
slouken@1722
    68
        window->flags |= SDL_WINDOW_MINIMIZED;
slouken@1722
    69
        break;
slouken@1722
    70
    case SDL_WINDOWEVENT_MAXIMIZED:
slouken@1722
    71
        if (window->flags & SDL_WINDOW_MAXIMIZED) {
slouken@1722
    72
            return 0;
slouken@1722
    73
        }
slouken@1722
    74
        window->flags |= SDL_WINDOW_MAXIMIZED;
slouken@1722
    75
        break;
slouken@1722
    76
    case SDL_WINDOWEVENT_RESTORED:
slouken@1722
    77
        if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
slouken@1722
    78
            return 0;
slouken@1722
    79
        }
slouken@1722
    80
        window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
slouken@1722
    81
        break;
slouken@1722
    82
    case SDL_WINDOWEVENT_ENTER:
slouken@1722
    83
        if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
slouken@1722
    84
            return 0;
slouken@1722
    85
        }
slouken@1722
    86
        window->flags |= SDL_WINDOW_MOUSE_FOCUS;
slouken@1722
    87
        break;
slouken@1722
    88
    case SDL_WINDOWEVENT_LEAVE:
slouken@1722
    89
        if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
slouken@1722
    90
            return 0;
slouken@1722
    91
        }
slouken@1722
    92
        window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
slouken@1722
    93
        break;
slouken@1722
    94
    case SDL_WINDOWEVENT_FOCUS_GAINED:
slouken@1722
    95
        if (window->flags & SDL_WINDOW_KEYBOARD_FOCUS) {
slouken@1722
    96
            return 0;
slouken@1722
    97
        }
slouken@1722
    98
        window->flags |= SDL_WINDOW_KEYBOARD_FOCUS;
slouken@1722
    99
        break;
slouken@1722
   100
    case SDL_WINDOWEVENT_FOCUS_LOST:
slouken@1722
   101
        if (!(window->flags & SDL_WINDOW_KEYBOARD_FOCUS)) {
slouken@1722
   102
            return 0;
slouken@1722
   103
        }
slouken@1722
   104
        window->flags &= ~SDL_WINDOW_KEYBOARD_FOCUS;
slouken@1722
   105
        break;
slouken@1722
   106
    }
slouken@1662
   107
slouken@1662
   108
    /* Post the event, if desired */
slouken@1662
   109
    posted = 0;
slouken@1662
   110
    if (SDL_ProcessEvents[SDL_WINDOWEVENT] == SDL_ENABLE) {
slouken@1662
   111
        SDL_Event event;
slouken@1662
   112
        event.type = SDL_WINDOWEVENT;
slouken@1662
   113
        event.window.event = windowevent;
slouken@1662
   114
        event.window.data1 = data1;
slouken@1662
   115
        event.window.data2 = data2;
slouken@1662
   116
        event.window.windowID = windowID;
slouken@1731
   117
        posted = (SDL_PushEvent(&event) > 0);
slouken@1662
   118
    }
slouken@1662
   119
    return (posted);
slouken@1662
   120
}
slouken@1662
   121
slouken@1662
   122
/* vi: set ts=4 sw=4 expandtab: */