KiCad PCB EDA Suite
DPI_SCALING Class Reference

Class to handle configuration and automatic determination of the DPI scale to use for canvases. More...

#include <dpi_scaling.h>

Public Member Functions

 DPI_SCALING (COMMON_SETTINGS *aConfig, const wxWindow *aWindow)
 Construct a DPI scale provider. More...
 
double GetScaleFactor () const
 Get the DPI scale from all known sources in order: More...
 
bool GetCanvasIsAutoScaled () const
 Is the current value auto scaled, or is it user-set in the config. More...
 
void SetDpiConfig (bool aAuto, double aValue)
 Set the common DPI config in a given config object. More...
 

Static Public Member Functions

static double GetMaxScaleFactor ()
 
static double GetMinScaleFactor ()
 
static double GetDefaultScaleFactor ()
 Get the "default" scaling factor to use if not other config is available. More...
 

Private Attributes

COMMON_SETTINGSm_config
 The configuration object to use to get/set user setting. More...
 
const wxWindow * m_window
 The WX window to use for WX's automatic DPI checking. More...
 

Detailed Description

Class to handle configuration and automatic determination of the DPI scale to use for canvases.

This has several sources and the availability of some of them are platform dependent.

Definition at line 36 of file dpi_scaling.h.

Constructor & Destructor Documentation

◆ DPI_SCALING()

DPI_SCALING::DPI_SCALING ( COMMON_SETTINGS aConfig,
const wxWindow *  aWindow 
)

Construct a DPI scale provider.

Parameters
aConfigthe config store to check for a user value (can be nullptr, in which case on automatically determined values are considered)
aWindowa WX window to use for automatic DPI determination
Returns
the scaling factor (1.0 = no scaling)

Definition at line 95 of file dpi_scaling.cpp.

96  : m_config( aConfig ), m_window( aWindow )
97 {
98 }
const wxWindow * m_window
The WX window to use for WX's automatic DPI checking.
Definition: dpi_scaling.h:100
COMMON_SETTINGS * m_config
The configuration object to use to get/set user setting.
Definition: dpi_scaling.h:95

Member Function Documentation

◆ GetCanvasIsAutoScaled()

bool DPI_SCALING::GetCanvasIsAutoScaled ( ) const

Is the current value auto scaled, or is it user-set in the config.

Definition at line 135 of file dpi_scaling.cpp.

136 {
137  if( m_config == nullptr )
138  {
139  // No configuration given, so has to be automatic scaling
140  return true;
141  }
142 
143  const bool automatic = getKiCadConfiguredScale( *m_config ) == boost::none;
144  wxLogTrace( traceHiDpi, "Scale is automatic: %d", automatic );
145  return automatic;
146 }
const wxChar *const traceHiDpi
Flag to enable trace for HiDPI scaling factors.
Definition: dpi_scaling.cpp:42
static OPT< double > getKiCadConfiguredScale(const COMMON_SETTINGS &aConfig)
Get a user-configured scale factor from KiCad config file.
Definition: dpi_scaling.cpp:50
COMMON_SETTINGS * m_config
The configuration object to use to get/set user setting.
Definition: dpi_scaling.h:95

References getKiCadConfiguredScale(), m_config, and traceHiDpi.

Referenced by PANEL_COMMON_SETTINGS::TransferDataToWindow().

◆ GetDefaultScaleFactor()

double DPI_SCALING::GetDefaultScaleFactor ( )
static

Get the "default" scaling factor to use if not other config is available.

Definition at line 173 of file dpi_scaling.cpp.

174 {
175  // no scaling => 1.0
176  return 1.0;
177 }

Referenced by GetScaleFactor(), and PANEL_COMMON_SETTINGS::PANEL_COMMON_SETTINGS().

◆ GetMaxScaleFactor()

double DPI_SCALING::GetMaxScaleFactor ( )
static

Definition at line 159 of file dpi_scaling.cpp.

160 {
161  // displays with higher than 4.0 DPI are not really going to be useful
162  // for KiCad (even an 8k display would be effectively only ~1080p at 4x)
163  return 6.0;
164 }

Referenced by PANEL_COMMON_SETTINGS::PANEL_COMMON_SETTINGS().

◆ GetMinScaleFactor()

double DPI_SCALING::GetMinScaleFactor ( )
static

Definition at line 167 of file dpi_scaling.cpp.

168 {
169  // scales under 1.0 don't make sense from a HiDPI perspective
170  return 1.0;
171 }

Referenced by PANEL_COMMON_SETTINGS::PANEL_COMMON_SETTINGS().

◆ GetScaleFactor()

double DPI_SCALING::GetScaleFactor ( ) const

Get the DPI scale from all known sources in order:

  • user config, if given
  • user's environment variables, if set and according to platform
  • WX's internal determination of the DPI scaling (WX > 3.1)

Definition at line 101 of file dpi_scaling.cpp.

102 {
103  OPT<double> val;
104 
105  if( m_config )
106  {
108  }
109 
110  if( !val )
111  {
112  val = getEnviromentScale();
113  }
114 
115  if( !val && m_window )
116  {
117  // Use the native WX reporting.
118  // On Linux, this will not work until WX 3.2 and GTK >= 3.10
119  // Otherwise it returns 1.0
120  val = m_window->GetContentScaleFactor();
121  wxLogTrace( traceHiDpi, "Scale factor (WX): %f", *val );
122  }
123 
124  if( !val )
125  {
126  // Nothing else we can do, give it a default value
127  val = GetDefaultScaleFactor();
128  wxLogTrace( traceHiDpi, "Scale factor (default): %f", *val );
129  }
130 
131  return *val;
132 }
static double GetDefaultScaleFactor()
Get the "default" scaling factor to use if not other config is available.
static OPT< double > getEnviromentScale()
Get the toolkit scale factor from a user-set environment variable (for example GDK_SCALE on GTK).
Definition: dpi_scaling.cpp:75
const wxChar *const traceHiDpi
Flag to enable trace for HiDPI scaling factors.
Definition: dpi_scaling.cpp:42
static OPT< double > getKiCadConfiguredScale(const COMMON_SETTINGS &aConfig)
Get a user-configured scale factor from KiCad config file.
Definition: dpi_scaling.cpp:50
boost::optional< T > OPT
Definition: optional.h:7
const wxWindow * m_window
The WX window to use for WX's automatic DPI checking.
Definition: dpi_scaling.h:100
COMMON_SETTINGS * m_config
The configuration object to use to get/set user setting.
Definition: dpi_scaling.h:95

References GetDefaultScaleFactor(), getEnviromentScale(), getKiCadConfiguredScale(), m_config, m_window, and traceHiDpi.

Referenced by PANEL_COMMON_SETTINGS::OnCanvasScaleAuto(), PANEL_COMMON_SETTINGS::TransferDataToWindow(), and KIGFX::GAL_DISPLAY_OPTIONS::UpdateScaleFactor().

◆ SetDpiConfig()

void DPI_SCALING::SetDpiConfig ( bool  aAuto,
double  aValue 
)

Set the common DPI config in a given config object.

The encoding of the automatic/manual nature of the config is handled internally.

Parameters
aAutostore a value meaning "no user-set scale"
aValuethe value to store (ignored if aAuto set)

Definition at line 149 of file dpi_scaling.cpp.

150 {
151  wxCHECK_RET( m_config != nullptr, "Setting DPI config without a config store." );
152 
153  const double value = aAuto ? 0.0 : aValue;
154 
156 }
APPEARANCE m_Appearance
COMMON_SETTINGS * m_config
The configuration object to use to get/set user setting.
Definition: dpi_scaling.h:95

References COMMON_SETTINGS::APPEARANCE::canvas_scale, COMMON_SETTINGS::m_Appearance, and m_config.

Referenced by PANEL_COMMON_SETTINGS::TransferDataFromWindow().

Member Data Documentation

◆ m_config

COMMON_SETTINGS* DPI_SCALING::m_config
private

The configuration object to use to get/set user setting.

nullptr if only automatic options are wanted

Definition at line 95 of file dpi_scaling.h.

Referenced by GetCanvasIsAutoScaled(), GetScaleFactor(), and SetDpiConfig().

◆ m_window

const wxWindow* DPI_SCALING::m_window
private

The WX window to use for WX's automatic DPI checking.

Definition at line 100 of file dpi_scaling.h.

Referenced by GetScaleFactor().


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