comparison nuklear_ui/blastem_nuklear.c @ 2376:1c09f5be285b

Very basic UI for media player
author Michael Pavone <pavone@retrodev.com>
date Fri, 17 Nov 2023 01:05:32 -0800
parents 3e064001594a
children 9e6cb50d0639
comparison
equal deleted inserted replaced
2375:02c04196c2da 2376:1c09f5be285b
19 #include "../config.h" 19 #include "../config.h"
20 #include "../io.h" 20 #include "../io.h"
21 #include "../png.h" 21 #include "../png.h"
22 #include "../controller_info.h" 22 #include "../controller_info.h"
23 #include "../bindings.h" 23 #include "../bindings.h"
24 #include "../mediaplayer.h"
24 25
25 static struct nk_context *context; 26 static struct nk_context *context;
26 static struct rawfb_context *fb_context; 27 static struct rawfb_context *fb_context;
27 28
28 typedef struct 29 typedef struct
68 num_prev = 0; 69 num_prev = 0;
69 } 70 }
70 71
71 void view_play(struct nk_context *context) 72 void view_play(struct nk_context *context)
72 { 73 {
73 74 if (current_system && current_system->type == SYSTEM_MEDIA_PLAYER) {
75 media_player *player = (media_player *)current_system;
76 if (nk_begin(context, "Media Player", nk_rect(0, 0, render_width(), render_height()), 0)) {
77 uint32_t desired_width = context->style.font->height * 10;
78 nk_layout_row_static(context, context->style.font->height * 1.25f, render_width() - 4 * context->style.font->height, 1);
79 nk_label(context, current_media()->name, NK_TEXT_LEFT);
80
81 uint32_t seconds = player->playback_time / 60;
82 uint32_t minutes = seconds / 60;
83 seconds %= 60;
84 uint32_t hours = minutes / 60;
85 minutes %= 60;
86 char buffer[10];
87 sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
88 nk_label(context, buffer, NK_TEXT_LEFT);
89
90 nk_layout_row_static(context, context->style.font->height * 1.25f, desired_width, 1);
91 if (nk_button_label(context, player->state == STATE_PLAY ? "Pause" : "Play")) {
92 uint8_t old_state = player->button_state[BUTTON_A];
93 player->button_state[BUTTON_A] = 0;
94 current_system->gamepad_down(current_system, 1, BUTTON_A);
95 player->button_state[BUTTON_A] = old_state;
96 }
97 nk_end(context);
98 }
99 }
74 } 100 }
75 101
76 static char *browser_cur_path; 102 static char *browser_cur_path;
77 static const char *browser_label; 103 static const char *browser_label;
78 static const char *browser_setting_path; 104 static const char *browser_setting_path;
1033 options[IDENTICAL_CONTROLLERS].title = "Use for identical controllers"; 1059 options[IDENTICAL_CONTROLLERS].title = "Use for identical controllers";
1034 options[DEFAULT].title = "Use as default"; 1060 options[DEFAULT].title = "Use as default";
1035 options[BY_INDEX].title = by_index_names[selected_controller]; 1061 options[BY_INDEX].title = by_index_names[selected_controller];
1036 options[SIMILAR_CONTROLLERS].title = make_human_readable_type_name(&selected_controller_info); 1062 options[SIMILAR_CONTROLLERS].title = make_human_readable_type_name(&selected_controller_info);
1037 1063
1038 if (nk_begin(context, "Select Binding Dest", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) { 1064 if ((context, "Select Binding Dest", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) {
1039 menu(context, NUM_DEST_TYPES, options, handle_dest_clicked); 1065 menu(context, NUM_DEST_TYPES, options, handle_dest_clicked);
1040 nk_end(context); 1066 nk_end(context);
1041 } 1067 }
1042 free((char *)options[SIMILAR_CONTROLLERS].title); 1068 free((char *)options[SIMILAR_CONTROLLERS].title);
1043 } 1069 }
1059 } 1085 }
1060 } 1086 }
1061 1087
1062 void view_controller_bindings(struct nk_context *context) 1088 void view_controller_bindings(struct nk_context *context)
1063 { 1089 {
1064 if (nk_begin(context, "Controller Bindings", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) { 1090 if ((context, "Controller Bindings", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) {
1065 if (!bindings) { 1091 if (!bindings) {
1066 bindings = calloc(1, sizeof(*bindings)); 1092 bindings = calloc(1, sizeof(*bindings));
1067 tern_node *pad = get_binding_node_for_pad(selected_controller, &selected_controller_info); 1093 tern_node *pad = get_binding_node_for_pad(selected_controller, &selected_controller_info);
1068 if (pad) { 1094 if (pad) {
1069 tern_foreach(tern_find_node(pad, "buttons"), button_iter, bindings); 1095 tern_foreach(tern_find_node(pad, "buttons"), button_iter, bindings);
1254 static void view_controller_mappings(struct nk_context *context) 1280 static void view_controller_mappings(struct nk_context *context)
1255 { 1281 {
1256 char buffer[512]; 1282 char buffer[512];
1257 static int quiet, button_a = -1, button_a_axis = -1; 1283 static int quiet, button_a = -1, button_a_axis = -1;
1258 uint8_t added_mapping = 0; 1284 uint8_t added_mapping = 0;
1259 if (nk_begin(context, "Controllers", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) { 1285 if ((context, "Controllers", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) {
1260 1286
1261 nk_layout_space_begin(context, NK_STATIC, render_height() - context->style.font->height, 3); 1287 nk_layout_space_begin(context, NK_STATIC, render_height() - context->style.font->height, 3);
1262 1288
1263 if (current_button < SDL_CONTROLLER_BUTTON_MAX) { 1289 if (current_button < SDL_CONTROLLER_BUTTON_MAX) {
1264 snprintf(buffer, sizeof(buffer), "Press Button %s", get_button_label(&selected_controller_info, current_button)); 1290 snprintf(buffer, sizeof(buffer), "Press Button %s", get_button_label(&selected_controller_info, current_button));
1395 } 1421 }
1396 1422
1397 static void view_controller_variant(struct nk_context *context) 1423 static void view_controller_variant(struct nk_context *context)
1398 { 1424 {
1399 uint8_t selected = 0; 1425 uint8_t selected = 0;
1400 if (nk_begin(context, "Controller Type", nk_rect(0, 0, render_width(), render_height()), 0)) { 1426 if ((context, "Controller Type", nk_rect(0, 0, render_width(), render_height()), 0)) {
1401 nk_layout_row_static(context, context->style.font->height*1.25, render_width() - context->style.font->height * 2, 1); 1427 nk_layout_row_static(context, context->style.font->height*1.25, render_width() - context->style.font->height * 2, 1);
1402 nk_label(context, "", NK_TEXT_CENTERED); 1428 nk_label(context, "", NK_TEXT_CENTERED);
1403 nk_label(context, "Select the layout that", NK_TEXT_CENTERED); 1429 nk_label(context, "Select the layout that", NK_TEXT_CENTERED);
1404 nk_label(context, "best matches your controller", NK_TEXT_CENTERED); 1430 nk_label(context, "best matches your controller", NK_TEXT_CENTERED);
1405 nk_label(context, "", NK_TEXT_CENTERED); 1431 nk_label(context, "", NK_TEXT_CENTERED);
1490 } 1516 }
1491 } 1517 }
1492 1518
1493 void view_controller_type(struct nk_context *context) 1519 void view_controller_type(struct nk_context *context)
1494 { 1520 {
1495 if (nk_begin(context, "Controller Type", nk_rect(0, 0, render_width(), render_height()), 0)) { 1521 if ((context, "Controller Type", nk_rect(0, 0, render_width(), render_height()), 0)) {
1496 controller_type_group(context, "Xbox", TYPE_XBOX, SUBTYPE_XBOX, (const char *[]){ 1522 controller_type_group(context, "Xbox", TYPE_XBOX, SUBTYPE_XBOX, (const char *[]){
1497 "Original", "Xbox 360", "Xbox One/Series", "Xbox Elite" 1523 "Original", "Xbox 360", "Xbox One/Series", "Xbox Elite"
1498 }, 4); 1524 }, 4);
1499 controller_type_group(context, "Playstation", TYPE_PSX, SUBTYPE_PS3, (const char *[]){ 1525 controller_type_group(context, "Playstation", TYPE_PSX, SUBTYPE_PS3, (const char *[]){
1500 "PS3", "PS4", "PS5" 1526 "PS3", "PS4", "PS5"
1576 nk_draw_symbol(&context->current->buffer, NK_SYMBOL_X, nk_rect(left + x, top + 0.25f * crosshair_size, crosshair_size, crosshair_size), nk_rgb(0, 0, 0), nk_rgb(255, 255, 255), 1, context->style.font); 1602 nk_draw_symbol(&context->current->buffer, NK_SYMBOL_X, nk_rect(left + x, top + 0.25f * crosshair_size, crosshair_size, crosshair_size), nk_rgb(0, 0, 0), nk_rgb(255, 255, 255), 1, context->style.font);
1577 } 1603 }
1578 1604
1579 void view_deadzones(struct nk_context *context) 1605 void view_deadzones(struct nk_context *context)
1580 { 1606 {
1581 if (nk_begin(context, "Deadzones", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) { 1607 if ((context, "Deadzones", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) {
1582 nk_layout_space_begin(context, NK_STATIC, render_height() - 3 * context->style.font->height, 4); 1608 nk_layout_space_begin(context, NK_STATIC, render_height() - 3 * context->style.font->height, 4);
1583 1609
1584 float left = render_width() / 8.0f, top = render_height() / 8.0f; 1610 float left = render_width() / 8.0f, top = render_height() / 8.0f;
1585 float size = render_height() / 3.0f; 1611 float size = render_height() / 3.0f;
1586 stick_deadzone_widget(left, top, size, SDL_CONTROLLER_AXIS_LEFTX); 1612 stick_deadzone_widget(left, top, size, SDL_CONTROLLER_AXIS_LEFTX);
1626 } 1652 }
1627 } 1653 }
1628 1654
1629 void view_controllers(struct nk_context *context) 1655 void view_controllers(struct nk_context *context)
1630 { 1656 {
1631 if (nk_begin(context, "Controllers", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) { 1657 if ((context, "Controllers", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) {
1632 int height = (render_height() - 2*context->style.font->height) / 5; 1658 int height = (render_height() - 2*context->style.font->height) / 5;
1633 int inner_height = height - context->style.window.spacing.y; 1659 int inner_height = height - context->style.window.spacing.y;
1634 const struct nk_user_font *font = context->style.font; 1660 const struct nk_user_font *font = context->style.font;
1635 int bindings_width = font->width(font->userdata, font->height, "Bindings", strlen("Bindings")) + context->style.button.padding.x * 2; 1661 int bindings_width = font->width(font->userdata, font->height, "Bindings", strlen("Bindings")) + context->style.button.padding.x * 2;
1636 int remap_width = font->width(font->userdata, font->height, "Remap", strlen("Remap")) + context->style.button.padding.x * 2; 1662 int remap_width = font->width(font->userdata, font->height, "Remap", strlen("Remap")) + context->style.button.padding.x * 2;
2006 uint32_t height = render_height(); 2032 uint32_t height = render_height();
2007 uint32_t desired_width = context->style.font->height * 10; 2033 uint32_t desired_width = context->style.font->height * 10;
2008 if (desired_width > width) { 2034 if (desired_width > width) {
2009 desired_width = width; 2035 desired_width = width;
2010 } 2036 }
2011 if (nk_begin(context, "Video Settings", nk_rect(0, 0, width, height), 0)) { 2037 if ((context, "Video Settings", nk_rect(0, 0, width, height), 0)) {
2012 nk_layout_row_static(context, context->style.font->height, desired_width, 2); 2038 nk_layout_row_static(context, context->style.font->height, desired_width, 2);
2013 settings_toggle(context, "Fullscreen", "video\0fullscreen\0", 0); 2039 settings_toggle(context, "Fullscreen", "video\0fullscreen\0", 0);
2014 settings_toggle(context, "Open GL", "video\0gl\0", 1); 2040 settings_toggle(context, "Open GL", "video\0gl\0", 1);
2015 settings_toggle(context, "Scanlines", "video\0scanlines\0", 0); 2041 settings_toggle(context, "Scanlines", "video\0scanlines\0", 0);
2016 selected_vsync = settings_dropdown_ex(context, "VSync", vsync_opts, vsync_opt_names, num_vsync_opts, selected_vsync, "video\0vsync\0"); 2042 selected_vsync = settings_dropdown_ex(context, "VSync", vsync_opts, vsync_opt_names, num_vsync_opts, selected_vsync, "video\0vsync\0");
2416 } 2442 }
2417 } 2443 }
2418 2444
2419 void blastem_nuklear_render(void) 2445 void blastem_nuklear_render(void)
2420 { 2446 {
2421 if (current_view != view_play) { 2447 if (current_view != view_play || (current_system && current_system->type == SYSTEM_MEDIA_PLAYER)) {
2422 nk_input_end(context); 2448 nk_input_end(context);
2423 current_view(context); 2449 current_view(context);
2424 if (fb_context) { 2450 if (fb_context) {
2425 fb_context->fb.pixels = render_get_framebuffer(FRAMEBUFFER_UI, &fb_context->fb.pitch); 2451 fb_context->fb.pixels = render_get_framebuffer(FRAMEBUFFER_UI, &fb_context->fb.pitch);
2426 nk_rawfb_render(fb_context, nk_rgb(0,0,0), 0); 2452 nk_rawfb_render(fb_context, nk_rgb(0,0,0), 0);