added fullbright
This commit is contained in:
1 parent
fafeee709f
commit
b1634d195c
21 files changed
+1263
-204
No files matched your search
+144
-93
@@ -1,20 +1,16 @@
|
||||
#pragma once
|
||||
#include <cfloat>
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include "imgui.h"
|
||||
#include "fonts.h"
|
||||
#include "theme.h"
|
||||
#include "widgets.h"
|
||||
#include "../input.h"
|
||||
#include "../modules/module_manager.h"
|
||||
|
||||
#if __has_include("../font_data.h")
|
||||
#include "../font_data.h"
|
||||
#define AMNESIA_HAS_FONT 1
|
||||
#else
|
||||
#define AMNESIA_HAS_FONT 0
|
||||
#endif
|
||||
|
||||
inline std::string key_name(int vk) {
|
||||
if (vk == 0) return "None";
|
||||
if (vk == 0) return "none";
|
||||
|
||||
LONG lparam = (LONG)(MapVirtualKeyA((UINT)vk, MAPVK_VK_TO_VSC) << 16);
|
||||
switch (vk) { // extended keys need bit 24 set to get the right name
|
||||
@@ -39,7 +35,7 @@ public:
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.IniFilename = nullptr; // never write imgui.ini into the game's folder
|
||||
io.LogFilename = nullptr;
|
||||
load_fonts();
|
||||
fonts::load();
|
||||
theme::apply();
|
||||
}
|
||||
|
||||
@@ -56,28 +52,36 @@ public:
|
||||
open_t_ = theme::approach(open_t_, g_menu_open ? 1.f : 0.f, ImGui::GetIO().DeltaTime * 14.f);
|
||||
}
|
||||
|
||||
// dim + title; call BEFORE modules().render() so the HUD stays above the dimming
|
||||
// dim + wordmark; call BEFORE modules().render() so the HUD stays above the dimming
|
||||
void draw_backdrop() {
|
||||
if (open_t_ <= 0.01f) return;
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImDrawList* dl = ImGui::GetBackgroundDrawList();
|
||||
const float a = open_t_;
|
||||
|
||||
dl->AddRectFilled(ImVec2(0.f, 0.f), io.DisplaySize,
|
||||
theme::u32(theme::with_alpha(theme::bg_dark(), 0.6f * open_t_)));
|
||||
theme::u32(theme::with_alpha(theme::bg(), k_backdrop_alpha * a)));
|
||||
|
||||
const char* title = "AMNESIA";
|
||||
const float tw = ImGui::CalcTextSize(title).x * k_title_size / ImGui::GetFontSize();
|
||||
const ImVec2 tp(io.DisplaySize.x * 0.5f - tw * 0.5f, 18.f);
|
||||
dl->AddText(font_title_, k_title_size, ImVec2(tp.x + 3.f, tp.y + 3.f),
|
||||
theme::u32(theme::with_alpha(theme::bg_dark(), open_t_)), title);
|
||||
dl->AddText(font_title_, k_title_size, tp,
|
||||
theme::u32(theme::with_alpha(theme::accent_bright(), open_t_)), title);
|
||||
// title bar, like the launcher: cube + lowercase wordmark
|
||||
const ImVec2 logo_pos(26.f, 18.f);
|
||||
const float logo_h = 30.f;
|
||||
const float logo_w = theme::draw_logo(dl, logo_pos, logo_h, a);
|
||||
const ImVec2 ts = fonts::text_size(fonts::heading, fonts::k_heading_size, "amnesia");
|
||||
dl->AddText(fonts::heading, fonts::k_heading_size,
|
||||
ImVec2(floorf(logo_pos.x + logo_w + 12.f), floorf(logo_pos.y + (logo_h - ts.y) * 0.5f)),
|
||||
theme::u32(theme::with_alpha(theme::fg(), a)), "amnesia");
|
||||
|
||||
const char* hint = "Right-click a module for settings | drag HUD elements to move them";
|
||||
const float hw = ImGui::CalcTextSize(hint).x;
|
||||
dl->AddText(ImVec2(io.DisplaySize.x * 0.5f - hw * 0.5f, tp.y + k_title_size + 8.f),
|
||||
theme::u32(theme::with_alpha(theme::fg_muted(), open_t_)), hint);
|
||||
// footer, like the launcher's status strip
|
||||
dl->AddText(fonts::label, fonts::k_label_size,
|
||||
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 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
|
||||
@@ -99,30 +103,21 @@ public:
|
||||
|
||||
private:
|
||||
static constexpr int k_menu_key = VK_RSHIFT;
|
||||
static constexpr float k_panel_w = 230.f;
|
||||
static constexpr float k_main_size = 18.f;
|
||||
static constexpr float k_title_size = 32.f;
|
||||
static constexpr float k_panel_w = 270.f;
|
||||
static constexpr float k_backdrop_alpha = 0.6f; // the launcher's overlay is 0.85; lower so you can see the game
|
||||
static constexpr category k_categories[] = { category::hud, category::visual, category::utility };
|
||||
|
||||
ImFont* font_main_ = nullptr;
|
||||
ImFont* font_title_ = nullptr;
|
||||
float open_t_ = 0.f;
|
||||
bool menu_key_was_down_ = false;
|
||||
bool esc_was_down_ = false;
|
||||
|
||||
void load_fonts() {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
#if AMNESIA_HAS_FONT
|
||||
ImFontConfig cfg;
|
||||
cfg.FontDataOwnedByAtlas = false; // the data lives in our DLL, ImGui must not free it
|
||||
font_main_ = io.Fonts->AddFontFromMemoryTTF((void*)k_font_data, (int)k_font_size, k_main_size, &cfg);
|
||||
font_title_ = io.Fonts->AddFontFromMemoryTTF((void*)k_font_data, (int)k_font_size, k_title_size, &cfg);
|
||||
#endif
|
||||
if (!font_main_) { // no font_data.h (or it failed): fall back to ImGui's built-in
|
||||
font_main_ = io.Fonts->AddFontDefault();
|
||||
font_title_ = font_main_;
|
||||
static const char* category_title(category c) {
|
||||
switch (c) {
|
||||
case category::hud: return "hud";
|
||||
case category::visual: return "visual";
|
||||
case category::utility: return "utility";
|
||||
}
|
||||
io.FontDefault = font_main_;
|
||||
return "";
|
||||
}
|
||||
|
||||
void set_open(bool open) {
|
||||
@@ -154,28 +149,49 @@ private:
|
||||
// ---------------- panels ----------------
|
||||
|
||||
void draw_panel(category cat, float default_x) {
|
||||
ImGui::SetNextWindowPos(ImVec2(default_x, 110.f), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetNextWindowPos(ImVec2(default_x, 100.f), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetNextWindowSize(ImVec2(k_panel_w, 0.f), ImGuiCond_Always); // fixed width, auto height
|
||||
|
||||
ImGuiWindowFlags flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
|
||||
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse |
|
||||
ImGuiWindowFlags_NoSavedSettings;
|
||||
ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
|
||||
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar |
|
||||
ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoSavedSettings;
|
||||
if (!g_menu_open) flags |= ImGuiWindowFlags_NoInputs; // fading out: no more clicks
|
||||
|
||||
if (ImGui::Begin(category_name(cat), nullptr, flags)) {
|
||||
const std::string id = std::string("##panel_") + category_name(cat);
|
||||
if (ImGui::Begin(id.c_str(), nullptr, flags)) {
|
||||
// header: small uppercase muted label + SemiBold heading (drag the panel by this area)
|
||||
/*fonts::push_font(fonts::label, fonts::k_label_size);
|
||||
ImGui::TextColored(theme::muted(), "%s", category_name(cat));
|
||||
ImGui::PopFont();*/
|
||||
|
||||
fonts::push_font(fonts::heading, fonts::k_heading_size);
|
||||
ImGui::TextUnformatted(category_title(cat));
|
||||
ImGui::PopFont();
|
||||
ImGui::Dummy(ImVec2(0.f, 4.f));
|
||||
|
||||
for (auto& m : modules().all())
|
||||
if (m->cat() == cat) draw_module(*m);
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void draw_tooltip(const module& m) {
|
||||
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::EndTooltip();
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
||||
void draw_module(module& m) {
|
||||
ImGui::PushID(&m);
|
||||
|
||||
ImDrawList* dl = ImGui::GetWindowDrawList();
|
||||
const float w = ImGui::GetContentRegionAvail().x;
|
||||
const float h = ImGui::GetFontSize() + 14.f;
|
||||
const float h = 38.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();
|
||||
@@ -185,35 +201,44 @@ private:
|
||||
m.ui.expanded = !m.ui.expanded;
|
||||
m.ui.binding = false;
|
||||
}
|
||||
if (hovered)
|
||||
ImGui::SetTooltip("%s\n\nLMB: toggle | RMB: settings", m.description().c_str());
|
||||
if (hovered) draw_tooltip(m);
|
||||
|
||||
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);
|
||||
|
||||
ImVec4 base = theme::mix(theme::bg_raised(), theme::accent(), m.ui.enable_t);
|
||||
base = theme::shade(base, 1.f + 0.15f * m.ui.hover_t);
|
||||
theme::bevel_box(dl, p, ImVec2(p.x + w, p.y + h), base, active);
|
||||
// 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; }
|
||||
|
||||
const ImVec4 text_col = theme::mix(theme::fg(), theme::bg_dark(), m.ui.enable_t);
|
||||
const float text_y = p.y + (h - ImGui::GetFontSize()) * 0.5f;
|
||||
theme::shadow_text(dl, ImVec2(p.x + 8.f, text_y), text_col, m.name().c_str());
|
||||
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);
|
||||
|
||||
if (m.toggle_key()) {
|
||||
const std::string k = "[" + key_name(m.toggle_key()) + "]";
|
||||
const float kw = ImGui::CalcTextSize(k.c_str()).x;
|
||||
const ImVec4 kcol = theme::mix(theme::fg_muted(), theme::bg_dark(), m.ui.enable_t * 0.6f);
|
||||
dl->AddText(ImVec2(p.x + w - kw - 8.f, text_y), theme::u32(kcol), k.c_str());
|
||||
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)),
|
||||
theme::u32(text_col), m.name().c_str());
|
||||
|
||||
if (m.toggle_key()) { // keycap chip on the right
|
||||
const std::string k = key_name(m.toggle_key());
|
||||
const ImVec2 ks = fonts::text_size(fonts::label, fonts::k_label_size, k.c_str());
|
||||
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());
|
||||
}
|
||||
|
||||
if (m.ui.expand_t > 0.01f) {
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * m.ui.expand_t);
|
||||
ImGui::Indent(6.f);
|
||||
draw_bind_button(m);
|
||||
for (auto& s : m.settings()) draw_setting(s);
|
||||
ImGui::Unindent(6.f);
|
||||
draw_settings(m, w);
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::Dummy(ImVec2(0.f, 2.f));
|
||||
}
|
||||
@@ -221,12 +246,41 @@ private:
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
void draw_bind_button(module& m) {
|
||||
std::string label;
|
||||
if (m.ui.binding) label = "Bind: press a key...";
|
||||
else label = "Bind: [" + key_name(m.toggle_key()) + "]";
|
||||
// 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;
|
||||
|
||||
if (ImGui::Button(label.c_str(), ImVec2(-FLT_MIN, 0.f))) m.ui.binding = !m.ui.binding;
|
||||
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 (m.ui.binding) {
|
||||
for (int vk = 0x08; vk < 0xFF; ++vk) { // starts above the mouse buttons
|
||||
@@ -239,47 +293,44 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void draw_setting(setting& s) {
|
||||
void draw_setting(setting& s, float w) {
|
||||
ImGui::PushID(&s);
|
||||
|
||||
switch (s.type) {
|
||||
case setting_type::toggle: {
|
||||
const std::string label = s.name + ": " + (s.bool_value ? "ON" : "OFF");
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, s.bool_value ? theme::accent_bright() : theme::fg_muted());
|
||||
if (ImGui::Button(label.c_str(), ImVec2(-FLT_MIN, 0.f))) s.bool_value = !s.bool_value;
|
||||
ImGui::PopStyleColor();
|
||||
case setting_type::toggle:
|
||||
widgets::checkbox(s.name.c_str(), &s.bool_value, w);
|
||||
break;
|
||||
}
|
||||
case setting_type::slider_float: {
|
||||
const std::string fmt = s.name + ": %.2f";
|
||||
ImGui::SetNextItemWidth(-FLT_MIN);
|
||||
ImGui::SliderFloat("##v", &s.float_value, s.float_min, s.float_max, fmt.c_str());
|
||||
|
||||
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");
|
||||
break;
|
||||
}
|
||||
case setting_type::slider_int: {
|
||||
const std::string fmt = s.name + ": %d";
|
||||
ImGui::SetNextItemWidth(-FLT_MIN);
|
||||
ImGui::SliderInt("##v", &s.int_value, s.int_min, s.int_max, fmt.c_str());
|
||||
|
||||
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");
|
||||
break;
|
||||
}
|
||||
case setting_type::mode: {
|
||||
|
||||
case setting_type::mode:
|
||||
if (!s.modes.empty()) {
|
||||
if (s.int_value < 0 || s.int_value >= (int)s.modes.size()) s.int_value = 0;
|
||||
const std::string label = s.name + ": " + s.modes[s.int_value];
|
||||
if (ImGui::Button(label.c_str(), ImVec2(-FLT_MIN, 0.f)))
|
||||
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();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case setting_type::color: {
|
||||
|
||||
case setting_type::color:
|
||||
ImGui::ColorEdit4("##c", s.color,
|
||||
ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel |
|
||||
ImGuiColorEditFlags_AlphaBar);
|
||||
ImGui::SameLine();
|
||||
ImGui::SameLine(0.f, 10.f);
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::TextUnformatted(s.name.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::PopID();
|
||||
}
|
||||
@@ -323,10 +374,10 @@ private:
|
||||
m.hud_pos.y += io.MouseDelta.y;
|
||||
}
|
||||
|
||||
const ImVec4 col = (hovered || active) ? theme::accent_bright() : theme::accent_dark();
|
||||
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), 0.f, 0, 2.f);
|
||||
theme::u32(col), 10.f, 0, 1.5f);
|
||||
}
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar(2);
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
#include <windows.h>
|
||||
#include <string>
|
||||
#include "imgui.h"
|
||||
|
||||
// optional fallback if the Segoe UI files can't be found
|
||||
#if __has_include("../font_data.h")
|
||||
#include "../font_data.h"
|
||||
#define AMNESIA_HAS_FONT 1
|
||||
#else
|
||||
#define AMNESIA_HAS_FONT 0
|
||||
#endif
|
||||
|
||||
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 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
|
||||
|
||||
// PushFont changed signature in ImGui 1.92 (fonts became size-flexible)
|
||||
inline void push_font(ImFont* font, float size) {
|
||||
#if IMGUI_VERSION_NUM >= 19200
|
||||
ImGui::PushFont(font, size);
|
||||
#else
|
||||
(void)size;
|
||||
ImGui::PushFont(font);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline ImVec2 text_size(ImFont* font, float size, const char* text) {
|
||||
push_font(font, size);
|
||||
const ImVec2 ts = ImGui::CalcTextSize(text);
|
||||
ImGui::PopFont();
|
||||
return ts;
|
||||
}
|
||||
|
||||
inline bool windows_font_path(const char* file, std::string& out) {
|
||||
char dir[MAX_PATH] = {};
|
||||
const UINT n = GetWindowsDirectoryA(dir, MAX_PATH);
|
||||
if (n == 0 || n >= MAX_PATH) return false;
|
||||
out = std::string(dir) + "\\Fonts\\" + file;
|
||||
return GetFileAttributesA(out.c_str()) != INVALID_FILE_ATTRIBUTES;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
#if AMNESIA_HAS_FONT
|
||||
ImFontConfig cfg;
|
||||
cfg.FontDataOwnedByAtlas = false;
|
||||
return io.Fonts->AddFontFromMemoryTTF((void*)k_font_data, (int)k_font_size, size, &cfg);
|
||||
#else
|
||||
return io.Fonts->AddFontDefault();
|
||||
#endif
|
||||
}
|
||||
|
||||
// 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.FontDefault = body;
|
||||
}
|
||||
|
||||
} // namespace fonts
|
||||
+67
-58
@@ -1,9 +1,15 @@
|
||||
#pragma once
|
||||
#include <utility>
|
||||
#include <cmath>
|
||||
#include "imgui.h"
|
||||
|
||||
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 float clampf(float v, float lo, float hi) { return v < lo ? lo : (v > hi ? hi : v); }
|
||||
|
||||
inline ImVec4 hex(unsigned int rgb, float a = 1.f) {
|
||||
@@ -33,93 +39,96 @@ namespace theme {
|
||||
return (v - target < 0.001f && target - v < 0.001f) ? target : v;
|
||||
}
|
||||
|
||||
// ---- "orphan" palette ----
|
||||
inline ImVec4 bg_dark() { return hex(0x17141c); }
|
||||
inline ImVec4 bg() { return hex(0x2b2632); }
|
||||
inline ImVec4 bg_raised() { return hex(0x38313c); }
|
||||
inline ImVec4 fg() { return hex(0xc9b5af); }
|
||||
inline ImVec4 fg_muted() { return hex(0x8372a0); }
|
||||
inline ImVec4 fg_dim() { return hex(0x625577); }
|
||||
inline ImVec4 accent() { return hex(0x8c79a5); }
|
||||
inline ImVec4 accent_dark() { return hex(0x74608e); }
|
||||
inline ImVec4 accent_bright() { return hex(0xbfa5ea); }
|
||||
inline ImVec4 border() { return hex(0x433a4f); }
|
||||
// ---- 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
|
||||
|
||||
// Minecraft-button look: flat fill, light top/left edge, dark bottom/right edge
|
||||
inline void bevel_box(ImDrawList* dl, ImVec2 a, ImVec2 b, const ImVec4& base, bool pressed = false) {
|
||||
const float t = 2.f;
|
||||
ImVec4 hi = shade(base, 1.35f), lo = shade(base, 0.6f);
|
||||
if (pressed) std::swap(hi, lo);
|
||||
// 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) {
|
||||
const float s = height / 199.f; // source art spans x 43..217, y 36..235
|
||||
auto pt = [&](float x, float y) { return ImVec2(pos.x + (x - 43.f) * s, pos.y + (y - 36.f) * s); };
|
||||
|
||||
dl->AddRectFilled(a, b, u32(base));
|
||||
dl->AddRectFilled(a, ImVec2(b.x, a.y + t), u32(hi));
|
||||
dl->AddRectFilled(a, ImVec2(a.x + t, b.y), u32(hi));
|
||||
dl->AddRectFilled(ImVec2(a.x, b.y - t), b, u32(lo));
|
||||
dl->AddRectFilled(ImVec2(b.x - t, a.y), b, u32(lo));
|
||||
}
|
||||
const ImVec2 top[4] = { pt(130, 36), pt(217, 86), pt(130, 137), pt(43, 86) };
|
||||
const ImVec2 left[4] = { pt(43, 86), pt(130, 137), pt(130, 235), pt(43, 184) };
|
||||
const ImVec2 right[4] = { pt(130, 137), pt(217, 86), pt(217, 184), pt(130, 235) };
|
||||
|
||||
// Minecraft-style drop shadow
|
||||
inline void shadow_text(ImDrawList* dl, ImVec2 pos, const ImVec4& col, const char* text) {
|
||||
dl->AddText(ImVec2(pos.x + 2.f, pos.y + 2.f), u32(with_alpha(bg_dark(), col.w)), text);
|
||||
dl->AddText(pos, u32(col), text);
|
||||
dl->AddConvexPolyFilled(top, 4, u32(with_alpha(accent(), alpha)));
|
||||
dl->AddConvexPolyFilled(left, 4, u32(with_alpha(dim(), alpha)));
|
||||
dl->AddConvexPolyFilled(right, 4, u32(with_alpha(line(), alpha)));
|
||||
return 174.f * s;
|
||||
}
|
||||
|
||||
inline void apply() {
|
||||
ImGuiStyle& s = ImGui::GetStyle();
|
||||
|
||||
s.WindowRounding = s.ChildRounding = s.FrameRounding = s.PopupRounding = 0.f;
|
||||
s.ScrollbarRounding = s.GrabRounding = s.TabRounding = 0.f;
|
||||
s.WindowBorderSize = 2.f;
|
||||
s.WindowRounding = k_radius_card;
|
||||
s.ChildRounding = k_radius_button;
|
||||
s.FrameRounding = k_radius_input;
|
||||
s.PopupRounding = k_radius_button;
|
||||
s.ScrollbarRounding = k_radius_input;
|
||||
s.GrabRounding = k_radius_input;
|
||||
s.TabRounding = k_radius_input;
|
||||
|
||||
s.WindowBorderSize = 1.f;
|
||||
s.ChildBorderSize = 1.f;
|
||||
s.PopupBorderSize = 2.f;
|
||||
s.PopupBorderSize = 1.f;
|
||||
s.FrameBorderSize = 1.f;
|
||||
|
||||
s.WindowPadding = ImVec2(6.f, 6.f);
|
||||
s.FramePadding = ImVec2(8.f, 5.f);
|
||||
s.ItemSpacing = ImVec2(6.f, 5.f);
|
||||
s.WindowTitleAlign = ImVec2(0.5f, 0.5f);
|
||||
s.GrabMinSize = 12.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.GrabMinSize = 16.f;
|
||||
s.ScrollbarSize = 10.f;
|
||||
|
||||
s.AntiAliasedLines = false; // crisp, blocky edges
|
||||
s.AntiAliasedFill = false;
|
||||
s.AntiAliasedLines = true;
|
||||
s.AntiAliasedFill = true;
|
||||
|
||||
ImVec4* c = s.Colors;
|
||||
const ImVec4 clear(0.f, 0.f, 0.f, 0.f);
|
||||
|
||||
c[ImGuiCol_Text] = fg();
|
||||
c[ImGuiCol_TextDisabled] = fg_dim();
|
||||
c[ImGuiCol_WindowBg] = with_alpha(bg(), 0.96f);
|
||||
c[ImGuiCol_TextDisabled] = dim();
|
||||
c[ImGuiCol_WindowBg] = with_alpha(surface(), 0.97f);
|
||||
c[ImGuiCol_ChildBg] = clear;
|
||||
c[ImGuiCol_PopupBg] = with_alpha(bg_dark(), 0.98f);
|
||||
c[ImGuiCol_Border] = bg_dark();
|
||||
c[ImGuiCol_PopupBg] = surface();
|
||||
c[ImGuiCol_Border] = line();
|
||||
c[ImGuiCol_BorderShadow] = clear;
|
||||
|
||||
c[ImGuiCol_FrameBg] = bg_raised();
|
||||
c[ImGuiCol_FrameBgHovered] = shade(bg_raised(), 1.25f);
|
||||
c[ImGuiCol_FrameBgActive] = shade(bg_raised(), 1.45f);
|
||||
c[ImGuiCol_FrameBg] = bg(); // inputs: Bg fill, Line border
|
||||
c[ImGuiCol_FrameBgHovered] = mix(bg(), raised(), 0.6f);
|
||||
c[ImGuiCol_FrameBgActive] = raised();
|
||||
|
||||
c[ImGuiCol_TitleBg] = shade(accent_dark(), 0.75f);
|
||||
c[ImGuiCol_TitleBgActive] = accent_dark();
|
||||
c[ImGuiCol_TitleBgCollapsed] = shade(accent_dark(), 0.75f);
|
||||
c[ImGuiCol_TitleBg] = surface();
|
||||
c[ImGuiCol_TitleBgActive] = surface();
|
||||
c[ImGuiCol_TitleBgCollapsed] = surface();
|
||||
|
||||
c[ImGuiCol_ScrollbarBg] = clear;
|
||||
c[ImGuiCol_ScrollbarGrab] = border();
|
||||
c[ImGuiCol_ScrollbarGrabHovered] = fg_dim();
|
||||
c[ImGuiCol_ScrollbarGrabActive] = fg_muted();
|
||||
c[ImGuiCol_ScrollbarGrab] = line();
|
||||
c[ImGuiCol_ScrollbarGrabHovered] = dim();
|
||||
c[ImGuiCol_ScrollbarGrabActive] = muted();
|
||||
|
||||
c[ImGuiCol_CheckMark] = accent_bright();
|
||||
c[ImGuiCol_CheckMark] = fg();
|
||||
c[ImGuiCol_SliderGrab] = accent();
|
||||
c[ImGuiCol_SliderGrabActive] = accent_bright();
|
||||
c[ImGuiCol_SliderGrabActive] = focus();
|
||||
|
||||
c[ImGuiCol_Button] = bg_raised();
|
||||
c[ImGuiCol_ButtonHovered] = shade(bg_raised(), 1.3f);
|
||||
c[ImGuiCol_ButtonActive] = accent_dark();
|
||||
c[ImGuiCol_Button] = raised();
|
||||
c[ImGuiCol_ButtonHovered] = hover();
|
||||
c[ImGuiCol_ButtonActive] = hover();
|
||||
|
||||
c[ImGuiCol_Header] = accent_dark();
|
||||
c[ImGuiCol_Header] = hover();
|
||||
c[ImGuiCol_HeaderHovered] = accent();
|
||||
c[ImGuiCol_HeaderActive] = accent();
|
||||
c[ImGuiCol_Separator] = border();
|
||||
c[ImGuiCol_Separator] = line();
|
||||
}
|
||||
|
||||
} // namespace theme
|
||||
@@ -0,0 +1,94 @@
|
||||
#pragma once
|
||||
#include <cmath>
|
||||
#include "imgui.h"
|
||||
#include "fonts.h"
|
||||
#include "theme.h"
|
||||
|
||||
namespace widgets {
|
||||
|
||||
inline constexpr float k_button_height = 36.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) {
|
||||
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;
|
||||
|
||||
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; }
|
||||
|
||||
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);
|
||||
|
||||
const ImVec2 ts = fonts::text_size(fonts::semibold, fonts::k_body_size, text);
|
||||
dl->AddText(fonts::semibold, fonts::k_body_size,
|
||||
ImVec2(floorf(p.x + (w - ts.x) * 0.5f), floorf(p.y + (h - ts.y) * 0.5f)),
|
||||
theme::u32(text_col), text);
|
||||
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) {
|
||||
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;
|
||||
|
||||
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 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)),
|
||||
theme::u32(theme::fg()), label);
|
||||
return pressed;
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
Reference in new issue
Block a user