Check if scaling factor has changed when top-level window is moved

Fixes #2592

(cherry picked from commit 712ae5a953)
This commit is contained in:
Jon Evans 2020-02-21 17:57:32 -05:00
parent 546260348d
commit a70cf464d6
7 changed files with 54 additions and 5 deletions

View File

@ -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 ) :

View File

@ -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" );

View File

@ -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

View File

@ -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

View File

@ -647,6 +647,8 @@ public:
*/
virtual void OnSize( wxSizeEvent& event );
void OnMove( wxMoveEvent& aEvent ) override;
void OnEraseBackground( wxEraseEvent& SizeEvent );
virtual void OnZoom( wxCommandEvent& event );

View File

@ -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; }

View File

@ -24,6 +24,7 @@
#ifndef GAL_DISPLAY_OPTIONS_H__
#define GAL_DISPLAY_OPTIONS_H__
#include <dpi_scaling.h>
#include <observable.h>
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;