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.

131 lines
4.5 KiB

  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016-2017 Kicad Developers, see change_log.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/gal_display_options.h>
  24. #include <wx/config.h>
  25. #include <config_map.h>
  26. using namespace KIGFX;
  27. /*
  28. * Config option strings
  29. */
  30. static const wxString GalGLAntialiasingKeyword( "OpenGLAntialiasingMode" );
  31. static const wxString GalGridStyleConfig( "GridStyle" );
  32. static const wxString GalGridLineWidthConfig( "GridLineWidth" );
  33. static const wxString GalGridMaxDensityConfig( "GridMaxDensity" );
  34. static const wxString GalGridAxesEnabledConfig( "GridAxesEnabled" );
  35. static const wxString GalFullscreenCursorConfig( "CursorFullscreen" );
  36. static const wxString GalForceDisplayCursorConfig( "ForceDisplayCursor" );
  37. static const UTIL::CFG_MAP<KIGFX::OPENGL_ANTIALIASING_MODE> aaModeConfigVals =
  38. {
  39. { KIGFX::OPENGL_ANTIALIASING_MODE::NONE, 0 },
  40. { KIGFX::OPENGL_ANTIALIASING_MODE::SUBSAMPLE_HIGH, 1 },
  41. { KIGFX::OPENGL_ANTIALIASING_MODE::SUBSAMPLE_ULTRA, 2 },
  42. { KIGFX::OPENGL_ANTIALIASING_MODE::SUPERSAMPLING_X2, 3 },
  43. { KIGFX::OPENGL_ANTIALIASING_MODE::SUPERSAMPLING_X4, 4 },
  44. };
  45. static const UTIL::CFG_MAP<KIGFX::GRID_STYLE> gridStyleConfigVals =
  46. {
  47. { KIGFX::GRID_STYLE::DOTS, 0 },
  48. { KIGFX::GRID_STYLE::LINES, 1 },
  49. { KIGFX::GRID_STYLE::SMALL_CROSS,2 },
  50. };
  51. GAL_DISPLAY_OPTIONS::GAL_DISPLAY_OPTIONS()
  52. : gl_antialiasing_mode( OPENGL_ANTIALIASING_MODE::NONE ),
  53. m_gridStyle( GRID_STYLE::DOTS ),
  54. m_gridLineWidth( 0.5 ),
  55. m_gridMinSpacing( 10.0 ),
  56. m_axesEnabled( false ),
  57. m_fullscreenCursor( false ),
  58. m_forceDisplayCursor( false )
  59. {}
  60. void GAL_DISPLAY_OPTIONS::ReadConfig( wxConfigBase* aCfg, wxString aBaseName )
  61. {
  62. long readLong; // Temp value buffer
  63. aCfg->Read( aBaseName + GalGLAntialiasingKeyword, &readLong,
  64. static_cast<long>( KIGFX::OPENGL_ANTIALIASING_MODE::NONE ) );
  65. gl_antialiasing_mode = UTIL::GetValFromConfig( aaModeConfigVals, readLong );
  66. aCfg->Read( aBaseName + GalGridStyleConfig, &readLong,
  67. static_cast<long>( KIGFX::GRID_STYLE::DOTS ) );
  68. m_gridStyle = UTIL::GetValFromConfig( gridStyleConfigVals, readLong );
  69. aCfg->Read( aBaseName + GalGridLineWidthConfig,
  70. &m_gridLineWidth, 0.5 );
  71. aCfg->Read( aBaseName + GalGridMaxDensityConfig,
  72. &m_gridMinSpacing, 10 );
  73. aCfg->Read( aBaseName + GalGridAxesEnabledConfig,
  74. &m_axesEnabled, false );
  75. aCfg->Read( aBaseName + GalFullscreenCursorConfig,
  76. &m_fullscreenCursor, false );
  77. aCfg->Read( aBaseName + GalForceDisplayCursorConfig,
  78. &m_forceDisplayCursor, false );
  79. NotifyChanged();
  80. }
  81. void GAL_DISPLAY_OPTIONS::WriteConfig( wxConfigBase* aCfg, wxString aBaseName )
  82. {
  83. aCfg->Write( aBaseName + GalGLAntialiasingKeyword,
  84. UTIL::GetConfigForVal( aaModeConfigVals, gl_antialiasing_mode ) );
  85. aCfg->Write( aBaseName + GalGridStyleConfig,
  86. UTIL::GetConfigForVal( gridStyleConfigVals, m_gridStyle ) );
  87. aCfg->Write( aBaseName + GalGridLineWidthConfig,
  88. m_gridLineWidth );
  89. aCfg->Write( aBaseName + GalGridMaxDensityConfig,
  90. m_gridMinSpacing );
  91. aCfg->Write( aBaseName + GalGridAxesEnabledConfig,
  92. m_axesEnabled );
  93. aCfg->Write( aBaseName + GalFullscreenCursorConfig,
  94. m_fullscreenCursor );
  95. aCfg->Write( aBaseName + GalForceDisplayCursorConfig,
  96. m_forceDisplayCursor );
  97. }
  98. void GAL_DISPLAY_OPTIONS::NotifyChanged()
  99. {
  100. Notify( &GAL_DISPLAY_OPTIONS_OBSERVER::OnGalDisplayOptionsChanged, *this );
  101. }