// SPDX-License-Identifier: MIT // Copyright (c) 2026 The Bozos (boubou666 and Arzaroth). MIT licence (see LICENSE at the repository root). // // The settings window (F2) and the frame rate counter (F3) (bozo/app/panel.h). // - The host (ImGui's context and backends, the keys, the tab bar, the counter) is written fresh for BozoEngine: the // fork's panel host lived in a file that cannot move (phase4-inventory.md section 2.2). // - The Settings window's Video and Controls tabs are moved from the team's lines of the fork's ps2_debug_panel.cpp // (2230-2519, phase4-inventory.md section 2.1): raylib's key reads replaced by SDL3 events // (input::bindingFromEvent), four players instead of two, no GS scale (kept in video.ini, not applied). #include "bozo/app/panel.h" #include "bozo/app/app.h" #include "bozo/app/frame_pacer.h" #include "bozo/app/input_bindings.h" #include "bozo/app/settings_tabs.h" #include "bozo/app/video_settings.h" #include "bozo/app/window.h" #include "bozo/render/gl.h" #include #include "imgui.h" #include "imgui_impl_opengl3.h" #include "imgui_impl_sdl3.h" #include #include #include #include #include #include #include #include #include #include #include #include #include namespace bozo::app { namespace { void drawNotice(); // While the game is fast-forwarded (FramePacer::speedPercent, set by the window): its speed at the top left. void drawFastForward() { const uint32_t speed = FramePacer::speedPercent().load(std::memory_order_relaxed); if (speed == 100u) return; const ImGuiViewport *viewport = ImGui::GetMainViewport(); const float pad = 10.0f * ImGui::GetStyle().FontScaleDpi; ImGui::SetNextWindowPos(ImVec2(viewport->WorkPos.x + pad, viewport->WorkPos.y + pad), ImGuiCond_Always); ImGui::SetNextWindowBgAlpha(0.45f); const ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoInputs; if (ImGui::Begin("##fast-forward", nullptr, flags)) { if (speed == 0u) ImGui::TextUnformatted(">> unlimited"); else if (speed % 100u == 0u) ImGui::Text(">> %ux", speed / 100u); else ImGui::Text(">> %u%%", speed); } ImGui::End(); } } struct Panel::Impl { SDL_Window *window = nullptr; bool ready = false; bool settings = false; // F2 bool focusSettings = false; // just opened: the settings window takes the focus (gamepad navigation) bool overlay = false; // F3 std::string openTab; // PS2X_SETTINGS_OPEN's tab, selected once std::string iniPath; // imgui.ini (ImGui keeps the pointer) int controlsPlayer = 0; int bindingAction = -1; // the action an Add waits an input for (-1: none) double gameFps = 0.0, presentFps = 0.0, frameMs = 0.0; void drawSettings(); void drawVideoTab(); void drawControlsTab(); void drawOverlay(); }; Panel::Panel() : impl_(new Impl) {} Panel::~Panel() { shutdown(); delete impl_; } bool Panel::init(SDL_Window *window, void *glContext) { Impl &m = *impl_; IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO &io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard | ImGuiConfigFlags_NavEnableGamepad; const std::filesystem::path &user = userDirectory(); m.iniPath = (user.empty() ? std::filesystem::path("imgui.ini") : user / "imgui.ini").string(); io.IniFilename = m.iniPath.c_str(); ImGui::StyleColorsDark(); // The monitor's scale (a 4K screen at 150 %: the panel at 150 %). const float scale = std::clamp(SDL_GetWindowDisplayScale(window), 1.0f, 4.0f); ImGuiStyle &style = ImGui::GetStyle(); style.ScaleAllSizes(scale); style.FontScaleDpi = scale; if (!ImGui_ImplSDL3_InitForOpenGL(window, glContext) || !ImGui_ImplOpenGL3_Init("#version 330")) { std::fprintf(stderr, "[panel] ImGui's SDL3 / OpenGL 3 backends could not start: no settings window\n"); ImGui::DestroyContext(); return false; } // Every gamepad steers the settings window (any player's), not only the first plugged in. ImGui_ImplSDL3_SetGamepadMode(ImGui_ImplSDL3_GamepadMode_AutoAll); m.window = window; m.ready = true; if (const char *show = std::getenv("PS2X_SHOW_FPS"); show && *show == '1') m.overlay = true; if (const char *open = std::getenv("PS2X_SETTINGS_OPEN"); open && *open) { m.settings = true; m.focusSettings = true; m.openTab = open; } return true; } void Panel::shutdown() { Impl &m = *impl_; if (!m.ready) return; ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplSDL3_Shutdown(); ImGui::DestroyContext(); m.ready = false; } void Panel::handleEvent(const SDL_Event &event) { Impl &m = *impl_; if (!m.ready) return; if (event.type == SDL_EVENT_KEY_DOWN && !event.key.repeat) { if (event.key.scancode == SDL_SCANCODE_F2) { toggleSettings(); return; } if (event.key.scancode == SDL_SCANCODE_F3) { m.overlay = !m.overlay; return; } } ImGui_ImplSDL3_ProcessEvent(&event); // Controls: the first input since Add was clicked (mouse input only over the game, not over the panel). if (m.settings && m.bindingAction >= 0) { input::Binding binding; if (input::bindingFromEvent(event, binding)) { const bool mouse = binding.source == input::Source::MouseButton || binding.source == input::Source::MouseWheel || binding.source == input::Source::MouseMove; if (!(mouse && ImGui::GetIO().WantCaptureMouse)) { // config() takes the same (non-recursive) mutex: fetched before the lock, as the other callers do. // Under the lock it threw "resource deadlock would occur" at the first input after Add. input::Config &config = input::config(); std::lock_guard lock(input::configMutex()); std::vector &list = config.players[m.controlsPlayer].actions[m.bindingAction]; if (std::find(list.begin(), list.end(), binding) == list.end()) list.push_back(binding); m.bindingAction = -1; } } } } void Panel::setRates(double gameFramesPerSecond, double presentsPerSecond, double frameMs) { impl_->gameFps = gameFramesPerSecond; impl_->presentFps = presentsPerSecond; impl_->frameMs = frameMs; } bool Panel::settingsOpen() const { return impl_->ready && impl_->settings; } void Panel::toggleSettings() { Impl &m = *impl_; if (!m.ready) return; m.settings = !m.settings; m.focusSettings = m.settings; if (!m.settings) m.bindingAction = -1; } bool Panel::holdsGamepads() const { return impl_->ready && impl_->settings; } bool Panel::overlayShown() const { return impl_->ready && impl_->overlay; } bool Panel::holdsKeyboard() const { return impl_->ready && impl_->settings && (impl_->bindingAction >= 0 || ImGui::GetIO().WantTextInput); } bool Panel::holdsMouse() const { return impl_->ready && impl_->settings; } void Panel::draw() { Impl &m = *impl_; if (!m.ready) return; ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplSDL3_NewFrame(); ImGui::NewFrame(); if (m.settings) m.drawSettings(); if (m.overlay) m.drawOverlay(); drawNotice(); drawFastForward(); ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } // ---- Notices (notify): a save state's result, bottom left for a few seconds ---- namespace { std::mutex s_noticeMutex; std::string s_notice; std::chrono::steady_clock::time_point s_noticeAt; void drawNotice() { std::string text; { std::lock_guard lock(s_noticeMutex); if (s_notice.empty() || std::chrono::steady_clock::now() - s_noticeAt > std::chrono::seconds(4)) return; text = s_notice; } const ImGuiViewport *viewport = ImGui::GetMainViewport(); const float pad = 10.0f * ImGui::GetStyle().FontScaleDpi; ImGui::SetNextWindowPos(ImVec2(viewport->WorkPos.x + pad, viewport->WorkPos.y + viewport->WorkSize.y - pad), ImGuiCond_Always, ImVec2(0.0f, 1.0f)); ImGui::SetNextWindowBgAlpha(0.55f); const ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoInputs; if (ImGui::Begin("##notice", nullptr, flags)) ImGui::TextUnformatted(text.c_str()); ImGui::End(); } } void notify(const std::string &text) { std::lock_guard lock(s_noticeMutex); s_notice = text; s_noticeAt = std::chrono::steady_clock::now(); } std::string stateSlotPath(int slot) { std::filesystem::path dir = userDirectory().empty() ? std::filesystem::path("states") : userDirectory() / "states"; std::error_code ec; std::filesystem::create_directories(dir, ec); return (dir / ("slot" + std::to_string(slot) + ".state")).string(); } std::string stateSlotPicturePath(int slot) { return std::filesystem::path(stateSlotPath(slot)).replace_extension(".png").string(); } std::string stateSlotSummary(int slot) { const std::filesystem::path path = stateSlotPath(slot); std::error_code ec; const auto written = std::filesystem::last_write_time(path, ec); if (ec) return "Slot " + std::to_string(slot) + ": empty"; const auto system = std::chrono::clock_cast(written); const std::time_t t = std::chrono::system_clock::to_time_t(system); char when[32] = ""; if (const std::tm *local = std::localtime(&t)) std::strftime(when, sizeof when, "%Y-%m-%d %H:%M", local); return "Slot " + std::to_string(slot) + ": saved " + when; } namespace { std::atomic s_stateSlot{0}; // The Save states tab's thumbnails: each slot's picture as a texture, loaded again when its file changes (the // window's thread, which owns the GL context; a file still being written fails to load and is tried again). struct Thumbnail { render::gl::GLuint texture = 0; std::filesystem::file_time_type loaded{}; int width = 0, height = 0; }; std::array s_thumbnails; const Thumbnail &thumbnail(int slot) { Thumbnail &t = s_thumbnails[static_cast(slot)]; const std::string path = stateSlotPicturePath(slot); std::error_code ec; const auto written = std::filesystem::last_write_time(path, ec); const render::gl::Api &g = render::gl::api(); if (ec) { if (t.texture) g.DeleteTextures(1, &t.texture); t = Thumbnail{}; return t; } if (t.texture && written == t.loaded) return t; SDL_Surface *file = SDL_LoadPNG(path.c_str()); SDL_Surface *rgba = file ? SDL_ConvertSurface(file, SDL_PIXELFORMAT_RGBA32) : nullptr; if (rgba) { if (!t.texture) g.GenTextures(1, &t.texture); g.BindTexture(render::gl::kTexture2D, t.texture); g.TexParameteri(render::gl::kTexture2D, render::gl::kTextureMinFilter, static_cast(render::gl::kLinear)); g.TexParameteri(render::gl::kTexture2D, render::gl::kTextureMagFilter, static_cast(render::gl::kLinear)); g.TexParameteri(render::gl::kTexture2D, render::gl::kTextureWrapS, static_cast(render::gl::kClampToEdge)); g.TexParameteri(render::gl::kTexture2D, render::gl::kTextureWrapT, static_cast(render::gl::kClampToEdge)); g.PixelStorei(render::gl::kUnpackAlignment, 4); g.TexImage2D(render::gl::kTexture2D, 0, static_cast(render::gl::kRgba8), rgba->w, rgba->h, 0, render::gl::kRgba, render::gl::kUnsignedByte, rgba->pixels); g.BindTexture(render::gl::kTexture2D, 0); t.loaded = written; t.width = rgba->w; t.height = rgba->h; SDL_DestroySurface(rgba); } if (file) SDL_DestroySurface(file); return t; } } int stateSlot() { return s_stateSlot.load(std::memory_order_relaxed); } void setStateSlot(int slot) { s_stateSlot.store(((slot % kStateSlots) + kStateSlots) % kStateSlots); } void registerStateTab(std::function save, std::function load) { ui::registerTab("Save states", [save, load] { ImGui::TextDisabled("F5 saves the selected slot, F7 loads it, F6 / Shift+F6 selects the next / previous."); ImGui::Separator(); const float unit = ImGui::GetStyle().FontScaleDpi; const ImVec2 picture(96.0f * unit, 72.0f * unit); for (int slot = 0; slot < kStateSlots; ++slot) { ImGui::PushID(slot); const std::string summary = stateSlotSummary(slot); const float buttons = ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - 120.0f * unit; // The picture taken when it was saved (a blank box without one), larger under the pointer. const Thumbnail &t = thumbnail(slot); const bool hasPicture = t.texture && !summary.ends_with(": empty"); if (hasPicture) { const ImTextureID id = static_cast(t.texture); ImGui::Image(id, picture); if (ImGui::BeginItemTooltip()) { ImGui::Image(id, ImVec2(static_cast(t.width) * unit, static_cast(t.height) * unit)); ImGui::EndTooltip(); } } else ImGui::Dummy(ImVec2(picture.x, ImGui::GetFrameHeight())); // an empty slot's row stays one line ImGui::SameLine(); // The slot's line, centred on its picture (a group: SameLine stays on its line). const float groupX = ImGui::GetCursorPosX(); ImGui::BeginGroup(); if (hasPicture) ImGui::Dummy(ImVec2(0.0f, (picture.y - ImGui::GetFrameHeight()) * 0.5f - ImGui::GetStyle().ItemSpacing.y)); if (ImGui::RadioButton(summary.c_str(), stateSlot() == slot)) setStateSlot(slot); ImGui::SameLine(buttons - groupX); if (ImGui::Button("Save")) { setStateSlot(slot); save(slot); } ImGui::SameLine(); ImGui::BeginDisabled(summary.ends_with(": empty")); if (ImGui::Button("Load")) { setStateSlot(slot); load(slot); } ImGui::EndDisabled(); ImGui::EndGroup(); ImGui::PopID(); } ImGui::Separator(); ImGui::TextDisabled("Files: %s", std::filesystem::path(stateSlotPath(0)).parent_path().string().c_str()); }); } // ---- F3: the frame rate counter ---- void Panel::Impl::drawOverlay() { const ImGuiViewport *viewport = ImGui::GetMainViewport(); const float pad = 10.0f * ImGui::GetStyle().FontScaleDpi; ImGui::SetNextWindowPos(ImVec2(viewport->WorkPos.x + viewport->WorkSize.x - pad, viewport->WorkPos.y + pad), ImGuiCond_Always, ImVec2(1.0f, 0.0f)); ImGui::SetNextWindowBgAlpha(0.45f); const ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoInputs; if (ImGui::Begin("##fps", nullptr, flags)) { // The game's frames a second: what the player gets (the presents can only show those). const ImVec4 colour = gameFps >= 59.0 ? ImVec4(0.55f, 1.0f, 0.55f, 1.0f) : gameFps >= 50.0 ? ImVec4(1.0f, 0.85f, 0.35f, 1.0f) : ImVec4(1.0f, 0.45f, 0.4f, 1.0f); ImGui::TextColored(colour, "%.1f FPS", gameFps); ImGui::TextDisabled("%.1f ms a frame, %.0f presents/s", frameMs, presentFps); } ImGui::End(); } // ---- F2: the settings window ---- void Panel::Impl::drawSettings() { const float unit = ImGui::GetStyle().FontScaleDpi; ImGui::SetNextWindowSize(ImVec2(640.0f * unit, 600.0f * unit), ImGuiCond_FirstUseEver); if (focusSettings) { ImGui::SetNextWindowFocus(); focusSettings = false; } if (!ImGui::Begin("Settings (F2)", &settings)) { ImGui::End(); return; } if (!settings) bindingAction = -1; if (ImGui::BeginTabBar("settings-tabs")) { // PS2X_SETTINGS_OPEN's tab, selected once. const auto flags = [this](const char *name) { if (openTab.empty() || openTab != name) return ImGuiTabItemFlags_None; openTab.clear(); return ImGuiTabItemFlags_SetSelected; }; if (ImGui::BeginTabItem("Controls", nullptr, flags("Controls"))) { drawControlsTab(); ImGui::EndTabItem(); } else bindingAction = -1; if (ImGui::BeginTabItem("Video", nullptr, flags("Video"))) { drawVideoTab(); ImGui::EndTabItem(); } // The port's own tabs (bozo::app::ui::registerTab). for (const ui::Tab &tab : ui::tabs()) if (ImGui::BeginTabItem(tab.name.c_str(), nullptr, flags(tab.name.c_str()))) { if (tab.draw) tab.draw(); ImGui::EndTabItem(); } ImGui::EndTabBar(); } ImGui::End(); } void Panel::Impl::drawVideoTab() { video::Settings &edited = video::edited(); const video::Settings ¤t = video::current(); const float unit = ImGui::GetStyle().FontScaleDpi; // What the environment sets wins over video.ini at the next launch too. const auto envNote = [](const char *name) { if (const char *value = std::getenv(name); value && *value) { ImGui::SameLine(); ImGui::TextDisabled("(%s=%s at launch)", name, value); } }; ImGui::SeparatorText("Display"); static const char *kModes[] = {"Windowed", "Fullscreen", "Borderless window"}; int mode = static_cast(edited.mode); ImGui::SetNextItemWidth(240.0f * unit); if (ImGui::Combo("Mode", &mode, kModes, IM_ARRAYSIZE(kModes))) edited.mode = static_cast(mode); envNote("PS2X_WINDOW_MODE"); const std::vector> sizes = video::resolutions(); const auto [monitorWidth, monitorHeight] = video::monitorSize(); const auto label = [&](int width, int height) { const int divisor = std::gcd(width, height); int ratioW = divisor ? width / divisor : 0, ratioH = divisor ? height / divisor : 0; if (ratioW == 8 && ratioH == 5) ratioW = 16, ratioH = 10; std::string text = std::to_string(width) + " x " + std::to_string(height); if (ratioW != 0 && ratioW <= 21 && ratioH <= 10) text += " (" + std::to_string(ratioW) + ":" + std::to_string(ratioH) + ")"; else if (std::abs(width * 9 - height * 16) < width / 50) text += " (16:9)"; if (width == monitorWidth && height == monitorHeight) text += " monitor"; return text; }; const bool borderless = edited.mode == video::WindowMode::Borderless; ImGui::BeginDisabled(borderless); ImGui::SetNextItemWidth(240.0f * unit); if (ImGui::BeginCombo("Resolution", label(edited.width, edited.height).c_str())) { for (const auto &[width, height] : sizes) { const bool selected = width == edited.width && height == edited.height; if (ImGui::Selectable(label(width, height).c_str(), selected)) edited.width = width, edited.height = height; if (selected) ImGui::SetItemDefaultFocus(); } ImGui::EndCombo(); } ImGui::EndDisabled(); envNote("PS2X_WINDOW_SIZE"); if (borderless) ImGui::TextDisabled("Borderless covers the monitor (%d x %d); the resolution is the window's when it leaves.", monitorWidth, monitorHeight); else if (edited.mode == video::WindowMode::Fullscreen) ImGui::TextDisabled("Fullscreen sets the monitor to this resolution."); else ImGui::TextDisabled("The window can also be resized with the mouse."); ImGui::SeparatorText("Rendering"); static const float kScales[] = {0.5f, 0.75f, 1.0f, 1.5f, 2.0f}; static const char *kScaleNames[] = {"50%", "75%", "100% (the window's)", "150%", "200% (supersampled)"}; int scaleIndex = 2; for (int i = 0; i < IM_ARRAYSIZE(kScales); ++i) if (std::fabs(edited.renderScale - kScales[i]) < 0.01f) scaleIndex = i; ImGui::SetNextItemWidth(240.0f * unit); if (ImGui::Combo("Render scale", &scaleIndex, kScaleNames, IM_ARRAYSIZE(kScaleNames))) edited.renderScale = kScales[scaleIndex]; envNote("PS2X_RENDER_SCALE"); ImGui::TextDisabled("The 3D against the window's resolution (applies at once)."); static const uint8_t kUpscales[] = {1, 2, 4}; static const char *kUpscaleNames[] = {"Off (the game's textures)", "2x", "4x"}; int upscaleIndex = 0; for (int i = 0; i < IM_ARRAYSIZE(kUpscales); ++i) if (edited.textureUpscale.factor == kUpscales[i]) upscaleIndex = i; ImGui::SetNextItemWidth(240.0f * unit); if (ImGui::Combo("Texture upscaling", &upscaleIndex, kUpscaleNames, IM_ARRAYSIZE(kUpscaleNames))) edited.textureUpscale.factor = kUpscales[upscaleIndex]; envNote("PS2X_TEXTURE_UPSCALE"); static const char *kFilterNames[] = {"Edge-directed (sharp edges)", "Smooth (bicubic)"}; int filterIndex = edited.textureUpscale.filter == render::UpscaleFilter::Smooth ? 1 : 0; ImGui::BeginDisabled(!edited.textureUpscale.on()); ImGui::SetNextItemWidth(240.0f * unit); if (ImGui::Combo("Upscaling filter", &filterIndex, kFilterNames, IM_ARRAYSIZE(kFilterNames))) edited.textureUpscale.filter = filterIndex == 1 ? render::UpscaleFilter::Smooth : render::UpscaleFilter::Edge; ImGui::EndDisabled(); envNote("PS2X_TEXTURE_FILTER"); ImGui::TextDisabled("The game's textures redrawn 2 or 4 times as large (applies at once; made in the background)."); static const int kSmoothings[] = {0, 1, 2, 4, 8, 16}; static const char *kSmoothingNames[] = {"Off (as the console)", "Trilinear", "Anisotropic 2x", "Anisotropic 4x", "Anisotropic 8x", "Anisotropic 16x"}; int smoothingIndex = 0; for (int i = 0; i < IM_ARRAYSIZE(kSmoothings); ++i) if (edited.textureSmoothing == kSmoothings[i]) smoothingIndex = i; ImGui::SetNextItemWidth(240.0f * unit); if (ImGui::Combo("Texture smoothing", &smoothingIndex, kSmoothingNames, IM_ARRAYSIZE(kSmoothingNames))) edited.textureSmoothing = kSmoothings[smoothingIndex]; envNote("PS2X_TEXTURE_SMOOTHING"); ImGui::TextDisabled("Distant textures without the shimmer: smaller copies made from each (applies at once)."); static const int kAntiAliasings[] = {0, 2, 4, 8}; static const char *kAntiAliasingNames[] = {"Off (as the console)", "2x MSAA", "4x MSAA", "8x MSAA"}; int antiAliasingIndex = 0; for (int i = 0; i < IM_ARRAYSIZE(kAntiAliasings); ++i) if (edited.antiAliasing == kAntiAliasings[i]) antiAliasingIndex = i; ImGui::SetNextItemWidth(240.0f * unit); if (ImGui::Combo("Anti-aliasing", &antiAliasingIndex, kAntiAliasingNames, IM_ARRAYSIZE(kAntiAliasingNames))) edited.antiAliasing = kAntiAliasings[antiAliasingIndex]; envNote("PS2X_ANTI_ALIASING"); ImGui::TextDisabled("The 3D's jagged edges smoothed, several samples a pixel (applies at once)."); if (video::widescreenOffered()) { ImGui::Checkbox("Widescreen (16:9)", &edited.widescreen); envNote("PS2X_WIDESCREEN"); ImGui::TextDisabled("More of the scene at the sides where the game can show it; the HUD stays in the middle."); } ImGui::Checkbox("Pause in the background", &edited.pauseInBackground); envNote("PS2X_PAUSE_IN_BACKGROUND"); ImGui::TextDisabled("The game holds while another window has the focus or this one is minimised."); static const int kFastForwards[] = {200, 300, 400, 0}; static const char *kFastForwardNames[] = {"2x", "3x", "4x", "Unlimited (as fast as the PC goes)"}; int fastIndex = -1; for (int i = 0; i < IM_ARRAYSIZE(kFastForwards); ++i) if (edited.fastForward == kFastForwards[i]) fastIndex = i; const std::string fastLabel = fastIndex >= 0 ? kFastForwardNames[fastIndex] : video::fastForwardName(edited.fastForward); ImGui::SetNextItemWidth(240.0f * unit); if (ImGui::BeginCombo("Fast forward", fastLabel.c_str())) { for (int i = 0; i < IM_ARRAYSIZE(kFastForwards); ++i) if (ImGui::Selectable(kFastForwardNames[i], i == fastIndex)) edited.fastForward = kFastForwards[i]; ImGui::EndCombo(); } envNote("PS2X_FAST_FORWARD"); ImGui::TextDisabled("The game's speed while Fast forward is held (` by default, the Controls tab binds it)."); // The player's texture pack (docs/texture-replace.md), when there is one: on or off (texture_pack = off). { static std::string s_lastOn; // a set folder (video.ini, PS2X_TEXTURE_PACK) given back when turned on again const bool on = edited.texturePack != "off" && edited.texturePack != "0"; if (on && !edited.texturePack.empty()) s_lastOn = edited.texturePack; const std::string folder = video::texturePackFolder(on ? edited.texturePack : s_lastOn); if (!folder.empty()) { bool use = on; if (ImGui::Checkbox("Texture pack", &use)) edited.texturePack = use ? s_lastOn : "off"; envNote("PS2X_TEXTURE_PACK"); ImGui::TextDisabled("Your own replacement textures, in %s (applies at once; over texture upscaling).", folder.c_str()); } } // The window's frame rate: the game's 60, or the monitor's with the frames between the game's interpolated (a set // rate, from video.ini or PS2X_FRAME_RATE, is offered as it is). const int refresh = video::monitorRefresh(); std::vector> rates = {{0, "60 (the game's)"}, {-1, "Match the monitor (" + std::to_string(refresh) + " Hz), smoothed (experimental)"}}; for (const int set : {current.frameRate, edited.frameRate}) if (set > 0 && std::none_of(rates.begin(), rates.end(), [&](const auto &r) { return r.first == set; })) rates.emplace_back(set, std::to_string(set) + " a second, smoothed (no vsync, experimental)"); int rateIndex = 0; for (size_t i = 0; i < rates.size(); ++i) if (rates[i].first == edited.frameRate) rateIndex = static_cast(i); ImGui::SetNextItemWidth(240.0f * unit); if (ImGui::BeginCombo("Frame rate", rates[static_cast(rateIndex)].second.c_str())) { for (size_t i = 0; i < rates.size(); ++i) if (ImGui::Selectable(rates[i].second.c_str(), static_cast(i) == rateIndex)) edited.frameRate = rates[i].first; ImGui::EndCombo(); } envNote("PS2X_FRAME_RATE"); ImGui::TextDisabled("The game runs at 60. Above that, each frame is drawn between the game's two latest:"); ImGui::TextDisabled("smoother on a high-refresh monitor, one game frame (17 ms) more input lag. Applies at once."); ImGui::TextDisabled("Experimental: a few effects (rain, lens flares, some trails) still move at 60."); ImGui::TextDisabled("The picture keeps its 4:3, centred with bars, whatever the window's shape."); ImGui::Separator(); const auto [windowWidth, windowHeight] = video::windowSize(); ImGui::Text("Now: %d x %d, %s, render scale %d%%, frame rate %s, textures %s; window %d x %d", current.width, current.height, video::modeName(current.mode), static_cast(std::lround(current.renderScale * 100.0f)), video::frameRateName(current.frameRate).c_str(), render::upscaleFactorName(current.textureUpscale.factor), windowWidth, windowHeight); static std::string s_status; if (ImGui::Button("Apply")) { video::requestApply(); s_status = "applied (not saved)"; } ImGui::SameLine(); if (ImGui::Button("Apply and save")) { video::requestApply(); s_status = video::save() ? "saved to " + video::configPath() : "could not write " + video::configPath(); } ImGui::SameLine(); if (ImGui::Button("Revert")) { edited = current; s_status.clear(); } ImGui::TextUnformatted(s_status.c_str()); ImGui::TextDisabled("F11 or Alt+Enter switches between the window and full screen."); } void Panel::Impl::drawControlsTab() { input::Config &config = input::config(); std::mutex &mutex = input::configMutex(); const float unit = ImGui::GetStyle().FontScaleDpi; for (int player = 0; player < input::kPlayers; ++player) { if (player) ImGui::SameLine(); char name[16]; std::snprintf(name, sizeof(name), "Player %d", player + 1); if (ImGui::RadioButton(name, &controlsPlayer, player)) bindingAction = -1; } input::Profile &profile = config.players[controlsPlayer]; { std::lock_guard lock(mutex); ImGui::SameLine(0.0f, 30.0f * unit); ImGui::SetNextItemWidth(90.0f * unit); ImGui::InputInt("Gamepad (-1: auto)", &profile.gamepad); profile.gamepad = std::clamp(profile.gamepad, -1, 3); ImGui::SameLine(0.0f, 30.0f * unit); ImGui::SetNextItemWidth(120.0f * unit); ImGui::SliderInt("Rumble", &profile.rumble, 0, 100, profile.rumble ? "%d%%" : "off", ImGuiSliderFlags_AlwaysClamp); } ImGui::SameLine(); if (ImGui::SmallButton("Test")) input::testRumble(controlsPlayer); ImGui::TextWrapped("Add: then press a key or a gamepad button, push a stick or trigger, or click, roll the wheel or " "move the mouse over the game picture. Click a binding to remove it."); if (ImGui::BeginTable("bindings", 3, ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_ScrollY, ImVec2(0.0f, ImGui::GetContentRegionAvail().y - 120.0f * unit))) { ImGui::TableSetupColumn("Action", ImGuiTableColumnFlags_WidthFixed, 150.0f * unit); ImGui::TableSetupColumn("Bindings", ImGuiTableColumnFlags_WidthStretch); ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, 70.0f * unit); for (int action = 0; action < input::ActionCount; ++action) { ImGui::PushID(action); ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::TextUnformatted(input::actionLabel(action)); ImGui::TableNextColumn(); { std::lock_guard lock(mutex); std::vector &list = profile.actions[action]; for (size_t i = 0; i < list.size(); ++i) { ImGui::PushID(static_cast(i)); if (i) ImGui::SameLine(); if (ImGui::SmallButton(input::bindingName(list[i]).c_str())) { list.erase(list.begin() + static_cast(i)); ImGui::PopID(); break; } ImGui::PopID(); } } ImGui::TableNextColumn(); if (bindingAction == action) { if (ImGui::SmallButton("Cancel")) bindingAction = -1; } else if (ImGui::SmallButton("Add")) bindingAction = action; // the next input event (Panel::handleEvent) ImGui::PopID(); } ImGui::EndTable(); } ImGui::SeparatorText("Mouse"); { std::lock_guard lock(mutex); ImGui::SetNextItemWidth(200.0f * unit); ImGui::SliderFloat("Sensitivity", &config.mouse.sensitivity, 0.1f, 5.0f, "%.2f"); ImGui::SameLine(); ImGui::Checkbox("Invert Y", &config.mouse.invertY); ImGui::SameLine(); ImGui::Checkbox("Capture the cursor while playing", &config.mouse.capture); } ImGui::Separator(); static std::string s_status; if (ImGui::Button("Save")) s_status = input::save() ? "saved to " + input::configPath() : "could not write " + input::configPath(); ImGui::SameLine(); if (ImGui::Button("Reset to defaults")) { input::resetToDefaults(); s_status = "defaults (not saved yet)"; } ImGui::SameLine(); ImGui::TextUnformatted(s_status.c_str()); } }