Use wxWidgets to track DPI.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17981
This commit is contained in:
Jeff Young 2024-05-31 17:06:03 +01:00
parent e3f77cd410
commit 931de12072
8 changed files with 2 additions and 73 deletions

View File

@ -103,11 +103,6 @@ EDA_3D_MODEL_VIEWER::EDA_3D_MODEL_VIEWER( wxWindow* aParent, const wxGLAttribute
m_BiuTo3dUnits = 1.0;
m_glRC = nullptr;
COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
const DPI_SCALING_COMMON dpi{ settings, this };
SetScaleFactor( dpi.GetScaleFactor() );
}

View File

@ -194,14 +194,6 @@ EDA_3D_VIEWER_FRAME::EDA_3D_VIEWER_FRAME( KIWAY* aKiway, PCB_BASE_FRAME* aParent
wxLogTrace( wxT( "KI_TRACE_NAVLIB" ), e.what() );
}
Bind( wxEVT_DPI_CHANGED,
[&]( wxDPIChangedEvent& aEvt )
{
const DPI_SCALING_COMMON dpi{ Pgm().GetCommonSettings(), this };
m_canvas->SetScaleFactor( dpi.GetScaleFactor() );
aEvt.Skip();
} );
// Fixes bug in Windows (XP and possibly others) where the canvas requires the focus
// in order to receive mouse events. Otherwise, the user has to click somewhere on
// the canvas before it will respond to mouse wheel events.
@ -819,9 +811,6 @@ void EDA_3D_VIEWER_FRAME::loadCommonSettings()
COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
const DPI_SCALING_COMMON dpi{ settings, this };
m_canvas->SetScaleFactor( dpi.GetScaleFactor() );
// TODO(JE) use all control options
m_boardAdapter.m_MousewheelPanning = settings->m_Input.scroll_modifier_zoom != 0;
}

View File

@ -163,14 +163,6 @@ PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL( wxWindow* aParent, PCB_BASE_FRAM
aFrame->Connect( EDA_EVT_UNITS_CHANGED,
wxCommandEventHandler( PANEL_PREVIEW_3D_MODEL::onUnitsChanged ),
nullptr, this );
Bind( wxEVT_DPI_CHANGED,
[&]( wxDPIChangedEvent& aEvt )
{
const DPI_SCALING_COMMON dpi{ Pgm().GetCommonSettings(), this };
m_previewPane->SetScaleFactor( dpi.GetScaleFactor() );
aEvt.Skip();
} );
}
@ -200,9 +192,6 @@ void PANEL_PREVIEW_3D_MODEL::loadSettings()
COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
const DPI_SCALING_COMMON dpi{ settings, this };
m_previewPane->SetScaleFactor( dpi.GetScaleFactor() );
// TODO(JE) use all control options
m_boardAdapter.m_MousewheelPanning = settings->m_Input.scroll_modifier_zoom != 0;

View File

@ -34,8 +34,7 @@ HIDPI_GL_CANVAS::HIDPI_GL_CANVAS( const KIGFX::VC_SETTINGS& aSettings, wxWindow*
const wxPoint& aPos, const wxSize& aSize, long aStyle,
const wxString& aName, const wxPalette& aPalette ) :
wxGLCanvas( aParent, aGLAttribs, aId, aPos, aSize, aStyle, aName, aPalette ),
m_settings( aSettings ),
m_scale_factor( DPI_SCALING::GetDefaultScaleFactor() )
m_settings( aSettings )
{
}
@ -64,13 +63,7 @@ wxPoint HIDPI_GL_CANVAS::GetNativePosition( const wxPoint& aPoint ) const
}
void HIDPI_GL_CANVAS::SetScaleFactor( double aNewScaleFactor )
{
m_scale_factor = aNewScaleFactor;
}
double HIDPI_GL_CANVAS::GetScaleFactor() const
{
return m_scale_factor;
return GetContentScaleFactor();
}

View File

@ -515,13 +515,6 @@ bool OPENGL_GAL::updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions )
refresh = true;
}
if( m_options.m_scaleFactor != GetScaleFactor() )
{
SetScaleFactor( m_options.m_scaleFactor );
m_gridLineWidth = m_options.m_scaleFactor * ( m_options.m_gridLineWidth + 0.25 );
refresh = true;
}
if( super::updatedGalDisplayOptions( aOptions ) || refresh )
{
Refresh();

View File

@ -54,11 +54,6 @@ public:
*/
wxPoint GetNativePosition( const wxPoint& aPoint ) const;
/**
* Set the canvas scale factor, probably for a hi-DPI display.
*/
void SetScaleFactor( double aFactor );
/**
* Get the current scale factor
*/
@ -69,12 +64,6 @@ public:
protected:
///< Current VIEW_CONTROLS settings.
KIGFX::VC_SETTINGS m_settings;
private:
/**
* The current scale factor (e.g. for hi-DPI displays)
*/
double m_scale_factor;
};
#endif // HIDPI_GL_CANVAS_H

View File

@ -137,14 +137,6 @@ DIALOG_FOOTPRINT_CHOOSER::DIALOG_FOOTPRINT_CHOOSER( PCB_BASE_FRAME* aParent,
Connect( FP_SELECTION_EVENT, wxCommandEventHandler( DIALOG_FOOTPRINT_CHOOSER::onFpChanged ),
nullptr, this );
Bind( wxEVT_DPI_CHANGED,
[&]( wxDPIChangedEvent& aEvt )
{
const DPI_SCALING_COMMON dpi{ Pgm().GetCommonSettings(), this };
m_preview3DCanvas->SetScaleFactor( dpi.GetScaleFactor() );
aEvt.Skip();
} );
}
@ -188,9 +180,6 @@ void DIALOG_FOOTPRINT_CHOOSER::build3DCanvas()
COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
const DPI_SCALING_COMMON dpi{ settings, this };
m_preview3DCanvas->SetScaleFactor( dpi.GetScaleFactor() );
// TODO(JE) use all control options
m_boardAdapter.m_MousewheelPanning = settings->m_Input.scroll_modifier_zoom != 0;

View File

@ -191,14 +191,6 @@ FOOTPRINT_CHOOSER_FRAME::FOOTPRINT_CHOOSER_FRAME( KIWAY* aKiway, wxWindow* aPare
Connect( FP_SELECTION_EVENT, // custom event fired by a PANEL_FOOTPRINT_CHOOSER
wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::onFpChanged ), nullptr, this );
Bind( wxEVT_DPI_CHANGED,
[&]( wxDPIChangedEvent& aEvt )
{
const DPI_SCALING_COMMON dpi{ Pgm().GetCommonSettings(), this };
m_preview3DCanvas->SetScaleFactor( dpi.GetScaleFactor() );
aEvt.Skip();
} );
// Needed on Linux to fix the position of widgets in bottomPanel
PostSizeEvent();
}