comparison io.c @ 916:20c464dbae8f

Finished implementation of mouse capture mode
author Michael Pavone <pavone@retrodev.com>
date Thu, 17 Dec 2015 20:03:50 -0800
parents 9e882eca717e
children 9364dad5561a
comparison
equal deleted inserted replaced
915:9e882eca717e 916:20c464dbae8f
63 UI_ENTER_DEBUGGER, 63 UI_ENTER_DEBUGGER,
64 UI_SAVE_STATE, 64 UI_SAVE_STATE,
65 UI_SET_SPEED, 65 UI_SET_SPEED,
66 UI_NEXT_SPEED, 66 UI_NEXT_SPEED,
67 UI_PREV_SPEED, 67 UI_PREV_SPEED,
68 UI_RELEASE_MOUSE,
68 UI_EXIT 69 UI_EXIT
69 } ui_action; 70 } ui_action;
70 71
71 typedef enum { 72 typedef enum {
72 MOUSE_ABSOLUTE, //really only useful for menu ROM 73 MOUSE_ABSOLUTE, //really only useful for menu ROM
98 keybinding * joybindings[MAX_JOYSTICKS]; 99 keybinding * joybindings[MAX_JOYSTICKS];
99 joydpad * joydpads[MAX_JOYSTICKS]; 100 joydpad * joydpads[MAX_JOYSTICKS];
100 mousebinding mice[MAX_MICE]; 101 mousebinding mice[MAX_MICE];
101 const uint8_t dpadbits[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT}; 102 const uint8_t dpadbits[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT};
102 mouse_modes mouse_mode; 103 mouse_modes mouse_mode;
104 char mouse_captured;
103 105
104 void bind_key(int keycode, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value) 106 void bind_key(int keycode, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value)
105 { 107 {
106 int bucket = keycode >> 15 & 0xFFFF; 108 int bucket = keycode >> 15 & 0xFFFF;
107 if (!bindings[bucket]) { 109 if (!bindings[bucket]) {
263 handle_binding_down(binding); 265 handle_binding_down(binding);
264 } 266 }
265 267
266 void handle_mousedown(int mouse, int button) 268 void handle_mousedown(int mouse, int button)
267 { 269 {
270 if (mouse_mode == MOUSE_CAPTURE && !mouse_captured) {
271 mouse_captured = 1;
272 render_relative_mouse(1);
273 return;
274 }
268 if (mouse >= MAX_MICE || button > MAX_MOUSE_BUTTONS || button <= 0) { 275 if (mouse >= MAX_MICE || button > MAX_MOUSE_BUTTONS || button <= 0) {
269 return; 276 return;
270 } 277 }
271 keybinding * binding = mice[mouse].buttons + button - 1; 278 keybinding * binding = mice[mouse].buttons + button - 1;
272 handle_binding_down(binding); 279 handle_binding_down(binding);
357 } else { 364 } else {
358 printf("Setting speed to %d\n", speeds[current_speed]); 365 printf("Setting speed to %d\n", speeds[current_speed]);
359 set_speed_percent(genesis, binding->value); 366 set_speed_percent(genesis, binding->value);
360 } 367 }
361 break; 368 break;
369 case UI_RELEASE_MOUSE:
370 if (mouse_captured) {
371 mouse_captured = 0;
372 render_relative_mouse(0);
373 }
374 break;
362 case UI_EXIT: 375 case UI_EXIT:
363 genesis->m68k->should_return = 1; 376 genesis->m68k->should_return = 1;
364 } 377 }
365 break; 378 break;
366 } 379 }
433 mice[mouse].motion_port->device.mouse.cur_x += deltax; 446 mice[mouse].motion_port->device.mouse.cur_x += deltax;
434 mice[mouse].motion_port->device.mouse.cur_y += deltay; 447 mice[mouse].motion_port->device.mouse.cur_y += deltay;
435 break; 448 break;
436 } 449 }
437 case MOUSE_CAPTURE: { 450 case MOUSE_CAPTURE: {
451 if (mouse_captured) {
452 mice[mouse].motion_port->device.mouse.cur_x += deltax;
453 mice[mouse].motion_port->device.mouse.cur_y += deltay;
454 }
438 } 455 }
439 } 456 }
440 } 457 }
441 458
442 int parse_binding_target(char * target, tern_node * padbuttons, tern_node *mousebuttons, int * ui_out, int * padnum_out, int * padbutton_out) 459 int parse_binding_target(char * target, tern_node * padbuttons, tern_node *mousebuttons, int * ui_out, int * padnum_out, int * padbutton_out)
494 *padbutton_out = atoi(target + 3 + strlen("set_speed.")); 511 *padbutton_out = atoi(target + 3 + strlen("set_speed."));
495 } else if(!strcmp(target + 3, "next_speed")) { 512 } else if(!strcmp(target + 3, "next_speed")) {
496 *ui_out = UI_NEXT_SPEED; 513 *ui_out = UI_NEXT_SPEED;
497 } else if(!strcmp(target + 3, "prev_speed")) { 514 } else if(!strcmp(target + 3, "prev_speed")) {
498 *ui_out = UI_PREV_SPEED; 515 *ui_out = UI_PREV_SPEED;
516 } else if(!strcmp(target + 3, "release_mouse")) {
517 *ui_out = UI_RELEASE_MOUSE;
499 } else if(!strcmp(target + 3, "exit")) { 518 } else if(!strcmp(target + 3, "exit")) {
500 *ui_out = UI_EXIT; 519 *ui_out = UI_EXIT;
501 } else { 520 } else {
502 warning("Unreconized UI binding type %s\n", target); 521 warning("Unreconized UI binding type %s\n", target);
503 return 0; 522 return 0;
676 695
677 process_device(io_1, ports); 696 process_device(io_1, ports);
678 process_device(io_2, ports+1); 697 process_device(io_2, ports+1);
679 process_device(io_ext, ports+2); 698 process_device(io_ext, ports+2);
680 699
681 if (rom->mouse_mode && !strcmp(rom->mouse_mode, "absolute")) { 700 if (render_fullscreen()) {
682 mouse_mode = MOUSE_ABSOLUTE;
683 } else {
684 if (render_fullscreen()) {
685 mouse_mode = MOUSE_RELATIVE; 701 mouse_mode = MOUSE_RELATIVE;
686 render_relative_mouse(1); 702 render_relative_mouse(1);
703 } else {
704 if (rom->mouse_mode && !strcmp(rom->mouse_mode, "absolute")) {
705 mouse_mode = MOUSE_ABSOLUTE;
687 } else { 706 } else {
688 mouse_mode = MOUSE_CAPTURE; 707 mouse_mode = MOUSE_CAPTURE;
689 } 708 }
690 } 709 }
691 710