toggle fullscreen, toggle ui, invert mouse panning

This commit is contained in:
oxmox 2023-02-20 22:50:17 +01:00
parent 4a0117af36
commit fb3441f5d3

View file

@ -1,4 +1,5 @@
#include <nng/nng.h>
#include <imgui.h>
#include <backends/imgui_impl_sdl.h>
#include <backends/imgui_impl_sdlrenderer.h>
@ -46,7 +47,7 @@ struct DoomState
// So easy to get this wrong and destroy the texture by accident. Cleanup is
// now done in check_on_dooms() before erasing the state. Enabling this code
// still works though.
#if 1
#if 0
DoomState() = default;
~DoomState()
{
@ -93,6 +94,8 @@ struct ControllerContext
s32 offsetX = 0;
s32 offsetY = 0;
bool isMousePanning = false;
bool isFullscreen = false;
bool uiVisible = true;
};
struct ControllerActions
@ -579,7 +582,7 @@ ControllerActions run_ui(ControllerContext &ctx)
// Window contents
ControllerActions result = {};
static int doomsToSpawn = 1;
static int doomsToSpawn = 4;
ImGui::PushItemWidth(ImGui::GetFontSize() * -16); // affects stuff like slider widths
@ -641,6 +644,7 @@ int doom_controller_loop(ControllerContext &ctx)
if (io.KeyCtrl && ImGui::IsKeyDown(ImGuiKey_Q))
ctx.quit = true;
// keyboard zoom with - and =, reset with 0
if (ImGui::IsKeyDown(ImGuiKey_Equal))
ctx.scaleFactor += ScaleStep;
if (ImGui::IsKeyDown(ImGuiKey_Minus))
@ -648,6 +652,7 @@ int doom_controller_loop(ControllerContext &ctx)
if (ImGui::IsKeyDown(ImGuiKey_0))
ctx.scaleFactor = 1.0;
// hjkl scrolling and reset with g
if (ImGui::IsKeyDown(ImGuiKey_H))
ctx.offsetX -= PanStep;
if (ImGui::IsKeyDown(ImGuiKey_J))
@ -656,9 +661,19 @@ int doom_controller_loop(ControllerContext &ctx)
ctx.offsetY -= PanStep;
if (ImGui::IsKeyDown(ImGuiKey_L))
ctx.offsetX += PanStep;
if (ImGui::IsKeyDown(ImGuiKey_G))
ctx.offsetX = ctx.offsetY = 0;
// fullscreen toggle
if (io.KeyAlt && ImGui::IsKeyPressed(ImGuiKey_Enter, false))
{
u32 flag = (ctx.isFullscreen ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP);
SDL_SetWindowFullscreen(ctx.window, flag);
ctx.isFullscreen = !ctx.isFullscreen;
}
if (ImGui::IsKeyPressed(ImGuiKey_F10, false))
ctx.uiVisible = !ctx.uiVisible;
}
static ImVec2 panStartPos;
@ -682,8 +697,8 @@ int doom_controller_loop(ControllerContext &ctx)
auto curPos = io.MousePos;
auto dx = curPos.x - panStartPos.x;
auto dy = curPos.y - panStartPos.y;
ctx.offsetX += dx;
ctx.offsetY += dy;
ctx.offsetX -= dx;
ctx.offsetY -= dy;
panStartPos = curPos;
}
@ -698,6 +713,8 @@ int doom_controller_loop(ControllerContext &ctx)
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
actions = {};
if (ctx.uiVisible)
actions = run_ui(ctx);
// Rendering
@ -744,7 +761,7 @@ int main(int argc, char *argv[])
#endif
const auto windowFlags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_OPENGL;
auto window = SDL_CreateWindow("doompanning", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, windowFlags);
auto window = SDL_CreateWindow("doompanning", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 960, windowFlags);
if (!window)
dp_sdl_fatal("SDL_CreateWindow");