Mercurial > sdl-ios-xcode
comparison src/events/SDL_mouse.c @ 3764:2970fcfbdd54 gsoc2008_manymouse
Relative mode for tablets. Info on wiki.
author | Szymon Wilczek <kazeuser@gmail.com> |
---|---|
date | Thu, 03 Jul 2008 22:03:58 +0000 |
parents | 81ea7d9a6624 |
children | ed9b7fe8f902 |
comparison
equal
deleted
inserted
replaced
3763:81ea7d9a6624 | 3764:2970fcfbdd54 |
---|---|
31 static int SDL_num_mice; | 31 static int SDL_num_mice; |
32 static int SDL_current_mouse; | 32 static int SDL_current_mouse; |
33 static SDL_Mouse **SDL_mice; | 33 static SDL_Mouse **SDL_mice; |
34 int *SDL_IdIndex; | 34 int *SDL_IdIndex; |
35 int SDL_highestId; | 35 int SDL_highestId; |
36 | 36 int last_x, last_y; |
37 | 37 int x_max, y_max; |
38 /* Public functions */ | 38 /* Public functions */ |
39 int | 39 int |
40 SDL_MouseInit(void) | 40 SDL_MouseInit(void) |
41 { | 41 { |
42 return (0); | 42 return (0); |
83 SDL_mice[index]->cur_cursor = NULL; | 83 SDL_mice[index]->cur_cursor = NULL; |
84 SDL_mice[index]->def_cursor = | 84 SDL_mice[index]->def_cursor = |
85 SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH, | 85 SDL_CreateCursor(default_cdata, default_cmask, DEFAULT_CWIDTH, |
86 DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY); | 86 DEFAULT_CHEIGHT, DEFAULT_CHOTX, DEFAULT_CHOTY); |
87 SDL_SetCursor(SDL_mice[index]->def_cursor); | 87 SDL_SetCursor(SDL_mice[index]->def_cursor); |
88 SDL_mice[index]->proximity=SDL_TRUE; | |
89 SDL_mice[index]->relative_mode=SDL_FALSE; | |
88 SDL_SelectMouse(selected_mouse); | 90 SDL_SelectMouse(selected_mouse); |
89 | 91 |
90 return index; | 92 return index; |
91 } | 93 } |
92 | 94 |
178 return 1; | 180 return 1; |
179 } | 181 } |
180 } | 182 } |
181 | 183 |
182 int | 184 int |
183 SDL_SetRelativeMouseMode(SDL_bool enabled) | 185 SDL_SetRelativeMouseMode(SDL_bool enabled, int index) |
184 { | 186 { |
185 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse); | 187 SDL_Mouse *mouse = SDL_GetMouse(index); |
186 | 188 |
187 if (!mouse) { | 189 if (!mouse) { |
188 return -1; | 190 return -1; |
189 } | 191 } |
190 | 192 |
324 int index=SDL_GetIndexById(id); | 326 int index=SDL_GetIndexById(id); |
325 int posted=0; | 327 int posted=0; |
326 if(SDL_ProcessEvents[type]==SDL_ENABLE) | 328 if(SDL_ProcessEvents[type]==SDL_ENABLE) |
327 { | 329 { |
328 SDL_Event event; | 330 SDL_Event event; |
329 event.proximity.which=index; | 331 event.proximity.which=(Uint8)index; |
330 event.proximity.x=x; | 332 event.proximity.x=x; |
331 event.proximity.y=y; | 333 event.proximity.y=y; |
332 event.type=type; | 334 event.type=type; |
333 event.proximity.type=type; | 335 event.proximity.type=type; |
334 posted = (SDL_PushEvent(&event) > 0); | 336 posted = (SDL_PushEvent(&event) > 0); |
337 if(type==SDL_PROXIMITYIN) | |
338 { | |
339 SDL_mice[index]->proximity=SDL_TRUE; | |
340 } | |
341 else | |
342 { | |
343 SDL_mice[index]->proximity=SDL_FALSE; | |
344 } | |
335 } | 345 } |
336 return posted; | 346 return posted; |
337 } | 347 } |
338 | 348 |
339 int | 349 int |
346 int yrel; | 356 int yrel; |
347 | 357 |
348 if (!mouse || mouse->flush_motion) { | 358 if (!mouse || mouse->flush_motion) { |
349 return 0; | 359 return 0; |
350 } | 360 } |
351 | 361 if(mouse->proximity==SDL_FALSE) |
352 if (relative) { | 362 { |
363 last_x=x; | |
364 last_y=y; | |
365 return 0; | |
366 } | |
367 if (mouse->relative_mode==SDL_TRUE && mouse->proximity==SDL_TRUE) { | |
353 /* Push the cursor around */ | 368 /* Push the cursor around */ |
354 xrel = x; | 369 xrel = x - last_x; |
355 yrel = y; | 370 yrel = y - last_y; |
356 x = (mouse->x + xrel); | 371 //x = (mouse->x + xrel); |
357 y = (mouse->y + yrel); | 372 //y = (mouse->y + yrel); |
358 } else { | 373 } else { |
359 xrel = x - mouse->x; | 374 xrel = x - last_x; |
360 yrel = y - mouse->y; | 375 yrel = y - last_y; |
361 } | 376 } |
362 | 377 |
363 /* Drop events that don't change state */ | 378 /* Drop events that don't change state */ |
364 if (!xrel && !yrel) { | 379 if (!xrel && !yrel) { |
365 #if 0 | 380 #if 0 |
367 #endif | 382 #endif |
368 return 0; | 383 return 0; |
369 } | 384 } |
370 | 385 |
371 /* Update internal mouse state */ | 386 /* Update internal mouse state */ |
372 if (!mouse->relative_mode) { | 387 if (mouse->relative_mode==SDL_FALSE) { |
373 mouse->x = x; | 388 mouse->x = x; |
374 mouse->y = y; | 389 mouse->y = y; |
390 } | |
391 else | |
392 { | |
393 if(mouse->x+xrel>x_max) | |
394 { | |
395 mouse->x=x_max; | |
396 } | |
397 else if(mouse->x+xrel<0) | |
398 { | |
399 mouse->x=0; | |
400 } | |
401 else | |
402 { | |
403 mouse->x+=xrel; | |
404 } | |
405 if(mouse->y+yrel>y_max) | |
406 { | |
407 mouse->y=y_max; | |
408 } | |
409 else if(mouse->y+yrel<0) | |
410 { | |
411 mouse->y=0; | |
412 } | |
413 else | |
414 { | |
415 mouse->y+=yrel; | |
416 } | |
375 } | 417 } |
376 mouse->xdelta += xrel; | 418 mouse->xdelta += xrel; |
377 mouse->ydelta += yrel; | 419 mouse->ydelta += yrel; |
378 mouse->z=z; | 420 mouse->z=z; |
379 | 421 |
383 mouse->MoveCursor(mouse->cur_cursor); | 425 mouse->MoveCursor(mouse->cur_cursor); |
384 } | 426 } |
385 | 427 |
386 /* Post the event, if desired */ | 428 /* Post the event, if desired */ |
387 posted = 0; | 429 posted = 0; |
388 if (SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE) { | 430 if (SDL_ProcessEvents[SDL_MOUSEMOTION] == SDL_ENABLE && SDL_mice[index]->proximity==SDL_TRUE) { |
389 SDL_Event event; | 431 SDL_Event event; |
390 event.motion.type = SDL_MOUSEMOTION; | 432 event.motion.type = SDL_MOUSEMOTION; |
391 event.motion.which = (Uint8) index; | 433 event.motion.which = (Uint8) index; |
392 event.motion.state = mouse->buttonstate; | 434 event.motion.state = mouse->buttonstate; |
393 event.motion.x = mouse->x; | 435 event.motion.x = mouse->x; |
394 event.motion.y = mouse->y; | 436 event.motion.y = mouse->y; |
395 event.motion.z = mouse->z; | 437 event.motion.z = mouse->z; |
396 event.motion.xrel = xrel; | 438 event.motion.xrel = xrel; |
397 event.motion.yrel = yrel; | 439 event.motion.yrel = yrel; |
398 event.motion.windowID = mouse->focus; | 440 event.motion.windowID = mouse->focus; |
399 posted = (SDL_PushEvent(&event) > 0); | 441 posted = (SDL_PushEvent(&event) > 0); |
400 } | 442 } |
443 last_x=x; | |
444 last_y=y; | |
401 return posted; | 445 return posted; |
402 } | 446 } |
403 | 447 |
404 int | 448 int |
405 SDL_SendMouseButton(int id, Uint8 state, Uint8 button) | 449 SDL_SendMouseButton(int id, Uint8 state, Uint8 button) |
722 return NULL; | 766 return NULL; |
723 } | 767 } |
724 return mouse->name; | 768 return mouse->name; |
725 } | 769 } |
726 | 770 |
727 | 771 void SDL_UpdateCoordinates(int x, int y) |
772 { | |
773 x_max=x; | |
774 y_max=y; | |
775 } | |
728 /* vi: set ts=4 sw=4 expandtab: */ | 776 /* vi: set ts=4 sw=4 expandtab: */ |