1
0
mirror of synced 2025-01-18 17:14:13 +01:00

sys: Use custom literals for scaled values

This commit is contained in:
WerWolv 2022-01-11 23:48:18 +01:00
parent 2f1a707fd3
commit d399a6427a
12 changed files with 43 additions and 24 deletions

View File

@ -19,7 +19,7 @@ namespace hex::plugin::builtin {
[[nodiscard]] bool hasViewMenuItemEntry() const override { return false; }
[[nodiscard]] ImVec2 getMinSize() const override {
return ImVec2(500, 300) * SharedData::globalScale;
return scaled(ImVec2(500, 300));
}
};

View File

@ -55,7 +55,7 @@ namespace hex::plugin::builtin {
ImGui::SameLine();
ImGui::SmallProgressBar(taskProgress, (ImGui::GetCurrentWindow()->MenuBarHeight() - 10 * SharedData::globalScale) / 2.0);
ImGui::SmallProgressBar(taskProgress, (ImGui::GetCurrentWindow()->MenuBarHeight() - 10_scaled) / 2.0);
ImGui::InfoTooltip(taskName.c_str());
}
@ -133,7 +133,7 @@ namespace hex::plugin::builtin {
if (ImHexApi::Provider::isValid())
preview = providers[SharedData::currentProvider]->getName();
ImGui::SetNextItemWidth(200 * SharedData::globalScale);
ImGui::SetNextItemWidth(200_scaled);
if (ImGui::BeginCombo("", preview.c_str())) {
for (int i = 0; i < providers.size(); i++) {

View File

@ -48,7 +48,7 @@ namespace hex::plugin::builtin {
if (ImHexApi::Provider::isValid() && provider >= 0)
preview = providers[provider]->getName();
ImGui::SetNextItemWidth(200 * SharedData::globalScale);
ImGui::SetNextItemWidth(200_scaled);
if (ImGui::BeginCombo("", preview.c_str())) {
for (int i = 0; i < providers.size(); i++) {

View File

@ -113,7 +113,7 @@ namespace hex::plugin::builtin {
}
void ViewHelp::drawAboutPopup() {
ImGui::SetNextWindowSize(ImVec2(600, 350) * SharedData::globalScale, ImGuiCond_Always);
ImGui::SetNextWindowSize(scaled(ImVec2(600, 350)), ImGuiCond_Always);
if (ImGui::BeginPopupModal(View::toWindowName("hex.builtin.view.help.about.name").c_str(), &this->m_aboutWindowOpen, ImGuiWindowFlags_NoResize)) {
if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_Escape)))

View File

@ -177,7 +177,7 @@ namespace hex::plugin::builtin {
if (provider->getPageCount() > 1) {
ImGui::NewLine();
auto linePos = ImGui::GetCursorPosY() - 15 * SharedData::globalScale;
auto linePos = ImGui::GetCursorPosY() - 15_scaled;
ImGui::SetCursorPosY(linePos);

View File

@ -218,7 +218,7 @@ namespace hex::plugin::builtin {
}
void ViewStore::drawContent() {
ImGui::SetNextWindowSizeConstraints(ImVec2(600, 400) * SharedData::globalScale, ImVec2(FLT_MAX, FLT_MAX));
ImGui::SetNextWindowSizeConstraints(scaled(ImVec2(600, 400)), ImVec2(FLT_MAX, FLT_MAX));
if (ImGui::BeginPopupModal(View::toWindowName("hex.builtin.view.store.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_AlwaysAutoResize)) {
if (this->m_apiRequest.valid()) {
if (this->m_apiRequest.wait_for(0s) != std::future_status::ready)

View File

@ -23,8 +23,14 @@
#define TOKEN_CONCAT(x, y) TOKEN_CONCAT_IMPL(x, y)
#define ANONYMOUS_VARIABLE(prefix) TOKEN_CONCAT(prefix, __COUNTER__)
struct ImVec2;
namespace hex {
long double operator""_scaled(long double value);
long double operator""_scaled(unsigned long long value);
ImVec2 scaled(const ImVec2 &vector);
std::string to_string(u128 value);
std::string to_string(s128 value);

View File

@ -6,6 +6,7 @@
#include <filesystem>
#include <hex/helpers/fmt.hpp>
#include <hex/helpers/shared_data.hpp>
#if defined (OS_WINDOWS)
#include <windows.h>
@ -18,6 +19,18 @@
namespace hex {
long double operator""_scaled(long double value) {
return value * SharedData::globalScale;
}
long double operator""_scaled(unsigned long long value) {
return value * SharedData::globalScale;
}
ImVec2 scaled(const ImVec2 &vector) {
return vector * SharedData::globalScale;
}
std::string to_string(u128 value) {
char data[45] = { 0 };

View File

@ -23,7 +23,7 @@ namespace hex {
}
void View::drawCommonInterfaces() {
ImGui::SetNextWindowSizeConstraints(ImVec2(400, 100) * SharedData::globalScale, ImVec2(600, 300) * SharedData::globalScale);
ImGui::SetNextWindowSizeConstraints(scaled(ImVec2(400, 100)), scaled(ImVec2(600, 300)));
if (ImGui::BeginPopupModal("hex.common.info"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::TextWrapped("%s", SharedData::popupMessage.c_str());
ImGui::NewLine();
@ -35,7 +35,7 @@ namespace hex {
ImGui::EndPopup();
}
ImGui::SetNextWindowSizeConstraints(ImVec2(400, 100) * SharedData::globalScale, ImVec2(600, 300) * SharedData::globalScale);
ImGui::SetNextWindowSizeConstraints(scaled(ImVec2(400, 100)), scaled(ImVec2(600, 300)));
if (ImGui::BeginPopupModal("hex.common.error"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::TextWrapped("%s", SharedData::popupMessage.c_str());
ImGui::NewLine();
@ -47,7 +47,7 @@ namespace hex {
ImGui::EndPopup();
}
ImGui::SetNextWindowSizeConstraints(ImVec2(400, 100) * SharedData::globalScale, ImVec2(600, 300) * SharedData::globalScale);
ImGui::SetNextWindowSizeConstraints(scaled(ImVec2(400, 100)), scaled(ImVec2(600, 300)));
if (ImGui::BeginPopupModal("hex.common.fatal"_lang, nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::TextWrapped("%s", SharedData::popupMessage.c_str());
ImGui::NewLine();
@ -85,7 +85,7 @@ namespace hex {
}
ImVec2 View::getMinSize() const {
return ImVec2(480, 720) * SharedData::globalScale;
return scaled(ImVec2(480, 720));
}
ImVec2 View::getMaxSize() const {

View File

@ -175,7 +175,7 @@ namespace hex::init {
}
}
this->m_window = glfwCreateWindow(640 * SharedData::globalScale, 400 * SharedData::globalScale, "Starting ImHex...", nullptr, nullptr);
this->m_window = glfwCreateWindow(640_scaled, 400_scaled, "Starting ImHex...", nullptr, nullptr);
if (this->m_window == nullptr) {
log::fatal("Failed to create GLFW window!");
exit(EXIT_FAILURE);
@ -203,7 +203,7 @@ namespace hex::init {
ImFontConfig cfg;
cfg.OversampleH = cfg.OversampleV = 1, cfg.PixelSnapH = true;
cfg.SizePixels = 13.0f * SharedData::globalScale;
cfg.SizePixels = 13.0_scaled;
io.Fonts->AddFontDefault(&cfg);
cfg.MergeMode = true;
@ -214,7 +214,7 @@ namespace hex::init {
};
std::uint8_t *px;
int w, h;
io.Fonts->AddFontFromMemoryCompressedTTF(font_awesome_compressed_data, font_awesome_compressed_size, 11.0f * SharedData::globalScale, &cfg, fontAwesomeRange);
io.Fonts->AddFontFromMemoryCompressedTTF(font_awesome_compressed_data, font_awesome_compressed_size, 11.0_scaled, &cfg, fontAwesomeRange);
io.Fonts->GetTexDataAsRGBA32(&px, &w, &h);
// Create new font atlas

View File

@ -136,7 +136,7 @@ namespace hex::init {
fonts->Clear();
cfg.OversampleH = cfg.OversampleV = 1, cfg.PixelSnapH = true;
cfg.SizePixels = 13.0f * SharedData::fontScale;
cfg.SizePixels = 13.0F * SharedData::fontScale;
fonts->AddFontDefault(&cfg);
} else {
// Load custom font
@ -151,9 +151,9 @@ namespace hex::init {
cfg.MergeMode = true;
fonts->AddFontFromMemoryCompressedTTF(font_awesome_compressed_data, font_awesome_compressed_size, 13.0f * SharedData::fontScale, &cfg, fontAwesomeRange);
fonts->AddFontFromMemoryCompressedTTF(codicons_compressed_data, codicons_compressed_size, 13.0f * SharedData::fontScale, &cfg, codiconsRange);
fonts->AddFontFromMemoryCompressedTTF(unifont_compressed_data, unifont_compressed_size, 13.0f * SharedData::fontScale, &cfg, unifontRange);
fonts->AddFontFromMemoryCompressedTTF(font_awesome_compressed_data, font_awesome_compressed_size, 13.0F * SharedData::fontScale, &cfg, fontAwesomeRange);
fonts->AddFontFromMemoryCompressedTTF(codicons_compressed_data, codicons_compressed_size, 13.0F * SharedData::fontScale, &cfg, codiconsRange);
fonts->AddFontFromMemoryCompressedTTF(unifont_compressed_data, unifont_compressed_size, 13.0F * SharedData::fontScale, &cfg, unifontRange);
ImGuiFreeType::BuildFontAtlas(fonts);

View File

@ -417,7 +417,7 @@ namespace hex {
static char title[256];
ImFormatString(title, IM_ARRAYSIZE(title), "%s/DockSpace_%08X", ImGui::GetCurrentWindow()->Name, ImGui::GetID("MainDock"));
if (ImGui::Begin(title)) {
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10 * SharedData::globalScale, 10 * SharedData::globalScale));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10_scaled, 10_scaled));
if (ImGui::BeginChild("Welcome Screen", ImVec2(0, 0), false, ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_NoScrollWithMouse)) {
this->drawWelcomeScreen();
}
@ -598,7 +598,7 @@ namespace hex {
ImGui::UnderlinedText("hex.welcome.header.start"_lang);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5 * SharedData::globalScale);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5_scaled);
{
if (ImGui::IconHyperlink(ICON_VS_NEW_FILE, "hex.welcome.start.create_file"_lang))
EventManager::post<RequestOpenWindow>("Create File");
@ -626,7 +626,7 @@ namespace hex {
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 9);
ImGui::TableNextColumn();
ImGui::UnderlinedText("hex.welcome.start.recent"_lang);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5 * SharedData::globalScale);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5_scaled);
{
if (!SharedData::recentFilePaths.empty()) {
for (auto &path : SharedData::recentFilePaths) {
@ -651,7 +651,7 @@ namespace hex {
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetTextLineHeightWithSpacing() * 6);
ImGui::TableNextColumn();
ImGui:: UnderlinedText("hex.welcome.header.help"_lang);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5 * SharedData::globalScale);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 5_scaled);
{
if (ImGui::IconHyperlink(ICON_VS_GITHUB, "hex.welcome.help.repo"_lang)) hex::openWebpage("hex.welcome.help.repo.link"_lang);
if (ImGui::IconHyperlink(ICON_VS_ORGANIZATION, "hex.welcome.help.gethelp"_lang)) hex::openWebpage("hex.welcome.help.gethelp.link"_lang);
@ -778,7 +778,7 @@ namespace hex {
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
this->m_windowTitle = "ImHex";
this->m_window = glfwCreateWindow(1280 * SharedData::globalScale, 720 * SharedData::globalScale, this->m_windowTitle.c_str(), nullptr, nullptr);
this->m_window = glfwCreateWindow(1280_scaled, 720_scaled, this->m_windowTitle.c_str(), nullptr, nullptr);
glfwSetWindowUserPointer(this->m_window, this);
@ -903,7 +903,7 @@ namespace hex {
EventManager::post<EventWindowClosing>(window);
});
glfwSetWindowSizeLimits(this->m_window, 720 * SharedData::globalScale, 480 * SharedData::globalScale, GLFW_DONT_CARE, GLFW_DONT_CARE);
glfwSetWindowSizeLimits(this->m_window, 720_scaled, 480_scaled, GLFW_DONT_CARE, GLFW_DONT_CARE);
glfwShowWindow(this->m_window);
}