diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index 3dbad139a3..25e5e575ce 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -68,6 +68,12 @@ static const wxString entrySizeX = "Size_x"; ///< Width of frame, in pixels (suf static const wxString entryMaximized = "Maximized"; ///< Nonzero iff frame is maximized (suffix) ///@} + +BEGIN_EVENT_TABLE( EDA_BASE_FRAME, wxFrame ) + EVT_MOVE( EDA_BASE_FRAME::OnMove ) +END_EVENT_TABLE() + + EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType, const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize, long aStyle, const wxString& aFrameName ) : diff --git a/common/gal/gal_display_options.cpp b/common/gal/gal_display_options.cpp index 23cc0782b9..0e67852f15 100644 --- a/common/gal/gal_display_options.cpp +++ b/common/gal/gal_display_options.cpp @@ -64,6 +64,7 @@ static const wxChar* traceGalDispOpts = wxT( "KICAD_GAL_DISPLAY_OPTIONS" ); GAL_DISPLAY_OPTIONS::GAL_DISPLAY_OPTIONS() : gl_antialiasing_mode( OPENGL_ANTIALIASING_MODE::NONE ), cairo_antialiasing_mode( CAIRO_ANTIALIASING_MODE::NONE ), + m_dpi( nullptr, nullptr ), m_gridStyle( GRID_STYLE::DOTS ), m_gridLineWidth( 1.0 ), m_gridMinSpacing( 10.0 ), @@ -109,12 +110,10 @@ void GAL_DISPLAY_OPTIONS::ReadCommonConfig( wxConfigBase& aCommonConfig, wxWindo CAIRO_ANTIALIASING_MODE_KEY, &temp, (int) KIGFX::CAIRO_ANTIALIASING_MODE::NONE ); cairo_antialiasing_mode = (KIGFX::CAIRO_ANTIALIASING_MODE) temp; - { - const DPI_SCALING dpi{ &aCommonConfig, aWindow }; - m_scaleFactor = dpi.GetScaleFactor(); - } + m_dpi = DPI_SCALING( &aCommonConfig, aWindow ); - NotifyChanged(); + // Also calls NotifyChanged + UpdateScaleFactor(); } @@ -146,6 +145,13 @@ void GAL_DISPLAY_OPTIONS::WriteConfig( wxConfigBase& aCfg, const wxString& aBase } +void GAL_DISPLAY_OPTIONS::UpdateScaleFactor() +{ + m_scaleFactor = m_dpi.GetScaleFactor(); + NotifyChanged(); +} + + void GAL_DISPLAY_OPTIONS::NotifyChanged() { wxLogTrace( traceGalDispOpts, "Change notification" ); diff --git a/common/legacy_gal/eda_draw_frame.cpp b/common/legacy_gal/eda_draw_frame.cpp index 201d1ec801..f1c385221d 100644 --- a/common/legacy_gal/eda_draw_frame.cpp +++ b/common/legacy_gal/eda_draw_frame.cpp @@ -672,6 +672,23 @@ void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv ) } +void EDA_DRAW_FRAME::OnMove( wxMoveEvent& aEvent ) +{ + // If the window is moved to a different display, the scaling factor may change + double oldFactor = m_galDisplayOptions.m_scaleFactor; + m_galDisplayOptions.UpdateScaleFactor(); + + if( oldFactor != m_galDisplayOptions.m_scaleFactor ) + { + wxSize clientSize = GetClientSize(); + GetGalCanvas()->GetGAL()->ResizeScreen( clientSize.x, clientSize.y ); + GetGalCanvas()->GetView()->MarkDirty(); + } + + aEvent.Skip(); +} + + void EDA_DRAW_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg ) { // Keep default cursor in toolbars diff --git a/common/legacy_wx/eda_draw_frame.cpp b/common/legacy_wx/eda_draw_frame.cpp index 50d5eacbce..9a54692c78 100644 --- a/common/legacy_wx/eda_draw_frame.cpp +++ b/common/legacy_wx/eda_draw_frame.cpp @@ -687,6 +687,12 @@ void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv ) } +void EDA_DRAW_FRAME::OnMove( wxMoveEvent& aEvent ) +{ + aEvent.Skip(); +} + + void EDA_DRAW_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg ) { // Keep default cursor in toolbars diff --git a/include/draw_frame.h b/include/draw_frame.h index c0fb70e1a5..76581d7fd9 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -647,6 +647,8 @@ public: */ virtual void OnSize( wxSizeEvent& event ); + void OnMove( wxMoveEvent& aEvent ) override; + void OnEraseBackground( wxEraseEvent& SizeEvent ); virtual void OnZoom( wxCommandEvent& event ); diff --git a/include/eda_base_frame.h b/include/eda_base_frame.h index e8d58d5397..1a6d5380b2 100644 --- a/include/eda_base_frame.h +++ b/include/eda_base_frame.h @@ -198,6 +198,8 @@ protected: virtual wxString help_name(); + DECLARE_EVENT_TABLE() + public: EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType, const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize, @@ -213,6 +215,11 @@ public: */ bool ProcessEvent( wxEvent& aEvent ) override; + virtual void OnMove( wxMoveEvent& aEvent ) + { + aEvent.Skip(); + } + void SetAutoSaveInterval( int aInterval ); int GetAutoSaveInterval() const { return m_autoSaveInterval; } diff --git a/include/gal/gal_display_options.h b/include/gal/gal_display_options.h index 961bde78c1..c45e80e94f 100644 --- a/include/gal/gal_display_options.h +++ b/include/gal/gal_display_options.h @@ -24,6 +24,7 @@ #ifndef GAL_DISPLAY_OPTIONS_H__ #define GAL_DISPLAY_OPTIONS_H__ +#include #include class wxConfigBase; @@ -102,12 +103,16 @@ namespace KIGFX void WriteConfig( wxConfigBase& aCfg, const wxString& aBaseName ); + void UpdateScaleFactor(); + void NotifyChanged(); OPENGL_ANTIALIASING_MODE gl_antialiasing_mode; CAIRO_ANTIALIASING_MODE cairo_antialiasing_mode; + DPI_SCALING m_dpi; + ///> The grid style to draw the grid in KIGFX::GRID_STYLE m_gridStyle;