comparison src/events/SDL_windowevents.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents
children a228436a2404
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
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 break;
64 case SDL_WINDOWEVENT_RESIZED:
65 if (window->flags & SDL_WINDOW_FULLSCREEN) {
66 return 0;
67 }
68 if (data1 == window->w && data2 == window->h) {
69 return 0;
70 }
71 break;
72 case SDL_WINDOWEVENT_MINIMIZED:
73 if (window->flags & SDL_WINDOW_MINIMIZED) {
74 return 0;
75 }
76 window->flags |= SDL_WINDOW_MINIMIZED;
77 break;
78 case SDL_WINDOWEVENT_MAXIMIZED:
79 if (window->flags & SDL_WINDOW_MAXIMIZED) {
80 return 0;
81 }
82 window->flags |= SDL_WINDOW_MAXIMIZED;
83 break;
84 case SDL_WINDOWEVENT_RESTORED:
85 if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
86 return 0;
87 }
88 window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
89 break;
90 case SDL_WINDOWEVENT_ENTER:
91 if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
92 return 0;
93 }
94 window->flags |= SDL_WINDOW_MOUSE_FOCUS;
95 break;
96 case SDL_WINDOWEVENT_LEAVE:
97 if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
98 return 0;
99 }
100 window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
101 break;
102 case SDL_WINDOWEVENT_FOCUS_GAINED:
103 if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
104 return 0;
105 }
106 window->flags |= SDL_WINDOW_INPUT_FOCUS;
107 SDL_OnWindowFocusGained(window);
108 break;
109 case SDL_WINDOWEVENT_FOCUS_LOST:
110 if (!(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
111 return 0;
112 }
113 window->flags &= ~SDL_WINDOW_INPUT_FOCUS;
114 SDL_OnWindowFocusLost(window);
115 break;
116 }
117
118 /* Post the event, if desired */
119 posted = 0;
120 if (SDL_ProcessEvents[SDL_WINDOWEVENT] == SDL_ENABLE) {
121 SDL_Event event;
122 event.type = SDL_WINDOWEVENT;
123 event.window.event = windowevent;
124 event.window.data1 = data1;
125 event.window.data2 = data2;
126 event.window.windowID = windowID;
127 posted = (SDL_PushEvent(&event) > 0);
128 }
129 return (posted);
130 }
131
132 /* vi: set ts=4 sw=4 expandtab: */