src/events/SDL_windowevents.c
author Sam Lantinga
Sun, 09 Jul 2006 09:02:26 +0000
branchSDL-1.3
changeset 1733 0b1070f2f94d
parent 1731 875c3cf1a12c
child 1734 f7c667ded87d
permissions -rw-r--r--
Implemented gamma correction on Windows.
Added general code to restore the video mode and gamma when windows lose focus.
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@1733
    47
        SDL_OnWindowShown(window);
slouken@1722
    48
        break;
slouken@1722
    49
    case SDL_WINDOWEVENT_HIDDEN:
slouken@1722
    50
        if (!(window->flags & SDL_WINDOW_SHOWN)) {
slouken@1722
    51
            return 0;
slouken@1722
    52
        }
slouken@1722
    53
        window->flags &= ~SDL_WINDOW_SHOWN;
slouken@1733
    54
        SDL_OnWindowHidden(window);
slouken@1722
    55
        break;
slouken@1724
    56
    case SDL_WINDOWEVENT_MOVED:
slouken@1733
    57
        if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@1733
    58
            return 0;
slouken@1733
    59
        }
slouken@1724
    60
        if (data1 == window->x && data2 == window->y) {
slouken@1724
    61
            return 0;
slouken@1724
    62
        }
slouken@1724
    63
        break;
slouken@1724
    64
    case SDL_WINDOWEVENT_RESIZED:
slouken@1733
    65
        if (window->flags & SDL_WINDOW_FULLSCREEN) {
slouken@1733
    66
            return 0;
slouken@1733
    67
        }
slouken@1724
    68
        if (data1 == window->w && data2 == window->h) {
slouken@1724
    69
            return 0;
slouken@1724
    70
        }
slouken@1724
    71
        break;
slouken@1722
    72
    case SDL_WINDOWEVENT_MINIMIZED:
slouken@1722
    73
        if (window->flags & SDL_WINDOW_MINIMIZED) {
slouken@1722
    74
            return 0;
slouken@1722
    75
        }
slouken@1722
    76
        window->flags |= SDL_WINDOW_MINIMIZED;
slouken@1722
    77
        break;
slouken@1722
    78
    case SDL_WINDOWEVENT_MAXIMIZED:
slouken@1722
    79
        if (window->flags & SDL_WINDOW_MAXIMIZED) {
slouken@1722
    80
            return 0;
slouken@1722
    81
        }
slouken@1722
    82
        window->flags |= SDL_WINDOW_MAXIMIZED;
slouken@1722
    83
        break;
slouken@1722
    84
    case SDL_WINDOWEVENT_RESTORED:
slouken@1722
    85
        if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
slouken@1722
    86
            return 0;
slouken@1722
    87
        }
slouken@1722
    88
        window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
slouken@1722
    89
        break;
slouken@1722
    90
    case SDL_WINDOWEVENT_ENTER:
slouken@1722
    91
        if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
slouken@1722
    92
            return 0;
slouken@1722
    93
        }
slouken@1722
    94
        window->flags |= SDL_WINDOW_MOUSE_FOCUS;
slouken@1722
    95
        break;
slouken@1722
    96
    case SDL_WINDOWEVENT_LEAVE:
slouken@1722
    97
        if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
slouken@1722
    98
            return 0;
slouken@1722
    99
        }
slouken@1722
   100
        window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
slouken@1722
   101
        break;
slouken@1722
   102
    case SDL_WINDOWEVENT_FOCUS_GAINED:
slouken@1722
   103
        if (window->flags & SDL_WINDOW_KEYBOARD_FOCUS) {
slouken@1722
   104
            return 0;
slouken@1722
   105
        }
slouken@1722
   106
        window->flags |= SDL_WINDOW_KEYBOARD_FOCUS;
slouken@1733
   107
        SDL_OnWindowFocusGained(window);
slouken@1722
   108
        break;
slouken@1722
   109
    case SDL_WINDOWEVENT_FOCUS_LOST:
slouken@1722
   110
        if (!(window->flags & SDL_WINDOW_KEYBOARD_FOCUS)) {
slouken@1722
   111
            return 0;
slouken@1722
   112
        }
slouken@1722
   113
        window->flags &= ~SDL_WINDOW_KEYBOARD_FOCUS;
slouken@1733
   114
        SDL_OnWindowFocusLost(window);
slouken@1722
   115
        break;
slouken@1722
   116
    }
slouken@1662
   117
slouken@1662
   118
    /* Post the event, if desired */
slouken@1662
   119
    posted = 0;
slouken@1662
   120
    if (SDL_ProcessEvents[SDL_WINDOWEVENT] == SDL_ENABLE) {
slouken@1662
   121
        SDL_Event event;
slouken@1662
   122
        event.type = SDL_WINDOWEVENT;
slouken@1662
   123
        event.window.event = windowevent;
slouken@1662
   124
        event.window.data1 = data1;
slouken@1662
   125
        event.window.data2 = data2;
slouken@1662
   126
        event.window.windowID = windowID;
slouken@1731
   127
        posted = (SDL_PushEvent(&event) > 0);
slouken@1662
   128
    }
slouken@1662
   129
    return (posted);
slouken@1662
   130
}
slouken@1662
   131
slouken@1662
   132
/* vi: set ts=4 sw=4 expandtab: */