Mercurial > repos > blastem
comparison nuklear_ui/blastem_nuklear.c @ 1596:437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 22 Jul 2018 17:48:46 -0700 |
parents | 24508cb54f87 |
children | 5e2af89c3467 |
comparison
equal
deleted
inserted
replaced
1595:360d5bab199f | 1596:437e80a700aa |
---|---|
12 #include "../saves.h" | 12 #include "../saves.h" |
13 #include "../blastem.h" | 13 #include "../blastem.h" |
14 #include "../config.h" | 14 #include "../config.h" |
15 #include "../io.h" | 15 #include "../io.h" |
16 #include "../png.h" | 16 #include "../png.h" |
17 #include "../controller_info.h" | |
17 | 18 |
18 static struct nk_context *context; | 19 static struct nk_context *context; |
19 | 20 |
20 typedef void (*view_fun)(struct nk_context *); | 21 typedef void (*view_fun)(struct nk_context *); |
21 static view_fun current_view; | 22 static view_fun current_view; |
498 set_binding = set_label = NULL; | 499 set_binding = set_label = NULL; |
499 } | 500 } |
500 nk_end(context); | 501 nk_end(context); |
501 } | 502 } |
502 } | 503 } |
504 | |
505 static int selected_controller; | |
506 static controller_info selected_controller_info; | |
503 static struct nk_image controller_360_image; | 507 static struct nk_image controller_360_image; |
504 static uint32_t controller_360_width, controller_360_height; | 508 static uint32_t controller_360_width, controller_360_height; |
505 //#define MIN_BIND_BOX_WIDTH 140 | 509 //#define MIN_BIND_BOX_WIDTH 140 |
506 #define MAX_BIND_BOX_WIDTH 350 | 510 #define MAX_BIND_BOX_WIDTH 350 |
507 void view_controllers(struct nk_context *context) | 511 void view_controller_bindings(struct nk_context *context) |
508 { | 512 { |
509 if (nk_begin(context, "Controller Bindings", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) { | 513 if (nk_begin(context, "Controller Bindings", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) { |
510 float orig_height = def_font->handle.height; | 514 float orig_height = def_font->handle.height; |
511 def_font->handle.height *= 0.5f; | 515 def_font->handle.height *= 0.5f; |
512 | 516 |
552 | 556 |
553 nk_layout_space_push(context, nk_rect(bind_box_left, img_top, bind_box_width, 165)); | 557 nk_layout_space_push(context, nk_rect(bind_box_left, img_top, bind_box_width, 165)); |
554 nk_group_begin(context, "Action Buttons", NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR); | 558 nk_group_begin(context, "Action Buttons", NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR); |
555 float widths[] = {34, bind_box_width - 60}; | 559 float widths[] = {34, bind_box_width - 60}; |
556 nk_layout_row(context, NK_STATIC, 34, 2, widths); | 560 nk_layout_row(context, NK_STATIC, 34, 2, widths); |
557 nk_label(context, "A", NK_TEXT_LEFT); | 561 nk_label(context, get_button_label(&selected_controller_info, SDL_CONTROLLER_BUTTON_A), NK_TEXT_LEFT); |
558 nk_button_label(context, "A"); | 562 nk_button_label(context, "A"); |
559 nk_label(context, "B", NK_TEXT_LEFT); | 563 nk_label(context, get_button_label(&selected_controller_info, SDL_CONTROLLER_BUTTON_B), NK_TEXT_LEFT); |
560 nk_button_label(context, "B"); | 564 nk_button_label(context, "B"); |
561 nk_label(context, "X", NK_TEXT_LEFT); | 565 nk_label(context, get_button_label(&selected_controller_info, SDL_CONTROLLER_BUTTON_X), NK_TEXT_LEFT); |
562 nk_button_label(context, "X"); | 566 nk_button_label(context, "X"); |
563 nk_label(context, "Y", NK_TEXT_LEFT); | 567 nk_label(context, get_button_label(&selected_controller_info, SDL_CONTROLLER_BUTTON_Y), NK_TEXT_LEFT); |
564 nk_button_label(context, "Internal Screenshot"); | 568 nk_button_label(context, "Internal Screenshot"); |
565 nk_group_end(context); | 569 nk_group_end(context); |
566 | 570 |
567 bind_box_left -= img_right; | 571 bind_box_left -= img_right; |
568 widths[0] += 44; | 572 widths[0] += 44; |
576 nk_button_label(context, "Down"); | 580 nk_button_label(context, "Down"); |
577 nk_label(context, "Left", NK_TEXT_LEFT); | 581 nk_label(context, "Left", NK_TEXT_LEFT); |
578 nk_button_label(context, "Left"); | 582 nk_button_label(context, "Left"); |
579 nk_label(context, "Right", NK_TEXT_LEFT); | 583 nk_label(context, "Right", NK_TEXT_LEFT); |
580 nk_button_label(context, "Right"); | 584 nk_button_label(context, "Right"); |
581 nk_label(context, "Click", NK_TEXT_LEFT); | 585 nk_label(context, get_button_label(&selected_controller_info, SDL_CONTROLLER_BUTTON_LEFTSTICK), NK_TEXT_LEFT); |
582 nk_button_label(context, "None"); | 586 nk_button_label(context, "None"); |
583 | 587 |
584 nk_group_end(context); | 588 nk_group_end(context); |
585 | 589 |
586 nk_layout_space_end(context); | 590 nk_layout_space_end(context); |
587 | 591 |
588 def_font->handle.height = orig_height; | 592 def_font->handle.height = orig_height; |
589 nk_layout_row_static(context, orig_height + 4, (render_width() - 80) / 2, 1); | 593 nk_layout_row_static(context, orig_height + 4, (render_width() - 80) / 2, 1); |
594 if (nk_button_label(context, "Back")) { | |
595 pop_view(); | |
596 } | |
597 nk_end(context); | |
598 } | |
599 } | |
600 | |
601 void view_controllers(struct nk_context *context) | |
602 { | |
603 if (nk_begin(context, "Controllers", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) { | |
604 int height = (render_width() - 2*context->style.font->height) / MAX_JOYSTICKS; | |
605 int image_width = height * controller_360_width / controller_360_height; | |
606 for (int i = 0; i < MAX_JOYSTICKS; i++) | |
607 { | |
608 SDL_Joystick *joy = render_get_joystick(i); | |
609 if (joy) { | |
610 controller_info info = get_controller_info(i); | |
611 nk_layout_row_begin(context, NK_STATIC, height, 2); | |
612 nk_layout_row_push(context, image_width); | |
613 nk_image(context, controller_360_image); | |
614 nk_layout_row_push(context, render_width() - image_width - 2 * context->style.font->height); | |
615 if (nk_button_label(context, info.name)) { | |
616 selected_controller = i; | |
617 selected_controller_info = info; | |
618 push_view(view_controller_bindings); | |
619 } | |
620 nk_layout_row_end(context); | |
621 } | |
622 } | |
623 nk_layout_row_static(context, context->style.font->height, (render_width() - 2 * context->style.font->height) / 2, 2); | |
624 nk_label(context, "", NK_TEXT_LEFT); | |
590 if (nk_button_label(context, "Back")) { | 625 if (nk_button_label(context, "Back")) { |
591 pop_view(); | 626 pop_view(); |
592 } | 627 } |
593 nk_end(context); | 628 nk_end(context); |
594 } | 629 } |