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