mirror of https://github.com/inolen/redream.git
removed log spam on unmapped button presses
added fullscreen toggle to debug menu
This commit is contained in:
parent
ecf548dda6
commit
378508dbc0
|
@ -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;
|
||||
|
|
|
@ -9,7 +9,6 @@ struct maple {
|
|||
};
|
||||
|
||||
static bool maple_init(struct device *dev) {
|
||||
// struct maple *mp = (struct maple *)dev;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -48,6 +48,7 @@ struct window {
|
|||
/* read only */
|
||||
int width;
|
||||
int height;
|
||||
int fullscreen;
|
||||
bool debug_menu;
|
||||
bool text_input;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue