comparison nuklear_ui/blastem_nuklear.c @ 1571:3def7b216a5b

WIP controller binding view
author Michael Pavone <pavone@retrodev.com>
date Sat, 21 Apr 2018 14:48:01 -0700
parents bc96bb3a0998
children 5efeca06d942
comparison
equal deleted inserted replaced
1570:bc96bb3a0998 1571:3def7b216a5b
1 #define NK_IMPLEMENTATION 1 #define NK_IMPLEMENTATION
2 #define NK_SDL_GLES2_IMPLEMENTATION 2 #define NK_SDL_GLES2_IMPLEMENTATION
3 3
4 #include <stdlib.h> 4 #include <stdlib.h>
5 #include <limits.h>
5 #include "blastem_nuklear.h" 6 #include "blastem_nuklear.h"
6 #include "font.h" 7 #include "font.h"
7 #include "../render.h" 8 #include "../render.h"
8 #include "../render_sdl.h" 9 #include "../render_sdl.h"
9 #include "../util.h" 10 #include "../util.h"
496 nk_end(context); 497 nk_end(context);
497 } 498 }
498 } 499 }
499 static struct nk_image controller_360_image; 500 static struct nk_image controller_360_image;
500 static uint32_t controller_360_width, controller_360_height; 501 static uint32_t controller_360_width, controller_360_height;
502 #define MIN_BIND_BOX_WIDTH 140
503 #define MAX_BIND_BOX_WIDTH 350
501 void view_controllers(struct nk_context *context) 504 void view_controllers(struct nk_context *context)
502 { 505 {
503 if (nk_begin(context, "Controller Bindings", nk_rect(0, 0, render_width(), render_height()), 0)) { 506 if (nk_begin(context, "Controller Bindings", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) {
504 nk_layout_row_static(context, render_height() - 50, render_width() - 80, 1); 507 uint32_t avail_height = render_height() - 60;
508 float desired_width = render_width() * 0.5f, desired_height = avail_height * 0.5f;
509 float controller_ratio = (float)controller_360_width / (float)controller_360_height;
510 if (render_width() - desired_width < 2.5f*MIN_BIND_BOX_WIDTH) {
511 desired_width = render_width() - 2.5f*MIN_BIND_BOX_WIDTH;
512 }
513
514 if (desired_width / desired_height > controller_ratio) {
515 desired_width = desired_height * controller_ratio;
516 } else {
517 desired_height = desired_width / controller_ratio;
518 }
519 float img_left = render_width() / 2.0f - desired_width / 2.0f;
520 float img_top = avail_height / 2.0f - desired_height / 2.0f;
521 float img_right = img_left + desired_width;
522 nk_layout_space_begin(context, NK_STATIC, avail_height, INT_MAX);
523 nk_layout_space_push(context, nk_rect(img_left, img_top, desired_width, desired_height));
505 nk_image(context, controller_360_image); 524 nk_image(context, controller_360_image);
525
526 float bind_box_width = (render_width() - img_right) * 0.8f;
527 if (bind_box_width < MIN_BIND_BOX_WIDTH) {
528 bind_box_width = render_width() - img_right;
529 if (bind_box_width > MIN_BIND_BOX_WIDTH) {
530 bind_box_width = MIN_BIND_BOX_WIDTH;
531 }
532 } else if (bind_box_width > MAX_BIND_BOX_WIDTH) {
533 bind_box_width = MAX_BIND_BOX_WIDTH;
534 }
535 float bind_box_left;
536 if (bind_box_width >= (render_width() - img_right)) {
537 bind_box_left = img_right;
538 } else {
539 bind_box_left = img_right + (render_width() - img_right) / 2.0f - bind_box_width / 2.0f;
540 }
541
542 nk_layout_space_push(context, nk_rect(bind_box_left, img_top, bind_box_width, 165));
543 nk_group_begin(context, "Action Buttons", NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR);
544 float widths[] = {34, bind_box_width - 60};
545 nk_layout_row(context, NK_STATIC, 34, 2, widths);
546 nk_label(context, "A", NK_TEXT_LEFT);
547 nk_button_label(context, "A");
548 nk_label(context, "B", NK_TEXT_LEFT);
549 nk_button_label(context, "B");
550 nk_label(context, "X", NK_TEXT_LEFT);
551 nk_button_label(context, "X");
552 nk_label(context, "Y", NK_TEXT_LEFT);
553 nk_button_label(context, "Internal Screenshot");
554 nk_group_end(context);
555
556 bind_box_left -= img_right;
557 widths[0] += 44;
558 widths[1] -= 44;
559 nk_layout_space_push(context, nk_rect(bind_box_left, img_top, bind_box_width, 205));
560 nk_group_begin(context, "Left Stick", NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR);
561 nk_layout_row(context, NK_STATIC, 34, 2, widths);
562 nk_label(context, "Up", NK_TEXT_LEFT);
563 nk_button_label(context, "Up");
564 nk_label(context, "Down", NK_TEXT_LEFT);
565 nk_button_label(context, "Down");
566 nk_label(context, "Left", NK_TEXT_LEFT);
567 nk_button_label(context, "Left");
568 nk_label(context, "Right", NK_TEXT_LEFT);
569 nk_button_label(context, "Right");
570 nk_label(context, "Click", NK_TEXT_LEFT);
571 nk_button_label(context, "None");
572
573 nk_group_end(context);
574
575 nk_layout_space_end(context);
576
506 nk_layout_row_static(context, 34, (render_width() - 80) / 2, 1); 577 nk_layout_row_static(context, 34, (render_width() - 80) / 2, 1);
507 if (nk_button_label(context, "Back")) { 578 if (nk_button_label(context, "Back")) {
508 pop_view(); 579 pop_view();
509 } 580 }
510 nk_end(context); 581 nk_end(context);