mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 13:39:58 -04:00
Redraw the in-game menu with the game's own interface textures, and bring in the launcher's save import and faster builds.
In-game menu: the settings window, its tabs, rows, buttons and cursor, the performance overlay and the Preparing shaders box are drawn with the game's interface textures where the RomFS holds them (runtime/ui/menu_skin.cpp, perf_panel.cpp; plain shapes until they are decoded). Restart joins Continue and Quit, each behind a confirmation; VSync is an on/off switch; DLSS is listed only on NVIDIA GPUs; the menu sounds are quieter; Picture shape is gone and the setting descriptions are shorter; edge cases of input, layout and fonts are fixed. tools/menu_preview.py draws the menu without the game. Launcher: Import Saves takes a save from the game folder's saves/ folder or one the player picks; downloads fall back to Windows' own certificate check when Python's refuses a server; updates are faster; the title bar is drawn in the window and Navi is every icon. tools/make_game.py builds with CLANG64's clang where the launcher installed it, packs the RomFS beside the lift and the compile, takes a prebuilt runtime, and compiles the game's resources without cmd.exe, so a user folder with a space in its name builds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -192,13 +192,14 @@ static void capture_window(void) {
|
||||
if (!ImGui::IsPopupOpen("##bind_capture")) ImGui::OpenPopup("##bind_capture");
|
||||
uint64_t now = plat_now_ns();
|
||||
bool pad_cell = g_cap.cell == 2;
|
||||
// the timeout first: a press polled after it would compare with a held state long gone and bind what is held now
|
||||
if (!g_cap.done && now - g_cap.start > CAPTURE_SECONDS * 1000000000ull) g_cap.done = now;
|
||||
if (!g_cap.done) {
|
||||
int id = 0, got = input_capture(g_cap.reset, &id);
|
||||
g_cap.reset = false;
|
||||
if (got == INPUT_CAPTURE_KEY && !pad_cell) change(g_cap.action, g_cap.cell, id);
|
||||
if (got == INPUT_CAPTURE_PAD && pad_cell) change(g_cap.action, g_cap.cell, id);
|
||||
if (got != INPUT_CAPTURE_NONE && !(got == INPUT_CAPTURE_KEY && pad_cell)) g_cap.done = now;
|
||||
if (now - g_cap.start > CAPTURE_SECONDS * 1000000000ull) g_cap.done = now;
|
||||
}
|
||||
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
if (ImGui::BeginPopupModal("##bind_capture", nullptr,
|
||||
@@ -222,6 +223,8 @@ static void capture_window(void) {
|
||||
|
||||
bool binds_modal(void) { return g_cap.action >= 0; }
|
||||
|
||||
void binds_cancel(void) { g_cap.action = -1; }
|
||||
|
||||
static bool g_reset_asked; // the reset row was chosen this frame (acted on after the page)
|
||||
|
||||
void binds_rows(float scale) {
|
||||
|
||||
@@ -8,3 +8,6 @@ void binds_rows(float scale);
|
||||
void binds_after_page(void);
|
||||
// A cell waits for a press (or its press is still reaching the menu): B, Esc, L / R and the tab keys stay on the page.
|
||||
bool binds_modal(void);
|
||||
// The menu opened or closed (menu.cpp): a cell still waiting for a press stops waiting, unchanged. Its window is closed
|
||||
// with the menu's popups.
|
||||
void binds_cancel(void);
|
||||
|
||||
@@ -32,10 +32,12 @@ static int g_font_bad;
|
||||
#include "menu_sound.h"
|
||||
#include "menu_assets.h"
|
||||
#include "ui/menu_art.h"
|
||||
#include "ui/menu_skin.h"
|
||||
#pragma clang diagnostic pop
|
||||
#include "ui/amiibo_page.h"
|
||||
#include "ui/binds_page.h"
|
||||
#include "ui/option_rows.h"
|
||||
#include "ui/perf_panel.h"
|
||||
|
||||
extern "C" {
|
||||
#include "amiibo.h"
|
||||
@@ -86,13 +88,20 @@ static std::atomic<int> g_reset; // opened or closed since the last laid-out
|
||||
// (F1, Esc), the polling thread (combo) and the present path (Continue, B) race.
|
||||
static PlatMutex open_lock = PLAT_MUTEX_INIT;
|
||||
|
||||
// want 0 or 1 sets the state; -1 flips it. Returns the new state.
|
||||
static PlatMutex ev_lock = PLAT_MUTEX_INIT; // the event queue below
|
||||
static int ev_n;
|
||||
|
||||
// want 0 or 1 sets the state; -1 flips it. Returns the new state. The window events queued before the change go with it:
|
||||
// keys pressed just before a close would otherwise reach the menu when it next opens.
|
||||
static int change_open(int want) {
|
||||
plat_mutex_lock(&open_lock);
|
||||
int open = want < 0 ? !g_open.load() : want;
|
||||
if (g_open.load() != open) {
|
||||
g_open.store(open);
|
||||
g_reset.store(1);
|
||||
plat_mutex_lock(&ev_lock);
|
||||
ev_n = 0;
|
||||
plat_mutex_unlock(&ev_lock);
|
||||
input_menu(open);
|
||||
menu_sound_play(open ? MENU_SOUND_OPEN : MENU_SOUND_CLOSE);
|
||||
rt_log("menu: %s", open ? "open" : "closed");
|
||||
@@ -104,9 +113,9 @@ static int change_open(int want) {
|
||||
static void set_open(int open) { change_open(open); }
|
||||
|
||||
static int g_failed_flag();
|
||||
// The boot screen is up (menu_boot_set): the menu does not open, as it would not be drawn while its keys queued up and
|
||||
// changed settings once the game ran.
|
||||
static std::atomic<int> g_booting{0};
|
||||
// Until the game's first frame (menu_overlay_frame), boot screen included: the menu does not open, as it would not be
|
||||
// drawn while its keys queued up and changed settings once the game ran.
|
||||
static std::atomic<int> g_booting{1};
|
||||
extern "C" int menu_is_open(void) { return g_open.load(std::memory_order_relaxed); }
|
||||
extern "C" void menu_toggle(void) {
|
||||
if (!g_failed_flag() && !g_booting.load(std::memory_order_acquire)) change_open(-1);
|
||||
@@ -115,13 +124,17 @@ extern "C" void menu_toggle(void) {
|
||||
// ---- events from the window adapter, queued while the menu is open; the present path hands them to ImGui
|
||||
enum { EV_KEY, EV_POS, EV_BUTTON, EV_WHEEL, EV_FOCUS, EV_MAX = 256 };
|
||||
struct Ev { int type, a, b; float x, y; };
|
||||
static PlatMutex ev_lock = PLAT_MUTEX_INIT;
|
||||
static Ev ev_q[EV_MAX];
|
||||
static int ev_n;
|
||||
|
||||
static void push(Ev e) {
|
||||
if (!menu_is_open()) return;
|
||||
plat_mutex_lock(&ev_lock);
|
||||
// checked again under the lock: change_open empties the queue after the state changes, so an event of the closed
|
||||
// menu cannot slip in behind that
|
||||
if (!menu_is_open()) {
|
||||
plat_mutex_unlock(&ev_lock);
|
||||
return;
|
||||
}
|
||||
if (e.type == EV_POS && ev_n && ev_q[ev_n - 1].type == EV_POS) ev_q[ev_n - 1] = e; // only the newest position
|
||||
else if (ev_n < EV_MAX) ev_q[ev_n++] = e;
|
||||
plat_mutex_unlock(&ev_lock);
|
||||
@@ -143,7 +156,12 @@ static void drain_events(ImGuiIO &io) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
const Ev &e = q[i];
|
||||
switch (e.type) {
|
||||
case EV_KEY: io.AddKeyEvent((ImGuiKey)e.a, e.b != 0); break;
|
||||
case EV_KEY:
|
||||
io.AddKeyEvent((ImGuiKey)e.a, e.b != 0);
|
||||
// ImGui takes the modifier state (io.KeyShift, io.KeyCtrl: Shift+Tab, Ctrl+Up) from these keys only
|
||||
if (e.a == ImGuiKey_LeftShift) io.AddKeyEvent(ImGuiMod_Shift, e.b != 0);
|
||||
if (e.a == ImGuiKey_LeftCtrl) io.AddKeyEvent(ImGuiMod_Ctrl, e.b != 0);
|
||||
break;
|
||||
case EV_POS: io.AddMousePosEvent(e.x, e.y); break;
|
||||
case EV_BUTTON: io.AddMouseButtonEvent(e.a, e.b != 0); break;
|
||||
case EV_WHEEL: io.AddMouseWheelEvent(e.x, e.y); break;
|
||||
@@ -204,51 +222,17 @@ static ImGuiStyle g_base_style; // the menu's style at 1080 lines
|
||||
static uint64_t g_last_ns;
|
||||
static uint64_t g_cost_ns, g_cost_frames; // CPU time of layout and recording while open, logged per 600 frames
|
||||
|
||||
// Sizes are tuned for 1080 lines and follow the window's height. Under 720 lines at 100% display scale they stay at the
|
||||
// 720 size; that floor grows with the window's DPI, so a small window on a 150% or 200% display (sizes are physical
|
||||
// pixels) still gets text as large as the display scale asks for.
|
||||
static float menu_scale(uint32_t h) {
|
||||
float least = 720.0f * (float)gfx_window_dpi() / 96.0f;
|
||||
return ((float)h >= least ? (float)h : least) / 1080.0f;
|
||||
// Sizes are tuned for 1080 lines and follow the window's height, or its width in a window narrower than 1.47:1, where
|
||||
// the menu's 1400 pixels at 1080 lines would no longer fit 88 % of the width (layout_menu). Under 720 lines at 100%
|
||||
// display scale they stay at the 720 size; that floor grows with the window's DPI, so a small window on a 150% or 200%
|
||||
// display (sizes are physical pixels) still gets text as large as the display scale asks for.
|
||||
static float menu_scale(uint32_t w, uint32_t h) {
|
||||
float least = 720.0f * (float)gfx_window_dpi() / 96.0f, lines = fminf((float)h, (float)w * 0.68f);
|
||||
return (lines >= least ? lines : least) / 1080.0f;
|
||||
}
|
||||
|
||||
// The game's menu colours: a dark umber panel, warm browns for frames and what is selected, gold for the ornaments,
|
||||
// accents and the cursor, parchment text. kGreen and kOcarina keep their names for the selected and active controls.
|
||||
static const ImVec4 kGold(0.93f, 0.76f, 0.38f, 1), kGreen(0.36f, 0.26f, 0.13f, 1), kNavy(0.075f, 0.058f, 0.042f, 0.95f),
|
||||
kOcarina(0.62f, 0.47f, 0.22f, 1);
|
||||
static void style_init(ImGuiStyle &s) {
|
||||
ImGui::StyleColorsDark(&s);
|
||||
s.WindowRounding = 10; s.FrameRounding = 6; s.GrabRounding = 6; s.TabRounding = 6; s.ChildRounding = 8;
|
||||
s.WindowPadding = ImVec2(40, 30); s.FramePadding = ImVec2(14, 8); s.ItemSpacing = ImVec2(14, 12);
|
||||
s.WindowBorderSize = 2; s.ScrollbarSize = 16;
|
||||
ImVec4 *c = s.Colors;
|
||||
c[ImGuiCol_WindowBg] = kNavy;
|
||||
c[ImGuiCol_Border] = ImVec4(kGold.x, kGold.y, kGold.z, 0.55f);
|
||||
c[ImGuiCol_ChildBg] = ImVec4(0, 0, 0, 0);
|
||||
c[ImGuiCol_PopupBg] = kNavy;
|
||||
c[ImGuiCol_Text] = ImVec4(0.96f, 0.92f, 0.82f, 1);
|
||||
c[ImGuiCol_TextDisabled] = ImVec4(0.62f, 0.56f, 0.46f, 1);
|
||||
c[ImGuiCol_FrameBg] = ImVec4(0.15f, 0.115f, 0.08f, 1);
|
||||
c[ImGuiCol_FrameBgHovered] = ImVec4(0.24f, 0.18f, 0.10f, 1);
|
||||
c[ImGuiCol_FrameBgActive] = kGreen;
|
||||
c[ImGuiCol_SliderGrab] = kOcarina;
|
||||
c[ImGuiCol_SliderGrabActive] = kGold;
|
||||
c[ImGuiCol_CheckMark] = kGold;
|
||||
c[ImGuiCol_Button] = ImVec4(0.19f, 0.145f, 0.09f, 1);
|
||||
c[ImGuiCol_ButtonHovered] = kGreen;
|
||||
c[ImGuiCol_ButtonActive] = kOcarina;
|
||||
c[ImGuiCol_Header] = ImVec4(0.24f, 0.18f, 0.10f, 1);
|
||||
c[ImGuiCol_HeaderHovered] = kGreen;
|
||||
c[ImGuiCol_HeaderActive] = kOcarina;
|
||||
c[ImGuiCol_Tab] = ImVec4(0.13f, 0.10f, 0.07f, 1);
|
||||
c[ImGuiCol_TabHovered] = kGreen;
|
||||
c[ImGuiCol_TabSelected] = ImVec4(0.42f, 0.31f, 0.15f, 1);
|
||||
c[ImGuiCol_TabSelectedOverline] = kGold;
|
||||
c[ImGuiCol_NavCursor] = kGold;
|
||||
c[ImGuiCol_Separator] = ImVec4(kGold.x, kGold.y, kGold.z, 0.30f);
|
||||
c[ImGuiCol_ScrollbarGrab] = ImVec4(0.36f, 0.28f, 0.16f, 1);
|
||||
c[ImGuiCol_ScrollbarBg] = ImVec4(0, 0, 0, 0.2f);
|
||||
}
|
||||
// The gold of the title and its Triforce (the rest of the menu's colours: ui/menu_skin.cpp skin_style).
|
||||
static const ImVec4 kGold(0.93f, 0.76f, 0.38f, 1);
|
||||
|
||||
// The Triforce, its top at (x, y), h high, drawn with the title.
|
||||
static void triforce(ImDrawList *dl, float x, float y, float h, ImU32 col) {
|
||||
@@ -266,7 +250,9 @@ static void make_context(void) {
|
||||
io.LogFilename = nullptr;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard | ImGuiConfigFlags_NavEnableGamepad;
|
||||
io.BackendPlatformName = "nx2navi_menu";
|
||||
style_init(g_base_style);
|
||||
// no window switcher on Ctrl+Tab (the menu is one window; the switcher would list its inner windows by their ids)
|
||||
GImGui->ConfigNavWindowingKeyNext = GImGui->ConfigNavWindowingKeyPrev = 0;
|
||||
skin_style(g_base_style);
|
||||
ImGui::GetStyle() = g_base_style;
|
||||
g_ctx_ok = 1;
|
||||
}
|
||||
@@ -398,11 +384,12 @@ static int fonts_up(float scale) {
|
||||
fa->AddFontFromMemoryTTF((void *)roboto_ttf, (int)sizeof roboto_ttf, 26.0f * scale, &fc, kRanges);
|
||||
}
|
||||
uint8_t *data[N] = {};
|
||||
ImVector<ImWchar> ranges[N];
|
||||
uint64_t sizes[N] = {};
|
||||
ImVector<ImWchar> ranges[N], title_ranges[N];
|
||||
int merged = 0;
|
||||
for (int i = 0; i < N; i++) {
|
||||
char path[512];
|
||||
uint64_t size = 0;
|
||||
uint64_t &size = sizes[i];
|
||||
if (!plat_font_path(kCjk[i].lang, path, sizeof path) || !(data[i] = plat_file_read(path, &size))) continue;
|
||||
if (!font_usable(data[i], size)) {
|
||||
rt_log("menu: system font %s left out: the font parser cannot read it (%llu bytes)", path,
|
||||
@@ -435,7 +422,23 @@ static int fonts_up(float scale) {
|
||||
rc.MergeMode = true;
|
||||
rc.FontDataOwnedByAtlas = false;
|
||||
fa->AddFontFromMemoryTTF((void *)roboto_ttf, (int)sizeof roboto_ttf, 30.0f * scale, &rc, kRanges);
|
||||
// what the title face shows in the CJK languages: the menu's title and tabs (Simplified Chinese menu text) and
|
||||
// the boot screen's title (the game's language)
|
||||
static const UiTextId titles[] = {UI_MENU_TITLE, UI_MENU_TAB_SCREEN, UI_MENU_TAB_GAME, UI_MENU_TAB_SOUND,
|
||||
UI_MENU_TAB_CONTROLS, UI_BOOT_TITLE};
|
||||
for (int i = 0; i < N; i++) {
|
||||
if (!data[i]) continue;
|
||||
ImFontGlyphRangesBuilder b;
|
||||
for (UiTextId id : titles) b.AddText(ui_text_in(kCjk[i].lang, id));
|
||||
b.BuildRanges(&title_ranges[i]);
|
||||
ImFontConfig mc;
|
||||
mc.MergeMode = true;
|
||||
mc.FontDataOwnedByAtlas = false;
|
||||
fa->AddFontFromMemoryTTF(data[i], (int)sizes[i], 31.0f * scale, &mc, title_ranges[i].Data);
|
||||
}
|
||||
}
|
||||
skin_atlas_add(fa); // the boxes' grain tile (ui/menu_skin.cpp), drawn into the atlas once it is built
|
||||
skin_atlas_fill(fa); // builds the atlas, which the upload below then takes as it is
|
||||
vk_queue_lock(); // the upload submits on the queue and waits for it
|
||||
int ok = ImGui_ImplVulkan_CreateFontsTexture();
|
||||
// ClarimoUDPE's line (ascent to descent, which is all Dear ImGui spaces lines by) leaves wrapped lines touching: the
|
||||
@@ -450,19 +453,25 @@ static int fonts_up(float scale) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
// The font atlas follows the window's scale: rebuilt at once when it is more than 12% off (text would blur or shrink
|
||||
// visibly), else once the scale has held for half a second, so dragging a window's edge does not rebuild it, and read the
|
||||
// system's fonts again, every frame. Until then io.FontGlobalScale stretches the atlas there is. False: fonts_up failed.
|
||||
static bool fonts_follow(float scale) {
|
||||
static float last;
|
||||
static uint64_t since;
|
||||
uint64_t now = plat_now_ns();
|
||||
if (scale != last) last = scale, since = now;
|
||||
// The atlas for scale. While the scale keeps changing (the window being resized), the atlas is made again only once it
|
||||
// has held for a quarter of a second, and the old one is drawn scaled meanwhile (io.FontGlobalScale): each atlas reads
|
||||
// the system fonts from disk and waits for the queue to upload. 0 when no atlas could be made.
|
||||
static float g_scale_seen;
|
||||
static uint64_t g_scale_seen_ns;
|
||||
|
||||
static int fonts_for(float scale, uint64_t now) {
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
if (g_font_scale != scale && (!g_font_scale || fabsf(g_font_scale / scale - 1) > 0.12f || now - since > 500000000ull))
|
||||
if (!fonts_up(scale)) return false;
|
||||
io.FontGlobalScale = scale / g_font_scale;
|
||||
return true;
|
||||
if (g_font_scale == scale) {
|
||||
io.FontGlobalScale = 1;
|
||||
return 1;
|
||||
}
|
||||
if (scale != g_scale_seen) g_scale_seen = scale, g_scale_seen_ns = now;
|
||||
if (g_font_scale > 0 && now - g_scale_seen_ns < 250000000ull) {
|
||||
io.FontGlobalScale = scale / g_font_scale;
|
||||
return 1;
|
||||
}
|
||||
io.FontGlobalScale = 1;
|
||||
return fonts_up(scale);
|
||||
}
|
||||
|
||||
extern "C" void menu_vk_release(void) {
|
||||
@@ -740,21 +749,33 @@ static const char *present_name(const char *mode) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// "in use: VSync" under the Presentation value when the swapchain got another mode than the setting (a driver without
|
||||
// mailbox gets fifo); NULL when they agree or before the first swapchain.
|
||||
static const char *present_note(void) {
|
||||
const char *got = gfx_window_present_mode(), *name = present_name(got);
|
||||
if (!*got || !strcmp(got, cfg_value("NX2NAVI_VK_PRESENT")) || !name) return nullptr;
|
||||
// "in use: VSync" under the VSync row when it is off and the driver cannot present without waiting; NULL otherwise, and
|
||||
// before the first swapchain.
|
||||
static const char *vsync_note(void) {
|
||||
const char *got = gfx_window_present_mode();
|
||||
if (!*got || strcmp(cfg_value("NX2NAVI_VK_PRESENT"), "immediate") || !strcmp(got, "immediate")) return nullptr;
|
||||
static char note[96];
|
||||
snprintf(note, sizeof note, menu_text(UI_MENU_PRESENT_IN_USE), name);
|
||||
snprintf(note, sizeof note, menu_text(UI_MENU_PRESENT_IN_USE), menu_text(UI_MENU_PRESENT_VSYNC));
|
||||
return note;
|
||||
}
|
||||
|
||||
// ---- the tabs
|
||||
|
||||
// The PCI vendor of the GPU the game renders on (menu_overlay_frame reads it from the device it is given; 0 before the
|
||||
// first frame). DLSS runs on NVIDIA GPUs only, so the rows below leave it out elsewhere (AMD, Intel).
|
||||
static std::atomic<uint32_t> g_gpu_vendor;
|
||||
static VkPhysicalDevice g_gpu_vendor_of;
|
||||
static bool dlss_offered(void) {
|
||||
uint32_t v = g_gpu_vendor.load(std::memory_order_relaxed);
|
||||
return v == 0 || v == 0x10de; // unknown (no frame yet): as before, offered
|
||||
}
|
||||
|
||||
// One upscaling choice over three settings: NX2NAVI_UPSCALER (how the picture is fitted to the window), NX2NAVI_DLAA
|
||||
// (DLSS on) and NX2NAVI_DLSS (its mode, the render scale: widescreen.c wide_present). A DLSS mode fits the picture with
|
||||
// bilinear, DLSS having made it; the model is NVIDIA's own for the mode (vk_dlaa.c evaluate, dlss_preset at its default).
|
||||
// (DLSS or FSR 3.1 on) with NX2NAVI_TAA (which of them) and NX2NAVI_DLSS (the mode, the render scale: widescreen.c
|
||||
// wide_present). A temporal mode fits the picture with bilinear, the upscaler having made it; DLSS's model is NVIDIA's own
|
||||
// for the mode (vk_dlaa.c evaluate, dlss_preset at its default). The list: bilinear, FSR 1, the DLSS modes where DLSS
|
||||
// runs (dlss_offered), the FSR 3.1 modes; a DLSS mode still set where DLSS does not run stays listed last until another
|
||||
// choice replaces it, so the row shows what is set.
|
||||
static void row_upscaling(void) {
|
||||
static const char *const modes[] = {"dlaa", "quality", "balanced", "performance", "ultra_performance"};
|
||||
static const UiTextId mode_names[] = {UI_MENU_DLSS_DLAA, UI_MENU_DLSS_QUALITY, UI_MENU_DLSS_BALANCED,
|
||||
@@ -762,28 +783,51 @@ static void row_upscaling(void) {
|
||||
// FSR 3.1's modes take the same render scales as DLSS's (Native AA is FSR's name for DLAA's full size)
|
||||
static const UiTextId fsr_names[] = {UI_MENU_FSR3_NATIVE, UI_MENU_DLSS_QUALITY, UI_MENU_DLSS_BALANCED,
|
||||
UI_MENU_DLSS_PERFORMANCE, UI_MENU_DLSS_ULTRA};
|
||||
static char dl[10][96];
|
||||
const char *names[12] = {menu_text(UI_MENU_UPSCALER_BILINEAR), menu_text(UI_MENU_UPSCALER_FSR)};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
snprintf(dl[i], sizeof dl[i], i ? "DLSS %s" : "NVIDIA %s", menu_text(mode_names[i]));
|
||||
snprintf(dl[5 + i], sizeof dl[5 + i], "AMD FSR 3.1 %s", menu_text(fsr_names[i]));
|
||||
names[2 + i] = dl[i], names[7 + i] = dl[5 + i];
|
||||
}
|
||||
int cur = strcmp(cfg_value("NX2NAVI_UPSCALER"), "fsr") ? 0 : 1;
|
||||
enum { BILINEAR, FSR1, DLSS, FSR3 };
|
||||
struct Entry { int kind, mode; };
|
||||
static char text[10][96];
|
||||
Entry list[12];
|
||||
const char *names[12];
|
||||
int n = 0;
|
||||
auto add = [&](int kind, int mode) {
|
||||
list[n] = {kind, mode};
|
||||
if (kind == BILINEAR) names[n] = menu_text(UI_MENU_UPSCALER_BILINEAR);
|
||||
else if (kind == FSR1) names[n] = menu_text(UI_MENU_UPSCALER_FSR);
|
||||
else {
|
||||
char *t = text[(kind == FSR3 ? 5 : 0) + mode];
|
||||
if (kind == DLSS) snprintf(t, sizeof text[0], mode ? "DLSS %s" : "NVIDIA %s", menu_text(mode_names[mode]));
|
||||
else snprintf(t, sizeof text[0], "AMD FSR 3.1 %s", menu_text(fsr_names[mode]));
|
||||
names[n] = t;
|
||||
}
|
||||
n++;
|
||||
};
|
||||
// what is set now
|
||||
Entry now = {strcmp(cfg_value("NX2NAVI_UPSCALER"), "fsr") ? BILINEAR : FSR1, 0};
|
||||
if (cfg_bool("NX2NAVI_DLAA")) {
|
||||
int base = strcmp(cfg_value("NX2NAVI_TAA"), "fsr3") ? 2 : 7;
|
||||
cur = base;
|
||||
now = {strcmp(cfg_value("NX2NAVI_TAA"), "fsr3") ? DLSS : FSR3, 0};
|
||||
for (int i = 0; i < 5; i++)
|
||||
if (!strcmp(cfg_value("NX2NAVI_DLSS"), modes[i])) cur = base + i;
|
||||
if (!strcmp(cfg_value("NX2NAVI_DLSS"), modes[i])) now.mode = i;
|
||||
}
|
||||
int nv = opt_choice_index("NX2NAVI_UPSCALER", UI_MENU_UPSCALING, names, 12, cur, 1, UI_MENU_UPSCALING_DESC,
|
||||
cur >= 2 ? menu_text(UI_MENU_UPSCALING_DLSS_NOTE) : nullptr);
|
||||
if (nv < 0) return;
|
||||
opt_apply("NX2NAVI_UPSCALER", nv == 1 ? "fsr" : "bilinear");
|
||||
opt_apply("NX2NAVI_DLAA", nv >= 2 ? "1" : "0");
|
||||
if (nv < 2) opt_apply("NX2NAVI_FRAMEGEN", "off"); // it needs DLSS's or FSR 3.1's motion vectors (row_framegen)
|
||||
if (nv >= 2) opt_apply("NX2NAVI_DLSS", modes[(nv - 2) % 5]);
|
||||
if (nv >= 2) opt_apply("NX2NAVI_TAA", nv >= 7 ? "fsr3" : "dlss");
|
||||
const bool dlss = dlss_offered();
|
||||
add(BILINEAR, 0);
|
||||
add(FSR1, 0);
|
||||
for (int i = 0; dlss && i < 5; i++) add(DLSS, i);
|
||||
for (int i = 0; i < 5; i++) add(FSR3, i);
|
||||
if (!dlss && now.kind == DLSS) add(DLSS, now.mode);
|
||||
int cur = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
if (list[i].kind == now.kind && list[i].mode == now.mode) cur = i;
|
||||
bool temporal = now.kind >= DLSS;
|
||||
int nv = opt_choice_index("NX2NAVI_UPSCALER", UI_MENU_UPSCALING, names, n, cur, 1,
|
||||
dlss ? UI_MENU_UPSCALING_DESC : UI_MENU_UPSCALING_DESC_FSR,
|
||||
temporal ? menu_text(dlss ? UI_MENU_UPSCALING_DLSS_NOTE : UI_MENU_UPSCALING_FSR_NOTE) : nullptr);
|
||||
if (nv < 0 || nv >= n) return;
|
||||
const Entry e = list[nv];
|
||||
opt_apply("NX2NAVI_UPSCALER", e.kind == FSR1 ? "fsr" : "bilinear");
|
||||
opt_apply("NX2NAVI_DLAA", e.kind >= DLSS ? "1" : "0");
|
||||
if (e.kind < DLSS) opt_apply("NX2NAVI_FRAMEGEN", "off"); // it needs DLSS's or FSR 3.1's motion vectors (row_framegen)
|
||||
if (e.kind >= DLSS) opt_apply("NX2NAVI_DLSS", modes[e.mode]);
|
||||
if (e.kind >= DLSS) opt_apply("NX2NAVI_TAA", e.kind == FSR3 ? "fsr3" : "dlss");
|
||||
}
|
||||
|
||||
// "in use: off" under the HDR value when the game started with HDR on but the swapchain is not HDR10 (the display or
|
||||
@@ -813,7 +857,8 @@ static void row_hdr(void) {
|
||||
// Frame generation (vk_fg.cpp), after a restart; it needs a temporal upscaler's motion vectors
|
||||
static void row_framegen(void) {
|
||||
// the generated frames are made from DLSS's or FSR 3.1's motion vectors: without one of them it would do nothing
|
||||
if (!cfg_bool("NX2NAVI_DLAA")) opt_disable_next(UI_MENU_FRAMEGEN_NEEDS);
|
||||
const bool dlss = dlss_offered();
|
||||
if (!cfg_bool("NX2NAVI_DLAA")) opt_disable_next(dlss ? UI_MENU_FRAMEGEN_NEEDS : UI_MENU_FRAMEGEN_NEEDS_FSR);
|
||||
static const char *const values[] = {"off", "fsr3", "dlss"};
|
||||
const char *names[] = {menu_text(UI_MENU_FRAMEGEN_OFF), "AMD FSR 3.1", "NVIDIA DLSS"};
|
||||
const char *v = cfg_value("NX2NAVI_FRAMEGEN");
|
||||
@@ -821,9 +866,10 @@ static void row_framegen(void) {
|
||||
// NVIDIA DLSS (vk_dlssg.c) is listed only while it is set: Streamline now starts and takes the swapchain, but presents
|
||||
// no generated frames yet (one presented per frame, status OK)
|
||||
int n = cur == 2 ? 3 : 2;
|
||||
int nv = opt_choice_index("NX2NAVI_FRAMEGEN", UI_MENU_FRAMEGEN, names, n, cur, 0, UI_MENU_FRAMEGEN_DESC,
|
||||
menu_text(UI_MENU_FRAMEGEN_NOTE));
|
||||
if (nv >= 0) opt_apply("NX2NAVI_FRAMEGEN", values[nv]);
|
||||
int nv = opt_choice_index("NX2NAVI_FRAMEGEN", UI_MENU_FRAMEGEN, names, n, cur, 0,
|
||||
dlss ? UI_MENU_FRAMEGEN_DESC : UI_MENU_FRAMEGEN_DESC_FSR,
|
||||
menu_text(dlss ? UI_MENU_FRAMEGEN_NOTE : UI_MENU_FRAMEGEN_NOTE_FSR));
|
||||
if (nv >= 0 && nv < n) opt_apply("NX2NAVI_FRAMEGEN", values[nv]);
|
||||
}
|
||||
|
||||
// The picture's height (widescreen.c picture_height): the game's 1440 or more.
|
||||
@@ -837,8 +883,9 @@ static void tab_screen(float scale) {
|
||||
opt_begin("##screen", scale);
|
||||
opt_toggle("NX2NAVI_FULLSCREEN", UI_MENU_FULLSCREEN, UI_MENU_FULLSCREEN_DESC);
|
||||
row_window_size();
|
||||
static const UiTextId present[] = {UI_MENU_PRESENT_MAILBOX, UI_MENU_PRESENT_VSYNC, UI_MENU_PRESENT_IMMEDIATE};
|
||||
opt_choice("NX2NAVI_VK_PRESENT", UI_MENU_PRESENT, present, 3, UI_MENU_PRESENT_DESC, present_note());
|
||||
// On is the default mode, mailbox with its fallbacks (gfx_present.c pick_present_mode): plain fifo would drop the
|
||||
// game to 30 at every slow frame on a 60 Hz display. A fifo already saved also reads as on.
|
||||
opt_toggle_value("NX2NAVI_VK_PRESENT", UI_MENU_PRESENT_VSYNC, UI_MENU_PRESENT_DESC, "mailbox", "immediate", vsync_note());
|
||||
row_gpu();
|
||||
static const UiTextId perf[] = {UI_MENU_PERF_OFF, UI_MENU_PERF_FPS, UI_MENU_PERF_FULL};
|
||||
opt_choice("NX2NAVI_PERF_OVERLAY", UI_MENU_PERF_OVERLAY, perf, 3, UI_MENU_PERF_OVERLAY_DESC);
|
||||
@@ -859,8 +906,6 @@ static void tab_screen(float scale) {
|
||||
int dl = cfg_bool("NX2NAVI_DLAA"), fsr3 = dl && !strcmp(cfg_value("NX2NAVI_TAA"), "fsr3");
|
||||
if (!fsr3 && (strcmp(cfg_value("NX2NAVI_UPSCALER"), "fsr") || dl)) opt_disable_next(UI_MENU_SHARPNESS_NEEDS_FSR);
|
||||
opt_slider("NX2NAVI_SHARPNESS", UI_MENU_SHARPNESS, 0, 100, UI_MENU_SHARPNESS_DESC, 5, "%.0f %%");
|
||||
static const UiTextId aspect[] = {UI_MENU_ASPECT_FIT, UI_MENU_ASPECT_STRETCH};
|
||||
opt_choice("NX2NAVI_ASPECT", UI_MENU_ASPECT, aspect, 2, UI_MENU_ASPECT_DESC);
|
||||
opt_end();
|
||||
}
|
||||
|
||||
@@ -955,34 +1000,44 @@ static const char *prompts_note(bool *restart) {
|
||||
}
|
||||
}
|
||||
|
||||
// The confirmation of "Restart now", over the menu; Cancel has the cursor first. Restart writes nx2navi.ini, then closes
|
||||
// the game as Quit does and starts it again (gfx_window_request_restart). It waits while the game writes a save, and
|
||||
// the game stays when nx2navi.ini cannot be written, as the new prompts would not come back. From the Cheats tab
|
||||
// (restart_rebuild) Restart also lets the next start rebuild for cheats whose last rebuild failed (cheats_rebuild_allow).
|
||||
static bool restart_rebuild;
|
||||
static void restart_confirm(void) {
|
||||
// The confirmation of the menu's Restart button, over the menu; Cancel has the cursor first. Restart writes nx2navi.ini,
|
||||
// then closes the game as Quit does and starts it again (gfx_window_request_restart). It waits while the game writes a
|
||||
// save, and the game stays when nx2navi.ini cannot be written, as the changed settings would not come back. From the
|
||||
// Cheats tab (restart_rebuild) Restart also lets the next start rebuild for cheats whose last rebuild failed
|
||||
// (cheats_rebuild_allow). The Quit button's confirmation is the same box (g_confirm_quit): closing the window already
|
||||
// finishes a save in progress (gfx_window_closed), so it does not wait.
|
||||
static bool restart_rebuild, g_confirm_quit;
|
||||
static void restart_confirm(float scale) {
|
||||
g_modal = false;
|
||||
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
if (!ImGui::BeginPopupModal("##restart_confirm", nullptr,
|
||||
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize))
|
||||
return;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_PopupBorderSize, 0);
|
||||
const bool open = ImGui::BeginPopupModal("##confirm", nullptr,
|
||||
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize);
|
||||
ImGui::PopStyleVar();
|
||||
if (!open) return;
|
||||
g_modal = true;
|
||||
ImGui::TextUnformatted(menu_text(UI_MENU_RESTART_CONFIRM));
|
||||
bool saving = fs_save_busy() != 0;
|
||||
if (saving || !cfg_last_save_ok())
|
||||
const ImVec2 box = ImGui::GetWindowPos(), box_size = ImGui::GetWindowSize();
|
||||
skin_panel(ImGui::GetWindowDrawList(), box, ImVec2(box.x + box_size.x, box.y + box_size.y), scale);
|
||||
ImGui::TextUnformatted(menu_text(g_confirm_quit ? UI_MENU_QUIT_CONFIRM : UI_MENU_RESTART_CONFIRM));
|
||||
bool saving = !g_confirm_quit && fs_save_busy() != 0;
|
||||
if (saving || (!g_confirm_quit && !cfg_last_save_ok()))
|
||||
ImGui::TextColored(ImVec4(0.95f, 0.45f, 0.35f, 1), "%s",
|
||||
menu_text(saving ? UI_MENU_RESTART_SAVING : UI_MENU_SAVE_FAILED));
|
||||
ImGui::Spacing();
|
||||
const char *yes = menu_text(UI_MENU_RESTART_YES), *no = menu_text(UI_MENU_RESET_NO);
|
||||
const char *yes = menu_text(g_confirm_quit ? UI_MENU_QUIT : UI_MENU_RESTART_YES), *no = menu_text(UI_MENU_RESET_NO);
|
||||
const ImGuiStyle &st = ImGui::GetStyle();
|
||||
float bw = fmaxf(ImGui::CalcTextSize(yes).x, ImGui::CalcTextSize(no).x) + st.FramePadding.x * 4;
|
||||
bool close = ImGui::Button(no, ImVec2(bw, 0));
|
||||
bool close = skin_widget_button(no, ImVec2(bw, 0), scale);
|
||||
if (ImGui::IsWindowAppearing()) ImGui::SetItemDefaultFocus();
|
||||
ImGui::SameLine();
|
||||
ImGui::SameLine(0, st.ItemSpacing.x + skin_cursor_reach(scale));
|
||||
ImGui::BeginDisabled(saving);
|
||||
if (ImGui::Button(yes, ImVec2(bw, 0)) && cfg_save()) {
|
||||
if (restart_rebuild) cheats_rebuild_allow();
|
||||
gfx_window_request_restart();
|
||||
if (skin_widget_button(yes, ImVec2(bw, 0), scale)) {
|
||||
if (g_confirm_quit) {
|
||||
gfx_window_request_close();
|
||||
} else if (cfg_save()) {
|
||||
if (restart_rebuild) cheats_rebuild_allow();
|
||||
gfx_window_request_restart();
|
||||
}
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_Escape, false) || ImGui::IsKeyPressed(ImGuiKey_GamepadFaceRight, false))
|
||||
@@ -990,7 +1045,6 @@ static void restart_confirm(void) {
|
||||
if (close) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
restart_rebuild = false;
|
||||
opt_focus_key("##restart"); // back on the row it came from
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
@@ -1031,18 +1085,26 @@ static void go_to(int tab, const char *key) {
|
||||
}
|
||||
|
||||
// The game's interface sounds (menu_sound.c) for what the frame did: a press or click on an item, the cursor on another
|
||||
// item, another tab by a click (L and R play theirs where they are read). The first frame after opening only records.
|
||||
// item, another tab by a click (L, R, Q and E play theirs where they are read: g_tab_sounded). The first frame after
|
||||
// opening only records: the open sound has played, and the cursor going to the first row is part of it. g_sound_fresh
|
||||
// marks that frame, as the frame count alone does not when nothing was laid out while the menu was closed.
|
||||
static bool g_sound_fresh;
|
||||
static int g_tab_sounded = -1; // the tab L / R / Q / E asked for, its sound played
|
||||
|
||||
static void menu_sounds_frame(void) {
|
||||
ImGuiContext &g = *GImGui;
|
||||
static int last_frame = -2, last_tab = -1;
|
||||
static ImGuiID last_nav;
|
||||
bool fresh = g.FrameCount != last_frame + 1;
|
||||
bool fresh = g_sound_fresh || g.FrameCount != last_frame + 1;
|
||||
g_sound_fresh = false;
|
||||
last_frame = g.FrameCount;
|
||||
if (!fresh) {
|
||||
if (g.ActiveId && g.ActiveIdIsJustActivated) menu_sound_play(MENU_SOUND_DECIDE);
|
||||
else if (g.NavId && g.NavId != last_nav) menu_sound_play(MENU_SOUND_CURSOR);
|
||||
if (g_tab != last_tab && last_tab >= 0) menu_sound_play(g_tab > last_tab ? MENU_SOUND_TAB_RIGHT : MENU_SOUND_TAB_LEFT);
|
||||
if (g_tab != last_tab && last_tab >= 0 && g_tab != g_tab_sounded)
|
||||
menu_sound_play(g_tab > last_tab ? MENU_SOUND_TAB_RIGHT : MENU_SOUND_TAB_LEFT);
|
||||
}
|
||||
if (g_tab != last_tab) g_tab_sounded = -1;
|
||||
last_nav = g.NavId, last_tab = g_tab;
|
||||
}
|
||||
|
||||
@@ -1058,7 +1120,6 @@ static void layout_menu(uint32_t w, uint32_t h, float scale) {
|
||||
ImGuiWindowFlags_NoSavedSettings);
|
||||
if (framed) ImGui::PopStyleVar();
|
||||
const ImVec2 win_p = ImGui::GetWindowPos(), win_s = ImGui::GetWindowSize();
|
||||
const float inset = 7 * scale;
|
||||
// The game's ornamented frame (ui/menu_art.cpp; nothing without the RomFS's), in gold. Its lines lie inside the
|
||||
// texture (about 4 % of the width, 7 % of the height in), so the frame is drawn that far outside the window and its
|
||||
// lines run along the window's edge, clear of the title and the rows; unclipped, it may reach past the window.
|
||||
@@ -1085,19 +1146,24 @@ static void layout_menu(uint32_t w, uint32_t h, float scale) {
|
||||
ImGui::SameLine();
|
||||
ImGui::TextUnformatted(menu_text(UI_MENU_TITLE));
|
||||
}
|
||||
const float title_end = ImGui::GetItemRectMax().x;
|
||||
if (g_title_font) ImGui::PopFont();
|
||||
// the port version and the game update, right-aligned on the title line: what a bug report needs first
|
||||
// the port version and the game update, right-aligned on the title line: what a bug report needs first; left out
|
||||
// where it would run into the title (a narrow window, a long title)
|
||||
char game[16], version[96];
|
||||
snprintf(game, sizeof game, "%d.%d.%d", rt_game_version / 100, rt_game_version / 10 % 10, rt_game_version % 10);
|
||||
snprintf(version, sizeof version, "NX2navi %s - game %s", rt_port_version, game);
|
||||
ImGui::SameLine(ImGui::GetWindowWidth() - ImGui::GetStyle().WindowPadding.x - ImGui::CalcTextSize(version).x);
|
||||
ImGui::TextDisabled("%s", version);
|
||||
float version_x = win_s.x - ImGui::GetStyle().WindowPadding.x - ImGui::CalcTextSize(version).x;
|
||||
if (win_p.x + version_x >= title_end + ImGui::GetStyle().ItemSpacing.x * 2) {
|
||||
ImGui::SameLine(version_x);
|
||||
ImGui::TextDisabled("%s", version);
|
||||
}
|
||||
|
||||
int step = g_modal || binds_modal() ? 0
|
||||
: ImGui::IsKeyPressed(ImGuiKey_GamepadR1, false) || ImGui::IsKeyPressed(ImGuiKey_E, false) ? 1
|
||||
: ImGui::IsKeyPressed(ImGuiKey_GamepadL1, false) || ImGui::IsKeyPressed(ImGuiKey_Q, false) ? -1
|
||||
: 0;
|
||||
if (step) g_tab_request = (g_tab + step + TAB_COUNT) % TAB_COUNT;
|
||||
if (step) g_tab_request = g_tab_sounded = (g_tab + step + TAB_COUNT) % TAB_COUNT;
|
||||
if (step) menu_sound_play(step > 0 ? MENU_SOUND_TAB_RIGHT : MENU_SOUND_TAB_LEFT);
|
||||
if (g_tab_request >= 0) g_focus_page = g_tab_request; // the new page's first row takes the cursor
|
||||
|
||||
@@ -1107,9 +1173,8 @@ static void layout_menu(uint32_t w, uint32_t h, float scale) {
|
||||
for (int k = 0; k < TAB_COUNT; k++) {
|
||||
char label[128];
|
||||
snprintf(label, sizeof label, " %s ###tab%d", menu_text(kTabNames[k]), k); // the id stays per language
|
||||
if (g_title_font) ImGui::PushFont(g_title_font); // the tab labels in the title face
|
||||
bool shown = ImGui::BeginTabItem(label, nullptr, g_tab_request == k ? ImGuiTabItemFlags_SetSelected : 0);
|
||||
if (g_title_font) ImGui::PopFont();
|
||||
// the tab labels in the title face, on the rows' button (ui/menu_skin.cpp)
|
||||
bool shown = skin_tab_item(label, menu_text(kTabNames[k]), g_tab_request == k ? ImGuiTabItemFlags_SetSelected : 0, scale, g_title_font);
|
||||
if (!shown) continue;
|
||||
g_tab = k;
|
||||
if (g_focus_page == k) {
|
||||
@@ -1146,15 +1211,20 @@ static void layout_menu(uint32_t w, uint32_t h, float scale) {
|
||||
ImGui::SetCursorPosY(y + st.FramePadding.y);
|
||||
ImGui::TextColored(ImVec4(0.95f, 0.45f, 0.35f, 1), "%s", menu_text(UI_MENU_SAVE_FAILED));
|
||||
}
|
||||
const char *cont = menu_text(UI_MENU_CONTINUE), *quit = menu_text(UI_MENU_QUIT);
|
||||
float bw = fmaxf(ImGui::CalcTextSize(cont).x, ImGui::CalcTextSize(quit).x) + st.FramePadding.x * 4;
|
||||
ImGui::SetCursorPos(ImVec2(ImGui::GetWindowWidth() - st.WindowPadding.x - bw * 2 - st.ItemSpacing.x, y));
|
||||
if (ImGui::Button(cont, ImVec2(bw, 0))) set_open(0);
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(quit, ImVec2(bw, 0))) gfx_window_request_close();
|
||||
const char *cont = menu_text(UI_MENU_CONTINUE), *restart = menu_text(UI_MENU_RESTART_YES), *quit = menu_text(UI_MENU_QUIT);
|
||||
float bw = fmaxf(fmaxf(ImGui::CalcTextSize(cont).x, ImGui::CalcTextSize(restart).x), ImGui::CalcTextSize(quit).x) + st.FramePadding.x * 4;
|
||||
// the save menu's brown buttons, with the game's cursor on the selected one (ui/menu_skin.cpp)
|
||||
float gap = st.ItemSpacing.x + skin_cursor_reach(scale);
|
||||
// right-aligned; in a window too narrow for all three, from the left edge
|
||||
ImGui::SetCursorPos(ImVec2(fmaxf(st.WindowPadding.x, ImGui::GetWindowWidth() - st.WindowPadding.x - bw * 3 - gap * 2), y));
|
||||
if (skin_widget_button(cont, ImVec2(bw, 0), scale)) set_open(0);
|
||||
ImGui::SameLine(0, gap);
|
||||
if (skin_widget_button(restart, ImVec2(bw, 0), scale)) g_confirm_quit = false, ImGui::OpenPopup("##confirm");
|
||||
ImGui::SameLine(0, gap);
|
||||
if (skin_widget_button(quit, ImVec2(bw, 0), scale)) g_confirm_quit = true, ImGui::OpenPopup("##confirm");
|
||||
restart_confirm(scale);
|
||||
menu_sounds_frame();
|
||||
bool was_modal = g_modal || binds_modal();
|
||||
if (g_tab != TAB_CONTROLS) g_modal = false;
|
||||
if (!was_modal && (ImGui::IsKeyPressed(ImGuiKey_Escape, false) || ImGui::IsKeyPressed(ImGuiKey_GamepadFaceRight, false)))
|
||||
set_open(0);
|
||||
ImGui::End();
|
||||
@@ -1240,54 +1310,13 @@ static void perf_tick(uint64_t now, const MenuTarget *t) {
|
||||
g_perf_last_ns = now;
|
||||
}
|
||||
|
||||
// The panel keeps its width while the numbers change: every column is as wide as the widest text it can show, measured
|
||||
// on samples of 8s (Roboto's digits share one width), and the numbers are right-aligned in it.
|
||||
struct PerfCol { UiTextId fmt; float sample; };
|
||||
|
||||
static float perf_text_w(UiTextId fmt, float v) {
|
||||
char b[64];
|
||||
snprintf(b, sizeof b, menu_text(fmt), v);
|
||||
return ImGui::CalcTextSize(b).x;
|
||||
}
|
||||
|
||||
// A fixed column as wide as the widest of the formats (with their samples) and labels given.
|
||||
static void perf_column(const char *id, const PerfCol *cols, int n, const UiTextId *labels = nullptr, int nl = 0) {
|
||||
float w = ImGui::CalcTextSize(menu_text(UI_MENU_OV_NONE)).x;
|
||||
for (int i = 0; i < n; i++) w = fmaxf(w, perf_text_w(cols[i].fmt, cols[i].sample));
|
||||
for (int i = 0; i < nl; i++) w = fmaxf(w, ImGui::CalcTextSize(menu_text(labels[i])).x);
|
||||
ImGui::TableSetupColumn(id, ImGuiTableColumnFlags_WidthFixed, w);
|
||||
}
|
||||
|
||||
static void perf_right(const char *s, bool dim) {
|
||||
float pad = ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(s).x;
|
||||
if (pad > 0) ImGui::SetCursorPosX(ImGui::GetCursorPosX() + pad);
|
||||
if (dim) ImGui::TextDisabled("%s", s);
|
||||
else ImGui::TextUnformatted(s);
|
||||
}
|
||||
|
||||
// One cell of the full panel's table: fmt (a catalog format, one number) with v, or "-" when the machine gives none.
|
||||
static void perf_cell(UiTextId fmt, float v) {
|
||||
ImGui::TableNextColumn();
|
||||
if (v < 0) return perf_right(menu_text(UI_MENU_OV_NONE), true);
|
||||
char b[64];
|
||||
snprintf(b, sizeof b, menu_text(fmt), v);
|
||||
perf_right(b, false);
|
||||
}
|
||||
|
||||
static void perf_label(UiTextId label, const ImVec4 &c) {
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextColored(c, "%s", menu_text(label));
|
||||
}
|
||||
|
||||
static float perf_gb(float mb) { return mb < 0 ? -1 : mb / 1024; }
|
||||
|
||||
// The picture lines: the window, the game image the present shows and the 3D scene it holds (resolution.c), how the
|
||||
// present scales the image to the window (gfx_present.c, the last present), the frame limit and the presentation mode
|
||||
// in use.
|
||||
static void perf_picture(const MenuTarget *t, const ImVec4 &c) {
|
||||
// in use; formatted into the panel's picture lines.
|
||||
static void perf_picture(const MenuTarget *t, PerfPanel *p) {
|
||||
unsigned out[2], scene[2];
|
||||
res_sizes(out, scene);
|
||||
char v[6][64];
|
||||
char (*v)[64] = p->picture;
|
||||
snprintf(v[0], sizeof v[0], menu_text(UI_MENU_OV_FMT_SIZE), t->width, t->height);
|
||||
snprintf(v[1], sizeof v[1], menu_text(UI_MENU_OV_FMT_SIZE), (unsigned)t->image_w, (unsigned)t->image_h);
|
||||
snprintf(v[2], sizeof v[2], menu_text(UI_MENU_OV_FMT_SCENE), scene[0], scene[1], scene[0] * 100.0 / out[0]);
|
||||
@@ -1309,42 +1338,16 @@ static void perf_picture(const MenuTarget *t, const ImVec4 &c) {
|
||||
if (hz > 0) snprintf(v[4], sizeof v[4], menu_text(UI_MENU_OV_FPS), hz);
|
||||
const char *pm = present_name(gfx_window_present_mode());
|
||||
snprintf(v[5], sizeof v[5], "%s", pm ? pm : menu_text(UI_MENU_OV_NONE));
|
||||
static const UiTextId labels[6] = {UI_MENU_OV_WINDOW, UI_MENU_OV_OUTPUT, UI_MENU_OV_SCENE,
|
||||
UI_MENU_OV_SCALING, UI_MENU_OV_LIMIT, UI_MENU_OV_PRESENT};
|
||||
// The 3D scene's size is known only where resolution.c sets it (the builds with its patch sets); Ocarina sizes its own scene
|
||||
// dynamically and res_sizes would report a fixed 1600x900, so the line is left out
|
||||
bool scene_known = res_adjustable() != 0;
|
||||
if (!ImGui::BeginTable("##perfp", 2, ImGuiTableFlags_SizingFixedFit)) return;
|
||||
float vw = 0;
|
||||
for (auto &s : v) vw = fmaxf(vw, ImGui::CalcTextSize(s).x);
|
||||
ImGui::TableSetupColumn("##p0", ImGuiTableColumnFlags_WidthStretch);
|
||||
ImGui::TableSetupColumn("##p1", ImGuiTableColumnFlags_WidthFixed, vw);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (i == 2 && !scene_known) continue;
|
||||
perf_label(labels[i], c);
|
||||
ImGui::TableNextColumn();
|
||||
perf_right(v[i], false);
|
||||
}
|
||||
ImGui::EndTable();
|
||||
// The 3D scene's size is known only where resolution.c sets it (the builds with its patch sets); Ocarina sizes its
|
||||
// own scene dynamically and res_sizes would report a fixed 1600x900, so the line is left out
|
||||
p->scene_known = res_adjustable() != 0;
|
||||
}
|
||||
|
||||
// The full panel (ui/perf_panel.cpp draws it in the menu's look): the numbers of this frame.
|
||||
static void perf_full_draw(const MenuTarget *t, float scale) {
|
||||
float w = (float)t->width;
|
||||
PerfStats s;
|
||||
perfmon_snapshot(&s);
|
||||
ImGui::SetNextWindowPos(ImVec2(w - 12 * scale, 12 * scale), ImGuiCond_Always, ImVec2(1, 0));
|
||||
ImGui::SetNextWindowBgAlpha(0.6f);
|
||||
ImGui::Begin("##perf", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize |
|
||||
ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoNav |
|
||||
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoSavedSettings);
|
||||
// under the menu while it is open (the settings stay readable), else over everything
|
||||
if (g_open.load(std::memory_order_relaxed)) ImGui::BringWindowToDisplayBack(ImGui::GetCurrentWindow());
|
||||
else ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindow());
|
||||
ImGui::SetWindowFontScale(0.72f);
|
||||
const ImVec4 gpu_c(0.55f, 0.83f, 0.31f, 1), cpu_c(0.18f, 0.59f, 0.80f, 1), ram_c(0.80f, 0.45f, 0.70f, 1),
|
||||
fps_c(0.95f, 0.95f, 0.95f, 1), wait_c(0.93f, 0.76f, 0.33f, 1), pic_c(0.62f, 0.70f, 0.95f, 1);
|
||||
// the port version and the game update first, so a screenshot in a bug report carries both; formatted once per
|
||||
// menu language
|
||||
static PerfPanel p;
|
||||
perfmon_snapshot(&p.s);
|
||||
// the port version and the game update, formatted once per menu language
|
||||
static char ver[96];
|
||||
static const char *ver_fmt;
|
||||
if (ver_fmt != menu_text(UI_MENU_VERSION)) {
|
||||
@@ -1353,82 +1356,11 @@ static void perf_full_draw(const MenuTarget *t, float scale) {
|
||||
snprintf(game, sizeof game, "%d.%d.%d", rt_game_version / 100, rt_game_version / 10 % 10, rt_game_version % 10);
|
||||
snprintf(ver, sizeof ver, ver_fmt, rt_port_version, game);
|
||||
}
|
||||
ImGui::TextDisabled("%s", ver);
|
||||
if (ImGui::BeginTable("##perft", 4, ImGuiTableFlags_SizingFixedFit)) {
|
||||
static const UiTextId labels[] = {UI_MENU_OV_GPU, UI_MENU_OV_VRAM, UI_MENU_OV_CPU, UI_MENU_OV_RAM,
|
||||
UI_MENU_OV_FPS_LABEL, UI_MENU_OV_FRAME_LABEL};
|
||||
static const PerfCol c1[] = {{UI_MENU_OV_FMT_PCT, 100}, {UI_MENU_OV_FMT_GB, 888.8f}, {UI_MENU_OV_FMT_FPS, 888},
|
||||
{UI_MENU_OV_FRAME_MS, 888.8f}};
|
||||
static const PerfCol c2[] = {{UI_MENU_OV_FMT_TEMP, 188}, {UI_MENU_OV_FMT_GB_OF, 888.8f}, {UI_MENU_OV_LOW1, 888},
|
||||
{UI_MENU_OV_MAX_MS, 8888.8f}};
|
||||
static const PerfCol c3[] = {{UI_MENU_OV_FMT_POWER, 888}, {UI_MENU_OV_FMT_MHZ, 8888}, {UI_MENU_OV_GAME_PCT, 100},
|
||||
{UI_MENU_OV_GAME_GB, 888.8f}, {UI_MENU_OV_LOW01, 888}};
|
||||
perf_column("##c0", nullptr, 0, labels, 6);
|
||||
perf_column("##c1", c1, 4);
|
||||
perf_column("##c2", c2, 4);
|
||||
perf_column("##c3", c3, 5);
|
||||
perf_label(UI_MENU_OV_GPU, gpu_c);
|
||||
perf_cell(UI_MENU_OV_FMT_PCT, s.gpu_pct);
|
||||
perf_cell(UI_MENU_OV_FMT_TEMP, s.gpu_temp_c);
|
||||
perf_cell(UI_MENU_OV_FMT_POWER, s.gpu_power_w);
|
||||
perf_label(UI_MENU_OV_VRAM, gpu_c);
|
||||
perf_cell(UI_MENU_OV_FMT_GB, perf_gb(s.vram_used_mb));
|
||||
perf_cell(UI_MENU_OV_FMT_GB_OF, perf_gb(s.vram_total_mb));
|
||||
perf_cell(UI_MENU_OV_FMT_MHZ, s.gpu_clock_mhz);
|
||||
perf_label(UI_MENU_OV_CPU, cpu_c);
|
||||
perf_cell(UI_MENU_OV_FMT_PCT, s.cpu_total_pct);
|
||||
perf_cell(UI_MENU_OV_FMT_TEMP, s.cpu_temp_c);
|
||||
perf_cell(UI_MENU_OV_GAME_PCT, s.cpu_game_pct);
|
||||
perf_label(UI_MENU_OV_RAM, ram_c);
|
||||
perf_cell(UI_MENU_OV_FMT_GB, perf_gb(s.ram_used_mb));
|
||||
perf_cell(UI_MENU_OV_FMT_GB_OF, perf_gb(s.ram_total_mb));
|
||||
perf_cell(UI_MENU_OV_GAME_GB, perf_gb(s.ram_game_mb));
|
||||
ImGui::TableNextRow(ImGuiTableRowFlags_None, 6 * scale); // a gap between the machine and the frames
|
||||
// the frames: the rate over the last second with the lows over the last ten seconds, then the frame times
|
||||
perf_label(UI_MENU_OV_FPS_LABEL, fps_c);
|
||||
perf_cell(UI_MENU_OV_FMT_FPS, s.fps);
|
||||
perf_cell(UI_MENU_OV_LOW1, s.low1_fps);
|
||||
perf_cell(UI_MENU_OV_LOW01, s.low01_fps);
|
||||
if (gfx_output_fps() > 0) { // frame generation: what the display gets, generated frames included
|
||||
perf_label(UI_MENU_OV_FG_LABEL, fps_c);
|
||||
perf_cell(UI_MENU_OV_FMT_FPS, (float)gfx_output_fps());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TableNextColumn();
|
||||
}
|
||||
perf_label(UI_MENU_OV_FRAME_LABEL, fps_c);
|
||||
perf_cell(UI_MENU_OV_FRAME_MS, s.frame_ms_avg);
|
||||
perf_cell(UI_MENU_OV_MAX_MS, s.frame_ms_max);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::EndTable();
|
||||
}
|
||||
float top = s.frame_ms_max > 50 ? s.frame_ms_max : 50;
|
||||
// as wide as the panel the tables size; the plot does not count toward that width, so the panel can still shrink
|
||||
ImGuiWindow *win = ImGui::GetCurrentWindow();
|
||||
float max_x = win->DC.CursorMaxPos.x;
|
||||
ImGui::PlotLines("##ft", s.frame_ms, PERF_HISTORY, 0, nullptr, 0, top, ImVec2(-FLT_MIN, 48 * scale));
|
||||
win->DC.CursorMaxPos.x = max_x;
|
||||
// per frame, averaged over the last half second; the labels' column stretches, so the numbers end at the panel's
|
||||
// right edge, and the table still asks for no more than its widest label and number
|
||||
if (ImGui::BeginTable("##perfw", 2, ImGuiTableFlags_SizingFixedFit)) {
|
||||
static const PerfCol c1[] = {{UI_MENU_OV_FMT_MS, 888.88f}, {UI_MENU_OV_PER_FRAME, 888.8f}};
|
||||
ImGui::TableSetupColumn("##w0", ImGuiTableColumnFlags_WidthStretch);
|
||||
perf_column("##w1", c1, 2);
|
||||
perf_label(UI_MENU_OV_REPLAY, wait_c);
|
||||
perf_cell(UI_MENU_OV_FMT_MS, s.replay_ms);
|
||||
perf_label(UI_MENU_OV_GPU_TIME, wait_c);
|
||||
perf_cell(UI_MENU_OV_FMT_MS, s.gpu_ms);
|
||||
perf_label(UI_MENU_OV_PIPE_WAIT, wait_c);
|
||||
perf_cell(UI_MENU_OV_FMT_MS, s.pipe_wait_ms);
|
||||
perf_label(UI_MENU_OV_SHADER_WAIT, wait_c);
|
||||
perf_cell(UI_MENU_OV_FMT_MS, s.xlate_ms);
|
||||
perf_label(UI_MENU_OV_TEX_UPLOADS, wait_c);
|
||||
perf_cell(UI_MENU_OV_PER_FRAME, s.tex_uploads);
|
||||
ImGui::EndTable();
|
||||
}
|
||||
perf_picture(t, pic_c);
|
||||
if (s.gpu_name[0]) ImGui::TextDisabled("%s", s.gpu_name);
|
||||
if (s.cpu_name[0]) ImGui::TextDisabled("%s", s.cpu_name);
|
||||
ImGui::End();
|
||||
p.version = ver;
|
||||
perf_picture(t, &p);
|
||||
p.fg_fps = gfx_output_fps() > 0 ? (float)gfx_output_fps() : 0;
|
||||
p.under_menu = g_open.load(std::memory_order_relaxed) != 0;
|
||||
perf_panel_draw(&p, (float)t->width, scale);
|
||||
}
|
||||
|
||||
static void perf_draw(const MenuTarget *t, float scale) {
|
||||
@@ -1438,14 +1370,21 @@ static void perf_draw(const MenuTarget *t, float scale) {
|
||||
// with the menu open: under its window, over the dimming layout_menu drew before
|
||||
ImDrawList *dl = g_open.load(std::memory_order_relaxed) ? ImGui::GetBackgroundDrawList() : ImGui::GetForegroundDrawList();
|
||||
ImVec2 sz = ImGui::CalcTextSize(g_perf_text);
|
||||
float pad = 6 * scale;
|
||||
ImVec2 p(w - 12 * scale - sz.x - pad * 2, 12 * scale); // the top right corner: the game's HUD leaves it empty
|
||||
dl->AddRectFilled(p, ImVec2(p.x + sz.x + pad * 2, p.y + sz.y + pad * 2), IM_COL32(0, 0, 0, 150), 4 * scale);
|
||||
dl->AddText(ImVec2(p.x + pad, p.y + pad), IM_COL32(255, 255, 255, 235), g_perf_text);
|
||||
float padx = 14 * scale, pady = 9 * scale;
|
||||
ImVec2 p(w - 12 * scale - sz.x - padx * 2, 12 * scale); // the top right corner: the game's HUD leaves it empty
|
||||
// a small panel in the menu's look (ui/menu_skin.cpp), its frame scaled to the line
|
||||
skin_panel(dl, p, ImVec2(p.x + sz.x + padx * 2, p.y + sz.y + pady * 2), scale * 0.6f, 0.9f);
|
||||
dl->AddText(ImVec2(p.x + padx, p.y + pady), SKIN_TEXT, g_perf_text);
|
||||
}
|
||||
|
||||
extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const char **shot) {
|
||||
*shot = NULL;
|
||||
if (t->phys && t->phys != g_gpu_vendor_of) { // the GPU's vendor for the rows that depend on it (dlss_offered)
|
||||
VkPhysicalDeviceProperties props;
|
||||
vkGetPhysicalDeviceProperties(t->phys, &props);
|
||||
g_gpu_vendor.store(props.vendorID, std::memory_order_relaxed);
|
||||
g_gpu_vendor_of = t->phys;
|
||||
}
|
||||
menu_art_start(); // the game's interface textures decode on a worker from the first present on
|
||||
cheats_frame(frame); // the data cheats and the buttons of the cheats that need them held
|
||||
if (!g_test.parsed) test_parse();
|
||||
@@ -1453,7 +1392,13 @@ extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const cha
|
||||
if (g_perf_save.exchange(0)) cfg_save();
|
||||
perf_tick(plat_now_ns(), t);
|
||||
amiibo_tick();
|
||||
if (g_booting.load(std::memory_order_relaxed)) g_booting.store(0, std::memory_order_release); // the game runs
|
||||
bool open = g_open.load(std::memory_order_relaxed);
|
||||
// the frame the menu is first laid out after opening: also when its g_reset went to an earlier frame of the overlay
|
||||
// alone (the menu opened between the two loads), the pad's buttons held now must not count as presses
|
||||
static bool was_open;
|
||||
bool opened = open && !was_open;
|
||||
was_open = open;
|
||||
if (!open) {
|
||||
if (g_save_pending) g_save_pending = opt_save_tick(1); // closed: the last change goes to nx2navi.ini now
|
||||
if (g_test.at && !g_test.opened && frame >= g_test.at) {
|
||||
@@ -1472,8 +1417,8 @@ extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const cha
|
||||
}
|
||||
uint64_t t0 = plat_now_ns();
|
||||
if (!g_ctx_ok) make_context();
|
||||
float scale = menu_scale(t->height);
|
||||
if (!vk_up(t) || !fonts_follow(scale)) {
|
||||
float scale = menu_scale(t->width, t->height);
|
||||
if (!vk_up(t) || !fonts_for(scale, t0)) {
|
||||
rt_log("menu: Dear ImGui Vulkan back end set-up failed; the menu stays closed");
|
||||
g_failed.store(1);
|
||||
set_open(0);
|
||||
@@ -1492,8 +1437,11 @@ extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const cha
|
||||
// ran without its focus row and with the opening key still down.
|
||||
open = g_open.load(std::memory_order_acquire);
|
||||
if (reset) {
|
||||
io.ClearEventsQueue(); // events handed over before the close and not yet taken (ImGui spreads them over frames)
|
||||
io.ClearInputKeys();
|
||||
io.ClearInputMouse();
|
||||
binds_cancel(); // a cell waiting for a press when the menu closed: no press binds on the next opening
|
||||
g_sound_fresh = true;
|
||||
g_last_ns = 0;
|
||||
g_focus_page = g_tab_request >= 0 ? g_tab_request : g_tab; // opening: the first row has the cursor
|
||||
if (GImGui->OpenPopupStack.Size) ImGui::ClosePopupToLevel(0, false); // a confirmation left open on closing
|
||||
@@ -1506,7 +1454,7 @@ extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const cha
|
||||
if (!open) { // the overlay alone: no input reaches ImGui
|
||||
} else if (g_test.page < 0) {
|
||||
drain_events(io);
|
||||
pad_events(io, reset);
|
||||
pad_events(io, reset || opened);
|
||||
} else { // the test hook's pages: the user's input in a background test window must not change settings
|
||||
plat_mutex_lock(&ev_lock);
|
||||
ev_n = 0;
|
||||
@@ -1544,20 +1492,20 @@ extern "C" void menu_boot_set(int phase, long long done, long long total) {
|
||||
g_boot_done.store(done, std::memory_order_relaxed);
|
||||
g_boot_total.store(total, std::memory_order_relaxed);
|
||||
g_boot_phase.store(phase, std::memory_order_release);
|
||||
g_booting.store(phase >= 0, std::memory_order_release);
|
||||
}
|
||||
|
||||
// A panel in the middle of the screen in the menu's colours: the title, the step with its count and a bar, and why it
|
||||
// happens. The input queue is left alone: keys pressed now reach the menu once the game runs.
|
||||
// A box in the middle of the screen in the menu's look (ui/menu_skin.cpp skin_boot_panel): the title, the step with its
|
||||
// count and a bar, and why it happens. The input queue is left alone: keys pressed now reach the menu once the game runs.
|
||||
extern "C" int menu_boot_frame(const MenuTarget *t) {
|
||||
if (g_failed_flag() || g_boot_phase.load(std::memory_order_acquire) < 0) return 0; // -1: done, a black frame
|
||||
if (!g_ctx_ok) make_context();
|
||||
float scale = menu_scale(t->height);
|
||||
if (!vk_up(t) || !fonts_follow(scale)) {
|
||||
float scale = menu_scale(t->width, t->height);
|
||||
if (!vk_up(t) || !fonts_for(scale, plat_now_ns())) {
|
||||
rt_log("menu: Dear ImGui Vulkan back end set-up failed; no boot screen, and the menu stays closed");
|
||||
g_failed.store(1);
|
||||
return 0;
|
||||
}
|
||||
menu_art_start(); // the box takes the game's textures as soon as they are decoded, plain shapes until then
|
||||
if (g_style_scale != scale) {
|
||||
ImGui::GetStyle() = g_base_style;
|
||||
ImGui::GetStyle().ScaleAllSizes(scale);
|
||||
@@ -1582,41 +1530,16 @@ extern "C" int menu_boot_frame(const MenuTarget *t) {
|
||||
snprintf(step, sizeof step, "%s", ui_text(UI_BOOT_STARTING));
|
||||
const char *title = ui_text(UI_BOOT_TITLE), *hint = ui_text(UI_BOOT_HINT);
|
||||
|
||||
ImDrawList *dl = ImGui::GetForegroundDrawList();
|
||||
float w = (float)t->width, h = (float)t->height, pad = 34 * scale, gap = 16 * scale;
|
||||
// the box in the menu's look (ui/menu_skin.cpp): a filled bar while there is a count, else a sweeping segment
|
||||
ImFont *body = ImGui::GetFont();
|
||||
float body_px = ImGui::GetFontSize();
|
||||
ImFont *head = g_title_font ? g_title_font : body;
|
||||
float head_px = g_title_font ? g_title_font->FontSize * ImGui::GetIO().FontGlobalScale : body_px * 1.2f;
|
||||
ImVec2 ts = head->CalcTextSizeA(head_px, FLT_MAX, 0, title), ss = body->CalcTextSizeA(body_px, FLT_MAX, 0, step),
|
||||
hs = body->CalcTextSizeA(body_px * 0.8f, FLT_MAX, 0, hint);
|
||||
float bar_h = 10 * scale;
|
||||
float pw = fmaxf(fmaxf(ts.x, hs.x), 560 * scale) + pad * 2;
|
||||
float ph = pad + ts.y + gap * 1.5f + ss.y + gap * 0.6f + bar_h + gap * 1.4f + hs.y + pad;
|
||||
ImVec2 a((w - pw) / 2, (h - ph) / 2), b(a.x + pw, a.y + ph);
|
||||
ImU32 gold = ImGui::GetColorU32(kGold), panel = ImGui::GetColorU32(kNavy);
|
||||
ImU32 text = IM_COL32(236, 224, 196, 255), dim = IM_COL32(236, 224, 196, 150);
|
||||
dl->AddRectFilled(a, b, panel, 10 * scale);
|
||||
dl->AddRect(a, b, IM_COL32(237, 194, 97, 140), 10 * scale, 0, 1.5f * scale);
|
||||
float y = a.y + pad;
|
||||
dl->AddText(head, head_px, ImVec2((w - ts.x) / 2, y), gold, title);
|
||||
y += ts.y + gap * 1.5f;
|
||||
dl->AddText(body, body_px, ImVec2(a.x + pad, y), text, step);
|
||||
y += ss.y + gap * 0.6f;
|
||||
ImVec2 ba(a.x + pad, y), bb(b.x - pad, y + bar_h);
|
||||
dl->AddRectFilled(ba, bb, IM_COL32(255, 255, 255, 28), bar_h / 2);
|
||||
if ((phase == 1 || phase == 2) && total > 0) {
|
||||
float f = (float)done / (float)total;
|
||||
f = f < 0 ? 0 : f > 1 ? 1 : f;
|
||||
if (f > 0) dl->AddRectFilled(ba, ImVec2(ba.x + (bb.x - ba.x) * f, bb.y), gold, bar_h / 2);
|
||||
} else { // no count yet: a short segment sweeps along the bar
|
||||
float span = (bb.x - ba.x) * 0.2f, run = (bb.x - ba.x) - span;
|
||||
float s = (float)fmod((now - g_boot_t0) / 1e9 * 0.8, 2.0);
|
||||
float x = ba.x + run * (s < 1 ? s : 2 - s);
|
||||
dl->AddRectFilled(ImVec2(x, ba.y), ImVec2(x + span, bb.y), gold, bar_h / 2);
|
||||
}
|
||||
y += bar_h + gap * 1.4f;
|
||||
dl->AddText(body, body_px * 0.8f, ImVec2((w - hs.x) / 2, y), dim, hint);
|
||||
float head_px = g_title_font ? g_title_font->FontSize * io.FontGlobalScale : body_px * 1.2f; // as GetFontSize scales
|
||||
float frac = -1;
|
||||
if ((phase == 1 || phase == 2) && total > 0) frac = done <= 0 ? 0 : done >= total ? 1 : (float)done / (float)total;
|
||||
float s = (float)fmod((now - g_boot_t0) / 1e9 * 0.8, 2.0);
|
||||
skin_boot_panel(ImGui::GetForegroundDrawList(), head, head_px, body, body_px, title, step, hint, frac, s < 1 ? s : 2 - s,
|
||||
(float)t->width, (float)t->height, scale);
|
||||
ImGui::Render();
|
||||
return ImGui::GetDrawData()->TotalVtxCount > 0;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ extern "C" {
|
||||
|
||||
// ---- state, any thread
|
||||
int menu_is_open(void);
|
||||
void menu_toggle(void); // F1 / Esc on the keyboard, Minus+Plus on the pad
|
||||
void menu_toggle(void); // F1 / Esc on the keyboard, Minus+Plus on the pad; not before the game's first frame
|
||||
void menu_perf_cycle(void); // F10: the performance overlay off, fps, full
|
||||
|
||||
// ---- events from the window adapter, used only while the menu is open. key: an ImGuiKey; coordinates in pixels of the
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// The settings menu's art from the game's own interface textures (menu_assets.c reads them from the user's RomFS):
|
||||
// the cursor's glow and line, the frame's corner ornaments and the control guide's bar. A worker decodes them into
|
||||
// RGBA once at start (the archive unpacks to about 240 MB and takes a moment); the window thread uploads each to the GPU
|
||||
// the first time the menu asks for it, and registers it with Dear ImGui's Vulkan back end. Without the files the menu
|
||||
// draws its plain shapes.
|
||||
// the frame's corner ornaments, the control guide's bar, and the layers of the buttons, cursor, panels and divider that
|
||||
// ui/menu_skin.cpp puts together. A worker decodes them into RGBA once at start (the archive unpacks to about 240 MB and
|
||||
// takes a moment); the window thread uploads each to the GPU with its smaller levels the first time the menu asks for
|
||||
// it, and registers it with Dear ImGui's Vulkan back end. Without the files the menu draws its plain shapes.
|
||||
#include <atomic>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
@@ -18,12 +18,20 @@ extern "C" {
|
||||
}
|
||||
#include "menu_assets.h"
|
||||
#include "ui/menu_art.h"
|
||||
#include "ui/menu_skin.h"
|
||||
|
||||
#define COMMON_BNTX "UI/Layout2Archive/Common.Product.100.Nin_Ounce_NVN2.bntx.zs"
|
||||
|
||||
// in the order of MenuArt (tools/menu_preview.py reads this list too)
|
||||
static const char *const kNames[MENU_ART_COUNT] = {
|
||||
"CmnBtnCursorGlow_00", "CmnBtnCursorLine_00", "LocationDeco_00", "CtrlGuideBG_00", "MessageWindowCommonBase_00",
|
||||
"LocationDeco_00", "CtrlGuideBG_00", "MessageWindowCommonBase_00",
|
||||
"BtnThinBase_01", "BtnThinBase_00", "BtnThinBase_05", "BtnThinBase_04", "BtnThinBase_02",
|
||||
"OptionBtnThinCursorGlow_00", "OptionBtnThinCursorLine_00", "SystemCaptionBg_00",
|
||||
"OptionSeparateMark_00", "SystemLine_03", "MenuHeaderSelect_00",
|
||||
};
|
||||
// Levels uploaded for each art: the buttons draw it at about half size and smaller, where a line one or two texels wide
|
||||
// would break up if sampled from the full image alone.
|
||||
enum { MAX_LEVELS = 6 };
|
||||
|
||||
static struct Art {
|
||||
uint8_t *rgba;
|
||||
@@ -44,7 +52,7 @@ static void decode_all(void *) {
|
||||
if (!bntx) rt_log("menu: %s could not be read from the RomFS", COMMON_BNTX);
|
||||
for (int i = 0; bntx && i < MENU_ART_COUNT; i++) {
|
||||
Art &a = g_art[i];
|
||||
if (menu_asset_texture(bntx, n, kNames[i], &a.rgba, &a.w, &a.h)) got++;
|
||||
if (menu_asset_texture(bntx, n, kNames[i], &a.rgba, &a.w, &a.h)) got++, skin_art_prepare(i, a.rgba, a.w, a.h);
|
||||
else rt_log("menu: interface texture %s not decoded (archive of %llu bytes)", kNames[i], (unsigned long long)n);
|
||||
}
|
||||
free(bntx);
|
||||
@@ -66,26 +74,52 @@ static int upload(Art &a) {
|
||||
si.magFilter = si.minFilter = VK_FILTER_LINEAR;
|
||||
si.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
|
||||
si.addressModeU = si.addressModeV = si.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||
si.maxLod = 1;
|
||||
si.maxLod = MAX_LEVELS;
|
||||
if (vkCreateSampler(c->device, &si, nullptr, &g_sampler) != VK_SUCCESS) return 0;
|
||||
}
|
||||
uint32_t lw[MAX_LEVELS] = {a.w}, lh[MAX_LEVELS] = {a.h}, levels = 1;
|
||||
VkDeviceSize bytes = (VkDeviceSize)a.w * a.h * 4;
|
||||
while (levels < MAX_LEVELS && (lw[levels - 1] > 1 || lh[levels - 1] > 1)) {
|
||||
lw[levels] = lw[levels - 1] > 1 ? lw[levels - 1] / 2 : 1;
|
||||
lh[levels] = lh[levels - 1] > 1 ? lh[levels - 1] / 2 : 1;
|
||||
bytes += (VkDeviceSize)lw[levels] * lh[levels] * 4;
|
||||
levels++;
|
||||
}
|
||||
VkImageCreateInfo ii = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO};
|
||||
ii.imageType = VK_IMAGE_TYPE_2D;
|
||||
ii.format = VK_FORMAT_R8G8B8A8_UNORM;
|
||||
ii.extent = {a.w, a.h, 1};
|
||||
ii.mipLevels = ii.arrayLayers = 1;
|
||||
ii.mipLevels = levels;
|
||||
ii.arrayLayers = 1;
|
||||
ii.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
ii.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
ii.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
||||
VmaAllocationCreateInfo ai = {};
|
||||
ai.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
|
||||
if (vmaCreateImage(c->vma, &ii, &ai, &a.img, &a.alloc, nullptr) != VK_SUCCESS) return 0;
|
||||
VkDeviceSize bytes = (VkDeviceSize)a.w * a.h * 4;
|
||||
VkBuffer sb;
|
||||
VmaAllocation sa;
|
||||
void *map = vk_staging(bytes, &sb, &sa);
|
||||
uint8_t *map = (uint8_t *)vk_staging(bytes, &sb, &sa);
|
||||
if (!map) return 0;
|
||||
memcpy(map, a.rgba, (size_t)bytes);
|
||||
// the levels one after the other in a plain allocation, each halved from the one before (the staging memory may be
|
||||
// slow to read back)
|
||||
uint8_t *chain = (uint8_t *)malloc((size_t)bytes);
|
||||
if (!chain) {
|
||||
vmaDestroyBuffer(c->vma, sb, sa);
|
||||
return 0;
|
||||
}
|
||||
memcpy(chain, a.rgba, (size_t)a.w * a.h * 4);
|
||||
VkBufferImageCopy regions[MAX_LEVELS] = {};
|
||||
VkDeviceSize at = 0;
|
||||
for (uint32_t l = 0; l < levels; l++) {
|
||||
regions[l].bufferOffset = at;
|
||||
regions[l].imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, l, 0, 1};
|
||||
regions[l].imageExtent = {lw[l], lh[l], 1};
|
||||
if (l) skin_art_halve(chain + regions[l - 1].bufferOffset, lw[l - 1], lh[l - 1], chain + at, lw[l], lh[l]);
|
||||
at += (VkDeviceSize)lw[l] * lh[l] * 4;
|
||||
}
|
||||
memcpy(map, chain, (size_t)bytes);
|
||||
free(chain);
|
||||
VkCommandBuffer cb = vk_upload_begin();
|
||||
VkImageMemoryBarrier2 b = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2};
|
||||
b.srcStageMask = VK_PIPELINE_STAGE_2_NONE;
|
||||
@@ -95,15 +129,12 @@ static int upload(Art &a) {
|
||||
b.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||
b.srcQueueFamilyIndex = b.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
b.image = a.img;
|
||||
b.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
b.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, levels, 0, 1};
|
||||
VkDependencyInfo di = {VK_STRUCTURE_TYPE_DEPENDENCY_INFO};
|
||||
di.imageMemoryBarrierCount = 1;
|
||||
di.pImageMemoryBarriers = &b;
|
||||
vkCmdPipelineBarrier2(cb, &di);
|
||||
VkBufferImageCopy r = {};
|
||||
r.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1};
|
||||
r.imageExtent = {a.w, a.h, 1};
|
||||
vkCmdCopyBufferToImage(cb, sb, a.img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &r);
|
||||
vkCmdCopyBufferToImage(cb, sb, a.img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, levels, regions);
|
||||
b.srcStageMask = VK_PIPELINE_STAGE_2_COPY_BIT;
|
||||
b.srcAccessMask = VK_ACCESS_2_TRANSFER_WRITE_BIT;
|
||||
b.dstStageMask = VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT;
|
||||
@@ -118,7 +149,7 @@ static int upload(Art &a) {
|
||||
vi.image = a.img;
|
||||
vi.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||
vi.format = VK_FORMAT_R8G8B8A8_UNORM;
|
||||
vi.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
|
||||
vi.subresourceRange = {VK_IMAGE_ASPECT_COLOR_BIT, 0, levels, 0, 1};
|
||||
if (vkCreateImageView(c->device, &vi, nullptr, &a.view) != VK_SUCCESS) return 0;
|
||||
a.ds = ImGui_ImplVulkan_AddTexture(g_sampler, a.view, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||
return a.ds != VK_NULL_HANDLE; // the pixels stay (a few MB): the back end may start again on another format
|
||||
@@ -147,37 +178,3 @@ extern "C" void menu_art_release(void) {
|
||||
}
|
||||
if (g_sampler) vkDestroySampler(c->device, g_sampler, nullptr), g_sampler = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
extern "C" int menu_art_draw(ImDrawList *dl, MenuArt id, ImVec2 a, ImVec2 b, ImU32 tint) {
|
||||
ImTextureID t;
|
||||
if (!menu_art(id, &t, nullptr, nullptr)) return 0;
|
||||
dl->AddImage(t, a, b, ImVec2(0, 0), ImVec2(1, 1), tint);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Nine pieces: the corners at `corner` pixels on screen from the texture's outer `frac` of each side, the edges
|
||||
// stretched between them, the middle left out (frames) or stretched (fill).
|
||||
extern "C" int menu_art_draw9_turned(ImDrawList *dl, MenuArt id, ImVec2 a, ImVec2 b, float corner, float frac, ImU32 tint, int fill,
|
||||
int turned);
|
||||
extern "C" int menu_art_draw9(ImDrawList *dl, MenuArt id, ImVec2 a, ImVec2 b, float corner, float frac, ImU32 tint, int fill) {
|
||||
return menu_art_draw9_turned(dl, id, a, b, corner, frac, tint, fill, 0);
|
||||
}
|
||||
|
||||
// The same, the texture turned half a turn when turned: its top-left corner piece at the bottom right.
|
||||
extern "C" int menu_art_draw9_turned(ImDrawList *dl, MenuArt id, ImVec2 a, ImVec2 b, float corner, float frac, ImU32 tint, int fill,
|
||||
int turned) {
|
||||
ImTextureID t;
|
||||
if (!menu_art(id, &t, nullptr, nullptr)) return 0;
|
||||
float c = corner, maxc = fminf((b.x - a.x) / 2, (b.y - a.y) / 2);
|
||||
if (c > maxc) c = maxc;
|
||||
const float xs[4] = {a.x, a.x + c, b.x - c, b.x}, ys[4] = {a.y, a.y + c, b.y - c, b.y};
|
||||
float us[4] = {0, frac, 1 - frac, 1}, vs[4] = {0, frac, 1 - frac, 1};
|
||||
if (turned)
|
||||
for (int k = 0; k < 4; k++) us[k] = 1 - us[k], vs[k] = 1 - vs[k];
|
||||
for (int j = 0; j < 3; j++)
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (i == 1 && j == 1 && !fill) continue;
|
||||
dl->AddImage(t, ImVec2(xs[i], ys[j]), ImVec2(xs[i + 1], ys[j + 1]), ImVec2(us[i], vs[j]), ImVec2(us[i + 1], vs[j + 1]), tint);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -3,11 +3,21 @@
|
||||
#include "imgui.h"
|
||||
|
||||
typedef enum {
|
||||
MENU_ART_CURSOR_GLOW, // the glow of the game's button cursor (white mask; tinted by the caller)
|
||||
MENU_ART_CURSOR_LINE, // its outline
|
||||
MENU_ART_FRAME_DECO, // a frame with ornamented corners
|
||||
MENU_ART_GUIDE_BAR, // the control guide's bar
|
||||
MENU_ART_WINDOW_BASE, // a rounded window base
|
||||
// the layers of the save menu's Load and Cancel button, in drawing order; white masks except for the grain
|
||||
MENU_ART_BTN_RIM, // a soft line along the button's edge, reaching outside it
|
||||
MENU_ART_BTN_FILL, // the button's shape
|
||||
MENU_ART_BTN_GRAIN, // the mottling: light at the edge, dark and speckled in the middle
|
||||
MENU_ART_BTN_EDGE, // the light edge
|
||||
MENU_ART_BTN_LINE, // the inset line, a diamond and a curl at alternate corners
|
||||
MENU_ART_CURSOR_GLOW, // the options cursor's soft glow
|
||||
MENU_ART_CURSOR_LINE, // the options cursor's white frame (skin_art_prepare cuts it out of the texture)
|
||||
MENU_ART_PANEL_FILL, // a dark brown panel
|
||||
MENU_ART_DIVIDER, // the options menu's divider ornament
|
||||
MENU_ART_DIVIDER_LINE, // the line beside the ornament, ending in a dot
|
||||
MENU_ART_TAB_SELECT, // the plate of the selected category in the game's menu header
|
||||
MENU_ART_COUNT
|
||||
} MenuArt;
|
||||
|
||||
|
||||
545
runtime/ui/menu_skin.cpp
Normal file
545
runtime/ui/menu_skin.cpp
Normal file
@@ -0,0 +1,545 @@
|
||||
// The look of the game's own menus (ui/menu_skin.h). With the game's textures (ui/menu_art.cpp) each piece is those
|
||||
// textures tinted and laid over each other in nine slices; until they are decoded, or without them, it is plain shapes
|
||||
// whose colours and proportions are sampled from the game: the save menu's Load and Cancel buttons (brown fill, light
|
||||
// edge, an inset line about a twentieth of the height in with a diamond and a curl at alternate corners), the options
|
||||
// menu's cursor (a 3 px white frame with a soft white-blue glow) and its divider ornament (traced: two pointed lens
|
||||
// ends, S-waves into spiral hooks and a diamond knot under the middle, in a 120 x 38 box with its centre at (60, 21)).
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <initializer_list>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h" // NavCursorVisible
|
||||
#include "ui/menu_art.h"
|
||||
#include "ui/menu_skin.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// The mottled grain of the game's brown boxes: a tile in the font atlas (skin_atlas_add, skin_atlas_fill), white with
|
||||
// the grain in alpha, drawn over a box darkened in some places and lightened in others.
|
||||
const int kGrainW = 160, kGrainH = 48;
|
||||
int g_grain_rect = -1;
|
||||
ImVec2 g_grain_uv0, g_grain_uv1;
|
||||
bool g_grain_ok;
|
||||
|
||||
ImU32 rgba(int r, int g, int b, float a) { return IM_COL32(r, g, b, (int)(a * 255.0f + 0.5f)); }
|
||||
|
||||
ImU32 mix(const int c0[3], const int c1[3], float t, float a) {
|
||||
return rgba((int)(c0[0] + (c1[0] - c0[0]) * t), (int)(c0[1] + (c1[1] - c0[1]) * t), (int)(c0[2] + (c1[2] - c0[2]) * t),
|
||||
a);
|
||||
}
|
||||
|
||||
// A spiral of `turns` turns around c, from radius r at angle a0 (radians, clockwise on screen) in to 35 % of it.
|
||||
void curl(ImDrawList *dl, ImVec2 c, float r, float a0, float turns, ImU32 col, float thick) {
|
||||
const int n = 28;
|
||||
for (int i = 0; i <= n; i++) {
|
||||
float t = (float)i / n, a = a0 + t * turns * 6.2831853f, rad = r * (1.0f - 0.65f * t);
|
||||
dl->PathLineTo(ImVec2(c.x + cosf(a) * rad, c.y + sinf(a) * rad));
|
||||
}
|
||||
dl->PathStroke(col, 0, thick);
|
||||
}
|
||||
|
||||
void diamond(ImDrawList *dl, ImVec2 c, float d, ImU32 col) {
|
||||
dl->AddQuadFilled(ImVec2(c.x, c.y - d), ImVec2(c.x + d, c.y), ImVec2(c.x, c.y + d), ImVec2(c.x - d, c.y), col);
|
||||
}
|
||||
|
||||
// The inset line of the button and panel frames, `inset` inside [a, b]: a diamond at the top-left and bottom-right
|
||||
// corners, a curl at the top-right and bottom-left ones, the four lines running between them with a small gap.
|
||||
void ornament_line(ImDrawList *dl, ImVec2 a, ImVec2 b, float inset, float s, ImU32 col) {
|
||||
const float l = a.x + inset, t = a.y + inset, r = b.x - inset, bt = b.y - inset;
|
||||
// the ornaments grow with the box as on the game's buttons (a curl about a tenth of the height across), within limits
|
||||
const float span = fminf(r - l, bt - t);
|
||||
float rad = fminf(fmaxf(span * 0.13f, 3.5f * s), 7.0f * s), d = rad * 0.6f, gap = 2.4f * s, thick = 1.4f * s;
|
||||
// top: from the diamond into the curl, whose outer turn starts at the top of its circle
|
||||
dl->AddLine(ImVec2(l + d + gap, t), ImVec2(r - rad, t), col, thick);
|
||||
curl(dl, ImVec2(r - rad, t + rad), rad, -1.5707963f, 1.3f, col, thick);
|
||||
dl->AddLine(ImVec2(r, t + 2 * rad + gap), ImVec2(r, bt - d - gap), col, thick); // right: under the curl
|
||||
dl->AddLine(ImVec2(r - d - gap, bt), ImVec2(l + rad, bt), col, thick); // bottom: into the other curl
|
||||
curl(dl, ImVec2(l + rad, bt - rad), rad, 1.5707963f, 1.3f, col, thick);
|
||||
dl->AddLine(ImVec2(l, bt - 2 * rad - gap), ImVec2(l, t + d + gap), col, thick); // left: over the curl
|
||||
diamond(dl, ImVec2(l, t), d, col);
|
||||
diamond(dl, ImVec2(r, bt), d, col);
|
||||
}
|
||||
|
||||
// The divider ornament's paths: F_M x y, F_L x y, F_C x1 y1 x2 y2 x y, ending with F_END.
|
||||
enum { F_M = -1000, F_L = -1001, F_C = -1002, F_Z = -1003, F_END = -1004 };
|
||||
static const float kFiligree0[] = {
|
||||
F_M, 20, 17.4, F_C, 20.4, 17.3, 21.6, 16.8, 22.2, 16.9, F_C, 22.8, 17, 23.5, 17.7, 23.5, 18.2, F_C, 23.5, 18.7,
|
||||
23.1, 19.4, 22.4, 19.8, F_C, 21.6, 20.2, 20.3, 20.4, 19, 20.4, F_C, 17.7, 20.4, 15.9, 20.2, 14.5, 19.9, F_C,
|
||||
13.1, 19.6, 10.6, 19.4, 10.5, 18.6, F_C, 10.4, 17.9, 12.6, 16.3, 14, 15.4, F_C, 15.4, 14.5, 17.2, 13.6, 19, 13.2,
|
||||
F_C, 20.8, 12.8, 23.2, 12.8, 25, 13.1, F_C, 26.8, 13.4, 28.1, 13.9, 29.5, 14.8, F_C, 30.9, 15.7, 32.2, 17.4,
|
||||
33.5, 18.6, F_C, 34.8, 19.8, 36, 21.2, 37.5, 22, F_C, 39, 22.8, 40.8, 23.4, 42.5, 23.6, F_C, 44.2, 23.8, 46,
|
||||
23.5, 47.5, 23.1, F_C, 49, 22.7, 50.4, 21.9, 51.2, 21.2, F_C, 52, 20.5, 52.5, 19.5, 52.4, 18.8, F_C, 52.3, 18.1,
|
||||
51.5, 17.3, 50.6, 16.9, F_C, 49.7, 16.5, 48.2, 16.2, 47, 16.3, F_C, 45.8, 16.4, 44.2, 17.1, 43.6, 17.2, F_END};
|
||||
static const float kFiligree1[] = {
|
||||
F_M, 100, 17.4, F_C, 99.6, 17.3, 98.4, 16.8, 97.8, 16.9, F_C, 97.2, 17, 96.5, 17.7, 96.5, 18.2, F_C, 96.5, 18.7,
|
||||
96.8, 19.4, 97.6, 19.8, F_C, 98.3, 20.2, 99.7, 20.4, 101, 20.4, F_C, 102.3, 20.4, 104.1, 20.2, 105.5, 19.9, F_C,
|
||||
106.9, 19.6, 109.4, 19.4, 109.5, 18.6, F_C, 109.6, 17.9, 107.4, 16.3, 106, 15.4, F_C, 104.6, 14.5, 102.8, 13.6,
|
||||
101, 13.2, F_C, 99.2, 12.8, 96.8, 12.8, 95, 13.1, F_C, 93.2, 13.4, 91.9, 13.9, 90.5, 14.8, F_C, 89.1, 15.7, 87.8,
|
||||
17.4, 86.5, 18.6, F_C, 85.2, 19.8, 84, 21.2, 82.5, 22, F_C, 81, 22.8, 79.2, 23.4, 77.5, 23.6, F_C, 75.8, 23.8,
|
||||
74, 23.5, 72.5, 23.1, F_C, 71, 22.7, 69.6, 21.9, 68.8, 21.2, F_C, 68, 20.5, 67.5, 19.5, 67.6, 18.8, F_C, 67.7,
|
||||
18.1, 68.5, 17.3, 69.4, 16.9, F_C, 70.3, 16.5, 71.8, 16.2, 73, 16.3, F_C, 74.2, 16.4, 75.8, 17.1, 76.4, 17.2,
|
||||
F_END};
|
||||
static const float kFiligree2[] = {
|
||||
F_M, 40.6, 17.6, F_C, 40.7, 17, 40.7, 14.9, 41.2, 14, F_C, 41.7, 13.1, 42.6, 12.4, 43.8, 12, F_C, 45, 11.6, 46.7,
|
||||
11.4, 48.2, 11.5, F_C, 49.7, 11.6, 51.3, 11.8, 52.6, 12.3, F_C, 53.9, 12.8, 55, 13.6, 56, 14.6, F_C, 57, 15.6,
|
||||
58.2, 17.6, 58.6, 18.2, F_L, 64.6, 26, F_L, 60, 31.6, F_END};
|
||||
static const float kFiligree3[] = {
|
||||
F_M, 79.4, 17.6, F_C, 79.3, 17, 79.3, 14.9, 78.8, 14, F_C, 78.3, 13.1, 77.4, 12.4, 76.2, 12, F_C, 75, 11.6, 73.3,
|
||||
11.4, 71.8, 11.5, F_C, 70.3, 11.6, 68.7, 11.8, 67.4, 12.3, F_C, 66.1, 12.8, 65, 13.6, 64, 14.6, F_C, 63, 15.6,
|
||||
61.8, 17.6, 61.4, 18.2, F_L, 55.4, 26, F_L, 60, 31.6, F_END};
|
||||
const float *const kFiligree[] = {kFiligree0, kFiligree1, kFiligree2, kFiligree3};
|
||||
|
||||
// The settings menu's colours: a dark umber panel, warm browns for frames and what is selected, gold for the ornaments,
|
||||
// accents and the cursor, parchment text. kGreen and kOcarina keep their names for the selected and active controls.
|
||||
const ImVec4 kGold(0.93f, 0.76f, 0.38f, 1), kGreen(0.36f, 0.26f, 0.13f, 1), kNavy(0.075f, 0.058f, 0.042f, 0.95f),
|
||||
kOcarina(0.62f, 0.47f, 0.22f, 1);
|
||||
|
||||
// Where the art's boxes lie in its textures, in texels (measured from the textures). The button's layers are 489 x 133
|
||||
// with the button's box from (20, 19) to (469, 114); the cursor's are 640 x 173 and its box, the button it surrounds,
|
||||
// runs from (49, 48) to (591, 125); the panel's box runs from (53, 53) to (1147, 374) in 1200 x 427.
|
||||
const float kBtnW = 489, kBtnH = 133, kBtnL = 20, kBtnT = 19, kBtnBoxH = 95, kBtnCut = 60;
|
||||
const float kCurW = 640, kCurH = 173, kCurX = 49, kCurY = 48, kCurCut = 70, kCurScale = 0.72f;
|
||||
const float kPanelW = 1200, kPanelH = 427, kPanelM = 53;
|
||||
const float kTabL = 25, kTabT = 0, kTabR = 336, kTabB = 151; // the selected tab's plate in its 360 x 173 texture
|
||||
|
||||
bool have_art(std::initializer_list<MenuArt> ids) {
|
||||
ImTextureID t;
|
||||
for (MenuArt id : ids)
|
||||
if (!menu_art(id, &t, nullptr, nullptr)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
enum { MAX_COPIES = 15 };
|
||||
struct Piece { float p0, p1, t0, t1; };
|
||||
|
||||
// One axis of a slice: screen [a, b] from texels [x0, x1] of a texture `size` long, the outer `cut` texels c pixels
|
||||
// long. The middle is stretched, or with tile repeated at k pixels per texel: an odd number of copies, every other one
|
||||
// mirrored, so each copy meets the next on the same texels and the last meets the far corner. Mottled art stretched
|
||||
// across a wide box would turn into streaks.
|
||||
int axis(Piece *out, float a, float b, float x0, float x1, float size, float cut, float c, float k, bool tile) {
|
||||
const float m0 = a + c, m1 = b - c, t0 = (x0 + cut) / size, t1 = (x1 - cut) / size, unit = (x1 - x0 - 2 * cut) * k;
|
||||
int copies = 1, n = 0;
|
||||
if (tile && unit > 0) copies = 2 * (int)floorf(((m1 - m0) / unit - 1) * 0.5f + 0.5f) + 1;
|
||||
copies = copies < 1 ? 1 : copies > MAX_COPIES ? MAX_COPIES : copies;
|
||||
out[n++] = {a, m0, x0 / size, t0};
|
||||
for (int i = 0; i < copies; i++) {
|
||||
float w = (m1 - m0) / copies;
|
||||
out[n++] = {m0 + i * w, m0 + (i + 1) * w, i & 1 ? t1 : t0, i & 1 ? t0 : t1};
|
||||
}
|
||||
out[n++] = {m1, b, t1, x1 / size};
|
||||
return n;
|
||||
}
|
||||
|
||||
// The texels (x0, y0)-(x1, y1) of an art over [a, b] in nine slices: the outer `cut` texels on each side at k screen
|
||||
// pixels per texel, so corners keep their shape, the rest stretched or tiled. A box smaller than its two corners shrinks
|
||||
// them.
|
||||
void slice(ImDrawList *dl, MenuArt id, ImVec2 a, ImVec2 b, float x0, float y0, float x1, float y1, float cut, float k, ImU32 tint,
|
||||
bool tile_x = false, bool tile_y = false) {
|
||||
ImTextureID t;
|
||||
float tw, th;
|
||||
if (!menu_art(id, &t, &tw, &th)) return;
|
||||
Piece xs[MAX_COPIES + 2], ys[MAX_COPIES + 2];
|
||||
int nx = axis(xs, a.x, b.x, x0, x1, tw, cut, fminf(cut * k, (b.x - a.x) * 0.5f), k, tile_x);
|
||||
int ny = axis(ys, a.y, b.y, y0, y1, th, cut, fminf(cut * k, (b.y - a.y) * 0.5f), k, tile_y);
|
||||
for (int j = 0; j < ny; j++)
|
||||
for (int i = 0; i < nx; i++)
|
||||
dl->AddImage(t, ImVec2(xs[i].p0, ys[j].p0), ImVec2(xs[i].p1, ys[j].p1), ImVec2(xs[i].t0, ys[j].t0), ImVec2(xs[i].t1, ys[j].t1), tint);
|
||||
}
|
||||
|
||||
// A button layer over the box [a, b]: the whole texture, reaching past the box by its margins.
|
||||
void btn_layer(ImDrawList *dl, MenuArt id, ImVec2 a, ImVec2 b, float k, ImU32 tint, bool tile_x = false) {
|
||||
const float mx = kBtnL * k, my = kBtnT * k;
|
||||
slice(dl, id, ImVec2(a.x - mx, a.y - my), ImVec2(b.x + mx, b.y + my), 0, 0, kBtnW, kBtnH, kBtnCut, k, tint, tile_x);
|
||||
}
|
||||
|
||||
// A cursor layer around the box [a, b], at a fixed size so its frame keeps its width on any box.
|
||||
void cursor_layer(ImDrawList *dl, MenuArt id, ImVec2 a, ImVec2 b, float s, ImU32 tint) {
|
||||
const float k = kCurScale * s, mx = kCurX * k, my = kCurY * k;
|
||||
slice(dl, id, ImVec2(a.x - mx, a.y - my), ImVec2(b.x + mx, b.y + my), 0, 0, kCurW, kCurH, kCurCut, k, tint);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// The cursor line's texture is not the line: its alpha climbs from 0 at the outer edge to full about 28 texels in, and
|
||||
// is full inside. The white frame is a band of that ramp, about 3.5 texels wide just outside the box it surrounds
|
||||
// (alpha 102 lies about six texels out from the cursor's box), so the frame follows the texture's own corners.
|
||||
void skin_art_prepare(int art, uint8_t *rgba, uint32_t w, uint32_t h) {
|
||||
if (art != MENU_ART_CURSOR_LINE) return;
|
||||
const int mid = 102, full = 16, soft = 8; // in alpha steps; the ramp climbs about 8.7 of them per texel
|
||||
for (size_t i = 0, n = (size_t)w * h; i < n; i++) {
|
||||
int d = abs((int)rgba[i * 4 + 3] - mid) - full;
|
||||
rgba[i * 4 + 3] = d <= 0 ? 255 : d >= soft ? 0 : (uint8_t)(255 - d * 255 / soft);
|
||||
}
|
||||
}
|
||||
|
||||
// A box filter over the 2 x 2 texels each destination texel covers (an odd last row or column repeats). Colour is
|
||||
// weighted by alpha, so what is transparent does not bleed into the edges of the coloured art.
|
||||
void skin_art_halve(const uint8_t *src, uint32_t w, uint32_t h, uint8_t *dst, uint32_t dw, uint32_t dh) {
|
||||
for (uint32_t y = 0; y < dh; y++)
|
||||
for (uint32_t x = 0; x < dw; x++) {
|
||||
const uint32_t xs[2] = {x * 2 < w ? x * 2 : w - 1, x * 2 + 1 < w ? x * 2 + 1 : w - 1},
|
||||
ys[2] = {y * 2 < h ? y * 2 : h - 1, y * 2 + 1 < h ? y * 2 + 1 : h - 1};
|
||||
uint32_t rgb[3] = {0, 0, 0}, plain[3] = {0, 0, 0}, al = 0;
|
||||
for (int j = 0; j < 2; j++)
|
||||
for (int i = 0; i < 2; i++) {
|
||||
const uint8_t *p = src + ((size_t)ys[j] * w + xs[i]) * 4;
|
||||
for (int c = 0; c < 3; c++) rgb[c] += p[c] * (uint32_t)p[3], plain[c] += p[c];
|
||||
al += p[3];
|
||||
}
|
||||
uint8_t *d = dst + ((size_t)y * dw + x) * 4;
|
||||
for (int c = 0; c < 3; c++) d[c] = (uint8_t)(al ? (rgb[c] + al / 2) / al : (plain[c] + 2) / 4);
|
||||
d[3] = (uint8_t)((al + 2) / 4);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int menu_art_draw(ImDrawList *dl, MenuArt id, ImVec2 a, ImVec2 b, ImU32 tint) {
|
||||
ImTextureID t;
|
||||
if (!menu_art(id, &t, nullptr, nullptr)) return 0;
|
||||
dl->AddImage(t, a, b, ImVec2(0, 0), ImVec2(1, 1), tint);
|
||||
return 1;
|
||||
}
|
||||
|
||||
extern "C" int menu_art_draw9(ImDrawList *dl, MenuArt id, ImVec2 a, ImVec2 b, float corner, float frac, ImU32 tint, int fill) {
|
||||
return menu_art_draw9_turned(dl, id, a, b, corner, frac, tint, fill, 0);
|
||||
}
|
||||
|
||||
// Nine pieces: the corners at `corner` pixels on screen from the texture's outer `frac` of each side, the edges
|
||||
// stretched between them, the middle left out (frames) or stretched (fill); the texture turned half a turn when turned,
|
||||
// its top-left corner piece at the bottom right.
|
||||
extern "C" int menu_art_draw9_turned(ImDrawList *dl, MenuArt id, ImVec2 a, ImVec2 b, float corner, float frac, ImU32 tint, int fill,
|
||||
int turned) {
|
||||
ImTextureID t;
|
||||
if (!menu_art(id, &t, nullptr, nullptr)) return 0;
|
||||
float c = corner, maxc = fminf((b.x - a.x) / 2, (b.y - a.y) / 2);
|
||||
if (c > maxc) c = maxc;
|
||||
const float xs[4] = {a.x, a.x + c, b.x - c, b.x}, ys[4] = {a.y, a.y + c, b.y - c, b.y};
|
||||
float us[4] = {0, frac, 1 - frac, 1}, vs[4] = {0, frac, 1 - frac, 1};
|
||||
if (turned)
|
||||
for (int k = 0; k < 4; k++) us[k] = 1 - us[k], vs[k] = 1 - vs[k];
|
||||
for (int j = 0; j < 3; j++)
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (i == 1 && j == 1 && !fill) continue;
|
||||
dl->AddImage(t, ImVec2(xs[i], ys[j]), ImVec2(xs[i + 1], ys[j + 1]), ImVec2(us[i], vs[j]), ImVec2(us[i + 1], vs[j + 1]), tint);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void skin_style(ImGuiStyle &s) {
|
||||
ImGui::StyleColorsDark(&s);
|
||||
s.WindowRounding = 10; s.FrameRounding = 6; s.GrabRounding = 6; s.TabRounding = 6; s.ChildRounding = 8;
|
||||
s.WindowPadding = ImVec2(40, 30); s.FramePadding = ImVec2(14, 8); s.ItemSpacing = ImVec2(14, 12);
|
||||
s.WindowBorderSize = 2; s.ScrollbarSize = 16;
|
||||
ImVec4 *c = s.Colors;
|
||||
c[ImGuiCol_WindowBg] = kNavy;
|
||||
c[ImGuiCol_Border] = ImVec4(kGold.x, kGold.y, kGold.z, 0.55f);
|
||||
c[ImGuiCol_ChildBg] = ImVec4(0, 0, 0, 0);
|
||||
c[ImGuiCol_PopupBg] = kNavy;
|
||||
c[ImGuiCol_Text] = ImVec4(0.96f, 0.92f, 0.82f, 1);
|
||||
c[ImGuiCol_TextDisabled] = ImVec4(0.62f, 0.56f, 0.46f, 1);
|
||||
c[ImGuiCol_FrameBg] = ImVec4(0.15f, 0.115f, 0.08f, 1);
|
||||
c[ImGuiCol_FrameBgHovered] = ImVec4(0.24f, 0.18f, 0.10f, 1);
|
||||
c[ImGuiCol_FrameBgActive] = kGreen;
|
||||
c[ImGuiCol_SliderGrab] = kOcarina;
|
||||
c[ImGuiCol_SliderGrabActive] = kGold;
|
||||
c[ImGuiCol_CheckMark] = kGold;
|
||||
c[ImGuiCol_Button] = ImVec4(0.19f, 0.145f, 0.09f, 1);
|
||||
c[ImGuiCol_ButtonHovered] = kGreen;
|
||||
c[ImGuiCol_ButtonActive] = kOcarina;
|
||||
c[ImGuiCol_Header] = ImVec4(0.24f, 0.18f, 0.10f, 1);
|
||||
c[ImGuiCol_HeaderHovered] = kGreen;
|
||||
c[ImGuiCol_HeaderActive] = kOcarina;
|
||||
c[ImGuiCol_Tab] = ImVec4(0.13f, 0.10f, 0.07f, 1);
|
||||
c[ImGuiCol_TabHovered] = kGreen;
|
||||
c[ImGuiCol_TabSelected] = ImVec4(0.42f, 0.31f, 0.15f, 1);
|
||||
c[ImGuiCol_TabSelectedOverline] = kGold;
|
||||
c[ImGuiCol_NavCursor] = kGold;
|
||||
c[ImGuiCol_Separator] = ImVec4(kGold.x, kGold.y, kGold.z, 0.30f);
|
||||
c[ImGuiCol_ScrollbarGrab] = ImVec4(0.36f, 0.28f, 0.16f, 1);
|
||||
c[ImGuiCol_ScrollbarBg] = ImVec4(0, 0, 0, 0.2f);
|
||||
}
|
||||
|
||||
// The grain over [a, b]: the tile repeated at four pixels per texel (its noise wraps, so the copies join unseen), so the
|
||||
// blotches keep their size on any box; darkening where the tile is dense, lightening where its mirror image is.
|
||||
static void grain(ImDrawList *dl, ImVec2 a, ImVec2 b, float s, float strength) {
|
||||
if (!g_grain_ok) return;
|
||||
ImTextureID tex = ImGui::GetIO().Fonts->TexID;
|
||||
const float pw = kGrainW * 4.0f * s, ph = kGrainH * 4.0f * s;
|
||||
const ImVec2 du(g_grain_uv1.x - g_grain_uv0.x, g_grain_uv1.y - g_grain_uv0.y);
|
||||
const ImU32 dark = rgba(20, 12, 4, 0.30f * strength), light = rgba(255, 236, 196, 0.12f * strength);
|
||||
for (float y = a.y; y < b.y; y += ph)
|
||||
for (float x = a.x; x < b.x; x += pw) {
|
||||
float x1 = fminf(x + pw, b.x), y1 = fminf(y + ph, b.y);
|
||||
ImVec2 u0 = g_grain_uv0, u1(g_grain_uv0.x + du.x * (x1 - x) / pw, g_grain_uv0.y + du.y * (y1 - y) / ph);
|
||||
dl->AddImage(tex, ImVec2(x, y), ImVec2(x1, y1), u0, u1, dark);
|
||||
// the mirror image: the tile read from its far corner, over the same piece
|
||||
ImVec2 m0(g_grain_uv1.x, g_grain_uv1.y), m1(g_grain_uv1.x - du.x * (x1 - x) / pw, g_grain_uv1.y - du.y * (y1 - y) / ph);
|
||||
dl->AddImage(tex, ImVec2(x, y), ImVec2(x1, y1), m0, m1, light);
|
||||
}
|
||||
}
|
||||
|
||||
void skin_atlas_add(ImFontAtlas *fa) { g_grain_rect = fa->AddCustomRectRegular(kGrainW, kGrainH), g_grain_ok = false; }
|
||||
|
||||
void skin_atlas_fill(ImFontAtlas *fa) {
|
||||
unsigned char *px;
|
||||
int w, h;
|
||||
fa->GetTexDataAsRGBA32(&px, &w, &h);
|
||||
const ImFontAtlasCustomRect *r = g_grain_rect >= 0 ? fa->GetCustomRectByIndex(g_grain_rect) : nullptr;
|
||||
if (!px || !r || !r->IsPacked()) return;
|
||||
// value noise of three octaves on a lattice that wraps, with a little fine speckle: blotches and grain
|
||||
auto lattice = [](int x, int y, int seed) {
|
||||
unsigned v = (unsigned)(x * 374761393 + y * 668265263 + seed * 2246822519u);
|
||||
v = (v ^ (v >> 13)) * 1274126177u;
|
||||
return ((v ^ (v >> 16)) & 0xffff) / 65535.0f;
|
||||
};
|
||||
auto smooth = [&](float x, float y, int cell, int seed) {
|
||||
float gx = x / cell, gy = y / cell;
|
||||
int x0 = (int)floorf(gx), y0 = (int)floorf(gy);
|
||||
float fx = gx - x0, fy = gy - y0;
|
||||
fx = fx * fx * (3 - 2 * fx), fy = fy * fy * (3 - 2 * fy);
|
||||
int wx = kGrainW / cell, wy = kGrainH / cell;
|
||||
auto at = [&](int i, int j) { return lattice(((i % wx) + wx) % wx, ((j % wy) + wy) % wy, seed); };
|
||||
float top = at(x0, y0) + (at(x0 + 1, y0) - at(x0, y0)) * fx;
|
||||
float bot = at(x0, y0 + 1) + (at(x0 + 1, y0 + 1) - at(x0, y0 + 1)) * fx;
|
||||
return top + (bot - top) * fy;
|
||||
};
|
||||
for (int y = 0; y < kGrainH; y++)
|
||||
for (int x = 0; x < kGrainW; x++) {
|
||||
float n = 0.55f * smooth((float)x, (float)y, 16, 1) + 0.30f * smooth((float)x, (float)y, 8, 2) +
|
||||
0.15f * smooth((float)x, (float)y, 4, 3);
|
||||
n = n * 0.85f + 0.15f * lattice(x, y, 9);
|
||||
float v = fminf(1.0f, fmaxf(0.0f, (n - 0.35f) * 1.8f));
|
||||
unsigned char *d = px + 4 * ((size_t)(r->Y + y) * w + r->X + x);
|
||||
d[0] = d[1] = d[2] = 255, d[3] = (unsigned char)(v * 255.0f + 0.5f);
|
||||
}
|
||||
fa->CalcCustomRectUV(r, &g_grain_uv0, &g_grain_uv1);
|
||||
g_grain_ok = true;
|
||||
}
|
||||
|
||||
// The button from the game's layers; false while they are not there. plate: the selected tab's plate under the lines.
|
||||
static bool button_art(ImDrawList *dl, ImVec2 a, ImVec2 b, float lift, bool dim, bool plate) {
|
||||
if (!have_art({MENU_ART_BTN_RIM, MENU_ART_BTN_FILL, MENU_ART_BTN_GRAIN, MENU_ART_BTN_EDGE, MENU_ART_BTN_LINE})) return false;
|
||||
static const int fill0[3] = {100, 76, 42}, fill1[3] = {128, 99, 58}, grain0[3] = {150, 118, 76}, grain1[3] = {178, 144, 96};
|
||||
static const int grey_fill[3] = {76, 67, 56}, grey_grain[3] = {128, 116, 100};
|
||||
const float t = (b.y - a.y) / kBtnBoxH;
|
||||
btn_layer(dl, MENU_ART_BTN_RIM, a, b, t, rgba(20, 14, 8, 0.85f));
|
||||
btn_layer(dl, MENU_ART_BTN_FILL, a, b, t, dim ? mix(grey_fill, grey_fill, 0, 1) : mix(fill0, fill1, lift, 1));
|
||||
btn_layer(dl, MENU_ART_BTN_GRAIN, a, b, t, dim ? mix(grey_grain, grey_grain, 0, 0.26f) : mix(grain0, grain1, lift, 0.32f), true);
|
||||
if (plate) slice(dl, MENU_ART_TAB_SELECT, a, b, kTabL, kTabT, kTabR, kTabB, 30, t, rgba(232, 186, 104, 0.55f));
|
||||
btn_layer(dl, MENU_ART_BTN_EDGE, a, b, t, dim ? rgba(98, 88, 74, 1) : rgba(140, 116, 74, 1));
|
||||
btn_layer(dl, MENU_ART_BTN_LINE, a, b, t, dim ? rgba(112, 102, 88, 1) : rgba(150 + (int)(24 * lift), 124 + (int)(20 * lift), 80 + (int)(12 * lift), 1));
|
||||
return true;
|
||||
}
|
||||
|
||||
void skin_button(ImDrawList *dl, ImVec2 a, ImVec2 b, float s, float lift, bool dim) {
|
||||
static const int top0[3] = {98, 75, 41}, top1[3] = {122, 95, 55}, bot0[3] = {84, 63, 32}, bot1[3] = {106, 81, 44};
|
||||
static const int grey_top[3] = {66, 58, 48}, grey_bot[3] = {56, 49, 40};
|
||||
lift = lift < 0 ? 0 : lift > 1 ? 1 : lift;
|
||||
if (button_art(dl, a, b, lift, dim, false)) return;
|
||||
const float k = 1.0f * s;
|
||||
dl->AddRectFilled(a, b, rgba(28, 22, 14, 0.92f)); // the dark rim between the button and what is behind it
|
||||
ImVec2 ia(a.x + k, a.y + k), ib(b.x - k, b.y - k);
|
||||
ImU32 top = dim ? mix(grey_top, grey_top, 0, 1) : mix(top0, top1, lift, 1);
|
||||
ImU32 bot = dim ? mix(grey_bot, grey_bot, 0, 1) : mix(bot0, bot1, lift, 1);
|
||||
dl->AddRectFilledMultiColor(ia, ib, top, top, bot, bot);
|
||||
grain(dl, ia, ib, s, dim ? 0.5f : 1.0f);
|
||||
dl->AddRect(ia, ib, dim ? rgba(98, 88, 74, 1) : rgba(126, 104, 68, 1), 0, 0, 1.4f * s); // the light edge
|
||||
float h = b.y - a.y, inset = fmaxf(4.0f * s, h * 0.1f);
|
||||
ornament_line(dl, a, b, inset, s, dim ? rgba(104, 94, 80, 1) : rgba(134 + (int)(18 * lift), 111 + (int)(14 * lift),
|
||||
70 + (int)(8 * lift), 1));
|
||||
}
|
||||
|
||||
float skin_cursor_reach(float s) { return 3.0f * s + 2.5f * s + 12.0f * s; }
|
||||
|
||||
// one slow breath every 1.6 s, as the game's cursor pulses
|
||||
static float breath(void) { return 0.5f - 0.5f * cosf((float)ImGui::GetTime() * 6.2831853f / 1.6f); }
|
||||
|
||||
void skin_cursor_glow(ImDrawList *dl, ImVec2 a, ImVec2 b, float s, float alpha) {
|
||||
if (have_art({MENU_ART_CURSOR_GLOW})) {
|
||||
cursor_layer(dl, MENU_ART_CURSOR_GLOW, a, b, s, rgba(164, 194, 240, alpha * (0.78f + 0.22f * breath())));
|
||||
return;
|
||||
}
|
||||
// filled rounded boxes stacked from the outside in, each faint, so the glow brightens towards the frame; the box
|
||||
// drawn over them hides their middle
|
||||
const float ring = 3.0f * s + 1.25f * s, br = breath();
|
||||
const int n = 12;
|
||||
for (int i = n; i >= 1; i--) {
|
||||
float o = ring + i * 0.95f * s;
|
||||
dl->AddRectFilled(ImVec2(a.x - o, a.y - o), ImVec2(b.x + o, b.y + o), rgba(160, 190, 236, alpha * (0.055f + 0.03f * br)),
|
||||
2.0f * s + i * 0.9f * s);
|
||||
}
|
||||
}
|
||||
|
||||
void skin_cursor_frame(ImDrawList *dl, ImVec2 a, ImVec2 b, float s, float alpha) {
|
||||
if (have_art({MENU_ART_CURSOR_LINE})) {
|
||||
cursor_layer(dl, MENU_ART_CURSOR_LINE, a, b, s, rgba(240, 242, 245, alpha));
|
||||
return;
|
||||
}
|
||||
const float gap = 3.0f * s, thick = 2.5f * s, ring = gap + thick * 0.5f;
|
||||
// a little glow in the gap between the box and the frame, then the white frame
|
||||
dl->AddRect(ImVec2(a.x - gap * 0.5f, a.y - gap * 0.5f), ImVec2(b.x + gap * 0.5f, b.y + gap * 0.5f),
|
||||
rgba(190, 210, 240, alpha * (0.30f + 0.15f * breath())), gap * 0.4f, 0, gap);
|
||||
dl->AddRect(ImVec2(a.x - ring, a.y - ring), ImVec2(b.x + ring, b.y + ring), rgba(236, 238, 241, alpha), 2.0f * s, 0, thick);
|
||||
}
|
||||
|
||||
float skin_filigree_height(float s) { return 26.0f * s; }
|
||||
|
||||
// The divider from the game's art: the ornament (its ink runs from (28, 24) to (200, 65) in 228 x 80) and on each side
|
||||
// the line texture, turned round for the left one: its stroke from x = 38 to 217 stretched, then the dot up to x = 232
|
||||
// at its own proportions, the whole on the row y = 23 of 240 x 43.
|
||||
static bool filigree_art(ImDrawList *dl, float x0, float x1, float y, float s, float alpha) {
|
||||
ImTextureID mark, stroke;
|
||||
float mw, mh, lw, lh;
|
||||
if (!menu_art(MENU_ART_DIVIDER, &mark, &mw, &mh) || !menu_art(MENU_ART_DIVIDER_LINE, &stroke, &lw, &lh)) return false;
|
||||
const ImU32 orn = rgba(196, 164, 112, alpha), line = rgba(150, 126, 90, alpha);
|
||||
const float orn_w = fminf(84.0f * s, (x1 - x0) * 0.5f), k = orn_w / 172.0f, cx = (x0 + x1) * 0.5f;
|
||||
dl->AddImage(mark, ImVec2(cx - 114 * k, y - 44.5f * k), ImVec2(cx - 114 * k + mw * k, y - 44.5f * k + mh * k), ImVec2(0, 0), ImVec2(1, 1), orn);
|
||||
const float lk = 0.42f * s, top = y - 9 * lk, bot = y + 9 * lk, v0 = 14 / lh, v1 = 32 / lh, dot = (232 - 217) * lk;
|
||||
const float from = cx + orn_w * 0.5f + 5 * s, to = x1 - 4 * s;
|
||||
if (to - dot <= from) return true;
|
||||
const float u0 = 38 / lw, u1 = 217 / lw, u2 = 232 / lw, mirror = 2 * cx;
|
||||
dl->AddImage(stroke, ImVec2(from, top), ImVec2(to - dot, bot), ImVec2(u0, v0), ImVec2(u1, v1), line);
|
||||
dl->AddImage(stroke, ImVec2(to - dot, top), ImVec2(to, bot), ImVec2(u1, v0), ImVec2(u2, v1), line);
|
||||
dl->AddImage(stroke, ImVec2(mirror - (to - dot), top), ImVec2(mirror - from, bot), ImVec2(u1, v0), ImVec2(u0, v1), line);
|
||||
dl->AddImage(stroke, ImVec2(mirror - to, top), ImVec2(mirror - (to - dot), bot), ImVec2(u2, v0), ImVec2(u1, v1), line);
|
||||
return true;
|
||||
}
|
||||
|
||||
void skin_filigree(ImDrawList *dl, float x0, float x1, float y, float s, float alpha) {
|
||||
if (filigree_art(dl, x0, x1, y, s, alpha)) return;
|
||||
const ImU32 line = rgba(96, 80, 56, alpha), dot = rgba(110, 92, 64, alpha), orn = rgba(138, 114, 76, alpha);
|
||||
float orn_w = fminf(78.0f * s, (x1 - x0) * 0.5f), k = orn_w / 108.0f, cx = (x0 + x1) * 0.5f;
|
||||
float dot_r = 1.5f * s, gap = 5.0f * s;
|
||||
dl->AddCircleFilled(ImVec2(x0 + 4 * s + dot_r, y), dot_r, dot);
|
||||
dl->AddCircleFilled(ImVec2(x1 - 4 * s - dot_r, y), dot_r, dot);
|
||||
dl->AddLine(ImVec2(x0 + 4 * s + 2 * dot_r + gap, y), ImVec2(cx - orn_w * 0.5f - gap, y), line, 1.0f * s);
|
||||
dl->AddLine(ImVec2(cx + orn_w * 0.5f + gap, y), ImVec2(x1 - 4 * s - 2 * dot_r - gap, y), line, 1.0f * s);
|
||||
auto at = [&](float px, float py) { return ImVec2(cx + (px - 60.0f) * k, y + (py - 21.0f) * k); };
|
||||
for (const float *p : kFiligree) {
|
||||
ImVec2 cur(0, 0);
|
||||
bool open = false;
|
||||
for (int i = 0; p[i] != F_END;) {
|
||||
if (p[i] == F_M) {
|
||||
if (open) dl->PathStroke(orn, 0, 2.2f * k);
|
||||
cur = at(p[i + 1], p[i + 2]);
|
||||
dl->PathLineTo(cur);
|
||||
open = true;
|
||||
i += 3;
|
||||
} else if (p[i] == F_L) {
|
||||
cur = at(p[i + 1], p[i + 2]);
|
||||
dl->PathLineTo(cur);
|
||||
i += 3;
|
||||
} else if (p[i] == F_C) {
|
||||
cur = at(p[i + 5], p[i + 6]);
|
||||
dl->PathBezierCubicCurveTo(at(p[i + 1], p[i + 2]), at(p[i + 3], p[i + 4]), cur, 8);
|
||||
i += 7;
|
||||
} else { // F_Z: back to the path's start (no path here uses it)
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
if (open) dl->PathStroke(orn, 0, 2.2f * k);
|
||||
}
|
||||
}
|
||||
|
||||
void skin_panel(ImDrawList *dl, ImVec2 a, ImVec2 b, float s, float alpha) {
|
||||
if (have_art({MENU_ART_PANEL_FILL, MENU_ART_BTN_EDGE, MENU_ART_BTN_LINE})) {
|
||||
// the panel's own texture inside its box, with the button's edge and inset line at a size that suits a large box
|
||||
const float k = 0.62f * s;
|
||||
slice(dl, MENU_ART_PANEL_FILL, a, b, kPanelM, kPanelM, kPanelW - kPanelM, kPanelH - kPanelM, 40, k, rgba(255, 255, 255, alpha), true, true);
|
||||
btn_layer(dl, MENU_ART_BTN_EDGE, a, b, k, rgba(126, 104, 68, 1));
|
||||
btn_layer(dl, MENU_ART_BTN_LINE, a, b, k, rgba(150, 124, 80, 1));
|
||||
return;
|
||||
}
|
||||
dl->AddRectFilled(a, b, rgba(20, 15, 10, 0.85f * alpha));
|
||||
ImVec2 ia(a.x + 1.0f * s, a.y + 1.0f * s), ib(b.x - 1.0f * s, b.y - 1.0f * s);
|
||||
dl->AddRectFilledMultiColor(ia, ib, rgba(44, 35, 25, alpha), rgba(44, 35, 25, alpha), rgba(33, 26, 19, alpha),
|
||||
rgba(33, 26, 19, alpha));
|
||||
grain(dl, ia, ib, s, 0.6f * alpha);
|
||||
dl->AddRect(ia, ib, rgba(110, 90, 58, 1), 0, 0, 1.4f * s);
|
||||
ornament_line(dl, a, b, 7.0f * s, s, rgba(122, 101, 66, 1));
|
||||
}
|
||||
|
||||
bool skin_widget_button(const char *label, ImVec2 size, float s) {
|
||||
ImVec2 ts = ImGui::CalcTextSize(label, nullptr, true);
|
||||
const ImGuiStyle &st = ImGui::GetStyle();
|
||||
ImVec2 sz(size.x > 0 ? size.x : ts.x + st.FramePadding.x * 2, size.y > 0 ? size.y : ts.y + st.FramePadding.y * 2);
|
||||
ImVec2 a = ImGui::GetCursorScreenPos(), b(a.x + sz.x, a.y + sz.y);
|
||||
ImGui::PushStyleColor(ImGuiCol_NavCursor, ImVec4(0, 0, 0, 0)); // the cursor below shows the selection
|
||||
bool pressed = ImGui::InvisibleButton(label, sz, ImGuiButtonFlags_EnableNav);
|
||||
ImGui::PopStyleColor();
|
||||
bool hov = ImGui::IsItemHovered(), foc = ImGui::IsItemFocused() && ImGui::GetCurrentContext()->NavCursorVisible;
|
||||
bool held = ImGui::IsItemActive();
|
||||
ImDrawList *dl = ImGui::GetWindowDrawList();
|
||||
if (foc || hov) skin_cursor_glow(dl, a, b, s, foc ? 1.0f : 0.55f); // under the button
|
||||
skin_button(dl, a, b, s, held ? 0.4f : foc ? 1.0f : hov ? 0.7f : 0.15f, false);
|
||||
const char *end = ImGui::FindRenderedTextEnd(label);
|
||||
dl->AddText(ImVec2(floorf((a.x + b.x - ts.x) * 0.5f), floorf((a.y + b.y - ts.y) * 0.5f)), SKIN_TEXT, label, end);
|
||||
if (foc || hov) skin_cursor_frame(dl, a, b, s, foc ? 1.0f : 0.55f);
|
||||
return pressed;
|
||||
}
|
||||
|
||||
bool skin_tab_item(const char *id, const char *text, int flags, float s, ImFont *font) {
|
||||
// Dear ImGui keeps the bar's behaviour (selecting, sizing, the D-pad) and lays out the tab with everything it would
|
||||
// draw made invisible; the button and the text go over its rectangle here.
|
||||
static const ImGuiCol hide[] = {ImGuiCol_Tab, ImGuiCol_TabHovered, ImGuiCol_TabSelected, ImGuiCol_TabSelectedOverline, ImGuiCol_TabDimmed,
|
||||
ImGuiCol_TabDimmedSelected, ImGuiCol_TabDimmedSelectedOverline, ImGuiCol_Text, ImGuiCol_NavCursor};
|
||||
for (ImGuiCol c : hide) ImGui::PushStyleColor(c, ImVec4(0, 0, 0, 0));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, ImVec2(12.0f * s, ImGui::GetStyle().ItemInnerSpacing.y));
|
||||
if (font) ImGui::PushFont(font);
|
||||
const bool shown = ImGui::BeginTabItem(id, nullptr, flags);
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::PopStyleColor((int)(sizeof hide / sizeof *hide));
|
||||
ImVec2 a = ImGui::GetItemRectMin(), b = ImGui::GetItemRectMax();
|
||||
if (b.x > a.x && b.y > a.y) {
|
||||
b.y -= 4.0f * s; // clear of the line under the tabs
|
||||
const bool hov = ImGui::IsItemHovered(), foc = ImGui::IsItemFocused() && ImGui::GetCurrentContext()->NavCursorVisible;
|
||||
ImDrawList *dl = ImGui::GetWindowDrawList();
|
||||
if (foc) skin_cursor_glow(dl, a, b, s, 1.0f);
|
||||
const float lift = shown ? 1.0f : hov ? 0.6f : 0.0f;
|
||||
if (!button_art(dl, a, b, lift, false, shown)) skin_button(dl, a, b, s, lift, false);
|
||||
const ImVec2 ts = ImGui::CalcTextSize(text, nullptr, true);
|
||||
dl->AddText(ImVec2(floorf((a.x + b.x - ts.x) * 0.5f), floorf((a.y + b.y - ts.y) * 0.5f)), shown ? SKIN_GOLD : SKIN_TEXT, text);
|
||||
if (foc) skin_cursor_frame(dl, a, b, s, 1.0f);
|
||||
}
|
||||
if (font) ImGui::PopFont();
|
||||
return shown;
|
||||
}
|
||||
|
||||
void skin_boot_panel(ImDrawList *dl, ImFont *head, float head_px, ImFont *body, float body_px, const char *title,
|
||||
const char *step, const char *hint, float frac, float sweep, float w, float h, float s) {
|
||||
const float pad = 38 * s, gap = 16 * s, bar_h = 12 * s, fh = skin_filigree_height(s);
|
||||
ImVec2 ts = head->CalcTextSizeA(head_px, FLT_MAX, 0, title), ss = body->CalcTextSizeA(body_px, FLT_MAX, 0, step),
|
||||
hs = body->CalcTextSizeA(body_px * 0.8f, FLT_MAX, 0, hint);
|
||||
float pw = fminf(fmaxf(fmaxf(fmaxf(ts.x, hs.x), ss.x), 560 * s) + pad * 2, w - 24 * s);
|
||||
float ph = pad + ts.y + fh + gap * 0.4f + ss.y + gap * 0.7f + bar_h + gap * 1.4f + hs.y + pad;
|
||||
ImVec2 a(floorf((w - pw) / 2), floorf((h - ph) / 2)), b(a.x + pw, a.y + ph);
|
||||
skin_panel(dl, a, b, s);
|
||||
float y = a.y + pad;
|
||||
dl->AddText(head, head_px, ImVec2(floorf((w - ts.x) / 2), y), SKIN_GOLD, title);
|
||||
y += ts.y;
|
||||
skin_filigree(dl, a.x + pad, b.x - pad, y + fh * 0.5f, s);
|
||||
y += fh + gap * 0.4f;
|
||||
dl->AddText(body, body_px, ImVec2(a.x + pad, y), SKIN_TEXT, step);
|
||||
y += ss.y + gap * 0.7f;
|
||||
// the bar: a sunken track with the frames' brown edge, filled in gold from the left
|
||||
ImVec2 ba(a.x + pad, y), bb(b.x - pad, y + bar_h);
|
||||
dl->AddRectFilled(ba, bb, rgba(12, 9, 6, 0.85f), 2 * s);
|
||||
float x0 = ba.x + 2 * s, x1 = bb.x - 2 * s, top = ba.y + 2 * s, bot = bb.y - 2 * s;
|
||||
auto fill = [&](float from, float to) {
|
||||
if (to - from < 1) return;
|
||||
dl->AddRectFilledMultiColor(ImVec2(from, top), ImVec2(to, bot), rgba(246, 214, 128, 1), rgba(246, 214, 128, 1),
|
||||
rgba(196, 148, 66, 1), rgba(196, 148, 66, 1));
|
||||
dl->AddLine(ImVec2(from, top + 0.5f * s), ImVec2(to, top + 0.5f * s), rgba(255, 240, 196, 0.6f), 1.0f * s);
|
||||
};
|
||||
if (frac >= 0) {
|
||||
fill(x0, x0 + (x1 - x0) * fminf(frac, 1.0f));
|
||||
} else {
|
||||
float span = (x1 - x0) * 0.2f, run = (x1 - x0) - span, at = sweep < 0 ? 0 : sweep > 1 ? 1 : sweep;
|
||||
fill(x0 + run * at, x0 + run * at + span);
|
||||
}
|
||||
dl->AddRect(ba, bb, rgba(110, 90, 58, 1), 2 * s, 0, 1.3f * s);
|
||||
y += bar_h + gap * 1.4f;
|
||||
dl->AddText(body, body_px * 0.8f, ImVec2(floorf((w - hs.x) / 2), y), rgba(214, 198, 166, 0.85f), hint);
|
||||
}
|
||||
60
runtime/ui/menu_skin.h
Normal file
60
runtime/ui/menu_skin.h
Normal file
@@ -0,0 +1,60 @@
|
||||
// The look of the game's own menus (ui/menu_skin.cpp): the save menu's brown button with its inset line and corner
|
||||
// ornaments, the options menu's white selection cursor and its filigree divider, and a dark panel framed like the
|
||||
// buttons. Each is drawn from the game's textures when they are there (ui/menu_art.cpp), else from plain shapes in the
|
||||
// same colours. Sizes are in pixels at 1080 lines; s scales them (menu.cpp menu_scale).
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
// What the art needs after it is decoded: the cursor's frame is cut out of its texture here (art: a MenuArt).
|
||||
void skin_art_prepare(int art, uint8_t *rgba, uint32_t w, uint32_t h);
|
||||
// One level of an art at half the size of the last: dst is dw x dh (each half of the source's, at least 1).
|
||||
void skin_art_halve(const uint8_t *src, uint32_t w, uint32_t h, uint8_t *dst, uint32_t dw, uint32_t dh);
|
||||
|
||||
// The settings menu's Dear ImGui style at 1080 lines: the colours of the game's menus (a dark umber panel, warm browns
|
||||
// for frames and what is selected, gold ornaments and accents, parchment text) and the sizes of its frames.
|
||||
void skin_style(ImGuiStyle &s);
|
||||
|
||||
// The boxes' mottled grain lives in the font atlas: skin_atlas_add before the atlas is built (it reserves the tile),
|
||||
// skin_atlas_fill after it is built and before it is uploaded (it draws the tile). Without them the boxes are plain.
|
||||
void skin_atlas_add(ImFontAtlas *fa);
|
||||
void skin_atlas_fill(ImFontAtlas *fa);
|
||||
|
||||
// The brown button over [a, b]: a dark rim, a light edge, the fill, and an inset line that stops short of a diamond at
|
||||
// the top-left and bottom-right corners and of a curl at the other two. lift 0..1 brightens the fill (hovered or
|
||||
// selected); dim mutes it (a row the environment fixes).
|
||||
void skin_button(ImDrawList *dl, ImVec2 a, ImVec2 b, float s, float lift, bool dim);
|
||||
// How far skin_cursor reaches outside the box it surrounds: a box needs that much room on every side.
|
||||
float skin_cursor_reach(float s);
|
||||
// The selection cursor around the box [a, b], in two parts: a soft white-blue glow, drawn before the box (the box hides
|
||||
// its middle, so it shows only around it), and a white frame a little outside the box, drawn after it. Both breathe
|
||||
// slowly; alpha 0..1 (a hovered row's cursor is fainter than the selected one's).
|
||||
void skin_cursor_glow(ImDrawList *dl, ImVec2 a, ImVec2 b, float s, float alpha);
|
||||
void skin_cursor_frame(ImDrawList *dl, ImVec2 a, ImVec2 b, float s, float alpha);
|
||||
// The divider: a thin line with a dot at each end and the ornament in its middle, centred on y between x0 and x1.
|
||||
void skin_filigree(ImDrawList *dl, float x0, float x1, float y, float s, float alpha = 1);
|
||||
float skin_filigree_height(float s);
|
||||
// A dark panel over [a, b] with the button's edge, inset line and corner ornaments (the description pane, the
|
||||
// performance overlay). alpha scales its fill.
|
||||
void skin_panel(ImDrawList *dl, ImVec2 a, ImVec2 b, float s, float alpha = 1);
|
||||
|
||||
// The boot screen's box (menu.cpp menu_boot_frame) centred in a w x h frame: the panel, the title in gold over the
|
||||
// divider, the step's line, a bar filled to frac (0..1; a negative frac: a short segment sweeping at position sweep
|
||||
// 0..1, no count yet) and the hint under it.
|
||||
void skin_boot_panel(ImDrawList *dl, ImFont *head, float head_px, ImFont *body, float body_px, const char *title,
|
||||
const char *step, const char *hint, float frac, float sweep, float w, float h, float s);
|
||||
|
||||
// A button widget drawn as skin_button with its label centred and skin_cursor round it while selected or hovered (the
|
||||
// save menu's Load and Cancel). True when pressed (click, A, Enter). size: as for ImGui::Button.
|
||||
bool skin_widget_button(const char *label, ImVec2 size, float s);
|
||||
|
||||
// One tab of the bar: ImGui::BeginTabItem drawn as the rows' button, with the game's plate behind the selected tab's
|
||||
// lines and its text in gold. id: BeginTabItem's label (it sizes the tab); text: what is shown. font: the label's font,
|
||||
// NULL for the current one. True when selected: call ImGui::EndTabItem then.
|
||||
bool skin_tab_item(const char *id, const char *text, int flags, float s, ImFont *font);
|
||||
|
||||
// The colours the boxes are drawn in, for text on them.
|
||||
#define SKIN_TEXT IM_COL32(244, 236, 214, 255) // labels on a button
|
||||
#define SKIN_TEXT_DIM IM_COL32(206, 188, 150, 255) // notes on a button
|
||||
#define SKIN_GOLD IM_COL32(236, 196, 104, 255) // headings and accents
|
||||
@@ -40,8 +40,12 @@ static ImGuiKey key_of(WPARAM vk) {
|
||||
}
|
||||
}
|
||||
|
||||
// The mouse buttons pressed on the open menu and not yet released, one bit each. While any is held the window has the
|
||||
// mouse capture, so the release reaches the menu where the pointer went outside the window (else ImGui would hold the
|
||||
// button down and miss the next click). The game itself only clips the cursor (input_win.c), it takes no capture.
|
||||
static unsigned g_held;
|
||||
|
||||
extern "C" int menu_window_msg(HWND h, UINT m, WPARAM w, LPARAM l, LRESULT *res) {
|
||||
(void)h;
|
||||
switch (m) {
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
@@ -71,9 +75,17 @@ extern "C" int menu_window_msg(HWND h, UINT m, WPARAM w, LPARAM l, LRESULT *res)
|
||||
case WM_LBUTTONDOWN: case WM_LBUTTONUP:
|
||||
case WM_RBUTTONDOWN: case WM_RBUTTONUP:
|
||||
case WM_MBUTTONDOWN: case WM_MBUTTONUP: {
|
||||
if (!menu_is_open()) return 0;
|
||||
int b = m == WM_LBUTTONDOWN || m == WM_LBUTTONUP ? 0 : m == WM_RBUTTONDOWN || m == WM_RBUTTONUP ? 1 : 2;
|
||||
int down = m == WM_LBUTTONDOWN || m == WM_RBUTTONDOWN || m == WM_MBUTTONDOWN;
|
||||
if (!down && (g_held & 1u << b)) { // also when the menu closed meanwhile: the capture goes either way
|
||||
g_held &= ~(1u << b);
|
||||
if (!g_held && GetCapture() == h) ReleaseCapture();
|
||||
}
|
||||
if (!menu_is_open()) return 0;
|
||||
if (down) {
|
||||
if (!g_held) SetCapture(h);
|
||||
g_held |= 1u << b;
|
||||
}
|
||||
menu_event_mouse_pos((float)GET_X_LPARAM(l), (float)GET_Y_LPARAM(l));
|
||||
menu_event_mouse_button(b, down);
|
||||
return 0;
|
||||
@@ -81,6 +93,13 @@ extern "C" int menu_window_msg(HWND h, UINT m, WPARAM w, LPARAM l, LRESULT *res)
|
||||
case WM_MOUSEWHEEL:
|
||||
if (menu_is_open()) menu_event_wheel(0, (float)GET_WHEEL_DELTA_WPARAM(w) / WHEEL_DELTA);
|
||||
return 0;
|
||||
case WM_CAPTURECHANGED: // another window took the capture (ReleaseCapture above finds g_held empty)
|
||||
if ((HWND)l != h && g_held) {
|
||||
for (int b = 0; b < 3; b++)
|
||||
if (g_held & 1u << b) menu_event_mouse_button(b, 0);
|
||||
g_held = 0;
|
||||
}
|
||||
return 0;
|
||||
case WM_SETFOCUS:
|
||||
case WM_KILLFOCUS:
|
||||
menu_event_focus(m == WM_SETFOCUS);
|
||||
|
||||
@@ -12,20 +12,18 @@
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h" // SetKeyOwner, SetFocusID, NavCursorVisible
|
||||
|
||||
#include "ui/menu_skin.h"
|
||||
#include "ui/option_rows.h"
|
||||
|
||||
extern "C" {
|
||||
#include "cfg.h"
|
||||
#include "platform/platform.h"
|
||||
#include "ui_text.h"
|
||||
#include "ui/menu_art.h"
|
||||
#include "menu_sound.h"
|
||||
// host.h pulls in cpu.h, which is C only: the one function needed from it, as declared there.
|
||||
void rt_log(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||
}
|
||||
|
||||
static const ImU32 kGold = IM_COL32(236, 194, 84, 255);
|
||||
static const ImU32 kDim = IM_COL32(150, 150, 140, 255);
|
||||
static const ImU32 kGrey = IM_COL32(110, 110, 102, 255);
|
||||
|
||||
static float g_scale = 1;
|
||||
@@ -36,9 +34,18 @@ static float g_bottom; // opt_reserve_bottom: kept free under
|
||||
static bool g_disable_next; // opt_disable_next: the next row is greyed out with g_disable_note
|
||||
static const char *g_disable_note;
|
||||
|
||||
// The description pane: this frame's hovered and selected rows, the page's first row, and the last one shown.
|
||||
// The rows' cursor, drawn once all rows are (opt_end), its glow in the layer under the rows and its frame in the one
|
||||
// over them: the selected row's box, else the hovered one's (alpha: fainter for a hovered row, and for one the
|
||||
// environment fixes).
|
||||
static struct { bool on; ImVec2 a, b; float alpha; } g_cursor;
|
||||
// Room left on each side of a row for its cursor, which is drawn outside the row's box.
|
||||
static float row_margin(void) { return ceilf(skin_cursor_reach(g_scale) * 0.85f); }
|
||||
|
||||
// The description pane: this frame's hovered and selected rows, the page's first row, and the last one shown (of the
|
||||
// page g_page: another page starts from its first row's, however it was opened).
|
||||
struct Desc { char text[UI_DESC_BYTES]; };
|
||||
static Desc g_hover, g_focus, g_first, g_shown;
|
||||
static ImGuiID g_page;
|
||||
|
||||
// disabled: the note of a row opt_disable_next greyed out, else NULL.
|
||||
static void desc_set(Desc &d, const char *desc, const char *key, const CfgMeta *m, const char *disabled) {
|
||||
@@ -72,14 +79,30 @@ void opt_begin(const char *id, float scale) {
|
||||
g_focus_req = false;
|
||||
if (g_take_first) ImGui::NavMoveRequestCancel(); // this frame's move goes to the first row instead
|
||||
g_hover.text[0] = g_focus.text[0] = g_first.text[0] = 0;
|
||||
if (ImGuiID page = ImGui::GetID(id); page != g_page) g_page = page, g_shown.text[0] = 0;
|
||||
ImVec2 avail = ImGui::GetContentRegionAvail();
|
||||
avail.y -= g_bottom;
|
||||
ImGui::PushID(id);
|
||||
ImGui::BeginChild("##rows", ImVec2(avail.x * 0.58f, avail.y), ImGuiChildFlags_NavFlattened);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(ImGui::GetStyle().ItemSpacing.x, 5 * scale));
|
||||
// the rows sit far enough apart that the selected row's cursor frame clears its neighbours' boxes
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(ImGui::GetStyle().ItemSpacing.x, 9 * scale));
|
||||
ImGui::Dummy(ImVec2(0, row_margin())); // and the first row's cursor stays inside the pane
|
||||
g_cursor.on = false;
|
||||
// three layers: the cursor's glow under the rows, the rows, the cursor's frame over them (opt_end draws the cursor)
|
||||
ImGui::GetWindowDrawList()->ChannelsSplit(3);
|
||||
ImGui::GetWindowDrawList()->ChannelsSetCurrent(1);
|
||||
}
|
||||
|
||||
void opt_end(void) {
|
||||
ImGui::Dummy(ImVec2(0, row_margin())); // the last row's cursor stays inside the pane
|
||||
ImDrawList *dl = ImGui::GetWindowDrawList();
|
||||
if (g_cursor.on) {
|
||||
dl->ChannelsSetCurrent(0);
|
||||
skin_cursor_glow(dl, g_cursor.a, g_cursor.b, g_scale, g_cursor.alpha);
|
||||
dl->ChannelsSetCurrent(2);
|
||||
skin_cursor_frame(dl, g_cursor.a, g_cursor.b, g_scale, g_cursor.alpha);
|
||||
}
|
||||
dl->ChannelsMerge();
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::EndChild();
|
||||
// the hovered row (mouse) wins, else the selected one (controller), else the last shown, else the first row
|
||||
@@ -90,10 +113,10 @@ void opt_end(void) {
|
||||
ImVec2 p = ImGui::GetCursorScreenPos(), avail = ImGui::GetContentRegionAvail();
|
||||
avail.y -= g_bottom;
|
||||
float gap = 24 * g_scale;
|
||||
ImGui::GetWindowDrawList()->AddLine(ImVec2(p.x + gap * 0.5f, p.y), ImVec2(p.x + gap * 0.5f, p.y + avail.y),
|
||||
IM_COL32(236, 194, 84, 110), 1.0f);
|
||||
// the description on a dark panel framed like the rows' buttons
|
||||
skin_panel(ImGui::GetWindowDrawList(), ImVec2(p.x + gap * 0.5f, p.y), ImVec2(p.x + avail.x, p.y + avail.y), g_scale);
|
||||
ImGui::SetCursorScreenPos(ImVec2(p.x + gap, p.y));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(14 * g_scale, 6 * g_scale));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(22 * g_scale, 20 * g_scale));
|
||||
ImGui::BeginChild("##desc", ImVec2(0, avail.y), ImGuiChildFlags_AlwaysUseWindowPadding, ImGuiWindowFlags_NoNav);
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::PushTextWrapPos(0);
|
||||
@@ -120,10 +143,15 @@ static int row_text(const char *key, const char *label, const char *desc, const
|
||||
g_disable_next = false;
|
||||
bool off = disabled || cfg_from_env(key) != 0;
|
||||
ImGui::PushID(key);
|
||||
// the row's box, inset from the pane's sides by the room its cursor needs
|
||||
const float margin = row_margin();
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + margin);
|
||||
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||
// h whole pixels: ImGui truncates cursor positions, which rounds a fractional height the other way above the window's
|
||||
// top (negative y), so the page grew a pixel per row scrolled out and a row scrolled to the bottom was cut off
|
||||
float fs = ImGui::GetFontSize(), w = ImGui::GetContentRegionAvail().x, h = floorf(fs * 2.2f);
|
||||
// at least a pixel wide: InvisibleButton asserts on a zero size (a narrow window), and ImGui reads a negative one as
|
||||
// "up to that far before the right edge", away from the box drawn
|
||||
float fs = ImGui::GetFontSize(), w = fmaxf(ImGui::GetContentRegionAvail().x - margin, 1.0f), h = floorf(fs * 2.2f);
|
||||
ImGui::PushStyleColor(ImGuiCol_NavCursor, ImVec4(0, 0, 0, 0)); // the row's own border shows the selection
|
||||
bool clicked = ImGui::InvisibleButton("##row", ImVec2(w, h), ImGuiButtonFlags_EnableNav);
|
||||
ImGui::PopStyleColor();
|
||||
@@ -138,6 +166,8 @@ static int row_text(const char *key, const char *label, const char *desc, const
|
||||
}
|
||||
bool hov = ImGui::IsItemHovered(), foc = ImGui::IsItemFocused() && ImGui::GetCurrentContext()->NavCursorVisible;
|
||||
int step = clicked && !off ? 2 : 0;
|
||||
// a click of the mouse, not A / Enter / Space: only a click picks an arrow by where the pointer is
|
||||
const bool by_mouse = clicked && hov && ImGui::IsMouseReleased(ImGuiMouseButton_Left);
|
||||
g_held = false;
|
||||
if (foc && !off) {
|
||||
// the left stick arrives as the D-pad (menu.cpp pad_events)
|
||||
@@ -164,32 +194,31 @@ static int row_text(const char *key, const char *label, const char *desc, const
|
||||
|
||||
ImDrawList *dl = ImGui::GetWindowDrawList();
|
||||
ImFont *font = ImGui::GetFont();
|
||||
float r = 9 * g_scale, pad = 16 * g_scale, small = fs * 0.72f;
|
||||
dl->AddRectFilled(p, ImVec2(p.x + w, p.y + h), hov || foc ? IM_COL32(255, 230, 170, 18) : IM_COL32(0, 0, 0, 46), r);
|
||||
// the selected row in the game's own cursor (glow, then its line; ui/menu_art.cpp), else a gold border
|
||||
bool art = false;
|
||||
if (hov || foc) { // a halo around the row (the glow's middle left out, so the label stays readable), then the line
|
||||
float gx = h * 0.22f, gy = h * 0.16f;
|
||||
art = menu_art_draw9(dl, MENU_ART_CURSOR_GLOW, ImVec2(p.x - gx, p.y - gy), ImVec2(p.x + w + gx, p.y + h + gy), h * 0.5f, 0.3f,
|
||||
off ? IM_COL32(236, 194, 84, 50) : IM_COL32(244, 200, 96, 120), 0) &&
|
||||
menu_art_draw9(dl, MENU_ART_CURSOR_LINE, ImVec2(p.x - gx * 0.3f, p.y - gy * 0.3f),
|
||||
ImVec2(p.x + w + gx * 0.3f, p.y + h + gy * 0.3f), h * 0.12f, 0.1f,
|
||||
off ? IM_COL32(255, 236, 190, 80) : IM_COL32(255, 236, 180, 150), 0); // edges only: the art is a filled bar
|
||||
float pad = 20 * g_scale, small = fs * 0.72f;
|
||||
// the save menu's brown button, brighter while selected or hovered; the white cursor goes round it in opt_end
|
||||
skin_button(dl, p, ImVec2(p.x + w, p.y + h), g_scale, foc ? 1.0f : hov ? 0.6f : 0.0f, off);
|
||||
if (foc || (hov && !g_cursor.on)) {
|
||||
g_cursor.on = true, g_cursor.a = p, g_cursor.b = ImVec2(p.x + w, p.y + h);
|
||||
g_cursor.alpha = (foc ? 1.0f : 0.55f) * (off ? 0.5f : 1.0f);
|
||||
}
|
||||
if (!art)
|
||||
dl->AddRect(p, ImVec2(p.x + w, p.y + h),
|
||||
hov || foc ? (off ? IM_COL32(236, 194, 84, 120) : kGold) : IM_COL32(255, 236, 200, off ? 16 : 34), r, 0,
|
||||
hov || foc ? 2.0f : 1.0f);
|
||||
float ty = p.y + fs * 0.25f, ny = p.y + fs * 1.3f; // the label line and the note line under it
|
||||
float right = p.x + w - pad; // the value's right edge
|
||||
float value_left = right;
|
||||
// The value and its note take at most 60 % of the row: a longer value (a graphics card's full name) is drawn smaller,
|
||||
// down to 75 % of the font size, then clipped, so the label keeps room and nothing reaches past the box.
|
||||
const float cap = fmaxf((w - pad * 2) * 0.6f, 0.0f);
|
||||
float vfs = fs, tv = v.value[0] ? font->CalcTextSizeA(fs, FLT_MAX, 0, v.value).x : 0;
|
||||
if (tv > cap) {
|
||||
vfs = fmaxf(fs * cap / tv, fs * 0.75f);
|
||||
tv = fminf(font->CalcTextSizeA(vfs, FLT_MAX, 0, v.value).x, cap);
|
||||
}
|
||||
if (v.arrows && v.value[0]) { // < value >, drawn (the font has no arrow glyphs); a click on one steps
|
||||
float aw = fs * 0.42f, gap = fs * 0.55f, cy = ty + fs * 0.52f;
|
||||
float rx = right - aw, lx = rx - gap - ImGui::CalcTextSize(v.value).x - gap - aw;
|
||||
ImU32 ac = off ? kGrey : hov || foc ? kGold : IM_COL32(170, 170, 160, 255);
|
||||
float rx = right - aw, lx = rx - gap - tv - gap - aw;
|
||||
ImU32 ac = off ? kGrey : hov || foc ? SKIN_TEXT : SKIN_TEXT_DIM;
|
||||
dl->AddTriangleFilled(ImVec2(lx, cy), ImVec2(lx + aw, cy - aw * 0.75f), ImVec2(lx + aw, cy + aw * 0.75f), ac);
|
||||
dl->AddTriangleFilled(ImVec2(rx + aw, cy), ImVec2(rx, cy - aw * 0.75f), ImVec2(rx, cy + aw * 0.75f), ac);
|
||||
if (clicked && !off) {
|
||||
if (by_mouse && !off) {
|
||||
float mx = ImGui::GetIO().MousePos.x;
|
||||
if (mx >= lx - gap && mx <= lx + aw + gap) step = -1;
|
||||
else if (mx >= rx - gap && mx <= rx + aw + gap) step = 1;
|
||||
@@ -200,36 +229,45 @@ static int row_text(const char *key, const char *label, const char *desc, const
|
||||
if (movable) { // up and down arrows left of the value; a click on one moves the row
|
||||
// a fixed value column (On / Off differ in width) keeps the arrows of the rows in one line
|
||||
float aw = fs * 0.42f, gap = fs * 0.55f;
|
||||
float cx = right - fmaxf(ImGui::CalcTextSize(v.value).x, fs * 2.8f) - gap * 2 - aw;
|
||||
float cx = right - fmaxf(tv, fs * 2.8f) - gap * 2 - aw;
|
||||
float uy = ty + fs * 0.12f, dy = ty + fs * 0.92f;
|
||||
ImU32 ac = off ? kGrey : hov || foc ? kGold : IM_COL32(170, 170, 160, 255);
|
||||
ImU32 ac = off ? kGrey : hov || foc ? SKIN_TEXT : SKIN_TEXT_DIM;
|
||||
dl->AddTriangleFilled(ImVec2(cx, uy + aw * 0.7f), ImVec2(cx + aw, uy + aw * 0.7f), ImVec2(cx + aw * 0.5f, uy), ac);
|
||||
dl->AddTriangleFilled(ImVec2(cx, dy - aw * 0.7f), ImVec2(cx + aw, dy - aw * 0.7f), ImVec2(cx + aw * 0.5f, dy), ac);
|
||||
if (clicked && !off) {
|
||||
if (by_mouse && !off) {
|
||||
ImVec2 mp = ImGui::GetIO().MousePos;
|
||||
if (mp.x >= cx - gap * 0.5f && mp.x <= cx + aw + gap * 0.5f) step = mp.y < ty + fs * 0.52f ? 3 : 4;
|
||||
}
|
||||
value_left = cx - gap;
|
||||
}
|
||||
if (v.value[0]) {
|
||||
float vx = right - ImGui::CalcTextSize(v.value).x;
|
||||
dl->AddText(ImVec2(vx, ty), off ? kGrey : v.is_default ? IM_COL32(205, 205, 195, 255) : IM_COL32(255, 255, 255, 255),
|
||||
v.value);
|
||||
float vx = right - tv;
|
||||
ImVec4 vclip(vx, p.y, right, p.y + h);
|
||||
dl->AddText(font, vfs, ImVec2(vx, ty + (fs - vfs) * 0.5f),
|
||||
off ? kGrey : v.is_default ? IM_COL32(232, 222, 198, 255) : IM_COL32(255, 255, 255, 255), v.value, NULL,
|
||||
0, &vclip);
|
||||
if (!v.arrows && !movable) value_left = vx;
|
||||
}
|
||||
if (v.note || v.is_default) { // under the value, right-aligned with it
|
||||
float note_right = p.x + w - pad; // where the label's own note stops: short of the value's note, when there is one
|
||||
if (v.note || v.is_default) { // under the value, right-aligned with it; its start shows when it is too long
|
||||
const char *t = v.note ? v.note : menu_text(UI_MENU_DEFAULT_MARK);
|
||||
float tw = font->CalcTextSizeA(small, FLT_MAX, 0, t).x;
|
||||
dl->AddText(font, small, ImVec2(right - tw, ny), v.note ? IM_COL32(220, 170, 100, 255) : kDim, t);
|
||||
float tw = fminf(font->CalcTextSizeA(small, FLT_MAX, 0, t).x, cap);
|
||||
ImVec4 nclip(right - tw, p.y, right, p.y + h);
|
||||
dl->AddText(font, small, ImVec2(right - tw, ny), v.note ? IM_COL32(250, 206, 130, 255) : SKIN_TEXT_DIM, t, NULL, 0,
|
||||
&nclip);
|
||||
if (tw > 0) note_right = right - tw - fs * 0.6f;
|
||||
}
|
||||
// the label and its note, clipped before the value
|
||||
ImVec4 clip(p.x, p.y, value_left - fs * 0.6f, p.y + h);
|
||||
dl->AddText(font, fs, ImVec2(p.x + pad, ty), off ? kGrey : IM_COL32(240, 236, 224, 255), label, NULL, 0, &clip);
|
||||
dl->AddText(font, fs, ImVec2(p.x + pad, ty), off ? kGrey : SKIN_TEXT, label, NULL, 0, &clip);
|
||||
const char *note = disabled ? disabled
|
||||
: off ? menu_text(UI_MENU_SET_BY_ENV)
|
||||
: m && !m->live ? menu_text(UI_MENU_AFTER_RESTART)
|
||||
: NULL;
|
||||
if (note) dl->AddText(font, small, ImVec2(p.x + pad, ny), off ? IM_COL32(200, 150, 90, 255) : kDim, note);
|
||||
ImVec4 note_clip(p.x, p.y, note_right, p.y + h);
|
||||
if (note)
|
||||
dl->AddText(font, small, ImVec2(p.x + pad, ny), off ? IM_COL32(200, 150, 90, 255) : SKIN_TEXT_DIM, note, NULL, 0,
|
||||
¬e_clip);
|
||||
ImGui::PopID();
|
||||
return off ? 0 : step;
|
||||
}
|
||||
@@ -283,6 +321,15 @@ bool opt_toggle(const char *key, UiTextId label, UiTextId desc, bool inverted) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool opt_toggle_value(const char *key, UiTextId label, UiTextId desc, const char *on_value, const char *off_value, const char *note) {
|
||||
const CfgMeta *m = cfg_meta(key);
|
||||
bool on = strcmp(cfg_value(key), off_value) != 0, def = m && strcmp(m->def, off_value) != 0;
|
||||
RowView v = {menu_text(on ? UI_MENU_ON : UI_MENU_OFF), on == def, false, note};
|
||||
if (!row(key, label, desc, v)) return false; // any step flips it
|
||||
apply(key, on ? off_value : on_value);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool opt_button(const char *id, UiTextId label, UiTextId desc, const char *value) {
|
||||
RowView v = {value ? value : "", false, false, NULL};
|
||||
return row(id, label, desc, v) == 2; // A or a click; left and right do nothing
|
||||
@@ -294,32 +341,44 @@ bool opt_toggle_text(const char *id, const char *label, const char *desc, bool o
|
||||
return row_text(id, label, desc, v, false) != 0; // any step flips it
|
||||
}
|
||||
|
||||
void opt_group_text(const char *title) {
|
||||
ImGui::Dummy(ImVec2(0, 6 * g_scale));
|
||||
ImGui::PushTextWrapPos(0);
|
||||
ImGui::TextColored(ImVec4(0.93f, 0.76f, 0.33f, 1), "%s", title);
|
||||
ImGui::PopTextWrapPos();
|
||||
// A group heading: the game's divider ornament across the pane, then the title in the accent colour.
|
||||
static void group_divider(void) {
|
||||
float fh = skin_filigree_height(g_scale);
|
||||
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||
float m = row_margin();
|
||||
skin_filigree(ImGui::GetWindowDrawList(), p.x + m, p.x + ImGui::GetContentRegionAvail().x - m, p.y + fh * 0.5f, g_scale);
|
||||
ImGui::Dummy(ImVec2(0, fh));
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + m);
|
||||
}
|
||||
|
||||
void opt_text_str(const char *text, bool warn) {
|
||||
ImGui::PushTextWrapPos(0);
|
||||
if (warn) ImGui::TextColored(ImVec4(0.95f, 0.66f, 0.40f, 1), "%s", text);
|
||||
// Text across the rows' column, inset from its sides as the rows' boxes are and wrapped before their right edge. The
|
||||
// cursor already stands at the inset when indented is true (after group_divider).
|
||||
static void column_text(const char *text, const ImVec4 *col, bool indented) {
|
||||
const float m = row_margin();
|
||||
if (!indented) ImGui::SetCursorPosX(ImGui::GetCursorPosX() + m);
|
||||
ImGui::PushTextWrapPos(ImGui::GetCursorPosX() + fmaxf(ImGui::GetContentRegionAvail().x - m, 1.0f));
|
||||
if (col) ImGui::TextColored(*col, "%s", text);
|
||||
else ImGui::TextUnformatted(text);
|
||||
ImGui::PopTextWrapPos();
|
||||
}
|
||||
|
||||
void opt_group(UiTextId title) {
|
||||
ImGui::Dummy(ImVec2(0, 6 * g_scale));
|
||||
ImGui::TextColored(ImVec4(0.93f, 0.76f, 0.33f, 1), "%s", menu_text(title));
|
||||
static const ImVec4 kWarn(0.95f, 0.66f, 0.40f, 1);
|
||||
|
||||
void opt_group_text(const char *title) {
|
||||
group_divider();
|
||||
const ImVec4 gold = ImGui::ColorConvertU32ToFloat4(SKIN_GOLD);
|
||||
column_text(title, &gold, true);
|
||||
}
|
||||
|
||||
void opt_text(UiTextId text, bool warn) {
|
||||
ImGui::PushTextWrapPos(0);
|
||||
if (warn) ImGui::TextColored(ImVec4(0.95f, 0.66f, 0.40f, 1), "%s", menu_text(text));
|
||||
else ImGui::TextUnformatted(menu_text(text));
|
||||
ImGui::PopTextWrapPos();
|
||||
void opt_text_str(const char *text, bool warn) { column_text(text, warn ? &kWarn : nullptr, false); }
|
||||
|
||||
void opt_group(UiTextId title) {
|
||||
group_divider();
|
||||
ImGui::TextColored(ImGui::ColorConvertU32ToFloat4(SKIN_GOLD), "%s", menu_text(title));
|
||||
}
|
||||
|
||||
void opt_text(UiTextId text, bool warn) { column_text(menu_text(text), warn ? &kWarn : nullptr, false); }
|
||||
|
||||
bool opt_choice_list(const char *key, UiTextId label, const char *const *values, const char *const *names, int n,
|
||||
UiTextId desc, int cur, const char *note) {
|
||||
const char *d = cfg_default(key);
|
||||
@@ -428,20 +487,22 @@ static void fit_text(ImDrawList *dl, float x0, float x1, float y, float h, ImU32
|
||||
// The label column and the three cells of a binding row of width w.
|
||||
static void bind_columns(float x, float w, float cx[3], float *cw) {
|
||||
float lw = floorf(w * 0.34f), gap = floorf(8 * g_scale);
|
||||
*cw = floorf((w - lw - gap * 3) / 3);
|
||||
*cw = fmaxf(floorf((w - lw - gap * 3) / 3), 1.0f); // a pixel at least: InvisibleButton asserts on a zero width
|
||||
for (int c = 0; c < 3; c++) cx[c] = x + lw + gap + c * (*cw + gap);
|
||||
}
|
||||
|
||||
void opt_bind_header(UiTextId c0, UiTextId c1, UiTextId c2) {
|
||||
// over the cells of the binding rows: the same inset (opt_bind_row) and the same columns
|
||||
const float margin = row_margin();
|
||||
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||
float w = ImGui::GetContentRegionAvail().x, cx[3], cw, fs = ImGui::GetFontSize() * 0.8f;
|
||||
bind_columns(p.x, w, cx, &cw);
|
||||
float w = fmaxf(ImGui::GetContentRegionAvail().x - margin * 2, 1.0f), cx[3], cw, fs = ImGui::GetFontSize() * 0.8f;
|
||||
bind_columns(p.x + margin, w, cx, &cw);
|
||||
const UiTextId cols[3] = {c0, c1, c2};
|
||||
ImFont *font = ImGui::GetFont();
|
||||
for (int c = 0; c < 3; c++) {
|
||||
const char *t = menu_text(cols[c]);
|
||||
float tw = font->CalcTextSizeA(fs, FLT_MAX, 0, t).x;
|
||||
ImGui::GetWindowDrawList()->AddText(font, fs, ImVec2(cx[c] + (cw - tw) * 0.5f, p.y), kDim, t);
|
||||
ImGui::GetWindowDrawList()->AddText(font, fs, ImVec2(cx[c] + (cw - tw) * 0.5f, p.y), SKIN_TEXT_DIM, t);
|
||||
}
|
||||
ImGui::Dummy(ImVec2(w, fs * 1.2f));
|
||||
}
|
||||
@@ -449,11 +510,13 @@ void opt_bind_header(UiTextId c0, UiTextId c1, UiTextId c2) {
|
||||
int opt_bind_row(const char *key, const char *label, UiTextId desc, const char *const cells[3], const bool enabled[3],
|
||||
const char *note) {
|
||||
ImGui::PushID(key);
|
||||
const float margin = row_margin(); // room for the cursor, as the option rows leave
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + margin);
|
||||
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||
float fs = ImGui::GetFontSize(), w = ImGui::GetContentRegionAvail().x, h = floorf(fs * 1.9f), cx[3], cw;
|
||||
float fs = ImGui::GetFontSize(), w = ImGui::GetContentRegionAvail().x - margin, h = floorf(fs * 1.9f), cx[3], cw;
|
||||
bind_columns(p.x, w, cx, &cw);
|
||||
ImDrawList *dl = ImGui::GetWindowDrawList();
|
||||
float r = 8 * g_scale, pad = 6 * g_scale;
|
||||
float pad = 6 * g_scale;
|
||||
fit_text(dl, p.x + 16 * g_scale, cx[0] - fs * 0.3f, p.y, h, IM_COL32(240, 236, 224, 255), label, false);
|
||||
int result = -1;
|
||||
bool row_foc = false, row_hov = false;
|
||||
@@ -461,7 +524,7 @@ int opt_bind_row(const char *key, const char *label, UiTextId desc, const char *
|
||||
ImVec2 a(cx[c], p.y), b(cx[c] + cw, p.y + h);
|
||||
const char *t = cells[c] && cells[c][0] ? cells[c] : "-";
|
||||
if (!enabled[c]) { // not a nav item: the cursor skips it
|
||||
dl->AddRect(a, b, IM_COL32(255, 255, 255, 14), r);
|
||||
skin_button(dl, a, b, g_scale, 0, true);
|
||||
fit_text(dl, a.x + pad, b.x - pad, a.y, h, kGrey, t, true);
|
||||
continue;
|
||||
}
|
||||
@@ -488,9 +551,9 @@ int opt_bind_row(const char *key, const char *label, UiTextId desc, const char *
|
||||
if (foc && (ImGui::IsKeyPressed(ImGuiKey_Delete, false) || ImGui::IsKeyPressed(ImGuiKey_Backspace, false) ||
|
||||
ImGui::IsKeyPressed(ImGuiKey_GamepadFaceUp, false)))
|
||||
result = 10 + c;
|
||||
dl->AddRectFilled(a, b, hov || foc ? IM_COL32(255, 255, 255, 22) : IM_COL32(0, 0, 0, 40), r);
|
||||
dl->AddRect(a, b, hov || foc ? kGold : IM_COL32(255, 255, 255, 38), r, 0, hov || foc ? 2.0f : 1.0f);
|
||||
fit_text(dl, a.x + pad, b.x - pad, a.y, h, IM_COL32(255, 255, 255, 255), t, true);
|
||||
skin_button(dl, a, b, g_scale, foc ? 1.0f : hov ? 0.6f : 0.0f, false); // a small brown button per cell
|
||||
if (foc || (hov && !g_cursor.on)) g_cursor.on = true, g_cursor.a = a, g_cursor.b = b, g_cursor.alpha = foc ? 1.0f : 0.55f;
|
||||
fit_text(dl, a.x + pad, b.x - pad, a.y, h, SKIN_TEXT, t, true);
|
||||
ImGui::PopID();
|
||||
}
|
||||
char k[64];
|
||||
|
||||
@@ -36,6 +36,10 @@ void opt_text(UiTextId text, bool warn = false);
|
||||
// The return value of every row: true when it changed the setting this frame.
|
||||
// inverted: the row shows "on" while the key is 0 (a setting whose key names the opposite).
|
||||
bool opt_toggle(const char *key, UiTextId label, UiTextId desc, bool inverted = false);
|
||||
// An on/off row over a key with named values: off while the key holds off_value and on for any other, so a value the
|
||||
// row does not write itself still reads as on. Flipping it writes on_value or off_value. note: as for opt_choice.
|
||||
bool opt_toggle_value(const char *key, UiTextId label, UiTextId desc, const char *on_value, const char *off_value,
|
||||
const char *note = nullptr);
|
||||
// One name per value of the key's cfg_meta values list, in its order. When the key has no fixed default (an empty
|
||||
// def), names[0] is the automatic choice (the key unset) and names[1..] follow the values. note: a short line under
|
||||
// the value in place of the "default" mark (NULL: none).
|
||||
|
||||
221
runtime/ui/perf_panel.cpp
Normal file
221
runtime/ui/perf_panel.cpp
Normal file
@@ -0,0 +1,221 @@
|
||||
// The full performance overlay's panel (ui/perf_panel.h) in the settings menu's look: the menu's framed dark panel
|
||||
// (ui/menu_skin.cpp), the numbers in tables with gold labels and parchment values, the game's divider between the
|
||||
// machine, the frames, the per-frame waits and the picture, and the frame times as a gold line.
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h" // the window's draw cursor (the plot does not widen the panel)
|
||||
|
||||
#include "ui/menu_skin.h"
|
||||
#include "ui/perf_panel.h"
|
||||
|
||||
extern "C" {
|
||||
#include "ui_text.h"
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
const ImVec4 kLabel(236 / 255.0f, 196 / 255.0f, 104 / 255.0f, 1); // SKIN_GOLD
|
||||
const ImVec4 kValue(244 / 255.0f, 236 / 255.0f, 214 / 255.0f, 1); // SKIN_TEXT
|
||||
const ImVec4 kDimText(170 / 255.0f, 152 / 255.0f, 120 / 255.0f, 1);
|
||||
|
||||
struct PerfCol { UiTextId fmt; float sample; };
|
||||
|
||||
float text_w(UiTextId fmt, float v) {
|
||||
char b[64];
|
||||
snprintf(b, sizeof b, menu_text(fmt), v);
|
||||
return ImGui::CalcTextSize(b).x;
|
||||
}
|
||||
|
||||
// The panel keeps its width while the numbers change: every column is as wide as the widest text it can show, measured
|
||||
// on samples of 8s (the menu fonts' digits share one width), and the numbers are right-aligned in it.
|
||||
// A fixed column as wide as the widest of the formats (with their samples) and labels given.
|
||||
void column(const char *id, const PerfCol *cols, int n, const UiTextId *labels = nullptr, int nl = 0) {
|
||||
float w = ImGui::CalcTextSize(menu_text(UI_MENU_OV_NONE)).x;
|
||||
for (int i = 0; i < n; i++) w = fmaxf(w, text_w(cols[i].fmt, cols[i].sample));
|
||||
for (int i = 0; i < nl; i++) w = fmaxf(w, ImGui::CalcTextSize(menu_text(labels[i])).x);
|
||||
ImGui::TableSetupColumn(id, ImGuiTableColumnFlags_WidthFixed, w);
|
||||
}
|
||||
|
||||
void right(const char *s, bool dim) {
|
||||
float pad = ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(s).x;
|
||||
if (pad > 0) ImGui::SetCursorPosX(ImGui::GetCursorPosX() + pad);
|
||||
ImGui::TextColored(dim ? kDimText : kValue, "%s", s);
|
||||
}
|
||||
|
||||
// One cell: fmt (a catalog format, one number) with v, or "-" when the machine gives none.
|
||||
void cell(UiTextId fmt, float v) {
|
||||
ImGui::TableNextColumn();
|
||||
if (v < 0) return right(menu_text(UI_MENU_OV_NONE), true);
|
||||
char b[64];
|
||||
snprintf(b, sizeof b, menu_text(fmt), v);
|
||||
right(b, false);
|
||||
}
|
||||
|
||||
void label(UiTextId id) {
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextColored(kLabel, "%s", menu_text(id));
|
||||
}
|
||||
|
||||
float gb(float mb) { return mb < 0 ? -1 : mb / 1024; }
|
||||
|
||||
// The game's divider across the panel between two sections, smaller than the menu's.
|
||||
void divider(float scale) {
|
||||
float s = scale * 0.72f, h = skin_filigree_height(s);
|
||||
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||
ImGuiWindow *win = ImGui::GetCurrentWindow();
|
||||
float x1 = win->WorkRect.Max.x > p.x + 40 * s ? win->WorkRect.Max.x : p.x + 200 * s;
|
||||
skin_filigree(ImGui::GetWindowDrawList(), p.x - 4 * s, x1 + 4 * s, p.y + h * 0.5f, s);
|
||||
ImGui::Dummy(ImVec2(0, h));
|
||||
}
|
||||
|
||||
void machine_and_frames(const PerfPanel *p, float scale) {
|
||||
const PerfStats &s = p->s;
|
||||
if (!ImGui::BeginTable("##perft", 4, ImGuiTableFlags_SizingFixedFit)) return;
|
||||
static const UiTextId labels[] = {UI_MENU_OV_GPU, UI_MENU_OV_VRAM, UI_MENU_OV_CPU, UI_MENU_OV_RAM,
|
||||
UI_MENU_OV_FPS_LABEL, UI_MENU_OV_FRAME_LABEL};
|
||||
static const PerfCol c1[] = {{UI_MENU_OV_FMT_PCT, 100}, {UI_MENU_OV_FMT_GB, 888.8f}, {UI_MENU_OV_FMT_FPS, 888},
|
||||
{UI_MENU_OV_FRAME_MS, 888.8f}};
|
||||
static const PerfCol c2[] = {{UI_MENU_OV_FMT_TEMP, 188}, {UI_MENU_OV_FMT_GB_OF, 888.8f}, {UI_MENU_OV_LOW1, 888},
|
||||
{UI_MENU_OV_MAX_MS, 8888.8f}};
|
||||
static const PerfCol c3[] = {{UI_MENU_OV_FMT_POWER, 888}, {UI_MENU_OV_FMT_MHZ, 8888}, {UI_MENU_OV_GAME_PCT, 100},
|
||||
{UI_MENU_OV_GAME_GB, 888.8f}, {UI_MENU_OV_LOW01, 888}};
|
||||
column("##c0", nullptr, 0, labels, 6);
|
||||
column("##c1", c1, 4);
|
||||
column("##c2", c2, 4);
|
||||
column("##c3", c3, 5);
|
||||
label(UI_MENU_OV_GPU);
|
||||
cell(UI_MENU_OV_FMT_PCT, s.gpu_pct);
|
||||
cell(UI_MENU_OV_FMT_TEMP, s.gpu_temp_c);
|
||||
cell(UI_MENU_OV_FMT_POWER, s.gpu_power_w);
|
||||
label(UI_MENU_OV_VRAM);
|
||||
cell(UI_MENU_OV_FMT_GB, gb(s.vram_used_mb));
|
||||
cell(UI_MENU_OV_FMT_GB_OF, gb(s.vram_total_mb));
|
||||
cell(UI_MENU_OV_FMT_MHZ, s.gpu_clock_mhz);
|
||||
label(UI_MENU_OV_CPU);
|
||||
cell(UI_MENU_OV_FMT_PCT, s.cpu_total_pct);
|
||||
cell(UI_MENU_OV_FMT_TEMP, s.cpu_temp_c);
|
||||
cell(UI_MENU_OV_GAME_PCT, s.cpu_game_pct);
|
||||
label(UI_MENU_OV_RAM);
|
||||
cell(UI_MENU_OV_FMT_GB, gb(s.ram_used_mb));
|
||||
cell(UI_MENU_OV_FMT_GB_OF, gb(s.ram_total_mb));
|
||||
cell(UI_MENU_OV_GAME_GB, gb(s.ram_game_mb));
|
||||
ImGui::EndTable();
|
||||
divider(scale);
|
||||
if (!ImGui::BeginTable("##perff", 4, ImGuiTableFlags_SizingFixedFit)) return;
|
||||
column("##f0", nullptr, 0, labels, 6);
|
||||
column("##f1", c1, 4);
|
||||
column("##f2", c2, 4);
|
||||
column("##f3", c3, 5);
|
||||
// the frames: the rate over the last second with the lows over the last ten seconds, then the frame times
|
||||
label(UI_MENU_OV_FPS_LABEL);
|
||||
cell(UI_MENU_OV_FMT_FPS, s.fps);
|
||||
cell(UI_MENU_OV_LOW1, s.low1_fps);
|
||||
cell(UI_MENU_OV_LOW01, s.low01_fps);
|
||||
if (p->fg_fps > 0) { // frame generation: what the display gets, generated frames included
|
||||
label(UI_MENU_OV_FG_LABEL);
|
||||
cell(UI_MENU_OV_FMT_FPS, p->fg_fps);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TableNextColumn();
|
||||
}
|
||||
label(UI_MENU_OV_FRAME_LABEL);
|
||||
cell(UI_MENU_OV_FRAME_MS, s.frame_ms_avg);
|
||||
cell(UI_MENU_OV_MAX_MS, s.frame_ms_max);
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
// The frame times of the last PERF_HISTORY frames as a gold line over a dark band, as wide as the tables made the panel
|
||||
// (the plot does not count toward that width, so the panel can still shrink).
|
||||
void frame_plot(const PerfStats &s, float scale) {
|
||||
float top = s.frame_ms_max > 50 ? s.frame_ms_max : 50;
|
||||
ImGuiWindow *win = ImGui::GetCurrentWindow();
|
||||
float max_x = win->DC.CursorMaxPos.x;
|
||||
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0, 0, 0, 0.32f));
|
||||
ImGui::PushStyleColor(ImGuiCol_PlotLines, kLabel);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 0);
|
||||
ImGui::PlotLines("##ft", s.frame_ms, PERF_HISTORY, 0, nullptr, 0, top, ImVec2(-FLT_MIN, 48 * scale));
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::PopStyleColor(2);
|
||||
win->DC.CursorMaxPos.x = max_x;
|
||||
}
|
||||
|
||||
// Per frame, averaged over the last half second; the labels' column stretches, so the numbers end at the panel's right
|
||||
// edge, and the table still asks for no more than its widest label and number.
|
||||
void waits(const PerfStats &s) {
|
||||
if (!ImGui::BeginTable("##perfw", 2, ImGuiTableFlags_SizingFixedFit)) return;
|
||||
static const PerfCol c1[] = {{UI_MENU_OV_FMT_MS, 888.88f}, {UI_MENU_OV_PER_FRAME, 888.8f}};
|
||||
ImGui::TableSetupColumn("##w0", ImGuiTableColumnFlags_WidthStretch);
|
||||
column("##w1", c1, 2);
|
||||
label(UI_MENU_OV_REPLAY);
|
||||
cell(UI_MENU_OV_FMT_MS, s.replay_ms);
|
||||
label(UI_MENU_OV_GPU_TIME);
|
||||
cell(UI_MENU_OV_FMT_MS, s.gpu_ms);
|
||||
label(UI_MENU_OV_PIPE_WAIT);
|
||||
cell(UI_MENU_OV_FMT_MS, s.pipe_wait_ms);
|
||||
label(UI_MENU_OV_SHADER_WAIT);
|
||||
cell(UI_MENU_OV_FMT_MS, s.xlate_ms);
|
||||
label(UI_MENU_OV_TEX_UPLOADS);
|
||||
cell(UI_MENU_OV_PER_FRAME, s.tex_uploads);
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
void picture(const PerfPanel *p) {
|
||||
static const UiTextId labels[6] = {UI_MENU_OV_WINDOW, UI_MENU_OV_OUTPUT, UI_MENU_OV_SCENE,
|
||||
UI_MENU_OV_SCALING, UI_MENU_OV_LIMIT, UI_MENU_OV_PRESENT};
|
||||
if (!ImGui::BeginTable("##perfp", 2, ImGuiTableFlags_SizingFixedFit)) return;
|
||||
float vw = 0;
|
||||
for (const auto &v : p->picture) vw = fmaxf(vw, ImGui::CalcTextSize(v).x);
|
||||
ImGui::TableSetupColumn("##p0", ImGuiTableColumnFlags_WidthStretch);
|
||||
ImGui::TableSetupColumn("##p1", ImGuiTableColumnFlags_WidthFixed, vw);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (i == 2 && !p->scene_known) continue;
|
||||
label(labels[i]);
|
||||
ImGui::TableNextColumn();
|
||||
right(p->picture[i], false);
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void perf_panel_draw(const PerfPanel *p, float width, float scale) {
|
||||
const float m = 12 * scale;
|
||||
ImGui::SetNextWindowPos(ImVec2(width - m, m), ImGuiCond_Always, ImVec2(1, 0));
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0)); // the panel below is the background
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(24 * scale, 20 * scale));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(7 * scale, 1.5f * scale));
|
||||
ImGui::Begin("##perf", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize |
|
||||
ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoNav |
|
||||
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoSavedSettings);
|
||||
ImGui::PopStyleVar(3);
|
||||
ImGui::PopStyleColor();
|
||||
// under the menu while it is open (the settings stay readable), else over everything
|
||||
if (p->under_menu) ImGui::BringWindowToDisplayBack(ImGui::GetCurrentWindow());
|
||||
else ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindow());
|
||||
ImDrawList *dl = ImGui::GetWindowDrawList();
|
||||
dl->ChannelsSplit(2); // the panel goes under the text, drawn once the window's size is known
|
||||
dl->ChannelsSetCurrent(1);
|
||||
ImGui::SetWindowFontScale(0.72f);
|
||||
// the port version and the game update first, so a screenshot in a bug report carries both
|
||||
ImGui::TextColored(kDimText, "%s", p->version);
|
||||
divider(scale);
|
||||
machine_and_frames(p, scale);
|
||||
ImGui::Dummy(ImVec2(0, 4 * scale));
|
||||
frame_plot(p->s, scale);
|
||||
ImGui::Dummy(ImVec2(0, 2 * scale));
|
||||
waits(p->s);
|
||||
divider(scale);
|
||||
picture(p);
|
||||
if (p->s.gpu_name[0] || p->s.cpu_name[0]) divider(scale);
|
||||
if (p->s.gpu_name[0]) ImGui::TextColored(kDimText, "%s", p->s.gpu_name);
|
||||
if (p->s.cpu_name[0]) ImGui::TextColored(kDimText, "%s", p->s.cpu_name);
|
||||
dl->ChannelsSetCurrent(0);
|
||||
ImVec2 a = ImGui::GetWindowPos(), sz = ImGui::GetWindowSize();
|
||||
skin_panel(dl, a, ImVec2(a.x + sz.x, a.y + sz.y), scale * 0.8f, 0.94f);
|
||||
dl->ChannelsMerge();
|
||||
ImGui::End();
|
||||
}
|
||||
20
runtime/ui/perf_panel.h
Normal file
20
runtime/ui/perf_panel.h
Normal file
@@ -0,0 +1,20 @@
|
||||
// The full performance overlay's panel (ui/perf_panel.cpp), drawn in the settings menu's look: what menu.cpp
|
||||
// perf_full_draw gathered, laid out in tables on the menu's framed panel with the game's divider between the sections.
|
||||
#pragma once
|
||||
#include "imgui.h"
|
||||
|
||||
extern "C" {
|
||||
#include "perfmon.h"
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
PerfStats s; // perfmon_snapshot
|
||||
const char *version; // "NX2navi <version>, game <update>"
|
||||
char picture[6][64]; // window, game image, scene, scaling, frame limit, presentation (formatted)
|
||||
bool scene_known; // the scene line is shown (resolution.c sets the scene's size)
|
||||
float fg_fps; // frames the display gets with frame generation, 0 without it
|
||||
bool under_menu; // the menu is open: the panel goes under its window
|
||||
} PerfPanel;
|
||||
|
||||
// The panel at the top right corner of a width-pixel-wide frame.
|
||||
void perf_panel_draw(const PerfPanel *p, float width, float scale);
|
||||
Reference in New Issue
Block a user