diff --git a/3d-viewer/3d_canvas/eda_3d_canvas.cpp b/3d-viewer/3d_canvas/eda_3d_canvas.cpp index 77c671c242..92fdae73c8 100644 --- a/3d-viewer/3d_canvas/eda_3d_canvas.cpp +++ b/3d-viewer/3d_canvas/eda_3d_canvas.cpp @@ -90,7 +90,7 @@ EDA_3D_CANVAS::EDA_3D_CANVAS( wxWindow *aParent, BOARD *aBoard, CINFO3D_VISU &aSettings , S3D_CACHE *a3DCachePointer ) : - wxGLCanvas( aParent, + HIDPI_GL_CANVAS( aParent, wxID_ANY, aAttribList, wxDefaultPosition, @@ -516,8 +516,7 @@ void EDA_3D_CANVAS::OnMagnify( wxMouseEvent& event ) DisplayStatus(); Request_refresh(); - // Please someone test if this is need - //m_settings.CameraGet().SetCurMousePosition( event.GetPosition() ); + m_settings.CameraGet().SetCurMousePosition( event.GetPosition() ); } #endif diff --git a/3d-viewer/3d_canvas/eda_3d_canvas.h b/3d-viewer/3d_canvas/eda_3d_canvas.h index e0d601a613..b7b4a77f6e 100644 --- a/3d-viewer/3d_canvas/eda_3d_canvas.h +++ b/3d-viewer/3d_canvas/eda_3d_canvas.h @@ -36,9 +36,9 @@ #include "3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.h" #include "3d_rendering/3d_render_raytracing/c3d_render_raytracing.h" #include "3d_cache/3d_cache.h" +#include #include #include -#include #include #include #include @@ -50,7 +50,7 @@ * Class EDA_3D_CANVAS * Implement a canvas based on a wxGLCanvas */ -class EDA_3D_CANVAS : public wxGLCanvas +class EDA_3D_CANVAS : public HIDPI_GL_CANVAS { public: diff --git a/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp b/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp index f013de5339..e00a772f73 100644 --- a/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp +++ b/3d-viewer/3d_model_viewer/c3d_model_viewer.cpp @@ -83,7 +83,7 @@ END_EVENT_TABLE() C3D_MODEL_VIEWER::C3D_MODEL_VIEWER(wxWindow *aParent, const int *aAttribList , S3D_CACHE *aCacheManager) : - wxGLCanvas( aParent, + HIDPI_GL_CANVAS( aParent, wxID_ANY, aAttribList, wxDefaultPosition, diff --git a/3d-viewer/3d_model_viewer/c3d_model_viewer.h b/3d-viewer/3d_model_viewer/c3d_model_viewer.h index 2e8e3b8f29..22a65cab7b 100644 --- a/3d-viewer/3d_model_viewer/c3d_model_viewer.h +++ b/3d-viewer/3d_model_viewer/c3d_model_viewer.h @@ -33,7 +33,7 @@ #define _C3D_MODEL_VIEWER_H_ #include "3d_rendering/ctrack_ball.h" -#include +#include class S3D_CACHE; class C_OGL_3DMODEL; @@ -42,7 +42,7 @@ class C_OGL_3DMODEL; * Class C3D_MODEL_VIEWER * Implement a canvas based on a wxGLCanvas */ -class C3D_MODEL_VIEWER : public wxGLCanvas +class C3D_MODEL_VIEWER : public HIDPI_GL_CANVAS { public: diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index ae89ab4cbd..84cef320ee 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -41,6 +41,7 @@ set( GAL_SRCS view/view_controls.cpp view/wx_view_controls.cpp geometry/hetriang.cpp + gal/hidpi_gl_canvas.cpp # OpenGL GAL gal/opengl/opengl_gal.cpp diff --git a/common/gal/hidpi_gl_canvas.cpp b/common/gal/hidpi_gl_canvas.cpp new file mode 100644 index 0000000000..f54ac774a7 --- /dev/null +++ b/common/gal/hidpi_gl_canvas.cpp @@ -0,0 +1,73 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2017 Bernhard Stegmaier + * Copyright (C) 2016-2017 Kicad Developers, see change_log.txt for contributors. + * + * Base class for HiDPI aware wxGLCanvas implementations. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include + + +HIDPI_GL_CANVAS::HIDPI_GL_CANVAS( wxWindow *parent, + const wxGLAttributes& dispAttrs, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name, + const wxPalette& palette ) : + wxGLCanvas( parent, dispAttrs, id, pos, size, style, name, palette ) +{ +#ifdef RETINA_OPENGL_PATCH + SetViewWantsBestResolution( true ); + scaleFactor = GetBackingScaleFactor(); +#endif +} + +HIDPI_GL_CANVAS::HIDPI_GL_CANVAS( wxWindow *parent, + wxWindowID id, + const int *attribList, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name, + const wxPalette& palette ) : + wxGLCanvas( parent, id, attribList, pos, size, style, name, palette ) +{ +#ifdef RETINA_OPENGL_PATCH + SetViewWantsBestResolution( true ); + scaleFactor = GetBackingScaleFactor(); +#endif +} + + +wxSize HIDPI_GL_CANVAS::GetClientSize() const +{ + wxSize size = wxGLCanvas::GetClientSize(); + +#ifdef RETINA_OPENGL_PATCH + size.x *= scaleFactor; + size.y *= scaleFactor; +#endif + + return size; +} diff --git a/include/gal/hidpi_gl_canvas.h b/include/gal/hidpi_gl_canvas.h new file mode 100644 index 0000000000..0cd25a5c73 --- /dev/null +++ b/include/gal/hidpi_gl_canvas.h @@ -0,0 +1,70 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2017 Bernhard Stegmaier + * Copyright (C) 2016-2017 Kicad Developers, see change_log.txt for contributors. + * + * Base class for HiDPI aware wxGLCanvas implementations. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef HIDPI_GL_CANVAS_H +#define HIDPI_GL_CANVAS_H + +#include + + +/** + * @brief wxGLCanvas wrapper for HiDPI/Retina support. + * + * This is a small wrapper class to enable HiDPI/Retina support for wxGLCanvas. + * HiDPI currently only works with a patched wxWidgets version, see: + * http://trac.wxwidgets.org/ticket/15700 + */ +class HIDPI_GL_CANVAS : public wxGLCanvas +{ +public: + HIDPI_GL_CANVAS( wxWindow *parent, + const wxGLAttributes& dispAttrs, + wxWindowID id = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString& name = wxGLCanvasName, + const wxPalette& palette = wxNullPalette ); + + HIDPI_GL_CANVAS( wxWindow *parent, + wxWindowID id = wxID_ANY, + const int *attribList = NULL, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString& name = wxGLCanvasName, + const wxPalette& palette = wxNullPalette ); + + wxSize GetClientSize() const; + + +#ifdef RETINA_OPENGL_PATCH +private: + float scaleFactor; +#endif +}; + +#endif // HIDPI_GL_CANVAS_H