KiCad PCB EDA Suite
gal_display_options.cpp
Go to the documentation of this file.
1 /*
2 * This program source code file is part of KICAD, a free EDA CAD application.
3 *
4 * Copyright (C) 2016-2020 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 
25 #include <settings/app_settings.h>
27 
28 #include <wx/log.h>
29 
30 #include <config_map.h>
31 #include <gal/dpi_scaling.h>
32 
33 using namespace KIGFX;
34 
36 {
40 };
41 
43 {
47 };
48 
49 
57 static const wxChar* traceGalDispOpts = wxT( "KICAD_GAL_DISPLAY_OPTIONS" );
58 
59 
61  : gl_antialiasing_mode( OPENGL_ANTIALIASING_MODE::NONE ),
62  cairo_antialiasing_mode( CAIRO_ANTIALIASING_MODE::NONE ),
63  m_dpi( nullptr, nullptr ),
64  m_gridStyle( GRID_STYLE::DOTS ),
65  m_gridSnapping( GRID_SNAPPING::ALWAYS ),
66  m_gridLineWidth( 1.0 ),
67  m_gridMinSpacing( 10.0 ),
68  m_axesEnabled( false ),
69  m_fullscreenCursor( false ),
70  m_forceDisplayCursor( false ),
71  m_scaleFactor( DPI_SCALING::GetDefaultScaleFactor() )
72 {}
73 
74 
76 {
77  wxLogTrace( traceGalDispOpts, "Reading app-specific options" );
78 
84 
87 
88  NotifyChanged();
89 }
90 
91 
92 void GAL_DISPLAY_OPTIONS::ReadCommonConfig( COMMON_SETTINGS& aSettings, wxWindow* aWindow )
93 {
94  wxLogTrace( traceGalDispOpts, "Reading common config" );
95 
96  gl_antialiasing_mode = static_cast<KIGFX::OPENGL_ANTIALIASING_MODE>(
97  aSettings.m_Graphics.opengl_aa_mode );
98 
99  cairo_antialiasing_mode = static_cast<KIGFX::CAIRO_ANTIALIASING_MODE>(
100  aSettings.m_Graphics.cairo_aa_mode );
101 
102  m_dpi = DPI_SCALING( &aSettings, aWindow );
104 
105  NotifyChanged();
106 }
107 
108 
110  WINDOW_SETTINGS& aWindowConfig, wxWindow* aWindow )
111 {
112  wxLogTrace( traceGalDispOpts, "Reading common and app config" );
113 
114  ReadWindowSettings( aWindowConfig );
115 
116  ReadCommonConfig( aCommonConfig, aWindow );
117 }
118 
119 
121 {
122  wxLogTrace( traceGalDispOpts, "Writing window settings" );
123 
131 }
132 
133 
135 {
137  {
139  NotifyChanged();
140  }
141 }
142 
143 
145 {
146  wxLogTrace( traceGalDispOpts, "Change notification" );
147 
149 }
bool fullscreen_cursor
Definition: app_settings.h:43
Use lines for the grid.
GRID_STYLE
GRID_STYLE: Type definition of the grid style.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
KIGFX::GRID_STYLE m_gridStyle
The grid style to draw the grid in
double min_spacing
Definition: app_settings.h:59
static const UTIL::CFG_MAP< KIGFX::GRID_STYLE > gridStyleConfigVals
static const wxChar * traceGalDispOpts
Flag to enable GAL_DISPLAY_OPTIONS logging.
bool m_forceDisplayCursor
Force cursor display
double m_gridMinSpacing
Minimum pixel distance between displayed grid lines
void Notify(void(GAL_DISPLAY_OPTIONS_OBSERVER ::*Ptr)(Args1...), Args2 &&... aArgs)
Function Notify Notifies event to all subscribed observers.
Definition: observable.h:183
OPENGL_ANTIALIASING_MODE gl_antialiasing_mode
bool always_show_cursor
Definition: app_settings.h:42
double GetScaleFactor() const
Get the DPI scale from all known sources in order:
double line_width
Definition: app_settings.h:58
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
Definition: dpi_scaling.h:36
bool m_axesEnabled
Whether or not to draw the coordinate system axes
CAIRO_ANTIALIASING_MODE cairo_antialiasing_mode
Stores the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:81
GRID_SNAPPING m_gridSnapping
Snapping options for the grid
CURSOR_SETTINGS cursor
Definition: app_settings.h:88
void WriteConfig(WINDOW_SETTINGS &aCfg)
GRID_SETTINGS grid
Definition: app_settings.h:89
void ReadCommonConfig(COMMON_SETTINGS &aCommonSettings, wxWindow *aWindow)
Read GAL config options from the common config store.
static CFG_NATIVE_VAL< MAP > GetValFromConfig(const MAP &aMap, long aConf)
Get the native value corresponding to the config value (read from file or UI, probably) and find it i...
Definition: config_map.h:96
Use dots for the grid.
Use small cross instead of dots for the grid.
virtual void OnGalDisplayOptionsChanged(const GAL_DISPLAY_OPTIONS &)=0
double m_scaleFactor
The pixel scale factor (>1 for hi-DPI scaled displays)
static const UTIL::CFG_MAP< KIGFX::GRID_SNAPPING > gridSnapConfigVals
double m_gridLineWidth
Thickness to render grid lines/dots
void ReadConfig(COMMON_SETTINGS &aCommonConfig, WINDOW_SETTINGS &aWindowConfig, wxWindow *aWindow)
Read application and common configs.
std::vector< std::pair< T, long > > CFG_MAP
A config value table is a list of native values (usually enums) to a different set of values,...
Definition: config_map.h:49
bool m_fullscreenCursor
Fullscreen crosshair or small cross
void ReadWindowSettings(WINDOW_SETTINGS &aCfg)
Read GAL config options from applicaton-level config.
static long GetConfigForVal(const MAP &aMap, CFG_NATIVE_VAL< MAP > aVal)
Get the mapped config value (the one to write to file, or use in an index) from the given native (pro...
Definition: config_map.h:69