Foundation / checks (deploy) (push) Successful in 2m55s
Foundation / checks (ecs) (push) Successful in 1m47s
Foundation / checks (client) (push) Successful in 12m47s
Foundation / checks (network) (push) Successful in 9m48s
Foundation / checks (tsan) (push) Successful in 7m53s
Foundation / checks (checks) (push) Successful in 31m28s
Foundation / checks (postgres) (push) Successful in 38m52s
Foundation / server-image (push) Failing after 8s
Foundation / postgres-tools (push) Successful in 10s
Foundation / image (push) Successful in 2m18s
136 lines
5.4 KiB
C++
136 lines
5.4 KiB
C++
// M9.8a toolkit qualification only: no simulation, network, or authority state.
|
|
#include <SDL3/SDL.h>
|
|
#include <SDL3/SDL_main.h>
|
|
#include <charconv>
|
|
#include <cstdio>
|
|
#include <imgui.h>
|
|
#include <imgui_impl_sdl3.h>
|
|
#include <imgui_impl_sdlrenderer3.h>
|
|
#include <memory>
|
|
#include <stdexcept>
|
|
#include <string_view>
|
|
#include <system_error>
|
|
|
|
namespace {
|
|
void require(bool ok, const char* message) {
|
|
if (!ok)
|
|
throw std::runtime_error(message);
|
|
}
|
|
struct Runtime {
|
|
~Runtime() {
|
|
SDL_Quit();
|
|
}
|
|
};
|
|
struct Ui {
|
|
bool platform{}, renderer{};
|
|
Ui() {
|
|
ImGui::CreateContext();
|
|
}
|
|
~Ui() {
|
|
if (renderer)
|
|
ImGui_ImplSDLRenderer3_Shutdown();
|
|
if (platform)
|
|
ImGui_ImplSDL3_Shutdown();
|
|
ImGui::DestroyContext();
|
|
}
|
|
Ui(const Ui&) = delete;
|
|
Ui& operator=(const Ui&) = delete;
|
|
};
|
|
void run(const char* driver) {
|
|
require(SDL_Init(SDL_INIT_VIDEO), "SDL init");
|
|
const Runtime runtime;
|
|
const std::unique_ptr<SDL_Window, decltype(&SDL_DestroyWindow)> window{
|
|
SDL_CreateWindow("Aeternalis engineering UI probe", 640, 480, SDL_WINDOW_HIDDEN),
|
|
SDL_DestroyWindow};
|
|
require(window != nullptr, "window");
|
|
const std::unique_ptr<SDL_Renderer, decltype(&SDL_DestroyRenderer)> renderer{
|
|
SDL_CreateRenderer(window.get(), driver), SDL_DestroyRenderer};
|
|
require(renderer != nullptr, "renderer");
|
|
IMGUI_CHECKVERSION();
|
|
Ui ui;
|
|
auto& io = ImGui::GetIO();
|
|
io.IniFilename = nullptr;
|
|
io.LogFilename = nullptr;
|
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
|
require(io.Fonts->AddFontDefaultBitmap() != nullptr, "embedded font");
|
|
ui.platform = ImGui_ImplSDL3_InitForSDLRenderer(window.get(), renderer.get());
|
|
require(ui.platform, "platform backend");
|
|
ui.renderer = ImGui_ImplSDLRenderer3_Init(renderer.get());
|
|
require(ui.renderer, "render backend");
|
|
int clicks = 0;
|
|
ImVec2 button_center{};
|
|
bool edited = false;
|
|
for (int frame = 0; frame < 5; ++frame) {
|
|
SDL_Event event{};
|
|
while (SDL_PollEvent(&event))
|
|
ImGui_ImplSDL3_ProcessEvent(&event);
|
|
ImGui_ImplSDLRenderer3_NewFrame();
|
|
ImGui_ImplSDL3_NewFrame();
|
|
// Known synthetic input tests real widget state, not physical mouse hardware.
|
|
if (frame >= 1)
|
|
io.AddMousePosEvent(button_center.x, button_center.y);
|
|
if (frame == 2)
|
|
io.AddMouseButtonEvent(0, true);
|
|
if (frame == 3)
|
|
io.AddMouseButtonEvent(0, false);
|
|
ImGui::NewFrame();
|
|
ImGui::SetNextWindowPos({20, 20}, ImGuiCond_Always);
|
|
ImGui::SetNextWindowSize({560, 400}, ImGuiCond_Always);
|
|
ImGui::Begin("Engineering UI", nullptr,
|
|
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
|
|
ImGui::TextUnformatted("LOCAL FIXTURE | toolkit compatibility probe");
|
|
ImGui::TextUnformatted("Water (fg): present / missing / stale");
|
|
if (ImGui::Button("Select organism", {200, 40}))
|
|
++clicks;
|
|
const auto low = ImGui::GetItemRectMin(), high = ImGui::GetItemRectMax();
|
|
button_center = {(low.x + high.x) / 2, (low.y + high.y) / 2};
|
|
ImGui::Checkbox("Inspector", &edited);
|
|
ImGui::TextUnformatted("Keyboard and modal capture qualification follows in M9.8b.");
|
|
ImGui::End();
|
|
ImGui::Render();
|
|
auto* draw = ImGui::GetDrawData();
|
|
require(draw != nullptr && draw->TotalVtxCount > 0 && draw->TotalVtxCount < 100000,
|
|
"bounded nonempty widget geometry");
|
|
require(SDL_SetRenderDrawColor(renderer.get(), 16, 20, 28, 255) &&
|
|
SDL_RenderClear(renderer.get()),
|
|
"clear");
|
|
ImGui_ImplSDLRenderer3_RenderDrawData(draw, renderer.get());
|
|
const std::unique_ptr<SDL_Surface, decltype(&SDL_DestroySurface)> pixels{
|
|
SDL_RenderReadPixels(renderer.get(), nullptr), SDL_DestroySurface};
|
|
require(pixels != nullptr, "readback");
|
|
Uint8 red{}, green{}, blue{}, alpha{};
|
|
require(SDL_ReadSurfacePixel(pixels.get(), 25, 25, &red, &green, &blue, &alpha), "pixel");
|
|
require(red != 16 || green != 20 || blue != 28, "UI modifies render target");
|
|
require(SDL_RenderPresent(renderer.get()), "present");
|
|
}
|
|
require(clicks == 1, "press and release must activate exactly once");
|
|
std::printf("imgui=%s renderer=%s clicks=%d font=textured teardown=next\n", IMGUI_VERSION,
|
|
SDL_GetRendererName(renderer.get()), clicks);
|
|
}
|
|
} // namespace
|
|
int main(int argc, char** argv) try {
|
|
const char* driver = nullptr;
|
|
int cycles = 3;
|
|
for (int index = 1; index < argc;) {
|
|
const std::string_view option{argv[index++]};
|
|
if (option == "--renderer" && index < argc) {
|
|
driver = argv[index++];
|
|
} else if (option == "--cycles" && index < argc) {
|
|
const std::string_view value{argv[index++]};
|
|
const auto [end, error] =
|
|
std::from_chars(value.data(), value.data() + value.size(), cycles);
|
|
if (error != std::errc{} || end != value.data() + value.size() || cycles < 1 ||
|
|
cycles > 16)
|
|
return 2;
|
|
} else {
|
|
return 2;
|
|
}
|
|
}
|
|
for (int cycle = 0; cycle < cycles; ++cycle)
|
|
run(driver);
|
|
return 0;
|
|
} catch (const std::exception& error) {
|
|
std::fprintf(stderr, "UI probe failed: %s (%s)\n", error.what(), SDL_GetError());
|
|
return 1;
|
|
}
|