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