broken SDL input handling (WIP)
This commit is contained in:
parent
af1ef76c70
commit
eace519ea1
1 changed files with 73 additions and 14 deletions
|
@ -584,6 +584,9 @@ int doom_controller_loop(ControllerContext &ctx)
|
||||||
auto &io = ImGui::GetIO();
|
auto &io = ImGui::GetIO();
|
||||||
s32 mouseWheel = 0.0;
|
s32 mouseWheel = 0.0;
|
||||||
|
|
||||||
|
static const float ScaleStep = 0.01f;
|
||||||
|
static const s32 PanStep = 2;
|
||||||
|
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
ImGui_ImplSDL2_ProcessEvent(&event);
|
ImGui_ImplSDL2_ProcessEvent(&event);
|
||||||
|
@ -606,9 +609,67 @@ int doom_controller_loop(ControllerContext &ctx)
|
||||||
if (auto doomEvent = doomevent_from_sdlevent(event))
|
if (auto doomEvent = doomevent_from_sdlevent(event))
|
||||||
post_doom_event(ctx, *doomEvent);
|
post_doom_event(ctx, *doomEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!io.WantCaptureKeyboard && (event.type == SDL_KEYDOWN))
|
||||||
|
{
|
||||||
|
// FIXME: it doesn't work like this. use buttonstate and update it in here, then handle everything later like was done with imgui io
|
||||||
|
const auto sym = event.key.keysym.sym;
|
||||||
|
const auto mod = event.key.keysym.mod;
|
||||||
|
const auto repeat = event.key.repeat;
|
||||||
|
|
||||||
|
// Ctrl-Q to quit
|
||||||
|
if (mod & KMOD_CTRL && sym == SDLK_q)
|
||||||
|
ctx.quit = true;
|
||||||
|
|
||||||
|
// keyboard zoom with - and =, reset with 0
|
||||||
|
if (sym == SDLK_EQUALS)
|
||||||
|
ctx.scaleFactor += ScaleStep;
|
||||||
|
if (sym == SDLK_MINUS)
|
||||||
|
ctx.scaleFactor -= ScaleStep;
|
||||||
|
if (sym == SDLK_0)
|
||||||
|
ctx.scaleFactor = 1.0;
|
||||||
|
|
||||||
|
s32 PanFactor = mod & KMOD_CTRL ? 10 : 1;
|
||||||
|
|
||||||
|
// hjkl scrolling and reset with g
|
||||||
|
if (sym == SDLK_h)
|
||||||
|
ctx.offsetX -= PanStep;
|
||||||
|
if (sym == SDLK_j)
|
||||||
|
ctx.offsetY += PanStep;
|
||||||
|
if (sym == SDLK_k)
|
||||||
|
ctx.offsetY -= PanStep;
|
||||||
|
if (sym == SDLK_l)
|
||||||
|
ctx.offsetX += PanStep;
|
||||||
|
if (sym == SDLK_g)
|
||||||
|
ctx.offsetX = ctx.offsetY = 0;
|
||||||
|
|
||||||
|
// Alt-Enter fullscreen toggle
|
||||||
|
if (mod == KMOD_ALT && sym == SDLK_RETURN && !repeat)
|
||||||
|
{
|
||||||
|
u32 flag = (ctx.isFullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||||
|
SDL_SetWindowFullscreen(ctx.window, flag);
|
||||||
|
ctx.isFullscreen = !ctx.isFullscreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: F1 - help
|
||||||
|
|
||||||
|
// F2 - toggle publish inputs to dooms
|
||||||
|
if (sym == SDLK_F2 && !repeat)
|
||||||
|
{
|
||||||
|
ctx.publishInputsMode = !ctx.publishInputsMode;
|
||||||
|
if (SDL_SetRelativeMouseMode(ctx.publishInputsMode ? SDL_TRUE : SDL_FALSE) < 0)
|
||||||
|
log_warn("SDL_SetRelativeMouseMode: %s", SDL_GetError());
|
||||||
|
io.SetAppAcceptingEvents(!ctx.publishInputsMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// F3 to toggle ImGui visibility (skips the call to run_ui() if true)
|
||||||
|
if (sym == SDLK_F3 && !repeat)
|
||||||
|
ctx.uiVisible = !ctx.uiVisible;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process input events not consumed by ImGui
|
// Process input events not consumed by ImGui
|
||||||
|
#if 0
|
||||||
if (!io.WantCaptureKeyboard)
|
if (!io.WantCaptureKeyboard)
|
||||||
{
|
{
|
||||||
// TODO: make scaling scale with the current scale factor
|
// TODO: make scaling scale with the current scale factor
|
||||||
|
@ -647,24 +708,22 @@ int doom_controller_loop(ControllerContext &ctx)
|
||||||
ctx.isFullscreen = !ctx.isFullscreen;
|
ctx.isFullscreen = !ctx.isFullscreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
// F10 to toggle ImGui visibility (skips the call to run_ui() if true)
|
// TODO: F1 - help
|
||||||
if (ImGui::IsKeyPressed(ImGuiKey_F10, false))
|
|
||||||
|
// F2 - toggle publish inputs to dooms
|
||||||
|
if (ImGui::IsKeyPressed(ImGuiKey_F2, false))
|
||||||
{
|
{
|
||||||
ctx.uiVisible = !ctx.uiVisible;
|
|
||||||
// FIXME: sadly this has issues: after toggling the ui off and
|
|
||||||
// on again the mouse cursor is invisible. Even using
|
|
||||||
// SDL_ShowCursor() unconditionally did not fix it. I suspect
|
|
||||||
// it's caused by some interaction between SDL and ImGui.
|
|
||||||
//if (SDL_SetRelativeMouseMode(ctx.uiVisible ? SDL_TRUE : SDL_FALSE) < 0)
|
|
||||||
// log_warn("SDL_SetRelativeMouseMode: %s", SDL_GetError());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ctrl-A to toggle sending input events to dooms.
|
|
||||||
if (io.KeyCtrl && ImGui::IsKeyPressed(ImGuiKey_A, false))
|
|
||||||
ctx.publishInputsMode = !ctx.publishInputsMode;
|
ctx.publishInputsMode = !ctx.publishInputsMode;
|
||||||
|
if (SDL_SetRelativeMouseMode(ctx.publishInputsMode ? SDL_TRUE : SDL_FALSE) < 0)
|
||||||
|
log_warn("SDL_SetRelativeMouseMode: %s", SDL_GetError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// F3 to toggle ImGui visibility (skips the call to run_ui() if true)
|
||||||
|
if (ImGui::IsKeyPressed(ImGuiKey_F3, false))
|
||||||
|
ctx.uiVisible = !ctx.uiVisible;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static ImVec2 panStartPos;
|
static ImVec2 panStartPos;
|
||||||
|
|
||||||
if (!io.WantCaptureMouse)
|
if (!io.WantCaptureMouse)
|
||||||
|
@ -681,7 +740,7 @@ int doom_controller_loop(ControllerContext &ctx)
|
||||||
if (ImGui::IsKeyReleased(ImGuiKey_MouseLeft))
|
if (ImGui::IsKeyReleased(ImGuiKey_MouseLeft))
|
||||||
ctx.isMousePanning = false;
|
ctx.isMousePanning = false;
|
||||||
|
|
||||||
if (ctx.isMousePanning)
|
if (ctx.isMousePanning && !ctx.publishInputsMode)
|
||||||
{
|
{
|
||||||
auto curPos = io.MousePos;
|
auto curPos = io.MousePos;
|
||||||
auto dx = curPos.x - panStartPos.x;
|
auto dx = curPos.x - panStartPos.x;
|
||||||
|
|
Loading…
Reference in a new issue