1
0
mirror of synced 2024-09-25 03:58:27 +02:00

ui: Make splash screen DPI aware

This commit is contained in:
WerWolv 2021-08-04 18:57:53 +02:00
parent 0093d4418e
commit c75659db82
2 changed files with 23 additions and 10 deletions

View File

@ -27,6 +27,8 @@ namespace hex::init {
float m_progress = 0;
std::string m_currTaskName;
float m_globalScale = 1.0F;
void initGLFW();
void initImGui();

View File

@ -5,6 +5,7 @@
#include <hex/resources.hpp>
#include <imgui.h>
#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui_internal.h>
#include <imgui_imhex_extensions.h>
#include <imgui_impl_glfw.h>
@ -92,17 +93,18 @@ namespace hex::init {
auto drawList = ImGui::GetOverlayDrawList();
drawList->AddImage(splashTexture, ImVec2(0, 0), ImVec2(splashWidth, splashHeight));
drawList->AddImage(splashTexture, ImVec2(0, 0), ImVec2(splashWidth, splashHeight) * this->m_globalScale);
drawList->AddText(ImVec2(15, 120) * this->m_globalScale, ImColor(0xFF, 0xFF, 0xFF, 0xFF), hex::format("WerWolv 2020 - {0}", &__DATE__[7]).c_str());
#if defined(DEBUG)
drawList->AddText(ImVec2(15, 120), ImColor(0xFF, 0xFF, 0xFF, 0xFF), hex::format("WerWolv 2020 - {0}", &__DATE__[7]).c_str());
drawList->AddText(ImVec2(15, 140), ImColor(0xFF, 0xFF, 0xFF, 0xFF), hex::format("{0} : {1} {2}@{3}", IMHEX_VERSION, ICON_FA_CODE_BRANCH, GIT_BRANCH, GIT_COMMIT_HASH).c_str());
drawList->AddText(ImVec2(15, 140) * this->m_globalScale, ImColor(0xFF, 0xFF, 0xFF, 0xFF), hex::format("{0} : {1} {2}@{3}", IMHEX_VERSION, ICON_FA_CODE_BRANCH, GIT_BRANCH, GIT_COMMIT_HASH).c_str());
#else
drawList->AddText(ImVec2(15, 120), ImColor(0xFF, 0xFF, 0xFF, 0xFF), hex::format("WerWolv 2020 - {0}", &__DATE__[7]).c_str());
drawList->AddText(ImVec2(15, 140), ImColor(0xFF, 0xFF, 0xFF, 0xFF), hex::format("{0}", IMHEX_VERSION).c_str());
drawList->AddText(ImVec2(15, 140) * this->m_globalScale, ImColor(0xFF, 0xFF, 0xFF, 0xFF), hex::format("{0}", IMHEX_VERSION).c_str());
#endif
drawList->AddRectFilled(ImVec2(0, splashHeight - 5), ImVec2(splashWidth * this->m_progress, splashHeight), 0xFFFFFFFF);
drawList->AddText(ImVec2(15, splashHeight - 25), ImColor(0xFF, 0xFF, 0xFF, 0xFF),
drawList->AddRectFilled(ImVec2(0, splashHeight - 5) * this->m_globalScale, ImVec2(splashWidth * this->m_progress, splashHeight) * this->m_globalScale, 0xFFFFFFFF);
drawList->AddText(ImVec2(15, splashHeight - 25) * this->m_globalScale, ImColor(0xFF, 0xFF, 0xFF, 0xFF),
hex::format("[{}] {}", "|/-\\"[ImU32(ImGui::GetTime() * 15) % 4], this->m_currTaskName).c_str());
}
@ -164,7 +166,14 @@ namespace hex::init {
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
glfwWindowHint(GLFW_FLOATING, GLFW_TRUE);
this->m_window = glfwCreateWindow(640, 400, "ImHex", nullptr, nullptr);
if (GLFWmonitor *monitor = glfwGetPrimaryMonitor(); monitor != nullptr) {
float xscale, yscale;
glfwGetMonitorContentScale(monitor, &xscale, &yscale);
this->m_globalScale = std::midpoint(xscale, yscale);
}
this->m_window = glfwCreateWindow(640 * this->m_globalScale, 400 * this->m_globalScale, "ImHex", nullptr, nullptr);
if (this->m_window == nullptr) {
log::fatal("Failed to create GLFW window!");
exit(EXIT_FAILURE);
@ -191,11 +200,13 @@ namespace hex::init {
auto &io = ImGui::GetIO();
ImGui::GetStyle().ScaleAllSizes(this->m_globalScale);
io.Fonts->Clear();
ImFontConfig cfg;
cfg.OversampleH = cfg.OversampleV = 1, cfg.PixelSnapH = true;
cfg.SizePixels = 13.0f;
cfg.SizePixels = 13.0f * this->m_globalScale;
io.Fonts->AddFontDefault(&cfg);
cfg.MergeMode = true;
@ -206,7 +217,7 @@ namespace hex::init {
};
std::uint8_t *px;
int w, h;
io.Fonts->AddFontFromMemoryCompressedTTF(font_awesome_compressed_data, font_awesome_compressed_size, 11.0f, &cfg, fontAwesomeRange);
io.Fonts->AddFontFromMemoryCompressedTTF(font_awesome_compressed_data, font_awesome_compressed_size, 11.0f * this->m_globalScale, &cfg, fontAwesomeRange);
io.Fonts->GetTexDataAsRGBA32(&px, &w, &h);
// Create new font atlas