impr: Refactor previous commits to work with other environments too
This commit is contained in:
parent
534a2f1d28
commit
1298f2b688
@ -493,6 +493,7 @@ namespace hex {
|
||||
*/
|
||||
float getNativeScale();
|
||||
|
||||
float getBackingScaleFactor();
|
||||
|
||||
/**
|
||||
* @brief Gets the current main window position
|
||||
|
@ -18,6 +18,8 @@
|
||||
#include <algorithm>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <hex/helpers/utils_macos.hpp>
|
||||
|
||||
#if defined(OS_WINDOWS)
|
||||
#include <windows.h>
|
||||
#else
|
||||
@ -25,6 +27,10 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if defined(OS_WEB)
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
namespace hex {
|
||||
|
||||
|
||||
@ -608,6 +614,22 @@ namespace hex {
|
||||
return impl::s_nativeScale;
|
||||
}
|
||||
|
||||
float getBackingScaleFactor() {
|
||||
#if defined(OS_WINDOWS)
|
||||
return 1.0F;
|
||||
#elif defined(OS_MACOS)
|
||||
return ::getBackingScaleFactor();
|
||||
#elif defined(OS_LINUX)
|
||||
return 1.0F;
|
||||
#elif defined(OS_WEB)
|
||||
return EM_ASM_INT({
|
||||
return window.devicePixelRatio;
|
||||
});
|
||||
#else
|
||||
return 1.0F;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
ImVec2 getMainWindowPosition() {
|
||||
if ((ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) != ImGuiConfigFlags_None)
|
||||
|
@ -223,11 +223,7 @@ namespace ImGuiExt {
|
||||
}
|
||||
|
||||
Texture Texture::fromSVG(const char *path, int width, int height, Filter filter) {
|
||||
#if defined(OS_MACOS)
|
||||
const auto scaleFactor = getBackingScaleFactor();
|
||||
#else
|
||||
const auto scaleFactor = 1.0F;
|
||||
#endif
|
||||
const auto scaleFactor = hex::ImHexApi::System::getBackingScaleFactor();
|
||||
|
||||
auto document = lunasvg::Document::loadFromFile(path);
|
||||
auto bitmap = document->renderToBitmap(width * scaleFactor, height * scaleFactor);
|
||||
@ -247,11 +243,7 @@ namespace ImGuiExt {
|
||||
}
|
||||
|
||||
Texture Texture::fromSVG(std::span<const std::byte> buffer, int width, int height, Filter filter) {
|
||||
#if defined(OS_MACOS)
|
||||
const auto scaleFactor = getBackingScaleFactor();
|
||||
#else
|
||||
const auto scaleFactor = 1.0F;
|
||||
#endif
|
||||
const auto scaleFactor = hex::ImHexApi::System::getBackingScaleFactor();
|
||||
|
||||
auto document = lunasvg::Document::loadFromData(reinterpret_cast<const char*>(buffer.data()), buffer.size());
|
||||
auto bitmap = document->renderToBitmap(width * scaleFactor, height * scaleFactor);
|
||||
|
@ -469,11 +469,7 @@ namespace hex::init {
|
||||
if (meanScale <= 0.0F)
|
||||
meanScale = 1.0F;
|
||||
|
||||
#if defined(OS_MACOS)
|
||||
meanScale /= getBackingScaleFactor();
|
||||
#elif defined(OS_WEB)
|
||||
meanScale = 1.0F;
|
||||
#endif
|
||||
meanScale /= hex::ImHexApi::System::getBackingScaleFactor();
|
||||
|
||||
ImHexApi::System::impl::setGlobalScale(meanScale);
|
||||
ImHexApi::System::impl::setNativeScale(meanScale);
|
||||
|
@ -96,9 +96,6 @@ namespace hex {
|
||||
auto win = static_cast<Window *>(glfwGetWindowUserPointer(window));
|
||||
win->fullFrame();
|
||||
});
|
||||
|
||||
// Done to get super crisp font rendering together with GLFW_COCOA_RETINA_FRAMEBUFFER
|
||||
ImGui::GetIO().FontGlobalScale = 1.0F / getBackingScaleFactor();
|
||||
}
|
||||
|
||||
void Window::beginNativeWindowFrame() {
|
||||
|
@ -746,6 +746,8 @@ namespace hex {
|
||||
// NOTE: This needs to be done before a new frame is started, otherwise ImGui won't handle docking correctly
|
||||
LayoutManager::process();
|
||||
WorkspaceManager::process();
|
||||
|
||||
ImGui::GetIO().FontGlobalScale = 1.0F / ImHexApi::System::getBackingScaleFactor();
|
||||
}
|
||||
|
||||
void Window::initGLFW() {
|
||||
|
@ -218,15 +218,11 @@ namespace hex::fonts {
|
||||
}
|
||||
|
||||
private:
|
||||
float getAdjustedFontSize(float fontSize) {
|
||||
float getAdjustedFontSize(float fontSize) const {
|
||||
// Since macOS reports half the framebuffer size that's actually available,
|
||||
// we'll multiply all font sizes by that and then divide the global font scale
|
||||
// by the same amount to get super crisp font rendering.
|
||||
#if defined(OS_MACOS)
|
||||
return fontSize * getBackingScaleFactor();
|
||||
#else
|
||||
return fontSize;
|
||||
#endif
|
||||
return fontSize * hex::ImHexApi::System::getBackingScaleFactor();
|
||||
}
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user