Skip to content

Commit

Permalink
Add selectable ImGui themes for GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
narknon committed Dec 18, 2023
1 parent 9d980ac commit f621f68
Show file tree
Hide file tree
Showing 6 changed files with 353 additions and 60 deletions.
89 changes: 31 additions & 58 deletions src/Framework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "Mods.hpp"
#include "mods/PluginLoader.hpp"
#include "mods/VR.hpp"
#include "mods/ImGuiThemeHelpers.hpp"

#include "ExceptionHandler.hpp"
#include "LicenseStrings.hpp"
Expand Down Expand Up @@ -1072,6 +1073,11 @@ void Framework::invalidate_device_objects() {
void Framework::draw_ui() {
std::lock_guard _{m_input_mutex};

if (m_current_theme != get_imgui_theme_value()) {
set_imgui_style();
m_current_theme = get_imgui_theme_value();
}

ImGui::GetIO().MouseDrawCursor = m_draw_ui || FrameworkConfig::get()->is_always_show_cursor();
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange; // causes bugs with the cursor

Expand Down Expand Up @@ -1417,64 +1423,27 @@ void Framework::draw_about() {
}

void Framework::set_imgui_style() noexcept {
ImGui::StyleColorsDark();

auto& style = ImGui::GetStyle();
style.WindowRounding = 0.0f;
style.ChildRounding = 0.0f;
style.PopupRounding = 0.0f;
style.FrameRounding = 0.0f;
style.ScrollbarRounding = 2.0f;
style.GrabRounding = 0.0f;
style.TabRounding = 0.0f;
style.WindowBorderSize = 2.0f;
style.WindowPadding = ImVec2(2.0f, 0.0f);

auto& colors = ImGui::GetStyle().Colors;
// Window BG
colors[ImGuiCol_WindowBg] = ImVec4{0.1f, 0.105f, 0.11f, 1.0f};

// Navigatation highlight
colors[ImGuiCol_NavHighlight] = ImVec4{0.3f, 0.305f, 0.31f, 1.0f};

// Progress Bar
colors[ImGuiCol_PlotHistogram] = ImVec4{0.3f, 0.305f, 0.31f, 1.0f};

// Headers
colors[ImGuiCol_Header] = ImVec4{0.2f, 0.205f, 0.21f, 1.0f};
colors[ImGuiCol_HeaderHovered] = ImVec4{0.3f, 0.305f, 0.31f, 1.0f};
colors[ImGuiCol_HeaderActive] = ImVec4{0.55f, 0.5505f, 0.551f, 1.0f};

// Buttons
colors[ImGuiCol_Button] = ImVec4{0.2f, 0.205f, 0.21f, 1.0f};
colors[ImGuiCol_ButtonHovered] = ImVec4{0.3f, 0.305f, 0.31f, 1.0f};
colors[ImGuiCol_ButtonActive] = ImVec4{0.55f, 0.5505f, 0.551f, 1.0f};

// Checkbox
colors[ImGuiCol_CheckMark] = ImVec4(0.55f, 0.5505f, 0.551f, 1.0f);

// Frame BG
colors[ImGuiCol_FrameBg] = ImVec4{0.211f, 0.210f, 0.25f, 1.0f};
colors[ImGuiCol_FrameBgHovered] = ImVec4{0.3f, 0.305f, 0.31f, 1.0f};
colors[ImGuiCol_FrameBgActive] = ImVec4{0.55f, 0.5505f, 0.551f, 1.0f};

// Tabs
colors[ImGuiCol_Tab] = ImVec4{0.25f, 0.2505f, 0.251f, 1.0f};
colors[ImGuiCol_TabHovered] = ImVec4{0.38f, 0.3805f, 0.381f, 1.0f};
colors[ImGuiCol_TabActive] = ImVec4{0.28f, 0.2805f, 0.281f, 1.0f};
colors[ImGuiCol_TabUnfocused] = ImVec4{0.25f, 0.2505f, 0.251f, 1.0f};
colors[ImGuiCol_TabUnfocusedActive] = ImVec4{0.8f, 0.805f, 0.81f, 1.0f};

// Resize Grip
colors[ImGuiCol_ResizeGrip] = ImVec4{0.2f, 0.205f, 0.21f, 0.0f};
colors[ImGuiCol_ResizeGripHovered] = ImVec4{0.3f, 0.305f, 0.31f, 1.0f};
colors[ImGuiCol_ResizeGripActive] = ImVec4{0.55f, 0.5505f, 0.551f, 1.0f};

// Title
colors[ImGuiCol_TitleBg] = ImVec4{0.25f, 0.2505f, 0.251f, 1.0f};
colors[ImGuiCol_TitleBgActive] = ImVec4{0.55f, 0.5505f, 0.551f, 1.0f};
colors[ImGuiCol_TitleBgCollapsed] = ImVec4{0.25f, 0.2505f, 0.251f, 1.0f};


auto current_theme = get_imgui_theme_value();

switch (current_theme) {
case ImGuiThemes::DEFAULT_DARK:
ImGuiThemeHelper::StyleColorsDefaultDark();
break;
case ImGuiThemes::ALTERNATIVE_DARK:
ImGuiThemeHelper::StyleColorsAlternativeDark();
break;
case ImGuiThemes::DEFAULT_LIGHT:
ImGuiThemeHelper::StyleColorsDefaultLight();
break;
case ImGuiThemes::HIGH_CONTRAST:
ImGuiThemeHelper::StyleColorsHighContrast();
break;
default:
ImGuiThemeHelper::StyleColorsDefaultDark();
break;
}

// Font
set_font_size(m_font_size);

Expand Down Expand Up @@ -2009,4 +1978,8 @@ void Framework::deinit_d3d12() {

bool Framework::is_advanced_view_enabled() const {
return FrameworkConfig::get()->is_advanced_mode();
}

Framework::ImGuiThemes Framework::get_imgui_theme_value() const {
return static_cast<ImGuiThemes>(FrameworkConfig::get()->get_imgui_theme_value());
}
11 changes: 11 additions & 0 deletions src/Framework.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ class Framework {

bool is_advanced_view_enabled() const;

enum ImGuiThemes : int8_t {
DEFAULT_DARK,
ALTERNATIVE_DARK,
DEFAULT_LIGHT,
HIGH_CONTRAST,
};

ImGuiThemes get_imgui_theme_value() const;

private:
void consume_input();
void update_fonts();
Expand Down Expand Up @@ -263,6 +272,8 @@ class Framework {
ImVec2 m_last_window_size{};
Vector2f m_last_rt_size{1920, 1080};

ImGuiThemes m_current_theme;

struct AdditionalFont {
std::filesystem::path filepath{};
int size{16};
Expand Down
17 changes: 16 additions & 1 deletion src/mods/FrameworkConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,33 @@ std::optional<std::string> FrameworkConfig::on_initialize() {
return Mod::on_initialize();
}

void FrameworkConfig::on_draw_ui() {
void FrameworkConfig::draw_main() {
m_menu_key->draw("Menu Key");
m_show_cursor_key->draw("Show Cursor Key");
m_remember_menu_state->draw("Remember Menu Open/Closed State");
m_enable_l3_r3_toggle->draw("Enable L3 + R3 Toggle");
m_always_show_cursor->draw("Always Show Cursor");
}

void FrameworkConfig::draw_themes() {
get_imgui_theme()->draw("Select GUI Theme");

if (m_font_size->draw("Font Size")) {
g_framework->set_font_size(m_font_size->value());
}
}

void FrameworkConfig::on_draw_sidebar_entry(std::string_view in_entry) {
on_draw_ui();
ImGui::Separator();

if (in_entry == "Main") {
draw_main();
} else if (in_entry == "GUI/Themes") {
draw_themes();
}
}

void FrameworkConfig::on_frame() {
if (m_show_cursor_key->is_key_down_once()) {
m_always_show_cursor->toggle();
Expand Down
29 changes: 28 additions & 1 deletion src/mods/FrameworkConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,21 @@ class FrameworkConfig : public Mod {
return "FrameworkConfig";
}

std::vector<SidebarEntryInfo> get_sidebar_entries() override {
return {
{ "Main", false },
{ "GUI/Themes", false }
};
}

std::optional<std::string> on_initialize() override;
void on_draw_ui() override;
void on_frame() override;
void on_config_load(const utility::Config& cfg, bool set_defaults) override;
void on_config_save(utility::Config& cfg) override;
void on_draw_sidebar_entry(std::string_view in_entry) override;

void draw_themes();
void draw_main();

auto& get_menu_key() {
return m_menu_key;
Expand Down Expand Up @@ -49,17 +59,33 @@ class FrameworkConfig : public Mod {
return m_advanced_mode;
}

auto& get_imgui_theme_value() {
return m_imgui_theme->value();
}

auto& get_imgui_theme() {
return m_imgui_theme;
}

int32_t get_font_size() {
return m_font_size->value();
}

private:
static const inline std::vector<std::string> s_imgui_themes {
"Default Dark",
"Alternative Dark",
"Default Light",
"High Contrast",
};

ModKey::Ptr m_menu_key{ ModKey::create(generate_name("MenuKey"), VK_INSERT) };
ModToggle::Ptr m_menu_open{ ModToggle::create(generate_name("MenuOpen"), true) };
ModToggle::Ptr m_remember_menu_state{ ModToggle::create(generate_name("RememberMenuState"), false) };
ModToggle::Ptr m_enable_l3_r3_toggle{ ModToggle::create(generate_name("EnableL3R3Toggle"), true) };
ModToggle::Ptr m_always_show_cursor{ ModToggle::create(generate_name("AlwaysShowCursor"), false) };
ModToggle::Ptr m_advanced_mode{ ModToggle::create(generate_name("AdvancedMode"), false) };
ModCombo::Ptr m_imgui_theme{ ModCombo::create(generate_name("ImGuiTheme"), s_imgui_themes, Framework::ImGuiThemes::DEFAULT_DARK) };
ModKey::Ptr m_show_cursor_key{ ModKey::create(generate_name("ShowCursorKey")) };
ModInt32::Ptr m_font_size{ModInt32::create(generate_name("FontSize"), 16)};

Expand All @@ -70,6 +96,7 @@ class FrameworkConfig : public Mod {
*m_remember_menu_state,
*m_enable_l3_r3_toggle,
*m_advanced_mode,
*m_imgui_theme,
*m_always_show_cursor,
*m_font_size,
};
Expand Down
Loading

0 comments on commit f621f68

Please sign in to comment.