# HG changeset patch # User Michael Pavone # Date 1533953420 25200 # Node ID 9c8f587404508390f743e6cc528d70452eb2b592 # Parent 419a0a133b5c06fa136987b4c7c380e2f7d0dea3 Added PS4 controller image. Added code to use PS4 image for Playstation controllers diff -r 419a0a133b5c -r 9c8f58740450 images/ps4.png Binary file images/ps4.png has changed diff -r 419a0a133b5c -r 9c8f58740450 nuklear_ui/blastem_nuklear.c --- a/nuklear_ui/blastem_nuklear.c Fri Aug 03 19:32:21 2018 -0700 +++ b/nuklear_ui/blastem_nuklear.c Fri Aug 10 19:10:20 2018 -0700 @@ -504,8 +504,8 @@ static int selected_controller; static controller_info selected_controller_info; -static struct nk_image controller_360_image; -static uint32_t controller_360_width, controller_360_height; +static struct nk_image controller_360_image, controller_ps4_image; +static uint32_t controller_360_width, controller_360_height, controller_ps4_width, controller_ps4_height; //#define MIN_BIND_BOX_WIDTH 140 #define MAX_BIND_BOX_WIDTH 350 @@ -638,7 +638,16 @@ uint32_t avail_height = render_height() - 2 * orig_height; float desired_width = render_width() * 0.5f, desired_height = avail_height * 0.5f; - float controller_ratio = (float)controller_360_width / (float)controller_360_height; + uint32_t controller_width, controller_height; + if (selected_controller_info.type == TYPE_PSX) { + controller_width = controller_ps4_width; + controller_height = controller_ps4_height; + } else { + controller_width = controller_360_width; + controller_height = controller_360_height; + } + + float controller_ratio = (float)controller_width / (float)controller_height; const struct nk_user_font *font = context->style.font; int MIN_BIND_BOX_WIDTH = font->width(font->userdata, font->height, "Right", strlen("Right")) @@ -659,7 +668,7 @@ float img_bot = img_top + desired_height; nk_layout_space_begin(context, NK_STATIC, avail_height, INT_MAX); nk_layout_space_push(context, nk_rect(img_left, img_top, desired_width, desired_height)); - nk_image(context, controller_360_image); + nk_image(context, selected_controller_info.type == TYPE_PSX ? controller_ps4_image : controller_360_image); float bind_box_width = (render_width() - img_right) * 0.8f; if (bind_box_width < MIN_BIND_BOX_WIDTH) { @@ -937,18 +946,26 @@ { if (nk_begin(context, "Controllers", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) { int height = (render_width() - 2*context->style.font->height) / MAX_JOYSTICKS; - int image_width = height * controller_360_width / controller_360_height; for (int i = 0; i < MAX_JOYSTICKS; i++) { SDL_Joystick *joy = render_get_joystick(i); if (joy) { controller_info info = get_controller_info(i); + uint32_t controller_width, controller_height; + if (info.type == TYPE_PSX) { + controller_width = controller_ps4_width; + controller_height = controller_ps4_height; + } else { + controller_width = controller_360_width; + controller_height = controller_360_height; + } + int image_width = height * controller_width / controller_height; nk_layout_row_begin(context, NK_STATIC, height, 2); nk_layout_row_push(context, image_width); if (info.type == TYPE_UNKNOWN || info.type == TYPE_GENERIC_MAPPING) { nk_label(context, "?", NK_TEXT_CENTERED); } else { - nk_image(context, controller_360_image); + nk_image(context, info.type == TYPE_PSX ? controller_ps4_image : controller_360_image); } nk_layout_row_push(context, render_width() - image_width - 2 * context->style.font->height); if (nk_button_label(context, info.name)) { @@ -1449,7 +1466,20 @@ nk_sdl_shutdown(); } -static uint32_t *controller_360_buf; +static uint32_t *controller_360_buf, *controller_ps4_buf; + +static struct nk_image load_image_texture(uint32_t *buf, uint32_t width, uint32_t height) +{ + GLuint tex; + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D, tex); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, buf); + return nk_image_id((int)tex); +} static void texture_init(void) { @@ -1465,15 +1495,10 @@ nk_sdl_font_stash_end(); nk_style_set_font(context, &def_font->handle); if (controller_360_buf) { - GLuint tex; - glGenTextures(1, &tex); - glBindTexture(GL_TEXTURE_2D, tex); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, controller_360_width, controller_360_height, 0, GL_BGRA, GL_UNSIGNED_BYTE, controller_360_buf); - controller_360_image = nk_image_id((int)tex); + controller_360_image = load_image_texture(controller_360_buf, controller_360_width, controller_360_height); + } + if (controller_ps4_buf) { + controller_ps4_image = load_image_texture(controller_ps4_buf, controller_ps4_width, controller_ps4_height); } } @@ -1531,7 +1556,12 @@ if (buf) { controller_360_buf = load_png(buf, buf_size, &controller_360_width, &controller_360_height); free(buf); - } + } + buf = (uint8_t *)read_bundled_file("images/ps4.png", &buf_size); + if (buf) { + controller_ps4_buf = load_png(buf, buf_size, &controller_ps4_width, &controller_ps4_height); + free(buf); + } texture_init(); current_view = file_loaded ? view_play : view_menu;