KiCad PCB EDA Suite
KIGFX::GAL_DISPLAY_OPTIONS Class Reference

#include <gal_display_options.h>

Inheritance diagram for KIGFX::GAL_DISPLAY_OPTIONS:
UTIL::OBSERVABLE< GAL_DISPLAY_OPTIONS_OBSERVER > UTIL::DETAIL::OBSERVABLE_BASE

Public Member Functions

 GAL_DISPLAY_OPTIONS ()
 
void ReadWindowSettings (WINDOW_SETTINGS &aCfg)
 Read GAL config options from application-level config. More...
 
void ReadCommonConfig (COMMON_SETTINGS &aCommonSettings, wxWindow *aWindow)
 Read GAL config options from the common config store. More...
 
void ReadConfig (COMMON_SETTINGS &aCommonConfig, WINDOW_SETTINGS &aWindowConfig, wxWindow *aWindow)
 Read application and common configs. More...
 
void WriteConfig (WINDOW_SETTINGS &aCfg)
 
void UpdateScaleFactor ()
 
void NotifyChanged ()
 
void SubscribeUnmanaged (GAL_DISPLAY_OPTIONS_OBSERVER *aObserver)
 Add a subscription without RAII link. More...
 
LINK Subscribe (GAL_DISPLAY_OPTIONS_OBSERVER *aObserver)
 Add a subscription returning an RAII link. More...
 
void Unsubscribe (GAL_DISPLAY_OPTIONS_OBSERVER *aObserver)
 Cancel the subscription of a subscriber. More...
 
void Notify (void(ObserverInterface::*Ptr)(Args1...), Args2 &&... aArgs)
 Notify event to all subscribed observers. More...
 
void NotifyIgnore (void(ObserverInterface::*Ptr)(Args1...), GAL_DISPLAY_OPTIONS_OBSERVER *aIgnore, Args2 &&... aArgs)
 Notify event to all subscribed observers but one to be ignore. More...
 
size_t size () const
 

Public Attributes

OPENGL_ANTIALIASING_MODE gl_antialiasing_mode
 
CAIRO_ANTIALIASING_MODE cairo_antialiasing_mode
 
DPI_SCALING m_dpi
 The grid style to draw the grid in. More...
 
KIGFX::GRID_STYLE m_gridStyle
 Snapping options for the grid. More...
 
GRID_SNAPPING m_gridSnapping
 Thickness to render grid lines/dots. More...
 
double m_gridLineWidth
 Minimum pixel distance between displayed grid lines. More...
 
double m_gridMinSpacing
 Whether or not to draw the coordinate system axes. More...
 
bool m_axesEnabled
 Fullscreen crosshair or small cross. More...
 
bool m_fullscreenCursor
 Force cursor display. More...
 
bool m_forceDisplayCursor
 The pixel scale factor (>1 for hi-DPI scaled displays) More...
 
double m_scaleFactor
 

Protected Member Functions

void on_observers_empty ()
 
void enter_iteration ()
 
void leave_iteration ()
 
void add_observer (void *observer)
 
void remove_observer (void *observer)
 

Protected Attributes

std::shared_ptr< IMPLimpl_
 

Private Member Functions

void allocate_impl ()
 
void allocate_shared_impl ()
 
void deallocate_impl ()
 
std::shared_ptr< IMPLget_shared_impl ()
 

Detailed Description

Definition at line 80 of file gal_display_options.h.

Constructor & Destructor Documentation

◆ GAL_DISPLAY_OPTIONS()

GAL_DISPLAY_OPTIONS::GAL_DISPLAY_OPTIONS ( )

Definition at line 60 of file gal_display_options.cpp.

63 m_dpi( nullptr, nullptr ),
66 m_gridLineWidth( 1.0 ),
67 m_gridMinSpacing( 10.0 ),
68 m_axesEnabled( false ),
69 m_fullscreenCursor( false ),
70 m_forceDisplayCursor( false ),
72{}
static double GetDefaultScaleFactor()
Get the "default" scaling factor to use if not other config is available.
DPI_SCALING m_dpi
The grid style to draw the grid in.
double m_gridLineWidth
Minimum pixel distance between displayed grid lines.
double m_gridMinSpacing
Whether or not to draw the coordinate system axes.
OPENGL_ANTIALIASING_MODE gl_antialiasing_mode
CAIRO_ANTIALIASING_MODE cairo_antialiasing_mode
bool m_forceDisplayCursor
The pixel scale factor (>1 for hi-DPI scaled displays)
KIGFX::GRID_STYLE m_gridStyle
Snapping options for the grid.
bool m_axesEnabled
Fullscreen crosshair or small cross.
bool m_fullscreenCursor
Force cursor display.
GRID_SNAPPING m_gridSnapping
Thickness to render grid lines/dots.
@ DOTS
Use dots for the grid.

References KIGFX::ALWAYS, and KIGFX::DOTS.

Member Function Documentation

◆ add_observer()

void UTIL::DETAIL::OBSERVABLE_BASE::add_observer ( void *  observer)
protectedinherited

Definition at line 216 of file observable.cpp.

217 {
219 impl_->add_observer( observer );
220 }
std::shared_ptr< IMPL > impl_
Definition: observable.h:93

References UTIL::DETAIL::OBSERVABLE_BASE::allocate_impl(), and UTIL::DETAIL::OBSERVABLE_BASE::impl_.

◆ allocate_impl()

void UTIL::DETAIL::OBSERVABLE_BASE::allocate_impl ( )
privateinherited

Definition at line 188 of file observable.cpp.

189 {
190 if(!impl_)
191 impl_ = std::make_shared<IMPL>( this );
192 }

References UTIL::DETAIL::OBSERVABLE_BASE::impl_.

Referenced by UTIL::DETAIL::OBSERVABLE_BASE::add_observer().

◆ allocate_shared_impl()

void UTIL::DETAIL::OBSERVABLE_BASE::allocate_shared_impl ( )
privateinherited

Definition at line 195 of file observable.cpp.

196 {
197 if(!impl_)
198 impl_ = std::make_shared<IMPL>();
199 else
200 impl_->set_shared();
201 }

References UTIL::DETAIL::OBSERVABLE_BASE::impl_.

Referenced by UTIL::DETAIL::OBSERVABLE_BASE::get_shared_impl().

◆ deallocate_impl()

void UTIL::DETAIL::OBSERVABLE_BASE::deallocate_impl ( )
privateinherited

Definition at line 204 of file observable.cpp.

204 {
205 impl_.reset();
206 }

References UTIL::DETAIL::OBSERVABLE_BASE::impl_.

Referenced by UTIL::DETAIL::OBSERVABLE_BASE::on_observers_empty().

◆ enter_iteration()

void UTIL::DETAIL::OBSERVABLE_BASE::enter_iteration ( )
protectedinherited

Definition at line 230 of file observable.cpp.

231 {
232 if( impl_ )
233 impl_->enter_iteration();
234 }

References UTIL::DETAIL::OBSERVABLE_BASE::impl_.

Referenced by UTIL::OBSERVABLE< ObserverInterface >::Notify(), and UTIL::OBSERVABLE< ObserverInterface >::NotifyIgnore().

◆ get_shared_impl()

std::shared_ptr< OBSERVABLE_BASE::IMPL > UTIL::DETAIL::OBSERVABLE_BASE::get_shared_impl ( )
privateinherited

◆ leave_iteration()

void UTIL::DETAIL::OBSERVABLE_BASE::leave_iteration ( )
protectedinherited

Definition at line 237 of file observable.cpp.

238 {
239 if( impl_)
240 {
241 impl_->leave_iteration();
242
243 if( !impl_->is_iterating() && !impl_->is_shared() && impl_.use_count() == 1 )
244 impl_.reset();
245 }
246 }

References UTIL::DETAIL::OBSERVABLE_BASE::impl_.

Referenced by UTIL::OBSERVABLE< ObserverInterface >::Notify(), and UTIL::OBSERVABLE< ObserverInterface >::NotifyIgnore().

◆ Notify()

void UTIL::OBSERVABLE< GAL_DISPLAY_OPTIONS_OBSERVER >::Notify ( void(ObserverInterface::*)(Args1...)  Ptr,
Args2 &&...  aArgs 
)
inlineinherited

Notify event to all subscribed observers.

Parameters
Ptris a pointer to method of the observer interface.
aArgsis a list of arguments to each notification call, will be perfectly forwarded.

Definition at line 182 of file observable.h.

183 {
184 static_assert( sizeof...( Args1 ) == sizeof...( Args2 ), "argument counts don't match" );
185
186 if( impl_ )
187 {
189 try
190 {
191 for( auto* void_ptr : impl_->observers_ )
192 {
193 if( void_ptr )
194 {
195 auto* typed_ptr = static_cast<ObserverInterface*>( void_ptr );
196 ( typed_ptr->*Ptr )( std::forward<Args2>( aArgs )... );
197 }
198 }
199 }
200 catch( ... )
201 {
203 throw;
204 }
205
207 }
208 }

◆ NotifyChanged()

void GAL_DISPLAY_OPTIONS::NotifyChanged ( )

Definition at line 144 of file gal_display_options.cpp.

145{
146 wxLogTrace( traceGalDispOpts, "Change notification" );
147
149}
virtual void OnGalDisplayOptionsChanged(const GAL_DISPLAY_OPTIONS &)=0
void Notify(void(ObserverInterface::*Ptr)(Args1...), Args2 &&... aArgs)
Notify event to all subscribed observers.
Definition: observable.h:182
static const wxChar * traceGalDispOpts
Flag to enable GAL_DISPLAY_OPTIONS logging.

References UTIL::OBSERVABLE< GAL_DISPLAY_OPTIONS_OBSERVER >::Notify(), KIGFX::GAL_DISPLAY_OPTIONS_OBSERVER::OnGalDisplayOptionsChanged(), and traceGalDispOpts.

Referenced by ReadCommonConfig(), ReadWindowSettings(), EDA_DRAW_PANEL_GAL::SwitchBackend(), SYMBOL_VIEWER_FRAME::SYMBOL_VIEWER_FRAME(), COMMON_TOOLS::ToggleCursorStyle(), and UpdateScaleFactor().

◆ NotifyIgnore()

void UTIL::OBSERVABLE< GAL_DISPLAY_OPTIONS_OBSERVER >::NotifyIgnore ( void(ObserverInterface::*)(Args1...)  Ptr,
GAL_DISPLAY_OPTIONS_OBSERVER *  aIgnore,
Args2 &&...  aArgs 
)
inlineinherited

Notify event to all subscribed observers but one to be ignore.

Parameters
Ptris a pointer to method of the observer interface.
aIgnoreis an observer to ignore during this notification.
aArgsis a list of arguments to each notification call, will be perfectly forwarded.

Definition at line 218 of file observable.h.

220 {
221 static_assert( sizeof...( Args1 ) == sizeof...( Args2 ), "argument counts don't match" );
222
223 if( impl_ )
224 {
226
227 try
228 {
229 for( auto* void_ptr : impl_->observers_ )
230 {
231 if( void_ptr && void_ptr != aIgnore )
232 {
233 auto* typed_ptr = static_cast<ObserverInterface*>( void_ptr );
234 ( typed_ptr->*Ptr )( std::forward<Args2>( aArgs )... );
235 }
236 }
237 }
238 catch( ... )
239 {
241 throw;
242 }
243
245 }
246 }

◆ on_observers_empty()

void UTIL::DETAIL::OBSERVABLE_BASE::on_observers_empty ( )
protectedinherited

Definition at line 258 of file observable.cpp.

259 {
260 // called by an impl that is owned by this, ie. it is a non-shared impl
261 // also it is not iterating
263 }

References UTIL::DETAIL::OBSERVABLE_BASE::deallocate_impl().

◆ ReadCommonConfig()

void GAL_DISPLAY_OPTIONS::ReadCommonConfig ( COMMON_SETTINGS aCommonSettings,
wxWindow *  aWindow 
)

Read GAL config options from the common config store.

Parameters
aCommonSettingsthe common config store
aWindowthe wx parent window (used for DPI scaling)

Definition at line 92 of file gal_display_options.cpp.

93{
94 wxLogTrace( traceGalDispOpts, "Reading common config" );
95
97 aSettings.m_Graphics.opengl_aa_mode );
98
100 aSettings.m_Graphics.cairo_aa_mode );
101
102 m_dpi = DPI_SCALING( &aSettings, aWindow );
104
106}
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
Definition: dpi_scaling.h:37

References COMMON_SETTINGS::GRAPHICS::cairo_aa_mode, cairo_antialiasing_mode, gl_antialiasing_mode, m_dpi, COMMON_SETTINGS::m_Graphics, NotifyChanged(), COMMON_SETTINGS::GRAPHICS::opengl_aa_mode, traceGalDispOpts, and UpdateScaleFactor().

Referenced by EDA_DRAW_FRAME::CommonSettingsChanged(), and ReadConfig().

◆ ReadConfig()

void GAL_DISPLAY_OPTIONS::ReadConfig ( COMMON_SETTINGS aCommonConfig,
WINDOW_SETTINGS aWindowConfig,
wxWindow *  aWindow 
)

Read application and common configs.

Parameters
aCommonConfigthe common config store
aCfgthe application config base
aBaseNamethe application's GAL options key prefix
aWindowthe wx parent window (used for DPI scaling)

Definition at line 109 of file gal_display_options.cpp.

111{
112 wxLogTrace( traceGalDispOpts, "Reading common and app config" );
113
114 ReadWindowSettings( aWindowConfig );
115
116 ReadCommonConfig( aCommonConfig, aWindow );
117}
void ReadWindowSettings(WINDOW_SETTINGS &aCfg)
Read GAL config options from application-level config.
void ReadCommonConfig(COMMON_SETTINGS &aCommonSettings, wxWindow *aWindow)
Read GAL config options from the common config store.

References ReadCommonConfig(), ReadWindowSettings(), and traceGalDispOpts.

Referenced by EDA_DRAW_FRAME::LoadSettings(), PANEL_EESCHEMA_COLOR_SETTINGS::PANEL_EESCHEMA_COLOR_SETTINGS(), and SYMBOL_PREVIEW_WIDGET::SYMBOL_PREVIEW_WIDGET().

◆ ReadWindowSettings()

void GAL_DISPLAY_OPTIONS::ReadWindowSettings ( WINDOW_SETTINGS aCfg)

Read GAL config options from application-level config.

Parameters
aCfgthe window settings to load from

Definition at line 75 of file gal_display_options.cpp.

76{
77 wxLogTrace( traceGalDispOpts, "Reading app-specific options" );
78
84
87
89}
static const UTIL::CFG_MAP< KIGFX::GRID_STYLE > gridStyleConfigVals
static const UTIL::CFG_MAP< KIGFX::GRID_SNAPPING > gridSnapConfigVals
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
bool always_show_cursor
Definition: app_settings.h:43
bool fullscreen_cursor
Definition: app_settings.h:44
double line_width
Definition: app_settings.h:59
double min_spacing
Definition: app_settings.h:60
CURSOR_SETTINGS cursor
Definition: app_settings.h:89
GRID_SETTINGS grid
Definition: app_settings.h:90

References CURSOR_SETTINGS::always_show_cursor, GRID_SETTINGS::axes_enabled, WINDOW_SETTINGS::cursor, CURSOR_SETTINGS::fullscreen_cursor, UTIL::GetValFromConfig(), WINDOW_SETTINGS::grid, gridSnapConfigVals, gridStyleConfigVals, GRID_SETTINGS::line_width, m_axesEnabled, m_forceDisplayCursor, m_fullscreenCursor, m_gridLineWidth, m_gridMinSpacing, m_gridSnapping, m_gridStyle, GRID_SETTINGS::min_spacing, NotifyChanged(), GRID_SETTINGS::snap, GRID_SETTINGS::style, and traceGalDispOpts.

Referenced by SCH_EDIT_FRAME::CommonSettingsChanged(), SYMBOL_EDIT_FRAME::CommonSettingsChanged(), SYMBOL_VIEWER_FRAME::CommonSettingsChanged(), FOOTPRINT_EDIT_FRAME::CommonSettingsChanged(), PCB_EDIT_FRAME::CommonSettingsChanged(), SYMBOL_VIEWER_FRAME::LoadSettings(), FOOTPRINT_VIEWER_FRAME::LoadSettings(), and ReadConfig().

◆ remove_observer()

void UTIL::DETAIL::OBSERVABLE_BASE::remove_observer ( void *  observer)
protectedinherited

Definition at line 223 of file observable.cpp.

224 {
225 assert( impl_ );
226 impl_->remove_observer( observer );
227 }

References UTIL::DETAIL::OBSERVABLE_BASE::impl_.

◆ size()

size_t UTIL::DETAIL::OBSERVABLE_BASE::size ( ) const
inherited

Definition at line 249 of file observable.cpp.

250 {
251 if( impl_ )
252 return impl_->observers_.size();
253 else
254 return 0;
255 }

References UTIL::DETAIL::OBSERVABLE_BASE::impl_.

◆ Subscribe()

LINK UTIL::OBSERVABLE< GAL_DISPLAY_OPTIONS_OBSERVER >::Subscribe ( GAL_DISPLAY_OPTIONS_OBSERVER *  aObserver)
inlineinherited

Add a subscription returning an RAII link.

Parameters
aObserverobserver to subscribe
Returns
RAII link controlling the lifetime of the subscription

Definition at line 157 of file observable.h.

158 {
159 OBSERVABLE_BASE::add_observer( static_cast<void*>( aObserver ) );
160 return LINK( impl_, static_cast<void*>( aObserver ) );
161 }

◆ SubscribeUnmanaged()

void UTIL::OBSERVABLE< GAL_DISPLAY_OPTIONS_OBSERVER >::SubscribeUnmanaged ( GAL_DISPLAY_OPTIONS_OBSERVER *  aObserver)
inlineinherited

Add a subscription without RAII link.

Parameters
aObserverObserver to subscribe.

Definition at line 146 of file observable.h.

147 {
148 OBSERVABLE_BASE::add_observer( static_cast<void*>( aObserver ) );
149 }

◆ Unsubscribe()

void UTIL::OBSERVABLE< GAL_DISPLAY_OPTIONS_OBSERVER >::Unsubscribe ( GAL_DISPLAY_OPTIONS_OBSERVER *  aObserver)
inlineinherited

Cancel the subscription of a subscriber.

This can be called during notification calls.

Parameters
aObserverobserver to remove from the subscription list.

Definition at line 170 of file observable.h.

171 {
172 OBSERVABLE_BASE::remove_observer( static_cast<void*>( aObserver ) );
173 }

◆ UpdateScaleFactor()

void GAL_DISPLAY_OPTIONS::UpdateScaleFactor ( )

Definition at line 134 of file gal_display_options.cpp.

135{
137 {
140 }
141}
double GetScaleFactor() const
Get the DPI scale from all known sources in order:

References DPI_SCALING::GetScaleFactor(), m_dpi, m_scaleFactor, and NotifyChanged().

Referenced by EDA_DRAW_FRAME::OnMove(), and ReadCommonConfig().

◆ WriteConfig()

Member Data Documentation

◆ cairo_antialiasing_mode

CAIRO_ANTIALIASING_MODE KIGFX::GAL_DISPLAY_OPTIONS::cairo_antialiasing_mode

◆ gl_antialiasing_mode

◆ impl_

◆ m_axesEnabled

◆ m_dpi

DPI_SCALING KIGFX::GAL_DISPLAY_OPTIONS::m_dpi

The grid style to draw the grid in.

Definition at line 118 of file gal_display_options.h.

Referenced by ReadCommonConfig(), and UpdateScaleFactor().

◆ m_forceDisplayCursor

bool KIGFX::GAL_DISPLAY_OPTIONS::m_forceDisplayCursor

◆ m_fullscreenCursor

bool KIGFX::GAL_DISPLAY_OPTIONS::m_fullscreenCursor

◆ m_gridLineWidth

double KIGFX::GAL_DISPLAY_OPTIONS::m_gridLineWidth

Minimum pixel distance between displayed grid lines.

Definition at line 127 of file gal_display_options.h.

Referenced by ReadWindowSettings(), KIGFX::GAL::updatedGalDisplayOptions(), and WriteConfig().

◆ m_gridMinSpacing

double KIGFX::GAL_DISPLAY_OPTIONS::m_gridMinSpacing

Whether or not to draw the coordinate system axes.

Definition at line 130 of file gal_display_options.h.

Referenced by ReadWindowSettings(), SYMBOL_VIEWER_FRAME::SYMBOL_VIEWER_FRAME(), KIGFX::GAL::updatedGalDisplayOptions(), and WriteConfig().

◆ m_gridSnapping

GRID_SNAPPING KIGFX::GAL_DISPLAY_OPTIONS::m_gridSnapping

Thickness to render grid lines/dots.

Definition at line 124 of file gal_display_options.h.

Referenced by KIGFX::GAL::GetGridSnapping(), ReadWindowSettings(), and WriteConfig().

◆ m_gridStyle

KIGFX::GRID_STYLE KIGFX::GAL_DISPLAY_OPTIONS::m_gridStyle

Snapping options for the grid.

Definition at line 121 of file gal_display_options.h.

Referenced by ReadWindowSettings(), KIGFX::GAL::updatedGalDisplayOptions(), and WriteConfig().

◆ m_scaleFactor

double KIGFX::GAL_DISPLAY_OPTIONS::m_scaleFactor

The documentation for this class was generated from the following files: