Mercurial > sdl-ios-xcode
annotate src/video/bwindow/SDL_BWin.h @ 563:04dcaf3da918
Massive Quartz input enhancements from Darrell Walisser. His email:
Enclosed is a patch that addresses the following:
--Various minor cleanups.
Removed dead/obsolete code, made some style cleanups
--Mouse Events
Now keep track of what button(s) were pressed so we know when to send
the mouse up event. This fixes the case where the mouse is dragged
outside of the game window and released (in which case we want to send
the mouse up event even though the mouse is outside the game window).
--Input Grabbing
Here is my take on the grabbing situation, which is the basis for the
new implementation.
There are 3 grab states, ungrabbed (UG), visible (VG), and invisible
(IG). Both VG and IG keep the mouse constrained to the window and
produce relative motion events. In VG the cursor is visible (duh), in
IG it is not. In VG, absolute motion events also work.
There are 6 actions that can affect grabbing:
1. Set Fullscreen/Window (F/W). In fullscreen, a visible grab should do
nothing. However, a fullscreen visible grab can be treated just like a
windowed visible grab, which is what I have done to help simplify
things.
2. Cursor hide/show (H/S). If the cursor is hidden when grabbing, the
grab is an invisible grab. If the cursor is visible, the grab should
just constrain the mouse to the window.
3. Input grab/ungrab(G/U). If grabbed, the cursor should be confined to
the window as should the keyboard input. On Mac OS X, the keyboard
input is implicitly grabbed by confining the cursor, except for
command-tab which can switch away from the application. Should the
window come to the foreground if the application is deactivated and
grab input is called? This isn't necessary in this implementation
because the grab state will be asserted upon activation.
Using my notation, these are all the cases that need to be handled
(state + action = new state).
UG+U = UG
UG+G = VG or IG, if cursor is visible or not
UG+H = UG
UG+S = UG
VG+U = UG
VG+G = VG
VG+H = IG
VG+S = VG
IG+U = UG
IG+G = IG
IG+H = IG
IG+S = VG
The cases that result in the same state can be ignored in the code,
which cuts it down to just 5 cases.
Another issue is what happens when the app loses/gains input focus from
deactivate/activate or iconify/deiconify. I think that if input focus
is ever lost (outside of SDL's control), the grab state should be
suspended and the cursor should become visible and active again. When
regained, the cursor should reappear in its original location and/or
grab state. This way, when reactivating the cursor is still in the same
position as before so apps shouldn't get confused when the next motion
event comes in. This is what I've done in this patch.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Fri, 27 Dec 2002 20:52:41 +0000 |
parents | f6ffac90895c |
children | b8d311d90021 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
297
f6ffac90895c
Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 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 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
1
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #ifndef _SDL_BWin_h | |
29 #define _SDL_BWin_h | |
30 | |
31 #include <stdio.h> | |
32 #include <AppKit.h> | |
33 #include <InterfaceKit.h> | |
34 #include <be/game/DirectWindow.h> | |
35 #ifdef HAVE_OPENGL | |
36 #include <be/opengl/GLView.h> | |
37 #endif | |
38 | |
39 #include "SDL_BeApp.h" | |
40 #include "SDL_events.h" | |
41 #include "SDL_BView.h" | |
42 | |
43 extern "C" { | |
44 #include "SDL_events_c.h" | |
45 }; | |
46 | |
47 class SDL_BWin : public BDirectWindow | |
48 { | |
49 public: | |
50 SDL_BWin(BRect bounds) : | |
51 BDirectWindow(bounds, "Untitled", B_TITLED_WINDOW, 0) { | |
52 the_view = NULL; | |
53 #ifdef HAVE_OPENGL | |
54 SDL_GLView = NULL; | |
55 #endif | |
56 SDL_View = NULL; | |
57 Unlock(); | |
58 shown = false; | |
59 inhibit_resize = false; | |
60 } | |
61 virtual ~SDL_BWin() { | |
62 Lock(); | |
63 if ( the_view ) { | |
64 #ifdef HAVE_OPENGL | |
65 if ( the_view == SDL_GLView ) { | |
66 SDL_GLView->UnlockGL(); | |
67 } | |
68 #endif | |
69 RemoveChild(the_view); | |
70 the_view = NULL; | |
71 } | |
72 Unlock(); | |
73 #ifdef HAVE_OPENGL | |
74 if ( SDL_GLView ) { | |
75 delete SDL_GLView; | |
76 } | |
77 #endif | |
78 if ( SDL_View ) { | |
79 delete SDL_View; | |
80 } | |
81 } | |
82 | |
83 /* Override the Show() method so we can tell when we've been shown */ | |
84 virtual void Show(void) { | |
85 BWindow::Show(); | |
86 shown = true; | |
87 } | |
88 virtual bool Shown(void) { | |
89 return (shown); | |
90 } | |
91 /* If called, the next resize event will not be forwarded to SDL. */ | |
92 virtual void InhibitResize(void) { | |
93 inhibit_resize=true; | |
94 } | |
95 /* Handle resizing of the window */ | |
96 virtual void FrameResized(float width, float height) { | |
97 if(inhibit_resize) | |
98 inhibit_resize = false; | |
99 else | |
100 SDL_PrivateResize((int)width, (int)height); | |
101 } | |
102 virtual int CreateView(Uint32 flags) { | |
103 int retval; | |
104 | |
105 retval = 0; | |
106 Lock(); | |
107 if ( flags & SDL_OPENGL ) { | |
108 #ifdef HAVE_OPENGL | |
109 if ( SDL_GLView == NULL ) { | |
110 /* FIXME: choose BGL type via user flags */ | |
111 SDL_GLView = new BGLView(Bounds(), "SDL GLView", | |
112 B_FOLLOW_ALL_SIDES, | |
113 (B_WILL_DRAW|B_FRAME_EVENTS), | |
114 (BGL_RGB|BGL_DOUBLE|BGL_DEPTH)); | |
115 } | |
116 if ( the_view != SDL_GLView ) { | |
117 if ( the_view ) { | |
118 RemoveChild(the_view); | |
119 } | |
120 AddChild(SDL_GLView); | |
121 SDL_GLView->LockGL(); | |
122 the_view = SDL_GLView; | |
123 } | |
124 #else | |
125 SDL_SetError("OpenGL support not enabled"); | |
126 retval = -1; | |
127 #endif | |
128 } else { | |
129 if ( SDL_View == NULL ) { | |
130 SDL_View = new SDL_BView(Bounds()); | |
131 } | |
132 if ( the_view != SDL_View ) { | |
133 if ( the_view ) { | |
134 #ifdef HAVE_OPENGL | |
135 if ( the_view == SDL_GLView ) { | |
136 SDL_GLView->UnlockGL(); | |
137 } | |
138 #endif | |
139 RemoveChild(the_view); | |
140 } | |
141 AddChild(SDL_View); | |
142 the_view = SDL_View; | |
143 } | |
144 } | |
145 Unlock(); | |
146 return(retval); | |
147 } | |
148 virtual void SetBitmap(BBitmap *bitmap) { | |
149 SDL_View->SetBitmap(bitmap); | |
150 } | |
151 virtual void SetXYOffset(int x, int y) { | |
152 #ifdef HAVE_OPENGL | |
153 if ( the_view == SDL_GLView ) { | |
154 return; | |
155 } | |
156 #endif | |
157 SDL_View->SetXYOffset(x, y); | |
158 } | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
159 virtual void GetXYOffset(int &x, int &y) { |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
160 #ifdef HAVE_OPENGL |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
161 if ( the_view == SDL_GLView ) { |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
162 x = 0; |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
163 y = 0; |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
164 return; |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
165 } |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
166 #endif |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
167 SDL_View->GetXYOffset(x, y); |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
168 } |
0 | 169 virtual bool BeginDraw(void) { |
170 return(Lock()); | |
171 } | |
172 virtual void DrawAsync(BRect updateRect) { | |
173 SDL_View->DrawAsync(updateRect); | |
174 } | |
175 virtual void EndDraw(void) { | |
176 SDL_View->Sync(); | |
177 Unlock(); | |
178 } | |
179 #ifdef HAVE_OPENGL | |
180 virtual void SwapBuffers(void) { | |
181 SDL_GLView->UnlockGL(); | |
182 SDL_GLView->LockGL(); | |
183 SDL_GLView->SwapBuffers(); | |
184 } | |
185 #endif | |
186 virtual BView *View(void) { | |
187 return(the_view); | |
188 } | |
189 | |
190 /* Hook functions -- overridden */ | |
191 virtual void Minimize(bool minimize) { | |
192 /* This is only called when mimimized, not when restored */ | |
193 //SDL_PrivateAppActive(minimize, SDL_APPACTIVE); | |
194 BWindow::Minimize(minimize); | |
195 } | |
196 virtual void WindowActivated(bool active) { | |
197 SDL_PrivateAppActive(active, SDL_APPINPUTFOCUS); | |
198 } | |
199 virtual bool QuitRequested(void) { | |
200 if ( SDL_BeAppActive > 0 ) { | |
201 SDL_PrivateQuit(); | |
202 /* We don't ever actually close the window here because | |
203 the application should respond to the quit request, | |
204 or ignore it as desired. | |
205 */ | |
206 return(false); | |
207 } | |
208 return(true); /* Close the app window */ | |
209 } | |
210 | |
211 private: | |
212 #ifdef HAVE_OPENGL | |
213 BGLView *SDL_GLView; | |
214 #endif | |
215 SDL_BView *SDL_View; | |
216 BView *the_view; | |
217 | |
218 bool shown; | |
219 bool inhibit_resize; | |
220 }; | |
221 | |
222 #endif /* _SDL_BWin_h */ |