mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 05:27:41 -05:00
feat: Added DPI awareness on Windows, added FiraCode as optional default font
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
#include <hex/api/content_registry.hpp>
|
||||
#include <hex/api/theme_manager.hpp>
|
||||
|
||||
#include "window.hpp"
|
||||
|
||||
|
||||
@@ -45,6 +48,22 @@ namespace hex {
|
||||
// Custom Window procedure for receiving OS events
|
||||
static LRESULT commonWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
||||
switch (uMsg) {
|
||||
case WM_DPICHANGED: {
|
||||
int interfaceScaleSetting = int(hex::ContentRegistry::Settings::read<float>("hex.builtin.setting.interface", "hex.builtin.setting.interface.scaling_factor", 0.0F) * 10.0F);
|
||||
if (interfaceScaleSetting != 0)
|
||||
break;
|
||||
|
||||
const auto newScale = LOWORD(wParam) / 96.0F;
|
||||
const auto oldScale = ImHexApi::System::getNativeScale();
|
||||
|
||||
EventDPIChanged::post(oldScale, newScale);
|
||||
ImHexApi::System::impl::setNativeScale(newScale);
|
||||
|
||||
ThemeManager::reapplyCurrentTheme();
|
||||
ImGui::GetStyle().ScaleAllSizes(newScale);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
case WM_COPYDATA: {
|
||||
// Handle opening files in existing instance
|
||||
|
||||
@@ -371,6 +390,18 @@ namespace hex {
|
||||
|
||||
|
||||
void Window::initNative() {
|
||||
// Setup DPI Awareness
|
||||
{
|
||||
using SetProcessDpiAwarenessContextFunc = HRESULT(WINAPI *)(DPI_AWARENESS_CONTEXT);
|
||||
|
||||
SetProcessDpiAwarenessContextFunc SetProcessDpiAwarenessContext =
|
||||
(SetProcessDpiAwarenessContextFunc)(void*)GetProcAddress(GetModuleHandleW(L"user32.dll"), "SetProcessDpiAwarenessContext");
|
||||
|
||||
if (SetProcessDpiAwarenessContext != nullptr) {
|
||||
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
||||
}
|
||||
}
|
||||
|
||||
if (ImHexApi::System::isDebugBuild()) {
|
||||
// If the application is running in debug mode, ImHex runs under the CONSOLE subsystem,
|
||||
// so we don't need to do anything besides enabling ANSI colors
|
||||
|
||||
@@ -115,6 +115,21 @@ namespace hex {
|
||||
m_popupsToOpen.push_back(name);
|
||||
});
|
||||
|
||||
EventDPIChanged::subscribe([this](float oldScaling, float newScaling) {
|
||||
if (oldScaling == newScaling || oldScaling == 0 || newScaling == 0)
|
||||
return;
|
||||
|
||||
int width, height;
|
||||
glfwGetWindowSize(m_window, &width, &height);
|
||||
|
||||
width = float(width) * newScaling / oldScaling;
|
||||
height = float(height) * newScaling / oldScaling;
|
||||
|
||||
ImHexApi::System::impl::setMainWindowSize(width, height);
|
||||
glfwSetWindowSize(m_window, width, height);
|
||||
});
|
||||
|
||||
|
||||
LayoutManager::registerLoadCallback([this](std::string_view line) {
|
||||
int width = 0, height = 0;
|
||||
sscanf(line.data(), "MainWindowSize=%d,%d", &width, &height);
|
||||
@@ -827,6 +842,7 @@ namespace hex {
|
||||
|
||||
auto win = static_cast<Window *>(glfwGetWindowUserPointer(window));
|
||||
win->m_unlockFrameRate = true;
|
||||
win->fullFrame();
|
||||
});
|
||||
|
||||
// Register window resize callback
|
||||
|
||||
Reference in New Issue
Block a user