update client visuals, performance and diagnostics

This commit is contained in:
st committed 2026-10-14 23:30:29 -05:00
1 parent 361892bf0b
commit 875bab0310
155 files changed
+40855 -421

No files matched your search

+124 -107
View File
@@ -7,6 +7,7 @@
#include "fonts.h"
#include "theme.h"
#include "widgets.h"
#include "indent_section.h"
#include "../input.h"
#include "../modules/module_manager.h"
#include "../config/profiles.h"
@@ -32,6 +33,7 @@ inline std::string key_name(int vk) {
class clickgui {
public:
void open() { set_open(true); }
// after ImGui::CreateContext(), before the backends are initialized
void init() {
ImGuiIO& io = ImGui::GetIO();
@@ -51,11 +53,14 @@ public:
menu_key_was_down_ = menu_down;
const bool esc_down = is_key_down(VK_ESCAPE);
if (esc_down && !esc_was_down_ && g_menu_open && !any_binding()) set_open(false);
if (esc_down && !esc_was_down_ && g_menu_open && !any_binding()) {
if (editing_hud_) editing_hud_ = false;
else set_open(false);
}
esc_was_down_ = esc_down;
update_menu_cursor();
open_t_ = theme::approach(open_t_, g_menu_open ? 1.f : 0.f, ImGui::GetIO().DeltaTime * 14.f);
open_t_ = std::clamp(open_t_+(g_menu_open ? 1.f : -1.f)*ImGui::GetIO().DeltaTime*6.5f,0.f,1.f);
}
// dim + wordmark; call BEFORE modules().render() so the HUD stays above the dimming
@@ -69,7 +74,7 @@ public:
dl->AddRectFilled(ImVec2(0.f, 0.f), io.DisplaySize,
theme::u32(theme::with_alpha(theme::bg(), k_backdrop_alpha * a)));
if(g_menu_open && hud_editor::options.snap && hud_editor::options.show_grid) {
if(g_menu_open && editing_hud_ && hud_editor::options.snap && hud_editor::options.show_grid) {
const float spacing=float(std::clamp(hud_editor::options.grid_size,4,64));
const auto color=theme::u32(theme::with_alpha(theme::line(),.22f*a));
for(float x=0;x<io.DisplaySize.x;x+=spacing)dl->AddLine({x,0},{x,io.DisplaySize.y},color);
@@ -89,29 +94,42 @@ public:
ImVec2(28.f, io.DisplaySize.y - 30.f),
theme::u32(theme::with_alpha(theme::dim(), a)), "amnesia / v0.0.1");
const char* hint = "right click a module for settings | drag hud elements to move them | right shift or esc to close";
const char* hint = editing_hud_
? "drag hud elements to move them | shift to bypass grid | esc to return"
: "right click a module for settings | right shift or esc to close";
const ImVec2 hs = fonts::text_size(fonts::body, fonts::k_body_size, hint);
dl->AddText(fonts::body, fonts::k_body_size,
ImVec2(floorf(io.DisplaySize.x - hs.x - 28.f), io.DisplaySize.y - 32.f),
theme::u32(theme::with_alpha(theme::muted(), a)), hint);
}
// the panels and the HUD drag editor
// Separate module and HUD editing screens share the same compact controls.
void draw() {
if (open_t_ <= 0.01f) return;
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, open_t_);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(12.f, 8.f));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(8.f, 3.f));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(6.f, 3.f));
ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, ImVec2(6.f, 3.f));
draw_profiles();
float x = 40.f;
for (category cat : k_categories) {
if (!has_modules(cat)) continue;
draw_panel(cat, x);
x += k_panel_w + 20.f;
if (editing_hud_) {
draw_hud_editor();
draw_editor_toolbar();
} else {
draw_navigation();
// The navigation button can change screens in this frame.
if (!editing_hud_) {
float x = 40.f;
for (category cat : k_categories) {
if (!has_modules(cat)) continue;
draw_panel(cat, x);
x += k_panel_w + 12.f;
}
}
}
draw_hud_editor();
ImGui::PopStyleVar();
ImGui::PopStyleVar(5);
}
private:
@@ -123,46 +141,58 @@ private:
float open_t_ = 0.f;
bool menu_key_was_down_ = false;
bool esc_was_down_ = false;
bool editing_hud_ = false;
char profile_name_[49]{};
hud_editor::drag hud_drag_;
// An organizer entry, separate from toggleable gameplay modules and their
// saved settings. Autosaving remains active even while this card is closed.
class module profile_entry_{"profiles", "Switch, save and manage client profiles.", category::utility};
void draw_profiles() {
void draw_navigation() {
ImGui::SetNextWindowPos(ImVec2(40.f, 56.f), ImGuiCond_Always);
ImGui::SetNextWindowSize(ImVec2(850.f, 0.f), ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8.f, 4.f));
ImGui::SetNextWindowSize(ImVec2(0.f, 0.f), ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8.f, 3.f));
auto flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize;
if (!g_menu_open) flags |= ImGuiWindowFlags_NoInputs;
if (ImGui::Begin("##profiles", nullptr, flags)) {
ImGui::AlignTextToFramePadding(); ImGui::TextUnformatted("profile"); ImGui::SameLine();
ImGui::SetNextItemWidth(200.f);
if (ImGui::BeginCombo("##active", profiles().active().c_str())) {
if (ImGui::Begin("##navigation", nullptr, flags)) {
if(ImGui::Button("hud editor")) {
editing_hud_ = true;
for (auto& m : modules().all()) {
m->ui.binding = false;
for (auto& s : m->settings()) s.binding = false;
}
}
}
ImGui::End(); ImGui::PopStyleVar();
}
void draw_profile_controls(float w) {
ImGui::TextUnformatted("active profile");
ImGui::SetNextItemWidth(w);
if (widgets::begin_combo("##active", profiles().active().c_str(),w)) {
if (ImGui::IsWindowAppearing()) profiles().refresh();
const auto choices = profiles().names();
for (const auto& name : choices) {
const bool selected = name == profiles().active();
if (ImGui::Selectable(name.c_str(), selected)) profiles().switch_to(name);
if (widgets::selectable(name.c_str(), selected)) profiles().switch_to(name);
if (selected) ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
ImGui::SameLine(); if (ImGui::Button("save now")) profiles().save();
ImGui::SameLine(); if (ImGui::Button("manage profiles")) { profiles().refresh(); ImGui::OpenPopup("manage profiles"); }
ImGui::SameLine();
if (widgets::button("##save_profile", "save now", false, w, 22.f)) profiles().save();
if (widgets::button("##manage_profiles", "manage profiles", false, w, 22.f)) { profiles().refresh(); ImGui::OpenPopup("manage profiles"); }
ImGui::PushTextWrapPos(ImGui::GetCursorPosX() + w);
ImGui::TextColored(profiles().blocked() ? theme::accent() : theme::muted(), "%s",
profiles().blocked() ? "autosave paused: file error" : profiles().dirty() ? "autosaving..." : "autosave on / saved");
ImGui::SameLine();if(ImGui::Button("hud editor"))ImGui::OpenPopup("hud editor");
if(ImGui::BeginPopup("hud editor")) {
widgets::checkbox("snap to grid",&hud_editor::options.snap,220);
widgets::checkbox("show grid",&hud_editor::options.show_grid,220);
ImGui::TextUnformatted("grid size (px)");ImGui::SetNextItemWidth(220);
ImGui::SliderInt("##grid size",&hud_editor::options.grid_size,4,64);
ImGui::TextColored(theme::muted(),"hold Shift while dragging for free movement");
ImGui::EndPopup();
if (!profiles().last_error().empty()) {
ImGui::TextColored(theme::accent(), "%s", profiles().last_error().c_str());
}
ImGui::PopTextWrapPos();
if (ImGui::BeginPopup("manage profiles")) {
ImGui::TextUnformatted("New profiles copy your current settings.");
ImGui::TextUnformatted("Names: letters, numbers, spaces, _ or -");
ImGui::SetNextItemWidth(310.f); ImGui::InputText("name", profile_name_, sizeof(profile_name_));
ImGui::SetNextItemWidth(310.f); widgets::input_text("name", profile_name_, sizeof(profile_name_),310.f);
if (ImGui::Button("create & use")) { if (profiles().create(profile_name_)) profile_name_[0] = 0; }
ImGui::SameLine();
if (ImGui::Button("rename current")) { if (profiles().rename(profile_name_)) profile_name_[0] = 0; }
@@ -181,8 +211,23 @@ private:
}
ImGui::EndPopup();
}
}
void draw_editor_toolbar() {
ImGui::SetNextWindowPos(ImVec2(40.f, 56.f), ImGuiCond_Always);
ImGui::SetNextWindowSize(ImVec2(0.f, 0.f), ImGuiCond_Always);
auto flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize;
if (!g_menu_open) flags |= ImGuiWindowFlags_NoInputs;
if (ImGui::Begin("##hud_editor_toolbar", nullptr, flags)) {
if (ImGui::Button("back to modules")) editing_hud_ = false;
ImGui::SameLine(); ImGui::AlignTextToFramePadding(); ImGui::TextUnformatted("hud editor");
ImGui::SameLine(0.f, 18.f); ImGui::Checkbox("snap to grid", &hud_editor::options.snap);
ImGui::SameLine(); ImGui::Checkbox("show grid", &hud_editor::options.show_grid);
ImGui::SameLine(); ImGui::SetNextItemWidth(130.f);
widgets::slider_track("grid (px)", &hud_editor::options.grid_size, 4, 64,130.f,"%d");
}
ImGui::End(); ImGui::PopStyleVar();
ImGui::End();
}
static const char* category_title(category c) {
@@ -200,6 +245,7 @@ private:
update_menu_cursor();
if (open) {
editing_hud_ = false;
input::release_cursor();
}
else {
@@ -255,61 +301,58 @@ private:
fonts::push_font(fonts::heading, fonts::k_heading_size);
ImGui::TextUnformatted(category_title(cat));
ImGui::PopFont();
ImGui::Dummy(ImVec2(0.f, 4.f));
ImGui::Dummy(ImVec2(0.f, 1.f));
if (cat == category::utility) draw_module(profile_entry_, true);
for (auto& m : modules().all())
if (m->cat() == cat) draw_module(*m);
}
ImGui::End();
}
void draw_tooltip(const module& m) {
void draw_tooltip(const module& m, bool organizer = false) {
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(14.f, 12.f));
ImGui::BeginTooltip();
ImGui::TextUnformatted(m.description().c_str());
ImGui::TextColored(theme::muted(), "click to toggle | right click for settings");
ImGui::TextColored(theme::muted(), "%s", organizer ? "click or right click to expand" : "click to toggle | right click for settings");
ImGui::EndTooltip();
ImGui::PopStyleVar();
}
void draw_module(module& m) {
void draw_module(module& m, bool organizer = false) {
ImGui::PushID(&m);
ImDrawList* dl = ImGui::GetWindowDrawList();
const float w = ImGui::GetContentRegionAvail().x;
const float h = 38.f;
const float h = 26.f;
const ImVec2 p = ImGui::GetCursorScreenPos();
const ImVec2 q(p.x + w, p.y + h);
ImGui::InvisibleButton("##row", ImVec2(w, h));
const bool hovered = ImGui::IsItemHovered();
const bool active = ImGui::IsItemActive();
if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) m.toggle();
if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) {
if (organizer) m.ui.expanded = !m.ui.expanded;
else m.toggle();
}
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
m.ui.expanded = !m.ui.expanded;
m.ui.binding = false;
}
if (hovered) draw_tooltip(m);
if (hovered) draw_tooltip(m, organizer);
const float dt = ImGui::GetIO().DeltaTime;
m.ui.hover_t = theme::approach(m.ui.hover_t, hovered ? 1.f : 0.f, dt * 16.f);
m.ui.enable_t = theme::approach(m.ui.enable_t, m.enabled() ? 1.f : 0.f, dt * 12.f);
m.ui.expand_t = theme::approach(m.ui.expand_t, m.ui.expanded ? 1.f : 0.f, dt * 12.f);
m.ui.enable_t = theme::approach(m.ui.enable_t, (organizer ? m.ui.expanded : m.enabled()) ? 1.f : 0.f, dt * 12.f);
m.ui.expand_t = widgets::expand_step(m.ui.expand_t, m.ui.expanded, dt);
// off = secondary button, on = Primary (Accent fill, dark text)
const ImVec4 fill_off = theme::mix(theme::raised(), theme::hover(), m.ui.hover_t);
const ImVec4 fill_on = theme::shade(theme::accent(), 1.f + 0.10f * m.ui.hover_t);
ImVec4 fill = theme::mix(fill_off, fill_on, m.ui.enable_t);
ImVec4 border = theme::mix(theme::line(), theme::accent(), m.ui.hover_t);
ImVec4 text_col = theme::mix(theme::fg(), theme::bg(), m.ui.enable_t);
if (active) { fill.w *= 0.7f; border.w *= 0.7f; text_col.w *= 0.7f; }
ImVec4 text_col = theme::mix(theme::muted(), theme::fg(), m.ui.enable_t);
dl->AddRectFilled(p, q, theme::u32(fill), theme::k_radius_button);
dl->AddRect(p, q, theme::u32(border), theme::k_radius_button, 0, 1.f);
theme::control(dl,p,q,organizer ? m.ui.expanded : m.enabled(),hovered,active);
const ImVec2 ts = fonts::text_size(fonts::semibold, fonts::k_body_size, m.name().c_str());
dl->AddText(fonts::semibold, fonts::k_body_size,
ImVec2(floorf(p.x + 16.f), floorf(p.y + (h - ts.y) * 0.5f)),
ImVec2(floorf(p.x + 10.f), floorf(p.y + (h - ts.y) * 0.5f)),
theme::u32(text_col), m.name().c_str());
if (m.toggle_key()) { // keycap chip on the right
@@ -318,59 +361,31 @@ private:
const float cw = ks.x + 14.f, ch = 20.f;
const ImVec2 c0(q.x - 12.f - cw, p.y + (h - ch) * 0.5f);
const ImVec2 c1(c0.x + cw, c0.y + ch);
dl->AddRectFilled(c0, c1, theme::u32(theme::with_alpha(theme::bg(), 0.55f)), 6.f);
dl->AddText(fonts::label, fonts::k_label_size,
ImVec2(floorf(c0.x + 7.f), floorf(c0.y + (ch - ks.y) * 0.5f)),
theme::u32(theme::muted()), k.c_str());
theme::u32(theme::fg()), k.c_str());
}
if (m.ui.expand_t > 0.01f) {
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * m.ui.expand_t);
draw_settings(m, w);
ImGui::PopStyleVar();
ImGui::Dummy(ImVec2(0.f, 2.f));
if (m.ui.expand_t > 0.f) {
widgets::indent_section(w,q.y,m.ui.expand_t,m.ui.settings_height,
m.ui.expanded && m.ui.expand_t>=.99f,[&](float inner_w) {
if (organizer) draw_profile_controls(inner_w);
else {
draw_bind(m,inner_w);
for (auto& s:m.settings()) if (!s.hidden) draw_setting(s,inner_w);
}
});
}
ImGui::PopID();
}
// settings live in an inset card (Bg fill, Line border), drawn behind the widgets
void draw_settings(module& m, float w) {
ImDrawList* dl = ImGui::GetWindowDrawList();
const ImVec2 start = ImGui::GetCursorScreenPos();
const float pad = 12.f;
const float inner_w = w - pad * 2.f;
dl->ChannelsSplit(2);
dl->ChannelsSetCurrent(1);
ImGui::BeginGroup();
ImGui::Dummy(ImVec2(w, 2.f));
ImGui::Indent(pad);
draw_bind(m, inner_w);
for (auto& s : m.settings()) draw_setting(s, inner_w);
ImGui::Unindent(pad);
ImGui::Dummy(ImVec2(0.f, 2.f));
ImGui::EndGroup();
const ImVec2 gmin = ImGui::GetItemRectMin();
const ImVec2 gmax = ImGui::GetItemRectMax();
dl->ChannelsSetCurrent(0);
const ImVec2 a(start.x, gmin.y), b(start.x + w, gmax.y);
dl->AddRectFilled(a, b, theme::u32(theme::bg()), theme::k_radius_button);
dl->AddRect(a, b, theme::u32(theme::line()), theme::k_radius_button, 0, 1.f);
dl->ChannelsMerge();
}
void draw_bind(module& m, float w) {
ImGui::TextUnformatted("bind");
const std::string text = m.ui.binding ? std::string("press a key...") : key_name(m.toggle_key());
if (widgets::button("##bind", text.c_str(), false, w)) m.ui.binding = !m.ui.binding;
if (widgets::keybind("##bind", text.c_str(), m.ui.binding, w)) m.ui.binding = !m.ui.binding;
if (m.ui.binding) {
if (m.ui.binding && !(ImGui::GetCurrentContext()->CurrentItemFlags & ImGuiItemFlags_Disabled)) {
for (int vk = 0x08; vk < 0xFF; ++vk) { // starts above the mouse buttons
if (is_key_down(vk)) {
m.set_toggle_key(vk == VK_ESCAPE ? 0 : vk); // Esc clears the bind
@@ -388,17 +403,17 @@ private:
case setting_type::text: {
char value[257]{}; strncpy_s(value, s.text_value.c_str(), _TRUNCATE);
ImGui::TextUnformatted(s.name.c_str()); ImGui::SetNextItemWidth(w);
if (ImGui::InputText("##text", value, (std::min)(sizeof(value), size_t(s.int_max + 1)))) s.text_value = value;
if (widgets::input_text("##text", value, (std::min)(sizeof(value), size_t(s.int_max + 1)),w)) s.text_value = value;
break;
}
case setting_type::action:
if (widgets::button("##action", s.name.c_str(), false, w) && s.action) s.action();
if (widgets::button("##action", s.name.c_str(), false, w, 22.f) && s.action) s.action();
break;
case setting_type::keybind: {
ImGui::TextUnformatted(s.name.c_str());
const std::string text = s.binding ? "press a key..." : key_name(s.int_value);
if (widgets::button("##key", text.c_str(), false, w)) s.binding = !s.binding;
if (s.binding) {
if (widgets::keybind("##key", text.c_str(), s.binding, w)) s.binding = !s.binding;
if (s.binding && !(ImGui::GetCurrentContext()->CurrentItemFlags & ImGuiItemFlags_Disabled)) {
for (int vk = 0x08; vk < 0xFF; ++vk) {
if (is_key_down(vk)) {
// Keep modifiers specific so synthetic input and real input can be separated.
@@ -412,27 +427,29 @@ private:
break;
}
case setting_type::toggle:
widgets::checkbox(s.name.c_str(), &s.bool_value, w);
widgets::checkbox(s.name.c_str(), &s.bool_value, w, 20.f);
break;
case setting_type::slider_float:
ImGui::TextUnformatted(s.name.c_str());
ImGui::SetNextItemWidth(w);
ImGui::SliderFloat("##v", &s.float_value, s.float_min, s.float_max, "%.2f");
widgets::slider_float(s.name.c_str(), &s.float_value, s.float_min, s.float_max,w);
break;
case setting_type::slider_int:
ImGui::TextUnformatted(s.name.c_str());
ImGui::SetNextItemWidth(w);
ImGui::SliderInt("##v", &s.int_value, s.int_min, s.int_max, "%d");
widgets::slider_int(s.name.c_str(), &s.int_value, s.int_min, s.int_max,w);
break;
case setting_type::mode:
if (!s.modes.empty()) {
if (s.int_value < 0 || s.int_value >= (int)s.modes.size()) s.int_value = 0;
ImGui::TextUnformatted(s.name.c_str());
if (widgets::button("##mode", s.modes[s.int_value].c_str(), false, w))
s.int_value = (s.int_value + 1) % (int)s.modes.size();
// Compact dropdown height shared with action buttons.
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding,{8.f,(22.f-ImGui::GetFontSize())*.5f});
if(widgets::begin_combo("##mode",s.modes[s.int_value].c_str(),w)) {
for(int i=0;i<int(s.modes.size());++i)
if(widgets::selectable(s.modes[i].c_str(),s.int_value==i))s.int_value=i;
ImGui::EndCombo();
}
ImGui::PopStyleVar();
}
break;
@@ -490,7 +507,7 @@ private:
const ImVec4 col = (hovered || active) ? theme::focus() : theme::hover();
ImGui::GetForegroundDrawList()->AddRect(
m.hud_pos, ImVec2(m.hud_pos.x + size.x, m.hud_pos.y + size.y),
theme::u32(col), 10.f, 0, 1.5f);
theme::u32(col), 0.f, 0, 1.5f);
}
ImGui::End();
ImGui::PopStyleVar(2);
+175
View File
@@ -0,0 +1,175 @@
#pragma once
#include <windows.h>
#include <psapi.h>
#include <dxgi1_4.h>
#include <array>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include "hud_editor.h"
#include "hud_card.h"
#include "../config/profiles.h"
#include "../game/world.h"
#include "../game/world_weather.h"
#include "../game/world_filter.h"
#include "../game/inventory_tools.h"
#include "../game/qol_events.h"
#include "../game/media.h"
#pragma comment(lib,"psapi.lib")
// Included by main.cc only in Debug builds. Diagnostics never enable a reader
// or hook, and use the same published snapshots as the ordinary HUD modules.
namespace debug_metrics {
inline double seconds() {
static const double frequency=[] {LARGE_INTEGER value;QueryPerformanceFrequency(&value);return double(value.QuadPart);}();
LARGE_INTEGER value;QueryPerformanceCounter(&value);return double(value.QuadPart)/frequency;
}
struct frame_history {
std::array<float,240> values{};
size_t count=0,next=0;
void push(float ms) {if(!std::isfinite(ms)||ms<=0)return;values[next]=ms;next=(next+1)%values.size();count=(std::min)(count+1,values.size());}
struct summary {float mean=0,min=0,max=0,p95=0,low=0;};
summary summarize() const {
if(!count)return {};
auto sorted=values;std::sort(sorted.begin(),sorted.begin()+count);
double total=0;for(size_t i=0;i<count;++i)total+=sorted[i];
const size_t tail=(std::max)(size_t(1),(count+99)/100);
double slow=0;for(size_t i=count-tail;i<count;++i)slow+=sorted[i];
return {float(total/count),sorted[0],sorted[count-1],sorted[(count*95+99)/100-1],float(1000.*tail/slow)};
}
};
struct row {std::string label,value;bool heading=false;};
struct layout {
ImVec2 pos{},size{};int columns=1,rows=0;
float column_width=300,row_height=14,font_size=11,header=0,padding=0;
};
inline layout arrange(ImVec2 screen,size_t count,int grid) {
layout out;
const float step=float(std::clamp(grid,4,64));
if(screen.x<=0 || screen.y<=0 || !count)return out;
const float margin=(std::min)(step,(std::min)(screen.x,screen.y)*.05f);
const float width=(std::max)(1.f,screen.x-margin*2),height=(std::max)(1.f,screen.y-margin*2);
const int capacity=(std::max)(1,int((height-out.header-out.padding)/out.row_height));
out.columns=std::clamp(int((count+capacity-1)/capacity),1,(std::max)(1,int(width/260)));
out.rows=int((count+out.columns-1)/out.columns);
out.column_width=(std::min)(std::ceil(300.f/step)*step,std::floor(width/out.columns/step)*step);
out.column_width=(std::max)(1.f,out.column_width);
const float scale=(std::min)(1.f,(std::min)(out.column_width/260.f,height/(out.header+out.padding+out.rows*out.row_height)));
out.row_height*=scale;out.font_size*=scale;out.header*=scale;out.padding*=scale;
out.size={out.column_width*out.columns,(std::min)(height,std::ceil((out.header+out.padding+out.rows*out.row_height)/step)*step)};
out.pos={std::floor((screen.x-margin-out.size.x)/step)*step,std::floor(margin/step)*step};
out.pos.x=(std::max)(0.f,out.pos.x);out.pos.y=(std::max)(0.f,out.pos.y);
return out;
}
struct dashboard {
frame_history history;
frame_history::summary timing;
std::vector<row> rows;
double sampled=-1,started=seconds(),client_ms=0,module_ms=0,present_ms=0,overlay_ms=0,startup_ms=0;
uint64_t cpu_stamp=0,wall_stamp=0;
float cpu=0;bool cpu_known=false,memory_known=false,gpu_known=false;
PROCESS_MEMORY_COUNTERS_EX memory{};DWORD handles=0;
Microsoft::WRL::ComPtr<IDXGIAdapter3> adapter;
bool adapter_attempted=false;
DXGI_QUERY_VIDEO_MEMORY_INFO video{};
std::string gpu="unavailable";
static uint64_t ticks(FILETIME t){return (uint64_t(t.dwHighDateTime)<<32)|t.dwLowDateTime;}
void heading(const char* label){rows.push_back({label,"",true});}
template<class... Args> void add(const char* label,const char* format,Args... args) {
char value[256]{};snprintf(value,sizeof(value),format,args...);rows.push_back({label,value,false});
}
void flag(const char* label,bool value){add(label,"%s",value ? "yes" : "no");}
void sample(ID3D11Device* device) {
const auto now=seconds();if(sampled>=0 && now-sampled<.5)return;sampled=now;
timing=history.summarize();rows.clear();
FILETIME creation{},exit{},kernel{},user{},wall{};GetSystemTimeAsFileTime(&wall);
if(GetProcessTimes(GetCurrentProcess(),&creation,&exit,&kernel,&user)) {
const auto cpu_now=ticks(kernel)+ticks(user),wall_now=ticks(wall);
if(wall_stamp && wall_now>wall_stamp && cpu_now>=cpu_stamp) {
cpu=float(100.*double(cpu_now-cpu_stamp)/double(wall_now-wall_stamp)/(std::max)(1ul,GetActiveProcessorCount(ALL_PROCESSOR_GROUPS)));cpu_known=true;
}
cpu_stamp=cpu_now;wall_stamp=wall_now;
}
memory.cb=sizeof(memory);memory_known=GetProcessMemoryInfo(GetCurrentProcess(),reinterpret_cast<PROCESS_MEMORY_COUNTERS*>(&memory),sizeof(memory))!=FALSE;
GetProcessHandleCount(GetCurrentProcess(),&handles);
if(device && !adapter_attempted) {
adapter_attempted=true;Microsoft::WRL::ComPtr<IDXGIDevice> dxgi;Microsoft::WRL::ComPtr<IDXGIAdapter> base;
if(SUCCEEDED(device->QueryInterface(IID_PPV_ARGS(&dxgi))) && SUCCEEDED(dxgi->GetAdapter(&base))) {
base.As(&adapter);DXGI_ADAPTER_DESC desc{};
if(SUCCEEDED(base->GetDesc(&desc))){char name[256]{};WideCharToMultiByte(CP_UTF8,0,desc.Description,-1,name,sizeof(name),nullptr,nullptr);gpu=name;}
}
}
gpu_known=adapter && SUCCEEDED(adapter->QueryVideoMemoryInfo(0,DXGI_MEMORY_SEGMENT_GROUP_LOCAL,&video));
const auto scene=world::latest();
const bool fresh=world::fresh(*scene);
size_t active=0,huds=0;for(const auto& module:modules().all()){active+=module->enabled();huds+=module->enabled()&&module->is_hud();}
heading("client");
add("uptime / startup","%.0f s / %.0f ms",now-started,startup_ms);
add("modules / huds","%zu of %zu / %zu",active,modules().all().size(),huds);
add("profile","%s",profiles().ready() ? profiles().active().c_str() : "loading");
const bool hooks[]={world::ready,world::camera_ready,world::perspective_ready,world::time_ready,
world::name_ready,world::fog_ready,inventory_tools::ready,input::mouse_gate_ready.load()};
unsigned ready=0;for(bool hook:hooks)ready+=hook;
add("core hooks","%u / 8",ready);
if(fresh)add("world snapshot","%llu ms old",GetTickCount64()-scene->stamp);
else add("world snapshot","%s",scene->valid ? "stale" : "no world");
add("nearby / online","%zu / %s",scene->players.size(),scene->roster_known ? std::to_string(scene->online_players.size()).c_str() : "unknown");
heading("process / memory");
if(cpu_known)add("process cpu","%.1f%%",cpu);else add("process cpu","sampling");
if(memory_known)add("ram / private","%.0f / %.0f mib",memory.WorkingSetSize/1048576.,memory.PrivateUsage/1048576.);
else add("process memory","unavailable");
if(gpu_known)add("gpu usage / budget","%.0f / %.0f mib",video.CurrentUsage/1048576.,video.Budget/1048576.);
else add("gpu memory","unavailable");
heading("rendering / events");
add("weather state / draws","%ld / %ld",InterlockedCompareExchange(&amnesia_weather_status,0,0),InterlockedCompareExchange(&amnesia_weather_draws,0,0));
add("particles seen / cut","%llu / %llu",qol_events::particles_seen.load(),qol_events::particles_suppressed.load());
add("sound events","%llu",qol_events::sounds_seen.load());
add("blocked clicks / wheel","%llu / %llu",input::blocked_mouse_buttons.load(),input::blocked_mouse_wheels.load());
add("metadata refresh","%d hz (0 = native)",performance::hud_hz.load());
flag("uncapped present",performance::uncapped_present.load());
}
void draw(ID3D11Device* device) {
const auto begin=seconds();const auto& io=ImGui::GetIO();history.push(io.DeltaTime*1000);sample(device);
std::vector<row> live;
auto add=[&](const char* label,const char* format,auto... args){char value[128]{};snprintf(value,sizeof(value),format,args...);live.push_back({label,value,false});};
live.push_back({"frame timing / 240-frame window","",true});
add("fps / 1%% low","%.0f / %.0f",io.Framerate,timing.low);
add("frame / mean","%.2f / %.2f ms",io.DeltaTime*1000,timing.mean);
add("frame min / max","%.2f / %.2f ms",timing.min,timing.max);add("frame p95","%.2f ms",timing.p95);
add("client / modules","%.2f / %.2f ms",client_ms,module_ms);add("present call / wait","%.2f ms",present_ms);add("diagnostics cost","%.2f ms",overlay_ms);
add("imgui vertices / indices","%d / %d",io.MetricsRenderVertices,io.MetricsRenderIndices);
add("display","%.0f x %.0f",io.DisplaySize.x,io.DisplaySize.y);
live.insert(live.end(),rows.begin(),rows.end());
const auto box=arrange(io.DisplaySize,live.size(),hud_editor::options.grid_size);
if(box.size.x<=0 || box.size.y<=0)return;
auto* draw=ImGui::GetForegroundDrawList();
draw->PushClipRect(box.pos,{box.pos.x+box.size.x,box.pos.y+box.size.y},true);
// Text and its existing font shadow only; leave gameplay visible.
auto* font=fonts::label ? fonts::label : ImGui::GetFont();
for(int column=0;column<box.columns;++column) {
const float x=box.pos.x+column*box.column_width;
for(int index=0;index<box.rows;++index) {
const size_t at=size_t(column*box.rows+index);if(at>=live.size())break;
const auto& line=live[at];const float y=box.pos.y+box.header+index*box.row_height;
const float left=x+box.padding,right=x+box.column_width-box.padding;
if(line.heading) {
draw->AddText(font,box.font_size,{left,y},theme::u32(theme::accent()),line.label.c_str());
}else {
const auto extent=font->CalcTextSizeA(box.font_size,FLT_MAX,0,line.value.c_str());
const float value_x=(std::max)(left+(right-left)*.48f,right-extent.x);
const float label_right=(std::min)(left+(right-left)*.56f,value_x-8);
draw->PushClipRect({left,y},{label_right,y+box.row_height},true);
draw->AddText(font,box.font_size,{left,y},theme::u32(theme::muted()),line.label.c_str());draw->PopClipRect();
draw->PushClipRect({value_x,y},{right,y+box.row_height},true);
draw->AddText(font,box.font_size,{value_x,y},theme::u32(theme::fg()),line.value.c_str());draw->PopClipRect();
}
}
}
draw->PopClipRect();overlay_ms=(seconds()-begin)*1000;
}
};
inline dashboard state;
}
+30 -12
View File
@@ -2,6 +2,7 @@
#include <windows.h>
#include <string>
#include "imgui.h"
#include "misc/freetype/imgui_freetype.h"
// optional fallback if the Segoe UI files can't be found
#if __has_include("../font_data.h")
@@ -14,14 +15,24 @@ int amnesia_fallback_font_size();
namespace fonts {
inline constexpr float k_body_size = 14.f; // launcher base font size
inline constexpr float k_label_size = 11.f; // the small uppercase labels
inline constexpr float k_heading_size = 20.f;
inline constexpr float k_body_size = 13.f; // reference menu Verdana size
inline constexpr float k_label_size = 11.f; // compact secondary labels
inline constexpr float k_heading_size = 13.f;
inline ImFont* body = nullptr; // Segoe UI
inline ImFont* semibold = nullptr; // Segoe UI Semibold (buttons, module names)
inline ImFont* label = nullptr; // Segoe UI Bold
inline ImFont* heading = nullptr; // Segoe UI Semibold, larger
inline ImFont* body = nullptr; // Verdana, matching the reference menu
inline ImFont* semibold = nullptr;
inline ImFont* label = nullptr;
inline ImFont* heading = nullptr;
inline ImFont* media = nullptr; // original glyphs for song/artist metadata
inline void lowercase_display(ImFont* font) {
// Render capitals with their lowercase glyph, including matching advance
// widths for layout, wrapping and text-input caret placement. Keep source
// strings intact: module/profile identifiers and external data retain case.
// Apply before any glyphs are baked, at every font weight and size.
for (ImWchar upper = 'A'; upper <= 'Z'; ++upper)
font->AddRemapCodepoint(upper, upper + ('a' - 'A'));
}
// PushFont changed signature in ImGui 1.92 (fonts became size-flexible)
inline void push_font(ImFont* font, float size) {
@@ -51,11 +62,13 @@ namespace fonts {
inline ImFont* load_one(ImGuiIO& io, const char* file, float size) {
std::string path;
if (windows_font_path(file, path)) {
if (ImFont* f = io.Fonts->AddFontFromFileTTF(path.c_str(), size)) return f;
ImFontConfig config;config.PixelSnapH=true;
if (ImFont* f = io.Fonts->AddFontFromFileTTF(path.c_str(), size,&config)) return f;
}
#if AMNESIA_HAS_FONT
ImFontConfig cfg;
cfg.FontDataOwnedByAtlas = false;
cfg.PixelSnapH = true;
return io.Fonts->AddFontFromMemoryTTF((void*)amnesia_fallback_font(), amnesia_fallback_font_size(), size, &cfg);
#else
return io.Fonts->AddFontDefault();
@@ -65,10 +78,15 @@ namespace fonts {
// after ImGui::CreateContext(), before the backends are initialized
inline void load() {
ImGuiIO& io = ImGui::GetIO();
body = load_one(io, "segoeui.ttf", k_body_size);
semibold = load_one(io, "seguisb.ttf", k_body_size);
label = load_one(io, "segoeuib.ttf", k_label_size);
heading = load_one(io, "seguisb.ttf", k_heading_size);
io.Fonts->SetFontLoader(ImGuiFreeType::GetFontLoader());
// Strong mono-grid hinting with native Verdana hints; keep grayscale antialiasing.
io.Fonts->FontLoaderFlags = ImGuiFreeTypeLoaderFlags_NoAutoHint | ImGuiFreeTypeLoaderFlags_MonoHinting;
body = load_one(io, "verdana.ttf", k_body_size);
semibold = load_one(io, "verdana.ttf", k_body_size);
label = load_one(io, "verdana.ttf", k_label_size);
heading = load_one(io, "verdana.ttf", k_heading_size);
for (ImFont* font : {body, semibold, label, heading}) lowercase_display(font);
media = load_one(io, "verdana.ttf", k_body_size);
io.FontDefault = body;
}
+19 -14
View File
@@ -1,34 +1,39 @@
#pragma once
#include <algorithm>
#include <cmath>
#include "fonts.h"
#include "theme.h"
namespace hud_card {
inline constexpr float pad_x = 12.f, pad_y = 7.f, gap = 6.f;
inline ImVec2 size(const char* label, const char* value, float scale, const char* reserve = "") {
const auto a = fonts::text_size(fonts::body, fonts::k_body_size, label);
const auto b = fonts::text_size(fonts::semibold, fonts::k_body_size, value);
const auto c = fonts::text_size(fonts::semibold, fonts::k_body_size, reserve);
return ImVec2((pad_x * 2 + a.x + (a.x > 0 ? gap : 0) + (std::max)(b.x, c.x)) * scale,
(pad_y * 2 + (std::max)(a.y, b.y)) * scale);
const float font_size=fonts::k_body_size*scale;
const auto a = fonts::text_size(fonts::body, font_size, label);
const auto b = fonts::text_size(fonts::semibold, font_size, value);
const auto c = fonts::text_size(fonts::semibold, font_size, reserve);
const float spacing=a.x>0 && (b.x>0 || c.x>0) ? gap*scale : 0.f;
return ImVec2(pad_x*2*scale+a.x+spacing+(std::max)(b.x,c.x),
pad_y*2*scale+(std::max)(a.y,b.y));
}
inline float rows_height(int count, float line_height=fonts::k_body_size, float stride=20.f) {
return pad_y*2+(std::max)(0,count-1)*stride+line_height;
}
inline void background(ImDrawList* draw, ImVec2 pos, ImVec2 size, float scale, bool enabled, float alpha = 1.f) {
if (!enabled) return;
const ImVec2 end(pos.x + size.x, pos.y + size.y);
draw->AddRectFilled(pos, end, theme::u32(theme::with_alpha(theme::surface(), .85f * alpha)), 10.f * scale);
draw->AddRect(pos, end, theme::u32(theme::with_alpha(theme::line(), alpha)), 10.f * scale, 0, scale);
theme::panel(draw,pos,end,alpha);
}
inline void text(ImDrawList* draw, ImFont* font, float scale, ImVec2 pos, ImU32 color, const char* value, bool card) {
if (!card) draw->AddText(font, fonts::k_body_size * scale, ImVec2(pos.x + scale, pos.y + scale),
theme::u32(theme::with_alpha(theme::bg(), .7f)), value);
draw->AddText(font, fonts::k_body_size * scale, pos, color, value);
color=theme::display_color(color);
draw->AddText(font, fonts::k_body_size * scale, {std::floor(pos.x),std::floor(pos.y)}, color, value);
}
inline void draw(ImVec2 pos, const char* label, const char* value, float scale, bool card, ImU32 color, const char* reserve = "") {
auto* draw = ImGui::GetBackgroundDrawList(); const auto bounds = size(label, value, scale, reserve);
background(draw, pos, bounds, scale, card);
const auto a = fonts::text_size(fonts::body, fonts::k_body_size, label);
const float y = pos.y + pad_y * scale;
text(draw, fonts::body, scale, ImVec2(pos.x + pad_x * scale, y), theme::u32(theme::muted()), label, card);
text(draw, fonts::semibold, scale, ImVec2(pos.x + (pad_x + a.x + (a.x > 0 ? gap : 0)) * scale, y), color, value, card);
const auto a = fonts::text_size(fonts::body, fonts::k_body_size*scale, label);
const auto b = fonts::text_size(fonts::semibold, fonts::k_body_size*scale, value);
const float y = pos.y+(bounds.y-b.y)*.5f;
text(draw, fonts::body, scale, ImVec2(pos.x+pad_x*scale,pos.y+(bounds.y-a.y)*.5f),theme::u32(theme::muted()),label,card);
text(draw, fonts::semibold, scale, ImVec2(pos.x+bounds.x-pad_x*scale-b.x,y),color,value,card);
}
}
+42
View File
@@ -0,0 +1,42 @@
#pragma once
#include <algorithm>
#include <cmath>
#include "imgui.h"
#include "imgui_internal.h"
#include "theme.h"
namespace widgets {
inline float expand_step(float value, bool open, float dt) {
return theme::approach(value, open ? 1.f : 0.f, 1.f-std::exp(-14.f*(std::max)(0.f,dt)));
}
// Measure controls at their natural height, but reserve/clip only the revealed part.
// Keep everything in the category window so its scrolling and widget IDs stay intact.
template<class Render>
void indent_section(float width, float anchor_y, float amount, float& content_height, bool interactive, Render render) {
const auto start=ImGui::GetCursorScreenPos();
auto* window=ImGui::GetCurrentWindow();
const auto old_max=window->DC.CursorMaxPos, old_ideal=window->DC.IdealMaxPos;
const float reveal=content_height*amount;
ImGui::PushClipRect(start,{start.x+width,start.y+reveal},true);
ImGui::PushStyleVar(ImGuiStyleVar_Alpha,ImGui::GetStyle().Alpha*amount);
if (!interactive) ImGui::BeginDisabled();
ImGui::BeginGroup();
ImGui::Indent(14.f);
render((std::max)(1.f,width-14.f));
ImGui::Unindent(14.f);
ImGui::EndGroup();
content_height=ImGui::GetItemRectSize().y;
if (!interactive) ImGui::EndDisabled();
ImGui::PopStyleVar();
ImGui::PopClipRect();
const float height=content_height*amount;
window->DrawList->AddLine({start.x+6.f,anchor_y},{start.x+6.f,start.y+height},
theme::u32(theme::with_alpha(theme::hex(0x141414),amount)),3.f);
// Discard the full measurement's scroll extent, then submit the animated bounds.
window->DC.CursorMaxPos=old_max;
window->DC.IdealMaxPos=old_ideal;
ImGui::SetCursorScreenPos(start);
ImGui::Dummy({width,height});
}
}
+58 -24
View File
@@ -16,20 +16,23 @@ namespace notifications {
kind type=kind::info;
double born=0,duration=3;
float progress=-1,y=-1;
bool dismissed=false;
};
inline std::deque<toast> items;
inline std::mutex mutex;
inline void dismiss(const std::string& key) {
std::lock_guard lock(mutex);
for(auto& item:items) if(item.key==key) item.duration=(std::max)(0.001,now()-item.born);
for(auto& item:items) if(item.key==key && !item.dismissed) {
item.duration=(std::max)(0.001,now()-item.born);item.dismissed=true;
}
}
inline void push(std::string title,std::string body,kind type=kind::info,double duration=3,
std::string key={},float progress=-1) {
std::lock_guard lock(mutex);
if(!key.empty()) for(auto& item:items) if(item.key==key) {
const bool changed=item.title!=title || item.type!=type || item.duration!=duration;
const bool changed=item.dismissed || item.title!=title || item.type!=type || item.duration!=duration;
item.title=std::move(title);item.body=std::move(body);item.type=type;
item.duration=duration;item.progress=progress;if(changed) item.born=now();return;
item.duration=duration;item.progress=progress;item.dismissed=false;if(changed) item.born=now();return;
}
if(items.size()>=6) {
auto removable=std::find_if(items.begin(),items.end(),[](const toast& t){return t.duration>0;});
@@ -38,34 +41,65 @@ namespace notifications {
items.push_back({std::move(key),std::move(title),std::move(body),type,now(),duration,progress,-1});
}
inline float entrance(float t) {t=std::clamp(t,0.f,1.f);return 1-(1-t)*(1-t);}
inline constexpr float slide_duration=.5f;
struct animation {float slide,alpha,remaining;};
inline animation animate(const toast& item,double time) {
const float age=float((std::max)(0.0,time-item.born));
const float out=item.duration>0 ? entrance((age-float(item.duration))/slide_duration) : 0;
const float in=entrance(age/slide_duration);
return {(std::max)(1-in,out),1-out,
item.duration>0 ? std::clamp(1-age/float(item.duration),0.f,1.f) : 1.f};
}
// The reference uses one compact message, rather than a title/icon/body card.
inline std::string message(const toast& item) {
if(item.title.empty())return item.body;
if(item.body.empty())return item.title;
return item.title + ": " + item.body;
}
inline void draw() {
std::lock_guard lock(mutex);const double time=now();
for(auto it=items.begin();it!=items.end();) {
if(it->duration>0 && time-it->born>it->duration+.2)it=items.erase(it);else ++it;
if(it->duration>0 && time-it->born>it->duration+slide_duration)it=items.erase(it);else ++it;
}
const auto& io=ImGui::GetIO();auto* draw=ImGui::GetForegroundDrawList();
const float width=std::clamp(io.DisplaySize.x-24.f,140.f,300.f);float y=16;int shown=0;
for(auto it=items.rbegin();it!=items.rend() && shown<3;++it,++shown) {
auto& item=*it;const float age=float(time-item.born),in=std::clamp(age/.18f,0.f,1.f);
const float out=item.duration>0 ? std::clamp((age-float(item.duration))/.2f,0.f,1.f) : 0;
const float alpha=entrance(in)*(1-out);
if(item.y<0)item.y=y;item.y+=(y-item.y)*(1-std::exp(-16.f*io.DeltaTime));
const float x=io.DisplaySize.x-width-16+(1-entrance(in)+out)*8;
fonts::push_font(fonts::body,fonts::k_body_size);
const auto body=ImGui::CalcTextSize(item.body.c_str(),nullptr,false,width-24);ImGui::PopFont();
const float height=28+(item.body.empty() ? 0 : body.y+5)+(item.progress>=0 ? 8 : 0);
if(io.DisplaySize.x<=30 || io.DisplaySize.y<=12)return;
fonts::push_font(fonts::body,fonts::k_body_size);
const float max_width=(std::min)(480.f,io.DisplaySize.x-10.f);
float y=5;
for(auto& item:items) {
const auto motion=animate(item,time);
const float age=float(time-item.born),alpha=motion.alpha;
const std::string text=message(item);
const float width=std::clamp(ImGui::CalcTextSize(text.c_str()).x+16.f,20.f,max_width);
const float wrap=width-16.f;
const auto size=ImGui::CalcTextSize(text.c_str(),nullptr,false,wrap);
const float height=size.y+12.f;
if(item.y<0)item.y=y;
item.y+=(y-item.y)*(1-std::exp(-12.f*io.DeltaTime));
// Preserve the reference's 400px travel; allow wider messages to clear the edge.
const float x=5-motion.slide*(std::max)(400.f,width+5.f);
auto color=[&](ImVec4 c){c.w*=alpha;return ImGui::ColorConvertFloat4ToU32(c);};
draw->AddRectFilled({x,item.y},{x+width,item.y+height},color(theme::with_alpha(theme::surface(),.85f)),10);
draw->AddRect({x,item.y},{x+width,item.y+height},color(theme::line()),10);
draw->PushClipRect({x+12,item.y},{x+width-12,item.y+height},true);
draw->AddText(fonts::semibold,fonts::k_body_size,{x+12,item.y+7},color(item.type==kind::error ? theme::danger() : theme::fg()),item.title.c_str());
if(!item.body.empty())draw->AddText(fonts::body,fonts::k_body_size,{x+12,item.y+26},color(theme::muted()),item.body.c_str(),nullptr,width-24);
if(item.progress>=0) {
const float p=std::isfinite(item.progress) ? std::clamp(item.progress,0.f,1.f) : 0;
draw->AddRectFilled({x+12,item.y+height-7},{x+width-12,item.y+height-4},color(theme::line()),2);
draw->AddRectFilled({x+12,item.y+height-7},{x+12+(width-24)*p,item.y+height-4},color(theme::accent()),2);
theme::panel(draw,{x,item.y},{x+width,item.y+height},alpha,false);
draw->AddRectFilled({x+2,item.y+2},{x+4,item.y+height-2},color(theme::accent()));
draw->AddLine({x+4,item.y+2},{x+4,item.y+height-2},color(theme::hex(0x000000,.4f)));
draw->PushClipRect({x+7,item.y+2},{x+width-2,item.y+height-2},true);
draw->AddText(fonts::body,fonts::k_body_size,{x+8,item.y+6},color(theme::fg()),text.c_str(),nullptr,wrap);
draw->PopClipRect();
const ImVec2 bar0(x+6,item.y+height-4),bar1(x+width-2,item.y+height-2);
if(item.progress>=0 || item.duration>0) {
const float fraction=item.progress>=0 ? (std::isfinite(item.progress) ? std::clamp(item.progress,0.f,1.f) : 0.f) : motion.remaining;
theme::bar(draw,bar0,bar1,fraction,theme::accent(),alpha);
}
draw->PopClipRect();y+=height+8;
if(item.type==kind::warning || item.type==kind::error) {
// Reference warning line: two-second bounce with a half-second blink.
const float segment=(std::min)(20.f,bar1.x-bar0.x);
const float offset=(.5f+.5f*std::sin(age*3.14159265f))*(bar1.x-bar0.x-segment);
const float pulse=.5f+.5f*std::sin(age*12.5663706f);
const auto tint=item.type==kind::error ? theme::danger() : theme::accent();
draw->AddRect({bar0.x+offset,bar0.y},{bar0.x+offset+segment,bar1.y},color(theme::with_alpha(tint,pulse)));
}
y+=height+2.f;
}
ImGui::PopFont();
}
}
+159
View File
@@ -0,0 +1,159 @@
#pragma once
#include <algorithm>
#include <cmath>
#include <atomic>
#include <array>
#include <cstdio>
#include <d3d11.h>
#include <wrl/client.h>
#include "fonts.h"
#include "theme.h"
namespace startup_intro {
inline constexpr float duration=2.8f;
inline constexpr float hold_age=1.85f;
inline float unit(float value){return std::clamp(value,0.f,1.f);}
inline float ease(float value){value=unit(value);return 1.f-std::pow(1.f-value,3.f);}
inline float smooth(float value){value=unit(value);return value*value*(3.f-2.f*value);}
inline ImU32 ink(ImVec4 color,float alpha){color.w*=unit(alpha);return ImGui::ColorConvertFloat4ToU32(color);}
enum class stage {hooks,modules,input,profile,hud,ready};
inline std::atomic<stage> loading_stage{stage::hooks};
inline std::atomic<unsigned> modules_done{0},modules_total{0};
inline float completion(stage phase,unsigned done,unsigned total) {
switch(phase) {
case stage::hooks:return .05f;
case stage::modules:return .35f+.4f*(total ? unit(float(done)/total) : 0);
case stage::input:return .75f;
case stage::profile:return .85f;
case stage::hud:return .95f;
case stage::ready:return 1.f;
}
return 0;
}
inline const char* stage_name(stage phase) {
switch(phase) {
case stage::hooks:return "loading hooks";
case stage::modules:return "loading modules";
case stage::input:return "setting up input";
case stage::profile:return "loading profile";
case stage::hud:return "preparing hud";
case stage::ready:return "ready";
}
return "loading";
}
inline Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> texture;
inline void initialize_texture(ID3D11Device* device) {
if(!device || texture)return;
// Small repeatable woven/grain tile; generated once and shared by every
// frame. No image decoding or per-pixel CPU work during the animation.
std::array<unsigned,128*128> pixels{};
unsigned seed=0x416d6e65;
for(unsigned y=0;y<128;++y)for(unsigned x=0;x<128;++x) {
seed^=seed<<13;seed^=seed>>17;seed^=seed<<5;
const unsigned weave=((x/2+y/2)&1) ? 9 : 0;
pixels[y*128+x]=IM_COL32(160,160,160,9+(seed&31)+weave);
}
D3D11_TEXTURE2D_DESC desc{};desc.Width=desc.Height=128;desc.MipLevels=desc.ArraySize=1;
desc.Format=DXGI_FORMAT_R8G8B8A8_UNORM;desc.SampleDesc.Count=1;
desc.Usage=D3D11_USAGE_IMMUTABLE;desc.BindFlags=D3D11_BIND_SHADER_RESOURCE;
D3D11_SUBRESOURCE_DATA data{pixels.data(),128*4,0};
Microsoft::WRL::ComPtr<ID3D11Texture2D> image;
if(SUCCEEDED(device->CreateTexture2D(&desc,&data,&image)))
device->CreateShaderResourceView(image.Get(),nullptr,&texture);
}
struct playback {
double previous=-1;
float age=0;
bool finished=false;
float step(double now,bool ready,bool skip_requested=false) {
if(finished)return -1;
const double delta=previous<0 ? 0 : (std::max)(0.0,now-previous);
previous=now;
// Start immediately, but keep the fully assembled mark on an opaque
// field until hooks, profile activation and a module frame are ready.
if(skip_requested)age=(std::max)(age,hold_age);
age+=float(delta>.25 ? 1.0/60.0 : delta);
if(!ready)age=(std::min)(age,hold_age);
if(age>=duration){finished=true;return -1;}
return age;
}
};
inline playback animation;
inline void render(float age,ImVec2 screen,float progress=0,const char* status="loading hooks",double motion=0) {
if(age<0 || age>=duration || screen.x<1 || screen.y<1)return;
auto* draw=ImGui::GetForegroundDrawList();
const float scale=std::clamp((std::min)(screen.x/900.f,screen.y/650.f),.35f,1.35f);
const float enter=smooth(age/.18f),exit=smooth((age-2.12f)/.68f);
const float alpha=enter*(1-smooth((age-2.02f)/.4f));
const ImVec2 center{screen.x*.5f,screen.y*.5f};
// The opaque field clears only after loading has completed.
const float edge=-screen.y*.2f+exit*(screen.x+screen.y*.4f);
const float top=std::clamp(edge+screen.y*.12f,0.f,screen.x);
const float bottom=std::clamp(edge-screen.y*.12f,0.f,screen.x);
const ImVec2 field[]={{top,0},{screen.x,0},screen,{bottom,screen.y}};
if(exit<=0)draw->AddRectFilled({0,0},screen,ink(theme::bg(),1.f));
else draw->AddConvexPolyFilled(field,4,ink(theme::bg(),1.f));
const float grain=1-smooth((age-1.95f)/.17f);
if(texture && grain>0) {
draw->PushClipRect({0,0},screen,true);
const float drift=float(std::fmod(motion*4,128.0));
for(float y=-128+drift;y<screen.y;y+=128)
for(float x=-128+drift*.5f;x<screen.x;x+=128)
draw->AddImage(reinterpret_cast<ImTextureID>(texture.Get()),{x,y},{x+128,y+128},{0,0},{1,1},ink({1,1,1,1},grain*.22f));
draw->PopClipRect();
}
if(exit>0 && exit<1)
draw->AddLine({edge+screen.y*.12f,0},{edge-screen.y*.12f,screen.y},ink(theme::accent(),(1-exit)*.5f),scale);
ImFont* face=fonts::heading ? fonts::heading : ImGui::GetFont();
const float title_size=51*scale;
const auto title=fonts::text_size(face,title_size,"amnesia");
const float logo_h=70*scale,logo_w=logo_h*174/199,gap=23*scale;
const float width=logo_w+gap+title.x;
const float left=center.x-width*.5f;
const ImVec2 origin{left,center.y-logo_h*.5f-6*scale};
// Short, precise face movements lock the familiar cube into place.
const float assemble=ease((age-.14f)/.48f);
auto pt=[&](float x,float y,float dx,float dy) {
return ImVec2{origin.x+(x-43)*logo_h/199+dx*(1-assemble)*scale,
origin.y+(y-36)*logo_h/199+dy*(1-assemble)*scale};
};
const ImVec2 cap[]={pt(130,36,0,-18),pt(217,86,0,-18),pt(130,137,0,-18),pt(43,86,0,-18)};
const ImVec2 lhs[]={pt(43,86,-16,9),pt(130,137,-16,9),pt(130,235,-16,9),pt(43,184,-16,9)};
const ImVec2 rhs[]={pt(130,137,16,9),pt(217,86,16,9),pt(217,184,16,9),pt(130,235,16,9)};
const float mark=alpha*smooth((age-.12f)/.3f);
draw->AddConvexPolyFilled(cap,4,ink(theme::accent(),mark));
draw->AddConvexPolyFilled(lhs,4,ink(theme::dim(),mark));
draw->AddConvexPolyFilled(rhs,4,ink(theme::line(),mark));
// The whole word slides out from behind the cube through a fixed mask.
// Keep the normal letter spacing used by the rest of the client.
const float reveal=ease((age-.4f)/.6f);
const float text_x=left+logo_w+gap;
draw->PushClipRect({text_x,center.y-logo_h},{text_x+title.x*reveal+1,center.y+logo_h},true);
draw->AddText(face,title_size,{text_x-(1-reveal)*24*scale,center.y-title.y*.5f-6*scale},ink(theme::fg(),alpha*reveal),"amnesia");
draw->PopClipRect();
// Stage completion comes from actual loader checkpoints, not intro age.
const float bar_alpha=alpha*smooth((age-.55f)/.3f);
const float y=center.y+logo_h*.5f+13*scale;
theme::bar(draw,{left,y},{left+width,y+5*scale},progress,theme::accent(),bar_alpha);
ImFont* body=fonts::body ? fonts::body : ImGui::GetFont();
draw->AddText(body,11*scale,{left,y+12*scale},ink(theme::muted(),bar_alpha),status);
char percent[8];snprintf(percent,sizeof(percent),"%d%%",int(unit(progress)*100+.5f));
const auto size=fonts::text_size(body,11*scale,percent);
draw->AddText(body,11*scale,{left+width-size.x,y+12*scale},ink(theme::muted(),bar_alpha),percent);
}
inline void draw(bool ready,bool skip_requested=false) {
const float age=animation.step(ImGui::GetTime(),ready,skip_requested);
const auto phase=loading_stage.load();
if(age>=0)render(age,ImGui::GetIO().DisplaySize,
completion(phase,modules_done.load(),modules_total.load()),stage_name(phase),ImGui::GetTime());
}
}
+71 -24
View File
@@ -4,11 +4,10 @@
namespace theme {
// radii straight from App.xaml
inline constexpr float k_radius_card = 20.f;
inline constexpr float k_radius_button = 12.f;
inline constexpr float k_radius_input = 10.f;
inline constexpr float k_radius_check = 6.f;
inline constexpr float k_radius_card = 0.f;
inline constexpr float k_radius_button = 0.f;
inline constexpr float k_radius_input = 0.f;
inline constexpr float k_radius_check = 0.f;
inline float clampf(float v, float lo, float hi) { return v < lo ? lo : (v > hi ? hi : v); }
@@ -39,18 +38,51 @@ namespace theme {
return (v - target < 0.001f && target - v < 0.001f) ? target : v;
}
// ---- names mirror App.xaml ----
inline ImVec4 bg() { return hex(0x17141c); } // Bg
inline ImVec4 surface() { return hex(0x2b2632); } // Surface
inline ImVec4 raised() { return hex(0x38313c); } // Raised
inline ImVec4 fg() { return hex(0xc9b5af); } // Fg
inline ImVec4 muted() { return hex(0x8372a0); } // Muted
inline ImVec4 dim() { return hex(0x625577); } // Dim
inline ImVec4 accent() { return hex(0x8c79a5); } // Accent
inline ImVec4 hover() { return hex(0x74608e); } // Hover
inline ImVec4 line() { return hex(0x433a4f); } // Line
inline ImVec4 focus() { return hex(0xd5c7eb); } // keyboard-focus ring
inline ImVec4 danger() { return hex(0xbc9ba1); } // error text
// Reference menu: neutral charcoal, black edging, white text and #7a459c.
inline ImVec4 bg() { return hex(0x212121); }
inline ImVec4 surface() { return hex(0x2b2b2b); }
inline ImVec4 raised() { return hex(0x1e1e1e); }
inline ImVec4 fg() { return hex(0xffffff); }
inline ImVec4 muted() { return hex(0xa0a0a0); }
inline ImVec4 dim() { return hex(0x787878); }
inline ImVec4 accent() { return hex(0x7a459c); }
inline ImVec4 hover() { return hex(0x282828); }
inline ImVec4 line() { return hex(0x000000); }
inline ImVec4 focus() { return hex(0xffffff); }
inline ImVec4 danger() { return hex(0xdf6868); }
inline ImU32 display_color(ImU32 color) {
const auto rgb=color&~IM_COL32_A_MASK;
ImU32 replacement=rgb;
if(rgb==(IM_COL32(201,181,175,255)&~IM_COL32_A_MASK))replacement=IM_COL32(255,255,255,0);
else if(rgb==(IM_COL32(140,121,165,255)&~IM_COL32_A_MASK))replacement=IM_COL32(122,69,156,0);
return replacement|(color&IM_COL32_A_MASK);
}
inline void gradient(ImDrawList* draw,ImVec2 p,ImVec2 q,ImVec4 top,ImVec4 bottom,float alpha=1.f) {
top.w*=alpha;bottom.w*=alpha;
draw->AddRectFilledMultiColor(p,q,u32(top),u32(top),u32(bottom),u32(bottom));
}
inline void panel(ImDrawList* draw,ImVec2 p,ImVec2 q,float alpha=1.f,bool accent_strip=true) {
gradient(draw,p,q,surface(),hex(0x1c1c1c),alpha);
if(accent_strip && q.y-p.y>8) {
draw->AddRectFilled({p.x+1,p.y+1},{q.x-1,p.y+3},u32(with_alpha(accent(),alpha)));
draw->AddRectFilled({p.x+1,p.y+3},{q.x-1,p.y+4},u32(with_alpha(shade(accent(),.5f),alpha)));
}
draw->AddRect({p.x+1,p.y+1},{q.x-1,q.y-1},u32(with_alpha(line(),alpha)));
}
inline void control(ImDrawList* draw,ImVec2 p,ImVec2 q,bool selected=false,bool hovered=false,bool held=false,float alpha=1.f) {
const auto top=selected ? hex(0x464646) : held ? hex(0x2d2d2d) : hovered ? hex(0x282828) : hex(0x1e1e1e);
const auto bottom=selected ? hex(0x282828) : held ? hex(0x232323) : hovered ? hex(0x1c1c1c) : hex(0x161616);
gradient(draw,p,q,top,bottom,alpha);
draw->AddRect(p,q,u32(with_alpha(line(),alpha)));
}
inline void bar(ImDrawList* draw,ImVec2 p,ImVec2 q,float fraction,ImVec4 tint,float alpha=1.f) {
gradient(draw,p,q,hex(0x232323),hex(0x2c2c2c),alpha);
fraction=std::isfinite(fraction) ? clampf(fraction,0.f,1.f) : 0;
if(fraction>0)gradient(draw,p,{p.x+(q.x-p.x)*fraction,q.y},tint,shade(tint,.5f),alpha);
draw->AddLine({p.x+1,p.y+1},{q.x-1,p.y+1},u32(with_alpha(hex(0x2e2e2e),alpha)));
draw->AddRect(p,q,u32(with_alpha(hex(0x0c0c0c),alpha)));
}
// the isometric cube from the launcher's login screen; returns its width
inline float draw_logo(ImDrawList* dl, ImVec2 pos, float height, float alpha = 1.f) {
@@ -84,9 +116,9 @@ namespace theme {
s.FrameBorderSize = 1.f;
s.WindowPadding = ImVec2(18.f, 18.f);
s.FramePadding = ImVec2(12.f, 8.f);
s.ItemSpacing = ImVec2(8.f, 8.f);
s.ItemInnerSpacing = ImVec2(8.f, 6.f);
s.FramePadding = ImVec2(8.f, 3.f);
s.ItemSpacing = ImVec2(6.f, 3.f);
s.ItemInnerSpacing = ImVec2(6.f, 3.f);
s.GrabMinSize = 16.f;
s.ScrollbarSize = 10.f;
@@ -94,11 +126,12 @@ namespace theme {
s.AntiAliasedFill = true;
ImVec4* c = s.Colors;
for(int i=0;i<ImGuiCol_COUNT;++i)c[i]=raised();
const ImVec4 clear(0.f, 0.f, 0.f, 0.f);
c[ImGuiCol_Text] = fg();
c[ImGuiCol_TextDisabled] = dim();
c[ImGuiCol_WindowBg] = with_alpha(surface(), 0.97f);
c[ImGuiCol_WindowBg] = bg();
c[ImGuiCol_ChildBg] = clear;
c[ImGuiCol_PopupBg] = surface();
c[ImGuiCol_Border] = line();
@@ -125,10 +158,24 @@ namespace theme {
c[ImGuiCol_ButtonHovered] = hover();
c[ImGuiCol_ButtonActive] = hover();
c[ImGuiCol_Header] = hover();
c[ImGuiCol_HeaderHovered] = accent();
c[ImGuiCol_Header] = shade(accent(),.5f);
c[ImGuiCol_HeaderHovered] = hover();
c[ImGuiCol_HeaderActive] = accent();
c[ImGuiCol_Separator] = line();
c[ImGuiCol_SeparatorHovered]=muted();c[ImGuiCol_SeparatorActive]=accent();
c[ImGuiCol_MenuBarBg]=bg();c[ImGuiCol_CheckboxSelectedBg]=accent();
c[ImGuiCol_InputTextCursor]=fg();c[ImGuiCol_TextSelectedBg]=with_alpha(accent(),.6f);
c[ImGuiCol_ResizeGrip]=dim();c[ImGuiCol_ResizeGripHovered]=muted();c[ImGuiCol_ResizeGripActive]=accent();
c[ImGuiCol_Tab]=raised();c[ImGuiCol_TabSelected]=hex(0x464646);c[ImGuiCol_TabHovered]=hover();
c[ImGuiCol_TabSelectedOverline]=accent();c[ImGuiCol_TabDimmedSelectedOverline]=shade(accent(),.5f);
c[ImGuiCol_PlotLines]=fg();c[ImGuiCol_PlotLinesHovered]=accent();
c[ImGuiCol_PlotHistogram]=accent();c[ImGuiCol_PlotHistogramHovered]=fg();
c[ImGuiCol_TableHeaderBg]=surface();c[ImGuiCol_TableBorderStrong]=line();c[ImGuiCol_TableBorderLight]=raised();
c[ImGuiCol_TableRowBg]=clear;c[ImGuiCol_TableRowBgAlt]=with_alpha(fg(),.025f);
c[ImGuiCol_TextLink]=accent();c[ImGuiCol_TreeLines]=dim();
c[ImGuiCol_DragDropTarget]=accent();c[ImGuiCol_DragDropTargetBg]=with_alpha(accent(),.15f);
c[ImGuiCol_UnsavedMarker]=accent();c[ImGuiCol_NavCursor]=fg();c[ImGuiCol_NavWindowingHighlight]=muted();
c[ImGuiCol_NavWindowingDimBg]=with_alpha(line(),.45f);c[ImGuiCol_ModalWindowDimBg]=with_alpha(line(),.6f);
}
} // namespace theme
} // namespace theme
+112 -46
View File
@@ -1,41 +1,32 @@
#pragma once
#include <cmath>
#include <algorithm>
#include <type_traits>
#include "imgui.h"
#include "fonts.h"
#include "theme.h"
namespace widgets {
inline constexpr float k_button_height = 36.f;
inline constexpr float k_button_height = 26.f;
// the launcher's Button: Raised fill + Line border, hover -> Hover fill + Accent border,
// pressed -> 70% opacity. primary = Accent fill with dark text. width 0 = fill the row.
inline bool button(const char* id, const char* text, bool primary = false, float width = 0.f) {
// Reference tab/button gradients fitted to the client's existing row bounds.
inline bool button(const char* id, const char* text, bool primary = false, float width = 0.f, float height = k_button_height) {
ImDrawList* dl = ImGui::GetWindowDrawList();
const ImVec2 p = ImGui::GetCursorScreenPos();
const float w = width > 0.f ? width : ImGui::GetContentRegionAvail().x;
const float h = k_button_height;
const float h = height;
ImGui::PushID(id);
const bool clicked = ImGui::InvisibleButton("##b", ImVec2(w, h));
const bool hovered = ImGui::IsItemHovered();
const bool held = ImGui::IsItemActive();
const ImGuiID key = ImGui::GetID("##hover_t");
ImGui::PopID();
ImGuiStorage* st = ImGui::GetStateStorage();
const float t = theme::approach(st->GetFloat(key, 0.f), hovered ? 1.f : 0.f,
ImGui::GetIO().DeltaTime * 16.f);
st->SetFloat(key, t);
ImVec4 fill = theme::mix(primary ? theme::accent() : theme::raised(), theme::hover(), t);
ImVec4 border = theme::mix(theme::line(), theme::accent(), t);
ImVec4 text_col = primary ? theme::bg() : theme::fg();
if (held) { fill.w *= 0.7f; border.w *= 0.7f; text_col.w *= 0.7f; }
ImVec4 text_col = primary || hovered ? theme::fg() : theme::muted();
const ImVec2 q(p.x + w, p.y + h);
dl->AddRectFilled(p, q, theme::u32(fill), theme::k_radius_button);
dl->AddRect(p, q, theme::u32(border), theme::k_radius_button, 0, 1.f);
theme::control(dl,p,q,primary,hovered,held);
const ImVec2 ts = fonts::text_size(fonts::semibold, fonts::k_body_size, text);
dl->AddText(fonts::semibold, fonts::k_body_size,
@@ -44,51 +35,126 @@ namespace widgets {
return clicked;
}
// the launcher's CheckBox: 20px box, radius 6, Bg fill + Line border; checked -> Hover fill + tick
inline bool checkbox(const char* label, bool* value, float width = 0.f) {
// The original hitbox and label position surround a text-height checkbox.
inline bool checkbox(const char* label, bool* value, float width = 0.f, float height = 22.f) {
ImDrawList* dl = ImGui::GetWindowDrawList();
const ImVec2 p = ImGui::GetCursorScreenPos();
const float w = width > 0.f ? width : ImGui::GetContentRegionAvail().x;
const float box = 20.f;
const float h = 28.f;
const float box = fonts::k_body_size + 6.f;
const float h = height;
ImGui::PushID(label);
const bool pressed = ImGui::InvisibleButton("##c", ImVec2(w, h));
const bool hovered = ImGui::IsItemHovered();
const ImGuiID hover_key = ImGui::GetID("##hover_t");
const ImGuiID on_key = ImGui::GetID("##on_t");
ImGui::PopID();
if (pressed) *value = !*value;
ImGuiStorage* st = ImGui::GetStateStorage();
const float dt = ImGui::GetIO().DeltaTime;
const float hover_t = theme::approach(st->GetFloat(hover_key, 0.f), hovered ? 1.f : 0.f, dt * 16.f);
const float on_t = theme::approach(st->GetFloat(on_key, *value ? 1.f : 0.f), *value ? 1.f : 0.f, dt * 14.f);
st->SetFloat(hover_key, hover_t);
st->SetFloat(on_key, on_t);
const ImVec2 b0(p.x, p.y + (h - box) * 0.5f);
const ImVec2 b1(b0.x + box, b0.y + box);
const ImVec4 fill = theme::mix(theme::bg(), theme::hover(), on_t);
const ImVec4 border = theme::mix(theme::line(), theme::accent(), hover_t > on_t ? hover_t : on_t);
dl->AddRectFilled(b0, b1, theme::u32(fill), theme::k_radius_check);
dl->AddRect(b0, b1, theme::u32(border), theme::k_radius_check, 0, 1.f);
if (on_t > 0.01f) { // vector tick, so we don't depend on the font having a check glyph
const ImU32 tick = theme::u32(theme::with_alpha(theme::fg(), on_t));
const ImVec2 a(b0.x + box * 0.27f, b0.y + box * 0.53f);
const ImVec2 b(b0.x + box * 0.43f, b0.y + box * 0.69f);
const ImVec2 c(b0.x + box * 0.74f, b0.y + box * 0.33f);
dl->AddLine(a, b, tick, 2.f);
dl->AddLine(b, c, tick, 2.f);
}
const float visual_box=fonts::k_body_size;
const ImVec2 b0(p.x, p.y + (h - visual_box) * 0.5f);
const ImVec2 b1(b0.x + visual_box, b0.y + visual_box);
const auto top=*value ? theme::accent() : theme::hex(hovered ? 0x282828 : 0x1e1e1e);
const auto bottom=*value ? theme::shade(theme::accent(),.5f) : theme::hex(hovered ? 0x3a3a3a : 0x303030);
theme::gradient(dl,b0,b1,top,bottom);
dl->AddRect(b0,b1,theme::u32(theme::line()));
const ImVec2 ts = fonts::text_size(fonts::body, fonts::k_body_size, label);
dl->AddText(fonts::body, fonts::k_body_size,
ImVec2(floorf(b1.x + 10.f), floorf(p.y + (h - ts.y) * 0.5f)),
ImVec2(floorf(p.x + box + 8.f), floorf(p.y + (h - ts.y) * 0.5f)),
theme::u32(theme::fg()), label);
return pressed;
}
} // namespace widgets
inline void transparent_frame() {
for(auto color:{ImGuiCol_FrameBg,ImGuiCol_FrameBgHovered,ImGuiCol_FrameBgActive,
ImGuiCol_SliderGrab,ImGuiCol_SliderGrabActive})ImGui::PushStyleColor(color,{0,0,0,0});
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize,0.f);
}
inline void end_transparent_frame(){ImGui::PopStyleVar();ImGui::PopStyleColor(5);}
inline bool input_text(const char* id,char* value,size_t capacity,float width=0) {
auto* draw=ImGui::GetWindowDrawList();const auto p=ImGui::GetCursorScreenPos();
const float w=width>0 ? width : ImGui::CalcItemWidth();
const ImVec2 q{p.x+w,p.y+ImGui::GetFrameHeight()};
theme::gradient(draw,p,q,theme::hex(0x232323),theme::hex(0x2c2c2c));
transparent_frame();ImGui::SetNextItemWidth(w);
const bool changed=ImGui::InputText(id,value,capacity);
end_transparent_frame();
draw->AddLine({p.x+1,p.y+1},{q.x-1,p.y+1},theme::u32(theme::hex(0x2e2e2e)));
draw->AddRect(p,q,theme::u32(theme::hex(0x0c0c0c)));
return changed;
}
inline bool begin_combo(const char* id,const char* preview,float width=0) {
auto* draw=ImGui::GetWindowDrawList();const auto p=ImGui::GetCursorScreenPos();
const float w=width>0 ? width : ImGui::CalcItemWidth();
const ImVec2 q{p.x+w,p.y+ImGui::GetFrameHeight()};
theme::gradient(draw,p,q,theme::hex(0x232323),theme::hex(0x2c2c2c));
transparent_frame();ImGui::SetNextItemWidth(w);
const bool open=ImGui::BeginCombo(id,nullptr,ImGuiComboFlags_NoArrowButton);
end_transparent_frame();
draw->AddLine({p.x+1,p.y+1},{q.x-1,p.y+1},theme::u32(theme::hex(0x2e2e2e)));
draw->AddRect(p,q,theme::u32(theme::hex(0x0c0c0c)));
draw->PushClipRect({p.x+5,p.y},{q.x-20,q.y},true);
draw->AddText({p.x+5,p.y+ImGui::GetStyle().FramePadding.y},theme::u32(theme::fg()),preview);
draw->PopClipRect();
draw->AddText({q.x-13,p.y+ImGui::GetStyle().FramePadding.y},theme::u32(open ? theme::accent() : theme::fg()),open ? "-" : "+");
return open;
}
inline bool selectable(const char* label,bool selected) {
const auto p=ImGui::GetCursorScreenPos();
if(selected)theme::gradient(ImGui::GetWindowDrawList(),p,{p.x+ImGui::GetContentRegionAvail().x,p.y+ImGui::GetTextLineHeight()},theme::accent(),theme::shade(theme::accent(),.5f));
ImGui::PushStyleColor(ImGuiCol_Header,{0,0,0,0});
const bool clicked=ImGui::Selectable(label,selected);
ImGui::PopStyleColor();return clicked;
}
// Preserve the existing label/control rows and native keyboard/Ctrl-click
// slider editing, while rendering the reference's filled gradient track.
inline bool text_button(const char* text) {
const auto p=ImGui::GetCursorScreenPos();const auto size=ImGui::CalcTextSize(text);
const bool pressed=ImGui::InvisibleButton(text,size);
ImGui::GetWindowDrawList()->AddText(p,theme::u32(ImGui::IsItemHovered() ? theme::accent() : theme::fg()),text);
return pressed;
}
inline bool keybind(const char* id,const char* text,bool listening,float width) {
const auto p=ImGui::GetCursorScreenPos();const bool clicked=ImGui::InvisibleButton(id,{width,22});
const auto size=fonts::text_size(fonts::body,fonts::k_body_size,text);
ImGui::GetWindowDrawList()->AddText(fonts::body,fonts::k_body_size,
{p.x+(width-size.x)*.5f,p.y+(22-size.y)*.5f},theme::u32(listening ? theme::accent() : theme::fg()),text);
return clicked;
}
template<class T> inline bool slider_track(const char* id,T* value,T minimum,T maximum,float width,const char* format) {
ImGui::SetNextItemWidth(width);bool changed=false;
auto* draw=ImGui::GetWindowDrawList();ImDrawListSplitter layers;layers.Split(draw,2);layers.SetCurrentChannel(draw,1);
const auto frame_p=ImGui::GetCursorScreenPos();const float inset=(std::max)(0.f,(ImGui::GetFrameHeight()-12.f)*.5f);
const ImVec2 p{frame_p.x,frame_p.y+inset},q{p.x+width,p.y+12.f};
transparent_frame();
if constexpr(std::is_same_v<T,int>)changed=ImGui::SliderInt(id,value,minimum,maximum,format);
else changed=ImGui::SliderFloat(id,value,minimum,maximum,format);
end_transparent_frame();layers.SetCurrentChannel(draw,0);
const float fraction=maximum>minimum ? float(*value-minimum)/float(maximum-minimum) : 0;
theme::bar(draw,p,q,fraction,theme::accent());layers.Merge(draw);
return changed;
}
template<class T> inline bool slider(const char* label,T* value,T minimum,T maximum,float width,const char* format,T step) {
ImGui::PushID(label);bool changed=false;
const auto origin=ImGui::GetCursorScreenPos();
ImGui::TextUnformatted(label);const auto next=ImGui::GetCursorScreenPos();
ImGui::SetCursorScreenPos({origin.x+width-29,origin.y});
if(text_button("-")){*value=std::clamp(T(*value-step),minimum,maximum);changed=true;}
ImGui::SameLine(0,3);
if(text_button("+")){*value=std::clamp(T(*value+step),minimum,maximum);changed=true;}
ImGui::SetCursorScreenPos(next);
changed|=slider_track("##value",value,minimum,maximum,width,format);
ImGui::PopID();return changed;
}
inline bool slider_float(const char* label,float* value,float minimum,float maximum,float width) {
const float range=maximum-minimum;
return slider(label,value,minimum,maximum,width,"%.2f",range<=2 ? .01f : range<=20 ? .1f : 1.f);
}
inline bool slider_int(const char* label,int* value,int minimum,int maximum,float width) {
return slider(label,value,minimum,maximum,width,"%d",1);
}
} // namespace widgets