Mercurial > repos > blastem
comparison nuklear_ui/blastem_nuklear.c @ 1569:0ec89dadb36d
Add code for loading PNG images. Added 360 controller image. WIP work on gamepad mapping UI
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 19 Apr 2018 00:51:10 -0700 |
parents | d14490dee01f |
children | bc96bb3a0998 |
comparison
equal
deleted
inserted
replaced
1568:d14490dee01f | 1569:0ec89dadb36d |
---|---|
10 #include "../paths.h" | 10 #include "../paths.h" |
11 #include "../saves.h" | 11 #include "../saves.h" |
12 #include "../blastem.h" | 12 #include "../blastem.h" |
13 #include "../config.h" | 13 #include "../config.h" |
14 #include "../io.h" | 14 #include "../io.h" |
15 #include "../png.h" | |
15 | 16 |
16 static struct nk_context *context; | 17 static struct nk_context *context; |
17 | 18 |
18 typedef void (*view_fun)(struct nk_context *); | 19 typedef void (*view_fun)(struct nk_context *); |
19 static view_fun current_view; | 20 static view_fun current_view; |
493 set_binding = set_label = NULL; | 494 set_binding = set_label = NULL; |
494 } | 495 } |
495 nk_end(context); | 496 nk_end(context); |
496 } | 497 } |
497 } | 498 } |
499 static struct nk_image controller_image; | |
498 void view_controllers(struct nk_context *context) | 500 void view_controllers(struct nk_context *context) |
499 { | 501 { |
500 if (nk_begin(context, "Controller Bindings", nk_rect(0, 0, render_width(), render_height()), 0)) { | 502 if (nk_begin(context, "Controller Bindings", nk_rect(0, 0, render_width(), render_height()), 0)) { |
503 nk_layout_row_static(context, render_height() - 50, render_width() - 80, 1); | |
504 nk_image(context, controller_image); | |
501 nk_layout_row_static(context, 34, (render_width() - 80) / 2, 1); | 505 nk_layout_row_static(context, 34, (render_width() - 80) / 2, 1); |
502 if (nk_button_label(context, "Back")) { | 506 if (nk_button_label(context, "Back")) { |
503 pop_view(); | 507 pop_view(); |
504 } | 508 } |
505 nk_end(context); | 509 nk_end(context); |
1011 nk_style_set_font(context, &def_font->handle); | 1015 nk_style_set_font(context, &def_font->handle); |
1012 current_view = file_loaded ? view_play : view_menu; | 1016 current_view = file_loaded ? view_play : view_menu; |
1013 render_set_ui_render_fun(blastem_nuklear_render); | 1017 render_set_ui_render_fun(blastem_nuklear_render); |
1014 render_set_event_handler(handle_event); | 1018 render_set_event_handler(handle_event); |
1015 render_set_gl_context_handlers(context_destroyed, context_created); | 1019 render_set_gl_context_handlers(context_destroyed, context_created); |
1020 | |
1021 FILE *f = fopen("images/360.png", "rb"); | |
1022 long buf_size = file_size(f); | |
1023 uint8_t *buf = malloc(buf_size); | |
1024 if (buf_size == fread(buf, 1, buf_size, f)) { | |
1025 uint32_t width, height; | |
1026 uint32_t *pixels = load_png(buf, buf_size, &width, &height); | |
1027 if (pixels) { | |
1028 GLuint tex; | |
1029 glGenTextures(1, &tex); | |
1030 glBindTexture(GL_TEXTURE_2D, tex); | |
1031 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
1032 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
1033 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
1034 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
1035 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixels); | |
1036 free(pixels); | |
1037 controller_image = nk_image_id((int)tex); | |
1038 } | |
1039 } | |
1040 free(buf); | |
1041 | |
1016 active = 1; | 1042 active = 1; |
1017 ui_idle_loop(); | 1043 ui_idle_loop(); |
1018 } | 1044 } |