From 378508dbc0ec472ac0929a8c67e12f1769560241 Mon Sep 17 00:00:00 2001 From: Anthony Pesch Date: Sat, 26 Nov 2016 18:15:07 -0800 Subject: [PATCH] removed log spam on unmapped button presses added fullscreen toggle to debug menu --- src/hw/maple/controller.c | 31 +++++++------- src/hw/maple/maple.c | 1 - src/ui/window.c | 86 ++++++++++++++++++++++++--------------- src/ui/window.h | 1 + src/video/gl_backend.c | 1 - 5 files changed, 71 insertions(+), 49 deletions(-) diff --git a/src/hw/maple/controller.c b/src/hw/maple/controller.c index d28a60b6..8a9c8e12 100644 --- a/src/hw/maple/controller.c +++ b/src/hw/maple/controller.c @@ -23,7 +23,7 @@ enum { CONT_DPAD2_DOWN = 0x2000, CONT_DPAD2_LEFT = 0x4000, CONT_DPAD2_RIGHT = 0x8000, - // only used by internal button map + /* only used by internal button map */ CONT_JOYX = 0x10000, CONT_JOYY = 0x20000, CONT_LTRIG = 0x40000, @@ -47,8 +47,10 @@ struct controller { int map[K_NUM_KEYS]; }; -// Constant device info structure sent as response to CMD_REQDEVINFO to -// identify the controller. +/* + * constant device info structure sent as response to CMD_REQDEVINFO to + * identify the controller + */ static struct maple_device_info controller_devinfo = { FN_CONTROLLER, {0xfe060f00, 0x0, 0x0}, @@ -129,14 +131,13 @@ static bool controller_input(struct maple_device *dev, enum keycode key, int16_t value) { struct controller *ctrl = (struct controller *)dev; - // map incoming key to dreamcast button + /* map incoming key to dreamcast button */ int button = ctrl->map[key]; - // scale incoming int16_t -> uint8_t + /* scale incoming int16_t -> uint8_t */ uint8_t scaled = ((int32_t)value - INT16_MIN) >> 8; if (!button) { - LOG_WARNING("Ignored key %s, no mapping found", get_name_by_key(key)); return false; } @@ -192,20 +193,20 @@ struct maple_device *controller_create() { ctrl->frame = &controller_frame; ctrl->cnd.function = FN_CONTROLLER; - // buttons bitfield contains 0s for pressed buttons and 1s for unpressed + /* buttons bitfield contains 0s for pressed buttons and 1s for unpressed */ ctrl->cnd.buttons = 0xffff; - // triggers completely unpressed + /* triggers completely unpressed */ ctrl->cnd.rtrig = ctrl->cnd.ltrig = 0; - // joysticks default to dead center + /* joysticks default to dead center */ ctrl->cnd.joyy = ctrl->cnd.joyx = ctrl->cnd.joyx2 = ctrl->cnd.joyy2 = 0x80; - // default profile - // CONT_JOYX - // CONT_JOYY - // CONT_LTRIG - // CONT_RTRIG + /* default profile */ + /* CONT_JOYX */ + /* CONT_JOYY */ + /* CONT_LTRIG */ + /* CONT_RTRIG */ ctrl->map[K_SPACE] = CONT_START; ctrl->map[(enum keycode)'k'] = CONT_A; ctrl->map[(enum keycode)'l'] = CONT_B; @@ -216,7 +217,7 @@ struct maple_device *controller_create() { ctrl->map[(enum keycode)'a'] = CONT_DPAD_LEFT; ctrl->map[(enum keycode)'d'] = CONT_DPAD_RIGHT; - // load profile + /* load profile */ controller_load_profile(ctrl, OPTION_profile); return (struct maple_device *)ctrl; diff --git a/src/hw/maple/maple.c b/src/hw/maple/maple.c index a0a8b76e..880752d6 100644 --- a/src/hw/maple/maple.c +++ b/src/hw/maple/maple.c @@ -9,7 +9,6 @@ struct maple { }; static bool maple_init(struct device *dev) { - // struct maple *mp = (struct maple *)dev; return true; } diff --git a/src/ui/window.c b/src/ui/window.c index 9071f295..7b3be4ba 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -35,6 +35,59 @@ static void win_init_joystick(struct window *win) { memset(win->hat_state, 0, sizeof(win->hat_state)); } +static void win_set_fullscreen(struct window *win, int fullscreen) { + win->fullscreen = fullscreen; + + SDL_SetWindowFullscreen(win->handle, fullscreen ? SDL_WINDOW_FULLSCREEN : 0); +} + +static void win_debug_menu(struct window *win) { + if (!win->debug_menu) { + return; + } + + struct nk_context *ctx = &win->nk->ctx; + struct nk_rect bounds = {0.0f, 0.0f, (float)win->width, DEBUG_MENU_HEIGHT}; + + nk_style_default(ctx); + + ctx->style.window.spacing = nk_vec2(0.0f, 0.0f); + ctx->style.window.padding = nk_vec2(0.0f, 0.0f); + + if (nk_begin(ctx, "debug menu", bounds, NK_WINDOW_NO_SCROLLBAR)) { + nk_menubar_begin(ctx); + nk_layout_row_begin(ctx, NK_STATIC, DEBUG_MENU_HEIGHT, MAX_WINDOW_LISTENERS + 2); + + /* add our own debug menu */ + nk_layout_row_push(ctx, 50.0f); + if (nk_menu_begin_label(ctx, "WINDOW", NK_TEXT_LEFT, nk_vec2(140.0f, 200.0f))) { + nk_layout_row_dynamic(ctx, DEBUG_MENU_HEIGHT, 1); + + int fullscreen = win->fullscreen; + if (nk_checkbox_label(ctx, "fullscreen", &fullscreen)) { + win_set_fullscreen(win, fullscreen); + } + + nk_menu_end(ctx); + } + + /* add each listener's debug menu */ + list_for_each_entry(listener, &win->listeners, struct window_listener, it) { + if (listener->debug_menu) { + listener->debug_menu(listener->data, ctx); + } + } + + /* fill up remaining space with status */ + nk_layout_row_push(ctx, (float)win->width - ctx->current->layout->row.item_offset); + nk_label(ctx, win->status, NK_TEXT_RIGHT); + + nk_layout_row_end(ctx); + nk_menubar_end(ctx); + } + nk_end(ctx); +} + static void win_handle_paint(struct window *win) { video_begin_frame(win->video); nk_begin_frame(win->nk); @@ -46,38 +99,7 @@ static void win_handle_paint(struct window *win) { } } - if (win->debug_menu) { - struct nk_context *ctx = &win->nk->ctx; - struct nk_rect bounds = {0.0f, 0.0f, (float)win->width, DEBUG_MENU_HEIGHT}; - - nk_style_default(ctx); - - ctx->style.window.spacing = nk_vec2(0.0f, 0.0f); - ctx->style.window.padding = nk_vec2(0.0f, 0.0f); - - if (nk_begin(ctx, "debug menu", bounds, NK_WINDOW_NO_SCROLLBAR)) { - nk_menubar_begin(ctx); - nk_layout_row_begin(ctx, NK_STATIC, DEBUG_MENU_HEIGHT, - MAX_WINDOW_LISTENERS + 1); - - /* add each listener's debug menu */ - list_for_each_entry(listener, &win->listeners, struct window_listener, - it) { - if (listener->debug_menu) { - listener->debug_menu(listener->data, ctx); - } - } - - /* fill up remaining space with status */ - nk_layout_row_push( - ctx, (float)win->width - ctx->current->layout->row.item_offset); - nk_label(ctx, win->status, NK_TEXT_RIGHT); - - nk_layout_row_end(ctx); - nk_menubar_end(ctx); - } - nk_end(ctx); - } + win_debug_menu(win); mp_end_frame(win->mp); nk_end_frame(win->nk); diff --git a/src/ui/window.h b/src/ui/window.h index 2683472a..cc03847e 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -48,6 +48,7 @@ struct window { /* read only */ int width; int height; + int fullscreen; bool debug_menu; bool text_input; diff --git a/src/video/gl_backend.c b/src/video/gl_backend.c index 464c1416..6addf74d 100644 --- a/src/video/gl_backend.c +++ b/src/video/gl_backend.c @@ -500,7 +500,6 @@ static void video_debug_menu(void *data, struct nk_context *ctx) { struct video_backend *video = data; nk_layout_row_push(ctx, 50.0f); - if (nk_menu_begin_label(ctx, "VIDEO", NK_TEXT_LEFT, nk_vec2(140.0f, 200.0f))) { nk_layout_row_dynamic(ctx, DEBUG_MENU_HEIGHT, 1);