summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--images/ps4.pngbin0 -> 104885 bytes
-rw-r--r--nuklear_ui/blastem_nuklear.c64
2 files changed, 47 insertions, 17 deletions
diff --git a/images/ps4.png b/images/ps4.png
new file mode 100644
index 0000000..afb8203
--- /dev/null
+++ b/images/ps4.png
Binary files differ
diff --git a/nuklear_ui/blastem_nuklear.c b/nuklear_ui/blastem_nuklear.c
index 2b4bb0f..24ee5f5 100644
--- a/nuklear_ui/blastem_nuklear.c
+++ b/nuklear_ui/blastem_nuklear.c
@@ -504,8 +504,8 @@ void view_key_bindings(struct nk_context *context)
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 @@ void view_controller_bindings(struct nk_context *context)
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 @@ void view_controller_bindings(struct nk_context *context)
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 @@ void view_controllers(struct nk_context *context)
{
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 @@ static void context_destroyed(void)
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 @@ static void texture_init(void)
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 @@ void blastem_nuklear_init(uint8_t file_loaded)
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;