Add M9.8c launcher, legend, labelled inspector and click selection
Toolkit-independent launcher, selection, label and outcome-log models with bounded inputs and fixed error text; Dear ImGui overlay in the native adapter with toolkit-first event routing and capture; engineering panels for fixture vs dev region, legend, inspector, session outcomes, notices and dialog. Additive SessionClient::unreachable_attempts() bounds unreachable connects. Docs, CI targets and validation evidence updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
#define SDL_MAIN_HANDLED
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include <cmath>
|
||||
#include <imgui.h>
|
||||
#include <imgui_impl_sdl3.h>
|
||||
#include <imgui_impl_sdlrenderer3.h>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
@@ -31,6 +34,42 @@ std::optional<Key> input_key(SDL_Scancode code) {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
// Private toolkit state (ADR-0084): created after the renderer, destroyed before it.
|
||||
struct Toolkit {
|
||||
bool context{}, platform{}, renderer{};
|
||||
Toolkit() = default;
|
||||
Toolkit(const Toolkit&) = delete;
|
||||
Toolkit& operator=(const Toolkit&) = delete;
|
||||
~Toolkit() {
|
||||
detach_renderer();
|
||||
if (platform)
|
||||
ImGui_ImplSDL3_Shutdown();
|
||||
if (context)
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
bool open(SDL_Window* window, SDL_Renderer* target) {
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
context = true;
|
||||
auto& io = ImGui::GetIO();
|
||||
io.IniFilename = nullptr; // Nothing is persisted (no paths, no window layout).
|
||||
io.LogFilename = nullptr;
|
||||
if (io.Fonts->AddFontDefaultBitmap() == nullptr)
|
||||
return false;
|
||||
platform = ImGui_ImplSDL3_InitForSDLRenderer(window, target);
|
||||
return platform && attach_renderer(target);
|
||||
}
|
||||
bool attach_renderer(SDL_Renderer* target) {
|
||||
renderer = ImGui_ImplSDLRenderer3_Init(target);
|
||||
return renderer;
|
||||
}
|
||||
void detach_renderer() {
|
||||
if (renderer)
|
||||
ImGui_ImplSDLRenderer3_Shutdown();
|
||||
renderer = false;
|
||||
}
|
||||
};
|
||||
constexpr float click_slop = 4; // Logical units between press and release.
|
||||
struct Runtime {
|
||||
bool acquired{false};
|
||||
~Runtime() {
|
||||
@@ -48,9 +87,33 @@ struct Application::Impl {
|
||||
std::string renderer_name;
|
||||
WindowState state;
|
||||
std::optional<Error> failure;
|
||||
Toolkit toolkit; // After window/renderer: destroyed first.
|
||||
Overlay overlay;
|
||||
InputState input;
|
||||
bool backlogged{false};
|
||||
bool external_capture{false};
|
||||
// Capture sources: an external modal/launcher, the legacy Tab toggle and the
|
||||
// toolkit's own keyboard focus. World actions run only when none applies.
|
||||
bool external_capture{false}, tab_capture{false}, toolkit_capture{false};
|
||||
bool toolkit_pointer{false};
|
||||
std::optional<SDL_FPoint> press; // Primary press not taken by the toolkit.
|
||||
std::string screenshot;
|
||||
|
||||
// `drain`: input may have queued while an external UI or toolkit widget held it, so
|
||||
// that batch is discarded first. The Tab toggle is ordered within its own batch
|
||||
// (CAMERA_INPUT.md): presses after it belong to the new state, no drain.
|
||||
void update_capture(bool drain = true) {
|
||||
const bool wanted = external_capture || tab_capture || toolkit_capture;
|
||||
if (wanted == input.captured())
|
||||
return;
|
||||
if (!wanted && drain) {
|
||||
// Releasing capture can leave old input queued in SDL: drain that batch
|
||||
// before admitting fresh world presses (no synthesized held keys).
|
||||
backlogged = true;
|
||||
input.admit(false);
|
||||
}
|
||||
input.capture(wanted);
|
||||
press.reset();
|
||||
}
|
||||
|
||||
std::expected<void, Error> refresh() {
|
||||
if (!SDL_GetWindowSize(window.get(), &state.logical_width, &state.logical_height) ||
|
||||
@@ -74,13 +137,21 @@ WindowState Application::state() const noexcept {
|
||||
}
|
||||
void Application::set_ui_capture(bool captured) noexcept {
|
||||
impl_->external_capture = captured;
|
||||
if (impl_->input.captured() && !captured) {
|
||||
// An external UI can release capture with old input still queued in SDL.
|
||||
// Drain that batch before admitting fresh world presses.
|
||||
impl_->backlogged = true;
|
||||
impl_->input.admit(false);
|
||||
}
|
||||
impl_->input.capture(captured);
|
||||
if (!captured)
|
||||
impl_->tab_capture = false; // An external release also ends the legacy toggle.
|
||||
impl_->update_capture();
|
||||
}
|
||||
void Application::set_overlay(Overlay overlay) {
|
||||
impl_->overlay = std::move(overlay);
|
||||
}
|
||||
bool Application::ui_wants_pointer() const noexcept {
|
||||
return impl_->toolkit_pointer;
|
||||
}
|
||||
bool Application::request_screenshot(std::string path) {
|
||||
if (path.empty() || path.size() > 1024 || path.find('\0') != std::string::npos)
|
||||
return false;
|
||||
impl_->screenshot = std::move(path);
|
||||
return true;
|
||||
}
|
||||
bool Application::ui_captured() const noexcept {
|
||||
return impl_->input.captured();
|
||||
@@ -120,6 +191,8 @@ std::expected<std::unique_ptr<Application>, Error> Application::open(const Confi
|
||||
impl->state.hidden = (window_flags & SDL_WINDOW_HIDDEN) != 0;
|
||||
if (auto result = impl->refresh(); !result)
|
||||
return std::unexpected(result.error());
|
||||
if (!impl->toolkit.open(impl->window.get(), impl->renderer.get()))
|
||||
return std::unexpected(Error::initialization);
|
||||
return std::unique_ptr<Application>{new Application{std::move(impl)}};
|
||||
}
|
||||
std::expected<Step, Error> Application::step(const render::Frame& frame) {
|
||||
@@ -135,10 +208,18 @@ std::expected<void, Error> Application::poll_events() {
|
||||
return {};
|
||||
p.input.admit(p.state.accepts_input() && !p.backlogged);
|
||||
const auto id = SDL_GetWindowID(p.window.get());
|
||||
// The toolkit's wishes from its last frame decide this batch: keyboard focus in a
|
||||
// widget captures world keys; a pointer over UI cannot click, pan or zoom the world.
|
||||
const auto& io = ImGui::GetIO();
|
||||
p.toolkit_capture = io.WantCaptureKeyboard;
|
||||
p.toolkit_pointer = io.WantCaptureMouse;
|
||||
p.update_capture();
|
||||
bool reset = false;
|
||||
SDL_Event event{};
|
||||
int count = 0;
|
||||
for (; count < 256 && SDL_PollEvent(&event); ++count) {
|
||||
// Toolkit first: widgets see every event before world input is derived.
|
||||
ImGui_ImplSDL3_ProcessEvent(&event);
|
||||
if (event.type == SDL_EVENT_QUIT)
|
||||
p.state.closed = true;
|
||||
if (event.type >= SDL_EVENT_WINDOW_FIRST && event.type <= SDL_EVENT_WINDOW_LAST &&
|
||||
@@ -176,8 +257,11 @@ std::expected<void, Error> Application::poll_events() {
|
||||
event.key.windowID == id) {
|
||||
const bool down = event.type == SDL_EVENT_KEY_DOWN;
|
||||
if (event.key.scancode == SDL_SCANCODE_TAB && down && !event.key.repeat &&
|
||||
p.state.accepts_input() && !p.backlogged && !p.external_capture)
|
||||
p.input.capture(!p.input.captured());
|
||||
p.state.accepts_input() && !p.backlogged && !p.external_capture &&
|
||||
!p.toolkit_capture) {
|
||||
p.tab_capture = !p.tab_capture;
|
||||
p.update_capture(false);
|
||||
}
|
||||
if (const auto key = input_key(event.key.scancode)) {
|
||||
if (auto result = p.input.key(*key, down, event.key.repeat); !result)
|
||||
p.input.admit(false);
|
||||
@@ -187,7 +271,22 @@ std::expected<void, Error> Application::poll_events() {
|
||||
if (auto result = p.input.pointer({event.motion.x, event.motion.y}); !result)
|
||||
p.input.admit(false);
|
||||
}
|
||||
if (event.type == SDL_EVENT_MOUSE_WHEEL && event.wheel.windowID == id) {
|
||||
if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN && event.button.windowID == id &&
|
||||
event.button.button == SDL_BUTTON_LEFT)
|
||||
p.press = p.toolkit_pointer || p.input.captured()
|
||||
? std::nullopt
|
||||
: std::optional<SDL_FPoint>{{event.button.x, event.button.y}};
|
||||
if (event.type == SDL_EVENT_MOUSE_BUTTON_UP && event.button.windowID == id &&
|
||||
event.button.button == SDL_BUTTON_LEFT) {
|
||||
// A click that operated a widget (pressed over UI) never selects through it.
|
||||
if (p.press && std::abs(event.button.x - p.press->x) <= click_slop &&
|
||||
std::abs(event.button.y - p.press->y) <= click_slop && !p.toolkit_pointer &&
|
||||
!p.input.click({event.button.x, event.button.y}))
|
||||
p.input.admit(false);
|
||||
p.press.reset();
|
||||
}
|
||||
if (event.type == SDL_EVENT_MOUSE_WHEEL && event.wheel.windowID == id &&
|
||||
!p.toolkit_pointer) {
|
||||
const double direction = event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED ? -1 : 1;
|
||||
if (!p.input.pointer({event.wheel.mouse_x, event.wheel.mouse_y}) ||
|
||||
!p.input.wheel(event.wheel.y * direction))
|
||||
@@ -210,6 +309,7 @@ std::expected<void, Error> Application::poll_events() {
|
||||
if (p.state.closed)
|
||||
return {};
|
||||
if (reset) {
|
||||
p.toolkit.detach_renderer(); // Toolkit textures belong to the old renderer.
|
||||
p.renderer.reset();
|
||||
auto renderer = detail::make_renderer(p.window.get(), p.renderer_name);
|
||||
if (!renderer) {
|
||||
@@ -218,6 +318,11 @@ std::expected<void, Error> Application::poll_events() {
|
||||
return std::unexpected(*p.failure);
|
||||
}
|
||||
p.renderer = std::move(*renderer);
|
||||
if (!p.toolkit.attach_renderer(p.renderer.get())) {
|
||||
p.failure = Error::renderer;
|
||||
p.input.admit(false);
|
||||
return std::unexpected(*p.failure);
|
||||
}
|
||||
}
|
||||
if (auto result = p.refresh(); !result) {
|
||||
p.failure = result.error();
|
||||
@@ -241,6 +346,27 @@ std::expected<Step, Error> Application::present(const render::Frame& frame) {
|
||||
p.input.admit(false);
|
||||
return std::unexpected(*p.failure);
|
||||
}
|
||||
if (p.overlay) {
|
||||
// Engineering UI over the immutable frame; the callback reads copies only.
|
||||
ImGui_ImplSDLRenderer3_NewFrame();
|
||||
ImGui_ImplSDL3_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
p.overlay();
|
||||
ImGui::Render();
|
||||
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), p.renderer.get());
|
||||
}
|
||||
if (!p.screenshot.empty()) {
|
||||
// Engineering visual review only: the composed frame as an uncompressed BMP.
|
||||
const std::unique_ptr<SDL_Surface, decltype(&SDL_DestroySurface)> pixels{
|
||||
SDL_RenderReadPixels(p.renderer.get(), nullptr), SDL_DestroySurface};
|
||||
const bool saved = pixels && SDL_SaveBMP(pixels.get(), p.screenshot.c_str());
|
||||
p.screenshot.clear();
|
||||
if (!saved) {
|
||||
p.failure = Error::draw;
|
||||
p.input.admit(false);
|
||||
return std::unexpected(*p.failure);
|
||||
}
|
||||
}
|
||||
if (!SDL_RenderPresent(p.renderer.get())) {
|
||||
p.failure = Error::draw;
|
||||
p.input.admit(false);
|
||||
|
||||
Reference in New Issue
Block a user