zenilib: zenilib/jni/external/sdl/src/events/SDL_windowevents.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_windowevents.c
Go to the documentation of this file.
1 /*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "SDL_config.h"
22
23 /* Window event handling code for SDL */
24
25 #include "SDL_events.h"
26 #include "SDL_events_c.h"
27 #include "SDL_mouse_c.h"
28 #include "../video/SDL_sysvideo.h"
29
30
31 static int
32 RemovePendingResizedEvents(void * userdata, SDL_Event *event)
33 {
34 SDL_Event *new_event = (SDL_Event *)userdata;
35
36 if (event->type == SDL_WINDOWEVENT &&
37 event->window.event == SDL_WINDOWEVENT_RESIZED &&
38 event->window.windowID == new_event->window.windowID) {
39 /* We're about to post a new size event, drop the old one */
40 return 0;
41 }
42 return 1;
43 }
44
45 static int
46 RemovePendingSizeChangedEvents(void * userdata, SDL_Event *event)
47 {
48 SDL_Event *new_event = (SDL_Event *)userdata;
49
50 if (event->type == SDL_WINDOWEVENT &&
51 event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED &&
52 event->window.windowID == new_event->window.windowID) {
53 /* We're about to post a new size event, drop the old one */
54 return 0;
55 }
56 return 1;
57 }
58
59 static int
60 RemovePendingMoveEvents(void * userdata, SDL_Event *event)
61 {
62 SDL_Event *new_event = (SDL_Event *)userdata;
63
64 if (event->type == SDL_WINDOWEVENT &&
65 event->window.event == SDL_WINDOWEVENT_MOVED &&
66 event->window.windowID == new_event->window.windowID) {
67 /* We're about to post a new move event, drop the old one */
68 return 0;
69 }
70 return 1;
71 }
72
73 int
74 SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,
75 int data2)
76 {
77 int posted;
78
79 if (!window) {
80 return 0;
81 }
82 switch (windowevent) {
83 case SDL_WINDOWEVENT_SHOWN:
84 if (window->flags & SDL_WINDOW_SHOWN) {
85 return 0;
86 }
87 window->flags &= ~SDL_WINDOW_HIDDEN;
88 window->flags |= SDL_WINDOW_SHOWN;
89 SDL_OnWindowShown(window);
90 break;
91 case SDL_WINDOWEVENT_HIDDEN:
92 if (!(window->flags & SDL_WINDOW_SHOWN)) {
93 return 0;
94 }
95 window->flags &= ~SDL_WINDOW_SHOWN;
96 window->flags |= SDL_WINDOW_HIDDEN;
97 SDL_OnWindowHidden(window);
98 break;
99 case SDL_WINDOWEVENT_MOVED:
100 if (SDL_WINDOWPOS_ISUNDEFINED(data1) ||
101 SDL_WINDOWPOS_ISUNDEFINED(data2)) {
102 return 0;
103 }
104 if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
105 window->windowed.x = data1;
106 window->windowed.y = data2;
107 }
108 if (data1 == window->x && data2 == window->y) {
109 return 0;
110 }
111 window->x = data1;
112 window->y = data2;
113 break;
114 case SDL_WINDOWEVENT_RESIZED:
115 if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
116 window->windowed.w = data1;
117 window->windowed.h = data2;
118 }
119 if (data1 == window->w && data2 == window->h) {
120 return 0;
121 }
122 window->w = data1;
123 window->h = data2;
124 SDL_OnWindowResized(window);
125 break;
126 case SDL_WINDOWEVENT_MINIMIZED:
127 if (window->flags & SDL_WINDOW_MINIMIZED) {
128 return 0;
129 }
130 window->flags |= SDL_WINDOW_MINIMIZED;
131 SDL_OnWindowMinimized(window);
132 break;
133 case SDL_WINDOWEVENT_MAXIMIZED:
134 if (window->flags & SDL_WINDOW_MAXIMIZED) {
135 return 0;
136 }
137 window->flags |= SDL_WINDOW_MAXIMIZED;
138 break;
139 case SDL_WINDOWEVENT_RESTORED:
140 if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
141 return 0;
142 }
143 window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
144 SDL_OnWindowRestored(window);
145 break;
146 case SDL_WINDOWEVENT_ENTER:
147 if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
148 return 0;
149 }
150 window->flags |= SDL_WINDOW_MOUSE_FOCUS;
151 SDL_OnWindowEnter(window);
152 break;
153 case SDL_WINDOWEVENT_LEAVE:
154 if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
155 return 0;
156 }
157 window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
158 SDL_OnWindowLeave(window);
159 break;
160 case SDL_WINDOWEVENT_FOCUS_GAINED:
161 if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
162 return 0;
163 }
164 window->flags |= SDL_WINDOW_INPUT_FOCUS;
165 SDL_OnWindowFocusGained(window);
166 break;
167 case SDL_WINDOWEVENT_FOCUS_LOST:
168 if (!(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
169 return 0;
170 }
171 window->flags &= ~SDL_WINDOW_INPUT_FOCUS;
172 SDL_OnWindowFocusLost(window);
173 break;
174 }
175
176 /* Post the event, if desired */
177 posted = 0;
178 if (SDL_GetEventState(SDL_WINDOWEVENT) == SDL_ENABLE) {
179 SDL_Event event;
180 event.type = SDL_WINDOWEVENT;
181 event.window.event = windowevent;
182 event.window.data1 = data1;
183 event.window.data2 = data2;
184 event.window.windowID = window->id;
185
186 /* Fixes queue overflow with resize events that aren't processed */
187 if (windowevent == SDL_WINDOWEVENT_RESIZED) {
188 SDL_FilterEvents(RemovePendingResizedEvents, &event);
189 }
190 if (windowevent == SDL_WINDOWEVENT_SIZE_CHANGED) {
191 SDL_FilterEvents(RemovePendingSizeChangedEvents, &event);
192 }
193 if (windowevent == SDL_WINDOWEVENT_MOVED) {
194 SDL_FilterEvents(RemovePendingMoveEvents, &event);
195 }
196
197 posted = (SDL_PushEvent(&event) > 0);
198 }
199
200 if (windowevent == SDL_WINDOWEVENT_CLOSE) {
201 if ( !window->prev && !window->next ) {
202 /* This is the last window in the list so send the SDL_QUIT event */
203 SDL_SendQuit();
204 }
205 }
206
207 return (posted);
208 }
209
210 /* vi: set ts=4 sw=4 expandtab: */
SDL_WINDOWPOS_ISUNDEFINED
#define SDL_WINDOWPOS_ISUNDEFINED(X)
Definition: SDL_video.h:120
SDL_Window::next
SDL_Window * next
Definition: SDL_sysvideo.h:102
SDL_PushEvent
DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event *event)
Add an event to the event queue.
Definition: SDL_events.c:457
SDL_WINDOWEVENT_MINIMIZED
Definition: SDL_video.h:146
SDL_WINDOW_MOUSE_FOCUS
Definition: SDL_video.h:108
SDL_Window::w
int w
Definition: SDL_sysvideo.h:78
SDL_Window::x
int x
Definition: SDL_sysvideo.h:77
SDL_OnWindowResized
void SDL_OnWindowResized(SDL_Window *window)
Definition: SDL_video.c:2057
SDL_events.h
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:688
SDL_WINDOWEVENT_MAXIMIZED
Definition: SDL_video.h:147
SDL_SendWindowEvent
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
Definition: SDL_windowevents.c:74
SDL_OnWindowEnter
void SDL_OnWindowEnter(SDL_Window *window)
Definition: SDL_video.c:2080
SDL_WINDOWEVENT_SIZE_CHANGED
Definition: SDL_video.h:145
SDL_WINDOW_HIDDEN
Definition: SDL_video.h:101
SDL_Window::windowed
SDL_Rect windowed
Definition: SDL_sysvideo.h:84
RemovePendingSizeChangedEvents
static int RemovePendingSizeChangedEvents(void *userdata, SDL_Event *event)
Definition: SDL_windowevents.c:46
SDL_config.h
RemovePendingResizedEvents
static int RemovePendingResizedEvents(void *userdata, SDL_Event *event)
Definition: SDL_windowevents.c:32
SDL_WINDOWEVENT_HIDDEN
Definition: SDL_video.h:139
SDL_WINDOW_SHOWN
Definition: SDL_video.h:100
SDL_OnWindowHidden
void SDL_OnWindowHidden(SDL_Window *window)
Definition: SDL_video.c:2051
SDL_WINDOWEVENT_FOCUS_GAINED
Definition: SDL_video.h:152
SDL_Event::window
SDL_WindowEvent window
Definition: SDL_events.h:499
SDL_OnWindowMinimized
void SDL_OnWindowMinimized(SDL_Window *window)
Definition: SDL_video.c:2064
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:701
SDL_mouse_c.h
SDL_WINDOWEVENT_RESTORED
Definition: SDL_video.h:148
SDL_WINDOWEVENT_FOCUS_LOST
Definition: SDL_video.h:153
SDL_WINDOWEVENT
Definition: SDL_events.h:89
SDL_OnWindowLeave
void SDL_OnWindowLeave(SDL_Window *window)
Definition: SDL_video.c:2088
SDL_WINDOW_MINIMIZED
Definition: SDL_video.h:104
SDL_Window::y
int y
Definition: SDL_sysvideo.h:77
SDL_Rect::x
int x
Definition: SDL_rect.h:65
SDL_WindowEvent::event
Uint8 event
Definition: SDL_events.h:165
SDL_WINDOWEVENT_LEAVE
Definition: SDL_video.h:151
SDL_Rect::w
int w
Definition: SDL_rect.h:66
SDL_WINDOWEVENT_CLOSE
Definition: SDL_video.h:154
SDL_Window::h
int h
Definition: SDL_sysvideo.h:78
SDL_events_c.h
SDL_WINDOW_INPUT_FOCUS
Definition: SDL_video.h:107
SDL_WINDOWEVENT_SHOWN
Definition: SDL_video.h:138
SDL_Window::prev
SDL_Window * prev
Definition: SDL_sysvideo.h:101
SDL_Rect::h
int h
Definition: SDL_rect.h:66
Uint8
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:129
SDL_Window
Definition: SDL_sysvideo.h:71
SDL_WINDOW_MAXIMIZED
Definition: SDL_video.h:105
SDL_Window::id
Uint32 id
Definition: SDL_sysvideo.h:74
SDL_WINDOW_FULLSCREEN
Definition: SDL_video.h:98
SDL_WINDOWEVENT_ENTER
Definition: SDL_video.h:150
SDL_OnWindowFocusLost
void SDL_OnWindowFocusLost(SDL_Window *window)
Definition: SDL_video.c:2123
SDL_OnWindowRestored
void SDL_OnWindowRestored(SDL_Window *window)
Definition: SDL_video.c:2070
SDL_Event
General event structure.
Definition: SDL_events.h:495
SDL_OnWindowShown
void SDL_OnWindowShown(SDL_Window *window)
Definition: SDL_video.c:2045
SDL_WINDOWEVENT_RESIZED
Definition: SDL_video.h:144
SDL_FilterEvents
DECLSPEC void SDLCALL SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
Definition: SDL_events.c:540
SDL_Window::flags
Uint32 flags
Definition: SDL_sysvideo.h:81
SDL_WINDOWEVENT_MOVED
Definition: SDL_video.h:142
SDL_Rect::y
int y
Definition: SDL_rect.h:65
SDL_WindowEvent::windowID
Uint32 windowID
Definition: SDL_events.h:164
RemovePendingMoveEvents
static int RemovePendingMoveEvents(void *userdata, SDL_Event *event)
Definition: SDL_windowevents.c:60
SDL_SendQuit
int SDL_SendQuit(void)
Definition: SDL_quit.c:115
SDL_Event::type
Uint32 type
Definition: SDL_events.h:497
event
cl_event event
Definition: glew.h:3556
SDL_OnWindowFocusGained
void SDL_OnWindowFocusGained(SDL_Window *window)
Definition: SDL_video.c:2093