2023-02-16 18:06:40 +01:00
|
|
|
#include "content/views/view_theme_manager.hpp"
|
|
|
|
|
|
|
|
#include <hex/api/theme_manager.hpp>
|
|
|
|
|
2023-03-12 18:27:29 +01:00
|
|
|
#include <wolv/io/file.hpp>
|
2023-02-16 18:06:40 +01:00
|
|
|
|
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
|
|
|
ViewThemeManager::ViewThemeManager() : View("hex.builtin.view.theme_manager.name") {
|
2023-05-12 08:38:32 +02:00
|
|
|
ContentRegistry::Interface::addMenuItem({ "hex.builtin.menu.extras", "hex.builtin.view.theme_manager.name" }, 2000, Shortcut::None, [&, this] {
|
2023-03-20 13:11:43 +01:00
|
|
|
this->m_viewOpen = true;
|
|
|
|
this->getWindowOpenState() = true;
|
2023-02-16 18:06:40 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewThemeManager::drawContent() {
|
|
|
|
if (ImGui::Begin(View::toWindowName("hex.builtin.view.theme_manager.name").c_str(), &this->m_viewOpen, ImGuiWindowFlags_NoCollapse)) {
|
|
|
|
ImGui::Header("hex.builtin.view.theme_manager.colors"_lang, true);
|
|
|
|
|
2023-08-29 12:14:12 +02:00
|
|
|
// Draw theme handlers
|
2023-02-16 18:06:40 +01:00
|
|
|
ImGui::PushID(1);
|
2023-08-29 12:14:12 +02:00
|
|
|
|
|
|
|
// Loop over each theme handler
|
|
|
|
for (auto &[name, handler] : ThemeManager::getThemeHandlers()) {
|
|
|
|
// Create a new collapsable header for each category
|
2023-02-16 18:06:40 +01:00
|
|
|
if (ImGui::CollapsingHeader(name.c_str())) {
|
2023-08-29 12:14:12 +02:00
|
|
|
|
|
|
|
// Loop over all the individual theme settings
|
2023-02-16 18:06:40 +01:00
|
|
|
for (auto &[colorName, colorId] : handler.colorMap) {
|
2023-08-29 12:14:12 +02:00
|
|
|
// Get the current color value
|
2023-02-16 18:06:40 +01:00
|
|
|
auto color = handler.getFunction(colorId);
|
2023-08-29 12:14:12 +02:00
|
|
|
|
|
|
|
// Draw a color picker for the color
|
|
|
|
if (ImGui::ColorEdit4(colorName.c_str(), (float*)&color.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaBar | ImGuiColorEditFlags_AlphaPreviewHalf)) {
|
|
|
|
// Update the color value
|
2023-02-16 18:06:40 +01:00
|
|
|
handler.setFunction(colorId, color);
|
2023-05-22 13:20:25 +02:00
|
|
|
EventManager::post<EventThemeChanged>();
|
2023-02-16 18:06:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::PopID();
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::Header("hex.builtin.view.theme_manager.styles"_lang);
|
|
|
|
|
2023-08-29 12:14:12 +02:00
|
|
|
// Draw style handlers
|
2023-02-16 18:06:40 +01:00
|
|
|
ImGui::PushID(2);
|
2023-08-29 12:14:12 +02:00
|
|
|
|
|
|
|
// Loop over each style handler
|
2023-03-23 20:35:16 +01:00
|
|
|
for (auto &[name, handler] : ThemeManager::getStyleHandlers()) {
|
2023-08-29 12:14:12 +02:00
|
|
|
// Create a new collapsable header for each category
|
2023-02-16 18:06:40 +01:00
|
|
|
if (ImGui::CollapsingHeader(name.c_str())) {
|
2023-08-29 12:14:12 +02:00
|
|
|
|
|
|
|
// Loop over all the individual style settings
|
2023-02-16 18:06:40 +01:00
|
|
|
for (auto &[styleName, style] : handler.styleMap) {
|
2023-08-29 12:14:12 +02:00
|
|
|
// Get the current style value
|
2023-03-18 10:52:50 +01:00
|
|
|
auto &[value, min, max, needsScaling] = style;
|
2023-02-16 18:06:40 +01:00
|
|
|
|
2023-08-29 12:14:12 +02:00
|
|
|
// Styles can either be floats or ImVec2s
|
|
|
|
// Determine which one it is and draw the appropriate slider
|
2023-05-22 13:20:25 +02:00
|
|
|
if (auto floatValue = std::get_if<float*>(&value); floatValue != nullptr) {
|
|
|
|
if (ImGui::SliderFloat(styleName.c_str(), *floatValue, min, max, "%.1f")) {
|
|
|
|
EventManager::post<EventThemeChanged>();
|
|
|
|
}
|
|
|
|
} else if (auto vecValue = std::get_if<ImVec2*>(&value); vecValue != nullptr) {
|
|
|
|
if (ImGui::SliderFloat2(styleName.c_str(), &(*vecValue)->x, min, max, "%.1f")) {
|
|
|
|
EventManager::post<EventThemeChanged>();
|
|
|
|
}
|
|
|
|
}
|
2023-02-16 18:06:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::PopID();
|
|
|
|
|
2023-08-29 12:14:12 +02:00
|
|
|
// Draw export settings
|
2023-02-16 18:06:40 +01:00
|
|
|
ImGui::Header("hex.builtin.view.theme_manager.export"_lang);
|
|
|
|
ImGui::InputTextIcon("hex.builtin.view.theme_manager.export.name"_lang, ICON_VS_SYMBOL_KEY, this->m_themeName);
|
2023-08-29 12:14:12 +02:00
|
|
|
|
|
|
|
// Draw the export buttons
|
2023-02-16 18:06:40 +01:00
|
|
|
if (ImGui::Button("hex.builtin.view.theme_manager.save_theme"_lang, ImVec2(ImGui::GetContentRegionAvail().x, 0))) {
|
|
|
|
fs::openFileBrowser(fs::DialogMode::Save, { { "ImHex Theme", "json" } }, [this](const std::fs::path &path){
|
2023-08-29 12:14:12 +02:00
|
|
|
// Export the current theme as json
|
2023-03-23 20:35:16 +01:00
|
|
|
auto json = ThemeManager::exportCurrentTheme(this->m_themeName);
|
2023-02-16 18:06:40 +01:00
|
|
|
|
2023-08-29 12:14:12 +02:00
|
|
|
// Write the json to the file
|
2023-03-12 18:27:29 +01:00
|
|
|
wolv::io::File outputFile(path, wolv::io::File::Mode::Create);
|
2023-03-23 11:23:07 +01:00
|
|
|
outputFile.writeString(json.dump(4));
|
2023-02-16 18:06:40 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
|
|
|
|
this->getWindowOpenState() = this->m_viewOpen;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|