comparison src/video/bwindow/SDL_sysevents.cc @ 4012:4e29535b821b SDL-1.2

Fixed bug #360 Fixed fullscreen video modes and improved the mouse grab code.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 07 Jul 2007 19:20:28 +0000
parents f5794774970d
children a1b03ba2fcd0
comparison
equal deleted inserted replaced
4011:f5794774970d 4012:4e29535b821b
164 { 164 {
165 SDL_VideoDevice *view = current_video; 165 SDL_VideoDevice *view = current_video;
166 BPoint where; 166 BPoint where;
167 int32 transit; 167 int32 transit;
168 if (msg->FindPoint("where", &where) == B_OK && msg->FindInt32("be:transit", &transit) == B_OK) { 168 if (msg->FindPoint("where", &where) == B_OK && msg->FindInt32("be:transit", &transit) == B_OK) {
169 169 int x, y;
170 //BeSman: I need another method for cursor catching !!! 170
171 if(view->input_grab != SDL_GRAB_OFF) 171 GetXYOffset(x, y);
172 { 172 x = (int)where.x - x;
173 BPoint center; 173 y = (int)where.y - y;
174 center.x = (SDL_VideoSurface->w/2); 174
175 center.y = (SDL_VideoSurface->h/2); 175 //BeSman: I need another method for cursor catching !!!
176 BPoint delta = where - center; 176 if (view->input_grab != SDL_GRAB_OFF)
177 if(delta.x > center.x) 177 {
178 SDL_WarpMouse((int)center.x*2,(int)where.y); 178 bool clipped = false;
179 179 if ( x < 0 ) {
180 if(delta.x < -center.x) 180 x = 0;
181 SDL_WarpMouse(0,(int)where.y); 181 clipped = true;
182 182 } else if ( x >= SDL_VideoSurface->w ) {
183 if(delta.y > center.y) 183 x = (SDL_VideoSurface->w-1);
184 SDL_WarpMouse((int)where.x,(int)center.y*2); 184 clipped = true;
185 185 }
186 if(delta.y < -center.y) 186 if ( y < 0 ) {
187 SDL_WarpMouse((int)where.x,0); 187 y = 0;
188 188 clipped = true;
189 189 } else if ( y >= SDL_VideoSurface->h ) {
190 if((delta.x-1 < -center.x)&&(delta.y-1 < -center.y)) 190 y = (SDL_VideoSurface->h-1);
191 SDL_WarpMouse(1,1); 191 clipped = true;
192 192 }
193 if((delta.x-1 < -center.x)&&(delta.y+1 > center.y)) 193 if ( clipped ) {
194 SDL_WarpMouse(1,(int)center.y*2-1); 194 BPoint edge;
195 195 GetXYOffset(edge.x, edge.y);
196 if((delta.x+1 > center.x)&&(delta.y-1 < -center.y)) 196 edge.x += x;
197 SDL_WarpMouse((int)center.x*2-1,1); 197 edge.y += y;
198 198 ConvertToScreen(&edge);
199 if((delta.x+1 > center.x)&&(delta.y+1 > center.y)) 199 set_mouse_position((int)edge.x, (int)edge.y);
200 SDL_WarpMouse((int)center.x*2-1,(int)center.y*2-1); 200 }
201 201 transit = B_INSIDE_VIEW;
202 } 202 }
203 if (transit == B_EXITED_VIEW) { 203 if (transit == B_EXITED_VIEW) {
204 if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) { 204 if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) {
205 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); 205 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
206 // be_app->SetCursor(B_HAND_CURSOR); 206 be_app->SetCursor(B_HAND_CURSOR);
207 } 207 }
208 } else { 208 } else {
209 209 if ( !(SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
210 int x, y;
211 if ( ! (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
212 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); 210 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
213 SDL_SetCursor(NULL); 211 SDL_SetCursor(NULL);
214 } 212 }
215 x = (int)where.x;
216 y = (int)where.y;
217 213
218 if ( mouse_relative ) { 214 if ( mouse_relative ) {
219 BPoint center; 215 int half_w = (SDL_VideoSurface->w/2);
220 center.x = (SDL_VideoSurface->w/2); 216 int half_h = (SDL_VideoSurface->h/2);
221 center.y = (SDL_VideoSurface->h/2); 217 x -= half_w;
222 x -= (int)center.x; 218 y -= half_h;
223 y -= (int)center.y;
224 if ( x || y ) { 219 if ( x || y ) {
220 BPoint center;
221 GetXYOffset(center.x, center.y);
222 center.x += half_w;
223 center.y += half_h;
225 ConvertToScreen(&center); 224 ConvertToScreen(&center);
226 set_mouse_position((int)center.x, (int)center.y); 225 set_mouse_position((int)center.x, (int)center.y);
227 SDL_PrivateMouseMotion(0, 1, x, y); 226 SDL_PrivateMouseMotion(0, 1, x, y);
228 } 227 }
229 } else { 228 } else {