comparison io.c @ 1541:f8ef74e7c800

Merged nuklear_ui into default
author Michael Pavone <pavone@retrodev.com>
date Sun, 25 Mar 2018 12:01:49 -0700
parents f29bd94ffa76
children 577253765192
comparison
equal deleted inserted replaced
1533:78b7fc03c7c6 1541:f8ef74e7c800
21 #include "genesis.h" 21 #include "genesis.h"
22 #include "sms.h" 22 #include "sms.h"
23 #include "render.h" 23 #include "render.h"
24 #include "util.h" 24 #include "util.h"
25 #include "menu.h" 25 #include "menu.h"
26 #include "saves.h"
27 #ifndef DISABLE_NUKLEAR
28 #include "nuklear_ui/blastem_nuklear.h"
29 #endif
26 30
27 #define CYCLE_NEVER 0xFFFFFFFF 31 #define CYCLE_NEVER 0xFFFFFFFF
28 #define MIN_POLL_INTERVAL 6840 32 #define MIN_POLL_INTERVAL 6840
29 33
30 const char * device_type_names[] = { 34 const char * device_type_names[] = {
354 } 358 }
355 } 359 }
356 360
357 void handle_keydown(int keycode, uint8_t scancode) 361 void handle_keydown(int keycode, uint8_t scancode)
358 { 362 {
363 if (!current_io) {
364 return;
365 }
359 int bucket = keycode >> 15 & 0xFFFF; 366 int bucket = keycode >> 15 & 0xFFFF;
360 int idx = keycode & 0x7FFF; 367 int idx = keycode & 0x7FFF;
361 keybinding * binding = bindings[bucket] ? bindings[bucket] + idx : NULL; 368 keybinding * binding = bindings[bucket] ? bindings[bucket] + idx : NULL;
362 if (binding && (!current_io->keyboard_captured || (binding->bind_type == BIND_UI && binding->subtype_a == UI_TOGGLE_KEYBOARD_CAPTURE))) { 369 if (binding && (!current_io->keyboard_captured || (binding->bind_type == BIND_UI && binding->subtype_a == UI_TOGGLE_KEYBOARD_CAPTURE))) {
363 handle_binding_down(binding); 370 handle_binding_down(binding);
375 handle_binding_down(binding); 382 handle_binding_down(binding);
376 } 383 }
377 384
378 void handle_mousedown(int mouse, int button) 385 void handle_mousedown(int mouse, int button)
379 { 386 {
387 if (!current_io) {
388 return;
389 }
380 if (current_io->mouse_mode == MOUSE_CAPTURE && !current_io->mouse_captured) { 390 if (current_io->mouse_mode == MOUSE_CAPTURE && !current_io->mouse_captured) {
381 current_io->mouse_captured = 1; 391 current_io->mouse_captured = 1;
382 render_relative_mouse(1); 392 render_relative_mouse(1);
383 return; 393 return;
384 } 394 }
530 free(screenshot_base); 540 free(screenshot_base);
531 render_save_screenshot(path); 541 render_save_screenshot(path);
532 break; 542 break;
533 } 543 }
534 case UI_EXIT: 544 case UI_EXIT:
545 #ifndef DISABLE_NUKLEAR
546 if (is_nuklear_active()) {
547 show_pause_menu();
548 } else {
549 #endif
535 current_system->request_exit(current_system); 550 current_system->request_exit(current_system);
536 if (current_system->type == SYSTEM_GENESIS) { 551 if (current_system->type == SYSTEM_GENESIS) {
537 genesis_context *gen = (genesis_context *)current_system; 552 genesis_context *gen = (genesis_context *)current_system;
538 if (gen->extra) { 553 if (gen->extra) {
539 //TODO: More robust mechanism for detecting menu 554 //TODO: More robust mechanism for detecting menu
540 menu_context *menu = gen->extra; 555 menu_context *menu = gen->extra;
541 menu->external_game_load = 1; 556 menu->external_game_load = 1;
542 } 557 }
543 } 558 }
559 #ifndef DISABLE_NUKLEAR
560 }
561 #endif
544 break; 562 break;
545 } 563 }
546 break; 564 break;
547 } 565 }
548 } 566 }
549 567
550 void handle_keyup(int keycode, uint8_t scancode) 568 void handle_keyup(int keycode, uint8_t scancode)
551 { 569 {
570 if (!current_io) {
571 return;
572 }
552 int bucket = keycode >> 15 & 0xFFFF; 573 int bucket = keycode >> 15 & 0xFFFF;
553 int idx = keycode & 0x7FFF; 574 int idx = keycode & 0x7FFF;
554 keybinding * binding = bindings[bucket] ? bindings[bucket] + idx : NULL; 575 keybinding * binding = bindings[bucket] ? bindings[bucket] + idx : NULL;
555 if (binding && (!current_io->keyboard_captured || (binding->bind_type == BIND_UI && binding->subtype_a == UI_TOGGLE_KEYBOARD_CAPTURE))) { 576 if (binding && (!current_io->keyboard_captured || (binding->bind_type == BIND_UI && binding->subtype_a == UI_TOGGLE_KEYBOARD_CAPTURE))) {
556 handle_binding_up(binding); 577 handle_binding_up(binding);