updated imgui implementation to filter small analog inputs

This commit is contained in:
Anthony Pesch 2017-12-03 20:43:40 -05:00
parent 572b397952
commit 4fb509246a
5 changed files with 30 additions and 12 deletions

View File

@ -88,7 +88,8 @@ static int boot_init(struct device *dev) {
return 1;
}
void boot_rom_write(struct boot *boot, uint32_t addr, uint32_t data, uint32_t mask) {
void boot_rom_write(struct boot *boot, uint32_t addr, uint32_t data,
uint32_t mask) {
WRITE_DATA(&boot->rom[addr]);
}

View File

@ -10,6 +10,7 @@ struct boot *boot_create(struct dreamcast *dc);
void boot_destroy(struct boot *boot);
uint32_t boot_rom_read(struct boot *boot, uint32_t addr, uint32_t mask);
void boot_rom_write(struct boot *boot, uint32_t addr, uint32_t data, uint32_t mask);
void boot_rom_write(struct boot *boot, uint32_t addr, uint32_t data,
uint32_t mask);
#endif

View File

@ -22,7 +22,7 @@ struct imgui {
int alt[2];
int ctrl[2];
int shift[2];
int16_t keys[K_NUM_KEYS];
int keys[K_NUM_KEYS];
};
/* maintain global pointer for ig* functions */
@ -385,23 +385,36 @@ void imgui_begin_frame(struct imgui *imgui) {
io.DisplaySize = ImVec2((float)width, (float)height);
/* update navigation inputs */
io.NavInputs[ImGuiNavInput_PadActivate] = imgui->keys[K_CONT_A];
io.NavInputs[ImGuiNavInput_PadCancel] = imgui->keys[K_CONT_B];
io.NavInputs[ImGuiNavInput_PadActivate] = (imgui->keys[K_CONT_A] != 0);
io.NavInputs[ImGuiNavInput_PadCancel] = (imgui->keys[K_CONT_B] != 0);
io.NavInputs[ImGuiNavInput_PadUp] =
imgui->keys[K_CONT_DPAD_UP] || (imgui->keys[K_CONT_JOYY] < 0);
(imgui->keys[K_CONT_DPAD_UP] != 0) || (imgui->keys[K_CONT_JOYY] < 0);
io.NavInputs[ImGuiNavInput_PadDown] =
imgui->keys[K_CONT_DPAD_DOWN] || (imgui->keys[K_CONT_JOYY] > 0);
(imgui->keys[K_CONT_DPAD_DOWN] != 0) || (imgui->keys[K_CONT_JOYY] > 0);
io.NavInputs[ImGuiNavInput_PadLeft] =
imgui->keys[K_CONT_DPAD_LEFT] || (imgui->keys[K_CONT_JOYX] < 0);
(imgui->keys[K_CONT_DPAD_LEFT] != 0) || (imgui->keys[K_CONT_JOYX] < 0);
io.NavInputs[ImGuiNavInput_PadRight] =
imgui->keys[K_CONT_DPAD_RIGHT] || (imgui->keys[K_CONT_JOYX] > 0);
(imgui->keys[K_CONT_DPAD_RIGHT] != 0) || (imgui->keys[K_CONT_JOYX] > 0);
ImGui::NewFrame();
}
int imgui_keydown(struct imgui *imgui, int key, int16_t value) {
ImGuiIO &io = ImGui::GetIO();
int down = value != 0;
/* digital inputs will always be either 0 or INT_MAX, but analog inputs will
range from INT16_MIN to INT16_MAX. filter small values to require very
intentional actions when using these analog inputs for navigation */
const int16_t min = 16384;
if (value > min) {
value = 1;
} else if (value < -min) {
value = -1;
} else {
value = 0;
}
bool down = value != 0;
if (key == K_MWHEELUP) {
io.MouseWheel = 1.0f;
@ -426,6 +439,7 @@ int imgui_keydown(struct imgui *imgui, int key, int16_t value) {
imgui->keys[key] = value;
io.KeysDown[key] = down;
}
return 0;
}

View File

@ -1005,7 +1005,8 @@ void ir_debug_break(struct ir *ir) {
ir_append_instr(ir, OP_DEBUG_BREAK, VALUE_V);
}
void ir_debug_log(struct ir *ir, struct ir_value *a, struct ir_value *b, struct ir_value *c) {
void ir_debug_log(struct ir *ir, struct ir_value *a, struct ir_value *b,
struct ir_value *c) {
struct ir_instr *instr = ir_append_instr(ir, OP_DEBUG_LOG, VALUE_V);
ir_set_arg0(ir, instr, a);
ir_set_arg1(ir, instr, b);

View File

@ -418,7 +418,8 @@ void ir_call_cond_2(struct ir *ir, struct ir_value *fn, struct ir_value *arg0,
/* debug */
void ir_debug_break(struct ir *ir);
void ir_debug_log(struct ir *ir, struct ir_value *a, struct ir_value *b, struct ir_value *c);
void ir_debug_log(struct ir *ir, struct ir_value *a, struct ir_value *b,
struct ir_value *c);
void ir_assert_eq(struct ir *ir, struct ir_value *a, struct ir_value *b);
void ir_assert_lt(struct ir *ir, struct ir_value *a, struct ir_value *b);