diff --git a/common/gal/hidpi_gl_canvas.cpp b/common/gal/hidpi_gl_canvas.cpp index f54ac774a7..2714797799 100644 --- a/common/gal/hidpi_gl_canvas.cpp +++ b/common/gal/hidpi_gl_canvas.cpp @@ -37,10 +37,7 @@ HIDPI_GL_CANVAS::HIDPI_GL_CANVAS( wxWindow *parent, const wxPalette& palette ) : wxGLCanvas( parent, dispAttrs, id, pos, size, style, name, palette ) { -#ifdef RETINA_OPENGL_PATCH - SetViewWantsBestResolution( true ); - scaleFactor = GetBackingScaleFactor(); -#endif + initialize(); } HIDPI_GL_CANVAS::HIDPI_GL_CANVAS( wxWindow *parent, @@ -53,10 +50,7 @@ HIDPI_GL_CANVAS::HIDPI_GL_CANVAS( wxWindow *parent, const wxPalette& palette ) : wxGLCanvas( parent, id, attribList, pos, size, style, name, palette ) { -#ifdef RETINA_OPENGL_PATCH - SetViewWantsBestResolution( true ); - scaleFactor = GetBackingScaleFactor(); -#endif + initialize(); } @@ -65,9 +59,29 @@ wxSize HIDPI_GL_CANVAS::GetClientSize() const wxSize size = wxGLCanvas::GetClientSize(); #ifdef RETINA_OPENGL_PATCH + const float scaleFactor = GetBackingScaleFactor(); size.x *= scaleFactor; size.y *= scaleFactor; #endif return size; } + +float HIDPI_GL_CANVAS::GetBackingScaleFactor() const +{ +#ifdef RETINA_OPENGL_PATCH + // this is ugly, but original method isn't marked const although it doesn't modify anything + // => clean up when it officially has arrived in wxWidgets + return static_cast< wxGLCanvas* >( const_cast< HIDPI_GL_CANVAS* >( this ))->GetBackingScaleFactor(); +#else + return 1.0f; +#endif +} + + +void HIDPI_GL_CANVAS::initialize() +{ +#ifdef RETINA_OPENGL_PATCH + SetViewWantsBestResolution( true ); +#endif +} diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 8e014a0c0d..3113345740 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -68,7 +68,7 @@ OPENGL_GAL::OPENGL_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent, wxEvtHandler* aMouseListener, wxEvtHandler* aPaintListener, const wxString& aName ) : GAL( aDisplayOptions ), - wxGLCanvas( aParent, wxID_ANY, (int*) glAttributes, wxDefaultPosition, wxDefaultSize, + HIDPI_GL_CANVAS( aParent, wxID_ANY, (int*) glAttributes, wxDefaultPosition, wxDefaultSize, wxEXPAND, aName ), mouseListener( aMouseListener ), paintListener( aPaintListener ), currentManager( nullptr ), cachedManager( nullptr ), nonCachedManager( nullptr ), overlayManager( nullptr ) @@ -96,10 +96,6 @@ OPENGL_GAL::OPENGL_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent, isGrouping = false; groupCounter = 0; -#ifdef RETINA_OPENGL_PATCH - SetViewWantsBestResolution( true ); -#endif - // Connecting the event handlers Connect( wxEVT_PAINT, wxPaintEventHandler( OPENGL_GAL::onPaint ) ); @@ -1155,13 +1151,8 @@ void OPENGL_GAL::ResizeScreen( int aWidth, int aHeight ) { screenSize = VECTOR2I( aWidth, aHeight ); -#ifdef RETINA_OPENGL_PATCH - const float scaleFactor = GetBackingScaleFactor(); -#else - const float scaleFactor = 1.0f; -#endif - // Resize framebuffers + const float scaleFactor = GetBackingScaleFactor(); compositor->Resize( aWidth * scaleFactor, aHeight * scaleFactor ); isFramebufferInitialized = false; diff --git a/include/gal/hidpi_gl_canvas.h b/include/gal/hidpi_gl_canvas.h index 0cd25a5c73..e740cc8fb6 100644 --- a/include/gal/hidpi_gl_canvas.h +++ b/include/gal/hidpi_gl_canvas.h @@ -40,6 +40,7 @@ class HIDPI_GL_CANVAS : public wxGLCanvas { public: + // wxGLCanvas constructor HIDPI_GL_CANVAS( wxWindow *parent, const wxGLAttributes& dispAttrs, wxWindowID id = wxID_ANY, @@ -49,6 +50,7 @@ public: const wxString& name = wxGLCanvasName, const wxPalette& palette = wxNullPalette ); + // wxGLCanvas constructor HIDPI_GL_CANVAS( wxWindow *parent, wxWindowID id = wxID_ANY, const int *attribList = NULL, @@ -58,13 +60,19 @@ public: const wxString& name = wxGLCanvasName, const wxPalette& palette = wxNullPalette ); - wxSize GetClientSize() const; + + // wxGLCanvas override + virtual wxSize GetClientSize() const; + + // wxGLCanvas override (with patch applied) or default value of 1.0 + virtual float GetBackingScaleFactor() const; -#ifdef RETINA_OPENGL_PATCH private: - float scaleFactor; -#endif + /** + * @brief Common initialization + */ + void initialize(); }; #endif // HIDPI_GL_CANVAS_H diff --git a/include/gal/opengl/opengl_gal.h b/include/gal/opengl/opengl_gal.h index 201302eeb6..30a3b70769 100644 --- a/include/gal/opengl/opengl_gal.h +++ b/include/gal/opengl/opengl_gal.h @@ -38,8 +38,7 @@ #include #include #include - -#include +#include #include #include @@ -62,7 +61,7 @@ class SHADER; * and quads. The purpose is to provide a fast graphics interface, that takes advantage of modern * graphics card GPUs. All methods here benefit thus from the hardware acceleration. */ -class OPENGL_GAL : public GAL, public wxGLCanvas +class OPENGL_GAL : public GAL, public HIDPI_GL_CANVAS { public: /**