1
0
mirror of synced 2024-11-15 19:43:23 +01:00
ImHex/plugins/builtin/source/content/settings_entries.cpp

134 lines
4.4 KiB
C++
Raw Normal View History

#include <hex/api/content_registry.hpp>
#include <hex/api/imhex_api.hpp>
#include <hex/helpers/lang.hpp>
using namespace hex::lang_literals;
#include <imgui.h>
#include <nlohmann/json.hpp>
namespace hex::plugin::builtin {
void registerSettings() {
2021-08-22 21:11:01 +02:00
/* General */
ContentRegistry::Settings::add("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", 1, [](auto name, nlohmann::json &setting) {
static bool enabled = static_cast<int>(setting);
2021-08-22 21:11:01 +02:00
if (ImGui::Checkbox(name.data(), &enabled)) {
setting = static_cast<int>(enabled);
return true;
}
return false;
});
/* Interface */
ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", 0, [](auto name, nlohmann::json &setting) {
static int selection = static_cast<int>(setting);
const char* themes[] = {
2021-09-16 22:23:51 +02:00
"hex.builtin.setting.interface.color.system"_lang,
"hex.builtin.setting.interface.color.dark"_lang,
"hex.builtin.setting.interface.color.light"_lang,
"hex.builtin.setting.interface.color.classic"_lang
};
if (ImGui::Combo(name.data(), &selection, themes, IM_ARRAYSIZE(themes))) {
setting = selection;
return true;
}
return false;
});
ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.scaling", 0, [](auto name, nlohmann::json &setting) {
static int selection = static_cast<int>(setting);
const char* scaling[] = {
"hex.builtin.setting.interface.scaling.native"_lang,
"hex.builtin.setting.interface.scaling.x0_5"_lang,
"hex.builtin.setting.interface.scaling.x1_0"_lang,
"hex.builtin.setting.interface.scaling.x1_5"_lang,
"hex.builtin.setting.interface.scaling.x2_0"_lang,
};
if (ImGui::Combo(name.data(), &selection, scaling, IM_ARRAYSIZE(scaling))) {
setting = selection;
ImHexApi::Common::restartImHex();
return true;
}
return false;
});
ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.language", "en-US", [](auto name, nlohmann::json &setting) {
auto &languages = LangEntry::getSupportedLanguages();
static int selection = [&]() -> int {
u16 index = 0;
for (auto &[languageCode, languageName] : languages){
if (languageCode == setting)
return index;
index++;
}
return 0;
}();
static auto languageNames = [&]() {
std::vector<const char*> result(languages.size());
for (auto &[languageCode, languageName] : languages)
result.push_back(languageName.c_str());
return result;
}();
if (ImGui::Combo(name.data(), &selection, languageNames.data(), languageNames.size())) {
u16 index = 0;
for (auto &[languageCode, languageName] : languages){
if (selection == index) {
setting = languageCode;
break;
}
index++;
}
return true;
}
return false;
});
ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.fps", 60, [](auto name, nlohmann::json &setting) {
static int fps = static_cast<int>(setting);
if (ImGui::SliderInt(name.data(), &fps, 15, 60)) {
setting = fps;
return true;
}
return false;
});
ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.highlight_alpha", 0x80, [](auto name, nlohmann::json &setting) {
static int alpha = static_cast<int>(setting);
if (ImGui::SliderInt(name.data(), &alpha, 0x00, 0xFF)) {
setting = alpha;
return true;
}
return false;
});
}
}