Browse Source

Windows: Added a workaround for non-DPI aware windows having an incorrect scale factor when using the OpenGL renderer

tags/2021-05-28
ed 7 years ago
parent
commit
97c100b9c1
3 changed files with 20 additions and 7 deletions
  1. +5
    -0
      modules/juce_gui_basics/native/juce_win32_Windowing.cpp
  2. +9
    -0
      modules/juce_opengl/native/juce_OpenGL_win32.h
  3. +6
    -7
      modules/juce_opengl/opengl/juce_OpenGLContext.cpp

+ 5
- 0
modules/juce_gui_basics/native/juce_win32_Windowing.cpp View File

@@ -4020,6 +4020,11 @@ JUCE_API ComponentPeer* createNonRepaintingEmbeddedWindowsPeer (Component& compo
(HWND) parentHWND, true);
}
JUCE_API bool shouldScaleGLWindow (void* hwnd)
{
return isPerMonitorDPIAwareWindow ((HWND) hwnd);
}
JUCE_IMPLEMENT_SINGLETON (HWNDComponentPeer::WindowClassHolder)
//==============================================================================


+ 9
- 0
modules/juce_opengl/native/juce_OpenGL_win32.h View File

@@ -28,6 +28,7 @@ namespace juce
{
extern ComponentPeer* createNonRepaintingEmbeddedWindowsPeer (Component&, void* parent);
extern bool shouldScaleGLWindow (void* hwnd);
//==============================================================================
class OpenGLContext::NativeContext
@@ -160,6 +161,14 @@ public:
}
#endif
double getWindowScaleFactor (const Rectangle<int>& screenBounds)
{
if (nativeWindow != nullptr && shouldScaleGLWindow (nativeWindow->getNativeHandle()))
return Desktop::getInstance().getDisplays().findDisplayForRect (screenBounds).scale;
return 1.0;
}
private:
struct DummyComponent : public Component
{


+ 6
- 7
modules/juce_opengl/opengl/juce_OpenGLContext.cpp View File

@@ -280,15 +280,14 @@ public:
{
if (auto* peer = component.getPeer())
{
lastScreenBounds = component.getTopLevelComponent()->getScreenBounds();
auto newScale = Desktop::getInstance().getDisplays().findDisplayForRect (lastScreenBounds).scale;
#if JUCE_WINDOWS
auto newScale = nativeContext->getWindowScaleFactor (component.getTopLevelComponent()->getScreenBounds());
#else
auto newScale = Desktop::getInstance().getDisplays().findDisplayForRect (component.getTopLevelComponent()->getScreenBounds()).scale;
#endif
auto localBounds = component.getLocalBounds();
auto newArea = peer->getComponent().getLocalArea (&component, localBounds)
.withZeroOrigin()
* newScale;
auto newArea = peer->getComponent().getLocalArea (&component, localBounds).withZeroOrigin() * newScale;
if (scale != newScale || viewportArea != newArea)
{


Loading…
Cancel
Save