You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.9 KiB

  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include <gal_display_options_common.h>
  24. #include <settings/app_settings.h>
  25. #include <settings/common_settings.h>
  26. #include <wx/log.h>
  27. #include <config_map.h>
  28. #include <dpi_scaling_common.h>
  29. using namespace KIGFX;
  30. /**
  31. * Flag to enable GAL_DISPLAY_OPTIONS logging
  32. *
  33. * Use "KICAD_GAL_DISPLAY_OPTIONS" to enable.
  34. *
  35. * @ingroup trace_env_vars
  36. */
  37. static const wxChar* traceGalDispOpts = wxT( "KICAD_GAL_DISPLAY_OPTIONS" );
  38. static const UTIL::CFG_MAP<KIGFX::GRID_STYLE> gridStyleConfigVals = {
  39. { KIGFX::GRID_STYLE::DOTS, 0 },
  40. { KIGFX::GRID_STYLE::LINES, 1 },
  41. { KIGFX::GRID_STYLE::SMALL_CROSS, 2 },
  42. };
  43. static const UTIL::CFG_MAP<KIGFX::GRID_SNAPPING> gridSnapConfigVals = {
  44. { KIGFX::GRID_SNAPPING::ALWAYS, 0 },
  45. { KIGFX::GRID_SNAPPING::WITH_GRID, 1 },
  46. { KIGFX::GRID_SNAPPING::NEVER, 2 }
  47. };
  48. GAL_DISPLAY_OPTIONS_IMPL::GAL_DISPLAY_OPTIONS_IMPL() :
  49. GAL_DISPLAY_OPTIONS(),
  50. m_dpi( { nullptr, nullptr } )
  51. {
  52. }
  53. void GAL_DISPLAY_OPTIONS_IMPL::ReadWindowSettings( WINDOW_SETTINGS& aCfg )
  54. {
  55. wxLogTrace( traceGalDispOpts, wxS( "Reading app-specific options" ) );
  56. m_gridStyle = UTIL::GetValFromConfig( gridStyleConfigVals, aCfg.grid.style );
  57. m_gridSnapping = UTIL::GetValFromConfig( gridSnapConfigVals, aCfg.grid.snap );
  58. m_gridLineWidth = aCfg.grid.line_width;
  59. m_gridMinSpacing = aCfg.grid.min_spacing;
  60. m_axesEnabled = aCfg.grid.axes_enabled;
  61. m_crossHairMode = aCfg.cursor.cross_hair_mode;
  62. m_forceDisplayCursor = aCfg.cursor.always_show_cursor;
  63. NotifyChanged();
  64. }
  65. void GAL_DISPLAY_OPTIONS_IMPL::ReadCommonConfig( COMMON_SETTINGS& aSettings, wxWindow* aWindow )
  66. {
  67. wxLogTrace( traceGalDispOpts, wxS( "Reading common config" ) );
  68. antialiasing_mode =
  69. static_cast<KIGFX::GAL_ANTIALIASING_MODE>( aSettings.m_Graphics.aa_mode );
  70. m_dpi = DPI_SCALING_COMMON( &aSettings, aWindow );
  71. UpdateScaleFactor();
  72. NotifyChanged();
  73. }
  74. void GAL_DISPLAY_OPTIONS_IMPL::ReadConfig( COMMON_SETTINGS& aCommonConfig,
  75. WINDOW_SETTINGS& aWindowConfig, wxWindow* aWindow )
  76. {
  77. wxLogTrace( traceGalDispOpts, wxS( "Reading common and app config" ) );
  78. ReadWindowSettings( aWindowConfig );
  79. ReadCommonConfig( aCommonConfig, aWindow );
  80. }
  81. void GAL_DISPLAY_OPTIONS_IMPL::WriteConfig( WINDOW_SETTINGS& aCfg )
  82. {
  83. wxLogTrace( traceGalDispOpts, wxS( "Writing window settings" ) );
  84. aCfg.grid.style = UTIL::GetConfigForVal( gridStyleConfigVals, m_gridStyle );
  85. aCfg.grid.snap = UTIL::GetConfigForVal( gridSnapConfigVals, m_gridSnapping );
  86. aCfg.grid.line_width = m_gridLineWidth;
  87. aCfg.grid.min_spacing = m_gridMinSpacing;
  88. aCfg.grid.axes_enabled = m_axesEnabled;
  89. aCfg.cursor.cross_hair_mode = m_crossHairMode;
  90. aCfg.cursor.always_show_cursor = m_forceDisplayCursor;
  91. }
  92. void GAL_DISPLAY_OPTIONS_IMPL::UpdateScaleFactor()
  93. {
  94. if( m_scaleFactor != m_dpi.GetScaleFactor() )
  95. {
  96. m_scaleFactor = m_dpi.GetScaleFactor();
  97. NotifyChanged();
  98. }
  99. }