diff --git a/common/gal/gal_display_options.cpp b/common/gal/gal_display_options.cpp index 3b4be00757..62c4ead449 100644 --- a/common/gal/gal_display_options.cpp +++ b/common/gal/gal_display_options.cpp @@ -27,6 +27,7 @@ #include #include +#include using namespace KIGFX; @@ -62,38 +63,71 @@ GAL_DISPLAY_OPTIONS::GAL_DISPLAY_OPTIONS() {} -void GAL_DISPLAY_OPTIONS::ReadConfig( wxConfigBase* aCfg, const wxString& aBaseName ) +void GAL_DISPLAY_OPTIONS::ReadAppConfig( wxConfigBase& aCfg, const wxString& aBaseName ) { + const wxString baseName = aBaseName + GAL_DISPLAY_OPTIONS_KEY; + long readLong; // Temp value buffer - aCfg->Read( aBaseName + GalGridStyleConfig, &readLong, - static_cast( KIGFX::GRID_STYLE::DOTS ) ); + aCfg.Read( baseName + GalGridStyleConfig, &readLong, + static_cast( KIGFX::GRID_STYLE::DOTS ) ); m_gridStyle = UTIL::GetValFromConfig( gridStyleConfigVals, readLong ); - aCfg->Read( aBaseName + GalGridLineWidthConfig, &m_gridLineWidth, 1.0 ); - aCfg->Read( aBaseName + GalGridMaxDensityConfig, &m_gridMinSpacing, 10 ); - aCfg->Read( aBaseName + GalGridAxesEnabledConfig, &m_axesEnabled, false ); - aCfg->Read( aBaseName + GalFullscreenCursorConfig, &m_fullscreenCursor, false ); - aCfg->Read( aBaseName + GalForceDisplayCursorConfig, &m_forceDisplayCursor, true ); + aCfg.Read( baseName + GalGridLineWidthConfig, &m_gridLineWidth, 1.0 ); + aCfg.Read( baseName + GalGridMaxDensityConfig, &m_gridMinSpacing, 10 ); + aCfg.Read( baseName + GalGridAxesEnabledConfig, &m_axesEnabled, false ); + aCfg.Read( baseName + GalFullscreenCursorConfig, &m_fullscreenCursor, false ); + aCfg.Read( baseName + GalForceDisplayCursorConfig, &m_forceDisplayCursor, true ); NotifyChanged(); } -void GAL_DISPLAY_OPTIONS::WriteConfig( wxConfigBase* aCfg, const wxString& aBaseName ) +void GAL_DISPLAY_OPTIONS::ReadCommonConfig( wxConfigBase& aCommonConfig, wxWindow* aWindow ) { - aCfg->Write( aBaseName + GalGridStyleConfig, + int temp; + aCommonConfig.Read( + GAL_ANTIALIASING_MODE_KEY, &temp, (int) KIGFX::OPENGL_ANTIALIASING_MODE::NONE ); + gl_antialiasing_mode = (KIGFX::OPENGL_ANTIALIASING_MODE) temp; + + aCommonConfig.Read( + 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(); + } + + NotifyChanged(); +} + + +void GAL_DISPLAY_OPTIONS::ReadConfig( wxConfigBase& aCommonConfig, wxConfigBase& aAppConfig, + const wxString& aBaseCfgName, wxWindow* aWindow ) +{ + ReadAppConfig( aAppConfig, aBaseCfgName ); + + ReadCommonConfig( aCommonConfig, aWindow ); +} + + +void GAL_DISPLAY_OPTIONS::WriteConfig( wxConfigBase& aCfg, const wxString& aBaseName ) +{ + const wxString baseName = aBaseName + GAL_DISPLAY_OPTIONS_KEY; + + aCfg.Write( baseName + GalGridStyleConfig, UTIL::GetConfigForVal( gridStyleConfigVals, m_gridStyle ) ); - aCfg->Write( aBaseName + GalGridLineWidthConfig, m_gridLineWidth ); - aCfg->Write( aBaseName + GalGridMaxDensityConfig, m_gridMinSpacing ); - aCfg->Write( aBaseName + GalGridAxesEnabledConfig, m_axesEnabled ); - aCfg->Write( aBaseName + GalFullscreenCursorConfig, m_fullscreenCursor ); - aCfg->Write( aBaseName + GalForceDisplayCursorConfig, m_forceDisplayCursor ); + aCfg.Write( baseName + GalGridLineWidthConfig, m_gridLineWidth ); + aCfg.Write( baseName + GalGridMaxDensityConfig, m_gridMinSpacing ); + aCfg.Write( baseName + GalGridAxesEnabledConfig, m_axesEnabled ); + aCfg.Write( baseName + GalFullscreenCursorConfig, m_fullscreenCursor ); + aCfg.Write( baseName + GalForceDisplayCursorConfig, m_forceDisplayCursor ); } void GAL_DISPLAY_OPTIONS::NotifyChanged() { Notify( &GAL_DISPLAY_OPTIONS_OBSERVER::OnGalDisplayOptionsChanged, *this ); -} +} \ No newline at end of file diff --git a/common/legacy_gal/eda_draw_frame.cpp b/common/legacy_gal/eda_draw_frame.cpp index 9a32d22d6e..e3f3f2746f 100644 --- a/common/legacy_gal/eda_draw_frame.cpp +++ b/common/legacy_gal/eda_draw_frame.cpp @@ -67,7 +67,6 @@ #include #include #include -#include /** * Definition for enabling and disabling scroll bar setting trace output. See the @@ -295,19 +294,7 @@ void EDA_DRAW_FRAME::CommonSettingsChanged() settings->Read( ENBL_AUTO_PAN_KEY, &option ); m_canvas->SetEnableAutoPan( option ); - int tmp; - settings->Read( GAL_ANTIALIASING_MODE_KEY, &tmp, (int) KIGFX::OPENGL_ANTIALIASING_MODE::NONE ); - m_galDisplayOptions.gl_antialiasing_mode = (KIGFX::OPENGL_ANTIALIASING_MODE) tmp; - - settings->Read( CAIRO_ANTIALIASING_MODE_KEY, &tmp, (int) KIGFX::CAIRO_ANTIALIASING_MODE::NONE ); - m_galDisplayOptions.cairo_antialiasing_mode = (KIGFX::CAIRO_ANTIALIASING_MODE) tmp; - - { - const DPI_SCALING dpi{ settings, this }; - m_galDisplayOptions.m_scaleFactor = dpi.GetScaleFactor(); - } - - m_galDisplayOptions.NotifyChanged(); + m_galDisplayOptions.ReadCommonConfig( *settings, this ); } @@ -849,21 +836,7 @@ void EDA_DRAW_FRAME::LoadSettings( wxConfigBase* aCfg ) aCfg->Read( baseCfgName + FirstRunShownKeyword, &m_firstRunDialogSetting, 0L ); - m_galDisplayOptions.ReadConfig( aCfg, baseCfgName + GAL_DISPLAY_OPTIONS_KEY ); - - int temp; - cmnCfg->Read( GAL_ANTIALIASING_MODE_KEY, &temp, (int) KIGFX::OPENGL_ANTIALIASING_MODE::NONE ); - m_galDisplayOptions.gl_antialiasing_mode = (KIGFX::OPENGL_ANTIALIASING_MODE) temp; - - cmnCfg->Read( CAIRO_ANTIALIASING_MODE_KEY, &temp, (int) KIGFX::CAIRO_ANTIALIASING_MODE::NONE ); - m_galDisplayOptions.cairo_antialiasing_mode = (KIGFX::CAIRO_ANTIALIASING_MODE) temp; - - { - const DPI_SCALING dpi{ cmnCfg, this }; - m_galDisplayOptions.m_scaleFactor = dpi.GetScaleFactor(); - } - - m_galDisplayOptions.NotifyChanged(); + m_galDisplayOptions.ReadConfig( *cmnCfg, *aCfg, baseCfgName, this ); } @@ -881,7 +854,7 @@ void EDA_DRAW_FRAME::SaveSettings( wxConfigBase* aCfg ) if( GetScreen() ) aCfg->Write( baseCfgName + MaxUndoItemsEntry, long( GetScreen()->GetMaxUndoItems() ) ); - m_galDisplayOptions.WriteConfig( aCfg, baseCfgName + GAL_DISPLAY_OPTIONS_KEY ); + m_galDisplayOptions.WriteConfig( *aCfg, baseCfgName ); } diff --git a/common/legacy_wx/eda_draw_frame.cpp b/common/legacy_wx/eda_draw_frame.cpp index 6e73422712..442e1c67b5 100644 --- a/common/legacy_wx/eda_draw_frame.cpp +++ b/common/legacy_wx/eda_draw_frame.cpp @@ -46,7 +46,6 @@ #include #include #include -#include #include #include @@ -297,19 +296,7 @@ void EDA_DRAW_FRAME::CommonSettingsChanged() settings->Read( ENBL_AUTO_PAN_KEY, &option ); m_canvas->SetEnableAutoPan( option ); - int tmp; - settings->Read( GAL_ANTIALIASING_MODE_KEY, &tmp, (int) KIGFX::OPENGL_ANTIALIASING_MODE::NONE ); - m_galDisplayOptions.gl_antialiasing_mode = (KIGFX::OPENGL_ANTIALIASING_MODE) tmp; - - settings->Read( CAIRO_ANTIALIASING_MODE_KEY, &tmp, (int) KIGFX::CAIRO_ANTIALIASING_MODE::NONE ); - m_galDisplayOptions.cairo_antialiasing_mode = (KIGFX::CAIRO_ANTIALIASING_MODE) tmp; - - { - const DPI_SCALING dpi{ settings, this }; - m_galDisplayOptions.m_scaleFactor = dpi.GetScaleFactor(); - } - - m_galDisplayOptions.NotifyChanged(); + m_galDisplayOptions.ReadCommonConfig( *settings, this ); } @@ -868,21 +855,7 @@ void EDA_DRAW_FRAME::LoadSettings( wxConfigBase* aCfg ) aCfg->Read( baseCfgName + FirstRunShownKeyword, &m_firstRunDialogSetting, 0L ); - m_galDisplayOptions.ReadConfig( aCfg, baseCfgName + GAL_DISPLAY_OPTIONS_KEY ); - - int temp; - cmnCfg->Read( GAL_ANTIALIASING_MODE_KEY, &temp, (int) KIGFX::OPENGL_ANTIALIASING_MODE::NONE ); - m_galDisplayOptions.gl_antialiasing_mode = (KIGFX::OPENGL_ANTIALIASING_MODE) temp; - - cmnCfg->Read( CAIRO_ANTIALIASING_MODE_KEY, &temp, (int) KIGFX::CAIRO_ANTIALIASING_MODE::NONE ); - m_galDisplayOptions.cairo_antialiasing_mode = (KIGFX::CAIRO_ANTIALIASING_MODE) temp; - - { - const DPI_SCALING dpi{ cmnCfg, this }; - m_galDisplayOptions.m_scaleFactor = dpi.GetScaleFactor(); - } - - m_galDisplayOptions.NotifyChanged(); + m_galDisplayOptions.ReadConfig( *cmnCfg, *aCfg, baseCfgName, this ); } @@ -902,7 +875,7 @@ void EDA_DRAW_FRAME::SaveSettings( wxConfigBase* aCfg ) if( GetScreen() ) aCfg->Write( baseCfgName + MaxUndoItemsEntry, long( GetScreen()->GetMaxUndoItems() ) ); - m_galDisplayOptions.WriteConfig( aCfg, baseCfgName + GAL_DISPLAY_OPTIONS_KEY ); + m_galDisplayOptions.WriteConfig( *aCfg, baseCfgName ); } diff --git a/eeschema/viewlib_frame.cpp b/eeschema/viewlib_frame.cpp index 49daa2488e..81311a6ce5 100644 --- a/eeschema/viewlib_frame.cpp +++ b/eeschema/viewlib_frame.cpp @@ -738,7 +738,7 @@ void LIB_VIEW_FRAME::LoadSettings( wxConfigBase* aCfg ) SetGridColor( wtmp ); // Grid shape, etc. - GetGalDisplayOptions().ReadConfig( aCfg, symbolEditor + GAL_DISPLAY_OPTIONS_KEY ); + GetGalDisplayOptions().ReadAppConfig( *aCfg, symbolEditor ); aCfg->Read( LIBLIST_WIDTH_KEY, &m_libListWidth, 150 ); aCfg->Read( CMPLIST_WIDTH_KEY, &m_cmpListWidth, 150 ); diff --git a/eeschema/widgets/symbol_preview_widget.cpp b/eeschema/widgets/symbol_preview_widget.cpp index 05715fb4cc..bb33440880 100644 --- a/eeschema/widgets/symbol_preview_widget.cpp +++ b/eeschema/widgets/symbol_preview_widget.cpp @@ -39,7 +39,7 @@ SYMBOL_PREVIEW_WIDGET::SYMBOL_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway, { wxString eeschemaFrameKey( SCH_EDIT_FRAME_NAME ); auto eeschemaConfig = GetNewConfig( Pgm().App().GetAppName() ); - m_galDisplayOptions.ReadConfig( eeschemaConfig.get(), eeschemaFrameKey + GAL_DISPLAY_OPTIONS_KEY ); + m_galDisplayOptions.ReadAppConfig( *eeschemaConfig, eeschemaFrameKey ); EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = aCanvasType; diff --git a/include/gal/gal_display_options.h b/include/gal/gal_display_options.h index 44bf3c0a7c..961bde78c1 100644 --- a/include/gal/gal_display_options.h +++ b/include/gal/gal_display_options.h @@ -28,6 +28,8 @@ class wxConfigBase; class wxString; +class wxWindow; + namespace KIGFX { @@ -74,8 +76,31 @@ namespace KIGFX public: GAL_DISPLAY_OPTIONS(); - void ReadConfig ( wxConfigBase* aCfg, const wxString& aBaseName ); - void WriteConfig( wxConfigBase* aCfg, const wxString& aBaseName ); + /** + * Read GAL config options from applicaton-level config + * @param aCfg the application config base + * @param aBaseName the application's GAL options key prefix + */ + void ReadAppConfig( wxConfigBase& aCfg, const wxString& aBaseName ); + + /** + * Read GAL config options from the common config store + * @param aCommonConfig the common config store + * @param aWindow the wx parent window (used for DPI scaling) + */ + void ReadCommonConfig( wxConfigBase& aCommonConfig, wxWindow* aWindow ); + + /** + * Read application and common configs + * @param aCommonConfig the common config store + * @param aCfg the application config base + * @param aBaseName the application's GAL options key prefix + * @param aWindow the wx parent window (used for DPI scaling) + */ + void ReadConfig( wxConfigBase& aCommonConfig, wxConfigBase& aAppCondfig, + const wxString& aBaseCfgName, wxWindow* aWindow ); + + void WriteConfig( wxConfigBase& aCfg, const wxString& aBaseName ); void NotifyChanged(); diff --git a/pcbnew/footprint_preview_panel.cpp b/pcbnew/footprint_preview_panel.cpp index ddd8112041..5052e81bc4 100644 --- a/pcbnew/footprint_preview_panel.cpp +++ b/pcbnew/footprint_preview_panel.cpp @@ -395,13 +395,7 @@ FOOTPRINT_PREVIEW_PANEL* FOOTPRINT_PREVIEW_PANEL::New( KIWAY* aKiway, wxWindow* // Make and populate a new one from config gal_opts = std::make_unique(); - gal_opts->ReadConfig( cfg, wxString( PCB_EDIT_FRAME_NAME ) + GAL_DISPLAY_OPTIONS_KEY ); - - commonCfg->Read( GAL_ANTIALIASING_MODE_KEY, &itemp, (int) KIGFX::OPENGL_ANTIALIASING_MODE::NONE ); - gal_opts->gl_antialiasing_mode = (KIGFX::OPENGL_ANTIALIASING_MODE) itemp; - - commonCfg->Read( CAIRO_ANTIALIASING_MODE_KEY, &itemp, (int) KIGFX::CAIRO_ANTIALIASING_MODE::NONE ); - gal_opts->cairo_antialiasing_mode = (KIGFX::CAIRO_ANTIALIASING_MODE) itemp; + gal_opts->ReadConfig( *commonCfg, *cfg, wxString( PCB_EDIT_FRAME_NAME ), aParent ); } #ifdef __WXMAC__ diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index 7bf3adbd3b..2ac57c7b14 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -513,7 +513,7 @@ void FOOTPRINT_VIEWER_FRAME::LoadSettings( wxConfigBase* aCfg ) SetGridColor( wtmp ); // Grid shape, etc. - GetGalDisplayOptions().ReadConfig( aCfg, footprintEditor + GAL_DISPLAY_OPTIONS_KEY ); + GetGalDisplayOptions().ReadAppConfig( *aCfg, footprintEditor ); m_configSettings.Load( aCfg ); // mainly, load the color config