Browse Source
Break out the boundary violating parts of gal into common through subclassing
newinvert
Break out the boundary violating parts of gal into common through subclassing
newinvert
30 changed files with 540 additions and 339 deletions
-
43d-viewer/3d_model_viewer/eda_3d_model_viewer.cpp
-
43d-viewer/3d_viewer/eda_3d_viewer_frame.cpp
-
53d-viewer/dialogs/appearance_controls_3D.cpp
-
43d-viewer/dialogs/panel_preview_3d_model.cpp
-
3common/CMakeLists.txt
-
8common/dialogs/panel_common_settings.cpp
-
1common/dialogs/panel_data_collection.cpp
-
191common/dpi_scaling_common.cpp
-
1common/gal/CMakeLists.txt
-
167common/gal/dpi_scaling.cpp
-
85common/gal/gal_display_options.cpp
-
130common/gal_display_options_common.cpp
-
2common/tool/common_tools.cpp
-
1common/view/view_overlay.cpp
-
4common/widgets/color_swatch.cpp
-
4common/widgets/layer_box_selector.cpp
-
4common/widgets/wx_infobar.cpp
-
3eeschema/dialogs/panel_eeschema_color_settings.h
-
4eeschema/widgets/symbol_preview_widget.h
-
4gerbview/widgets/gbr_layer_box_selector.cpp
-
95include/dpi_scaling_common.h
-
5include/eda_draw_frame.h
-
26include/gal/dpi_scaling.h
-
34include/gal/gal_display_options.h
-
71include/gal_display_options_common.h
-
2pcbnew/dialogs/dialog_pad_properties.cpp
-
5pcbnew/footprint_preview_panel.cpp
-
3pcbnew/pcb_layer_box_selector.cpp
-
5pcbnew/widgets/appearance_controls.cpp
-
4qa/qa_utils/pcb_test_frame.cpp
@ -0,0 +1,191 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2019 KiCad Developers, see AUTHORS.TXT for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#include <dpi_scaling_common.h>
|
|||
|
|||
#include <optional>
|
|||
|
|||
#include <env_vars.h>
|
|||
#include <settings/common_settings.h>
|
|||
#include <kiplatform/ui.h>
|
|||
|
|||
#include <wx/log.h>
|
|||
#include <wx/window.h>
|
|||
|
|||
|
|||
/**
|
|||
* Flag to enable trace for HiDPI scaling factors |
|||
* |
|||
* Use "KICAD_TRACE_HIGH_DPI" to enable. |
|||
* |
|||
* @ingroup trace_env_vars |
|||
*/ |
|||
const wxChar* const traceHiDpi = wxT( "KICAD_TRACE_HIGH_DPI" ); |
|||
|
|||
|
|||
/**
|
|||
* Get a user-configured scale factor from KiCad config file |
|||
* |
|||
* @return the scale factor, if set |
|||
*/ |
|||
static std::optional<double> getKiCadConfiguredScale( const COMMON_SETTINGS& aConfig ) |
|||
{ |
|||
std::optional<double> scale; |
|||
double canvas_scale = aConfig.m_Appearance.canvas_scale; |
|||
|
|||
if( canvas_scale > 0.0 ) |
|||
{ |
|||
scale = canvas_scale; |
|||
} |
|||
|
|||
return scale; |
|||
} |
|||
|
|||
|
|||
/**
|
|||
* Get the toolkit scale factor from a user-set environment variable |
|||
* (for example GDK_SCALE on GTK). |
|||
* |
|||
* @return the scale factor, if set |
|||
*/ |
|||
static std::optional<double> getEnvironmentScale() |
|||
{ |
|||
const wxPortId port_id = wxPlatformInfo::Get().GetPortId(); |
|||
std::optional<double> scale; |
|||
|
|||
if( port_id == wxPORT_GTK ) |
|||
{ |
|||
// Under GTK, the user can use GDK_SCALE to force the scaling
|
|||
scale = ENV_VAR::GetEnvVar<double>( wxS( "GDK_SCALE" ) ); |
|||
} |
|||
|
|||
return scale; |
|||
} |
|||
|
|||
|
|||
DPI_SCALING_COMMON::DPI_SCALING_COMMON( COMMON_SETTINGS* aConfig, const wxWindow* aWindow ) |
|||
: m_config( aConfig ), m_window( aWindow ) |
|||
{ |
|||
} |
|||
|
|||
|
|||
double DPI_SCALING_COMMON::GetScaleFactor() const |
|||
{ |
|||
std::optional<double> val; |
|||
wxString src; |
|||
|
|||
if( m_config ) |
|||
{ |
|||
val = getKiCadConfiguredScale( *m_config ); |
|||
src = wxS( "config" ); |
|||
} |
|||
|
|||
if( !val ) |
|||
{ |
|||
val = getEnvironmentScale(); |
|||
src = wxS( "env" ); |
|||
} |
|||
|
|||
if( !val && m_window ) |
|||
{ |
|||
// Use the native WX reporting.
|
|||
// On Linux, this will not work until WX 3.2 and GTK >= 3.10
|
|||
// Otherwise it returns 1.0
|
|||
val = KIPLATFORM::UI::GetPixelScaleFactor( m_window ); |
|||
src = wxS( "platform" ); |
|||
} |
|||
|
|||
if( !val ) |
|||
{ |
|||
// Nothing else we can do, give it a default value
|
|||
val = GetDefaultScaleFactor(); |
|||
src = wxS( "default" ); |
|||
} |
|||
|
|||
wxLogTrace( traceHiDpi, wxS( "Scale factor (%s): %f" ), src, *val ); |
|||
|
|||
return *val; |
|||
} |
|||
|
|||
|
|||
double DPI_SCALING_COMMON::GetContentScaleFactor() const |
|||
{ |
|||
std::optional<double> val; |
|||
wxString src; |
|||
|
|||
if( m_config ) |
|||
{ |
|||
val = getKiCadConfiguredScale( *m_config ); |
|||
src = wxS( "config" ); |
|||
} |
|||
|
|||
if( !val ) |
|||
{ |
|||
val = getEnvironmentScale(); |
|||
src = wxS( "env" ); |
|||
} |
|||
|
|||
if( !val && m_window ) |
|||
{ |
|||
// Use the native WX reporting.
|
|||
// On Linux, this will not work until WX 3.2 and GTK >= 3.10
|
|||
// Otherwise it returns 1.0
|
|||
val = KIPLATFORM::UI::GetContentScaleFactor( m_window ); |
|||
src = wxS( "platform" ); |
|||
} |
|||
|
|||
if( !val ) |
|||
{ |
|||
// Nothing else we can do, give it a default value
|
|||
val = GetDefaultScaleFactor(); |
|||
src = wxS( "default" ); |
|||
} |
|||
|
|||
wxLogTrace( traceHiDpi, wxS( "Content scale factor (%s): %f" ), src, *val ); |
|||
|
|||
return *val; |
|||
} |
|||
|
|||
|
|||
bool DPI_SCALING_COMMON::GetCanvasIsAutoScaled() const |
|||
{ |
|||
if( m_config == nullptr ) |
|||
{ |
|||
// No configuration given, so has to be automatic scaling
|
|||
return true; |
|||
} |
|||
|
|||
const bool automatic = getKiCadConfiguredScale( *m_config ) == std::nullopt; |
|||
wxLogTrace( traceHiDpi, wxS( "Scale is automatic: %d" ), automatic ); |
|||
return automatic; |
|||
} |
|||
|
|||
|
|||
void DPI_SCALING_COMMON::SetDpiConfig( bool aAuto, double aValue ) |
|||
{ |
|||
wxCHECK_RET( m_config != nullptr, wxS( "Setting DPI config without a config store." ) ); |
|||
|
|||
const double value = aAuto ? 0.0 : aValue; |
|||
|
|||
m_config->m_Appearance.canvas_scale = value; |
|||
} |
@ -0,0 +1,130 @@ |
|||
/*
|
|||
* This program source code file is part of KICAD, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2016-2020 Kicad Developers, see change_log.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 2 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#include <gal_display_options_common.h>
|
|||
#include <settings/app_settings.h>
|
|||
#include <settings/common_settings.h>
|
|||
|
|||
#include <wx/log.h>
|
|||
|
|||
#include <config_map.h>
|
|||
#include <dpi_scaling_common.h>
|
|||
|
|||
using namespace KIGFX; |
|||
|
|||
/**
|
|||
* Flag to enable GAL_DISPLAY_OPTIONS logging |
|||
* |
|||
* Use "KICAD_GAL_DISPLAY_OPTIONS" to enable. |
|||
* |
|||
* @ingroup trace_env_vars |
|||
*/ |
|||
static const wxChar* traceGalDispOpts = wxT( "KICAD_GAL_DISPLAY_OPTIONS" ); |
|||
|
|||
|
|||
static const UTIL::CFG_MAP<KIGFX::GRID_STYLE> gridStyleConfigVals = { |
|||
{ KIGFX::GRID_STYLE::DOTS, 0 }, |
|||
{ KIGFX::GRID_STYLE::LINES, 1 }, |
|||
{ KIGFX::GRID_STYLE::SMALL_CROSS, 2 }, |
|||
}; |
|||
|
|||
static const UTIL::CFG_MAP<KIGFX::GRID_SNAPPING> gridSnapConfigVals = { |
|||
{ KIGFX::GRID_SNAPPING::ALWAYS, 0 }, |
|||
{ KIGFX::GRID_SNAPPING::WITH_GRID, 1 }, |
|||
{ KIGFX::GRID_SNAPPING::NEVER, 2 } |
|||
}; |
|||
|
|||
GAL_DISPLAY_OPTIONS_IMPL::GAL_DISPLAY_OPTIONS_IMPL() : |
|||
GAL_DISPLAY_OPTIONS(), |
|||
m_dpi( { nullptr, nullptr } ) |
|||
{ |
|||
} |
|||
|
|||
|
|||
void GAL_DISPLAY_OPTIONS_IMPL::ReadWindowSettings( WINDOW_SETTINGS& aCfg ) |
|||
{ |
|||
wxLogTrace( traceGalDispOpts, wxS( "Reading app-specific options" ) ); |
|||
|
|||
m_gridStyle = UTIL::GetValFromConfig( gridStyleConfigVals, aCfg.grid.style ); |
|||
m_gridSnapping = UTIL::GetValFromConfig( gridSnapConfigVals, aCfg.grid.snap ); |
|||
m_gridLineWidth = aCfg.grid.line_width; |
|||
m_gridMinSpacing = aCfg.grid.min_spacing; |
|||
m_axesEnabled = aCfg.grid.axes_enabled; |
|||
|
|||
m_fullscreenCursor = aCfg.cursor.fullscreen_cursor; |
|||
m_forceDisplayCursor = aCfg.cursor.always_show_cursor; |
|||
|
|||
NotifyChanged(); |
|||
} |
|||
|
|||
|
|||
void GAL_DISPLAY_OPTIONS_IMPL::ReadCommonConfig( COMMON_SETTINGS& aSettings, wxWindow* aWindow ) |
|||
{ |
|||
wxLogTrace( traceGalDispOpts, wxS( "Reading common config" ) ); |
|||
|
|||
gl_antialiasing_mode = |
|||
static_cast<KIGFX::OPENGL_ANTIALIASING_MODE>( aSettings.m_Graphics.opengl_aa_mode ); |
|||
|
|||
cairo_antialiasing_mode = |
|||
static_cast<KIGFX::CAIRO_ANTIALIASING_MODE>( aSettings.m_Graphics.cairo_aa_mode ); |
|||
|
|||
m_dpi = DPI_SCALING_COMMON( &aSettings, aWindow ); |
|||
UpdateScaleFactor(); |
|||
|
|||
NotifyChanged(); |
|||
} |
|||
|
|||
|
|||
void GAL_DISPLAY_OPTIONS_IMPL::ReadConfig( COMMON_SETTINGS& aCommonConfig, |
|||
WINDOW_SETTINGS& aWindowConfig, wxWindow* aWindow ) |
|||
{ |
|||
wxLogTrace( traceGalDispOpts, wxS( "Reading common and app config" ) ); |
|||
|
|||
ReadWindowSettings( aWindowConfig ); |
|||
|
|||
ReadCommonConfig( aCommonConfig, aWindow ); |
|||
} |
|||
|
|||
|
|||
void GAL_DISPLAY_OPTIONS_IMPL::WriteConfig( WINDOW_SETTINGS& aCfg ) |
|||
{ |
|||
wxLogTrace( traceGalDispOpts, wxS( "Writing window settings" ) ); |
|||
|
|||
aCfg.grid.style = UTIL::GetConfigForVal( gridStyleConfigVals, m_gridStyle ); |
|||
aCfg.grid.snap = UTIL::GetConfigForVal( gridSnapConfigVals, m_gridSnapping ); |
|||
aCfg.grid.line_width = m_gridLineWidth; |
|||
aCfg.grid.min_spacing = m_gridMinSpacing; |
|||
aCfg.grid.axes_enabled = m_axesEnabled; |
|||
aCfg.cursor.fullscreen_cursor = m_fullscreenCursor; |
|||
aCfg.cursor.always_show_cursor = m_forceDisplayCursor; |
|||
} |
|||
|
|||
|
|||
void GAL_DISPLAY_OPTIONS_IMPL::UpdateScaleFactor() |
|||
{ |
|||
if( m_scaleFactor != m_dpi.GetScaleFactor() ) |
|||
{ |
|||
m_scaleFactor = m_dpi.GetScaleFactor(); |
|||
NotifyChanged(); |
|||
} |
|||
} |
@ -0,0 +1,95 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2019 KiCad Developers, see AUTHORS.TXT for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|||
* or you may search the http://www.gnu.org website for the version 2 license, |
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#ifndef DPI_SCALING_COMMON__H |
|||
#define DPI_SCALING_COMMON__H |
|||
|
|||
#include <gal/dpi_scaling.h> |
|||
|
|||
class COMMON_SETTINGS; |
|||
class wxWindow; |
|||
|
|||
/** |
|||
* 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. |
|||
*/ |
|||
class DPI_SCALING_COMMON : public DPI_SCALING |
|||
{ |
|||
public: |
|||
/** |
|||
* Construct a DPI scale provider. |
|||
* |
|||
* @param aConfig the config store to check for a user value (can be nullptr, |
|||
* in which case on automatically determined values are considered) |
|||
* @param aWindow a WX window to use for automatic DPI determination |
|||
* @return the scaling factor (1.0 = no scaling) |
|||
*/ |
|||
DPI_SCALING_COMMON( COMMON_SETTINGS* aConfig, const wxWindow* aWindow ); |
|||
|
|||
/** |
|||
* 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) |
|||
*/ |
|||
double GetScaleFactor() const override; |
|||
|
|||
/** |
|||
* Get the content scale factor, which may be different from the scale |
|||
* factor on some platforms. This value should be used for scaling |
|||
* user interface elements (fonts, icons, etc) whereas the scale |
|||
* factor should be used for scaling canvases. |
|||
*/ |
|||
double GetContentScaleFactor() const override; |
|||
|
|||
/** |
|||
* Is the current value auto scaled, or is it user-set in the config |
|||
*/ |
|||
bool GetCanvasIsAutoScaled() const override; |
|||
|
|||
/** |
|||
* Set the common DPI config in a given config object |
|||
* |
|||
* The encoding of the automatic/manual nature of the config is handled internally. |
|||
* |
|||
* @param aAuto store a value meaning "no user-set scale" |
|||
* @param aValue the value to store (ignored if aAuto set) |
|||
*/ |
|||
void SetDpiConfig( bool aAuto, double aValue ) override; |
|||
|
|||
private: |
|||
/** |
|||
* The configuration object to use to get/set user setting. nullptr |
|||
* if only automatic options are wanted |
|||
*/ |
|||
COMMON_SETTINGS* m_config; |
|||
|
|||
/** |
|||
* The WX window to use for WX's automatic DPI checking |
|||
*/ |
|||
const wxWindow* m_window; |
|||
}; |
|||
|
|||
#endif // DPI_SCALING__H |
@ -0,0 +1,71 @@ |
|||
/* |
|||
* This program source code file is part of KICAD, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 2 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
|||
* or you may search the http://www.gnu.org website for the version 2 license, |
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#ifndef GAL_DISPLAY_OPTIONS_COMMON_H__ |
|||
#define GAL_DISPLAY_OPTIONS_COMMON_H__ |
|||
|
|||
#include <gal/gal_display_options.h> |
|||
#include <dpi_scaling_common.h> |
|||
|
|||
class COMMON_SETTINGS; |
|||
struct WINDOW_SETTINGS; |
|||
class wxString; |
|||
class wxWindow; |
|||
|
|||
|
|||
class GAL_DISPLAY_OPTIONS_IMPL : public KIGFX::GAL_DISPLAY_OPTIONS |
|||
{ |
|||
public: |
|||
GAL_DISPLAY_OPTIONS_IMPL(); |
|||
|
|||
/** |
|||
* Read GAL config options from application-level config |
|||
* @param aCfg the window settings to load from |
|||
*/ |
|||
void ReadWindowSettings( WINDOW_SETTINGS& aCfg ); |
|||
|
|||
/** |
|||
* Read GAL config options from the common config store |
|||
* @param aCommonSettings the common config store |
|||
* @param aWindow the wx parent window (used for DPI scaling) |
|||
*/ |
|||
void ReadCommonConfig( COMMON_SETTINGS& aCommonSettings, wxWindow* aWindow ); |
|||
|
|||
/** |
|||
* Read application and common configs |
|||
* @param aCommonConfig the common config store |
|||
* @param aCfg the application config base |
|||
* @param aBaseName the application's GAL options key prefix |
|||
* @param aWindow the wx parent window (used for DPI scaling) |
|||
*/ |
|||
void ReadConfig( COMMON_SETTINGS& aCommonConfig, WINDOW_SETTINGS& aWindowConfig, |
|||
wxWindow* aWindow ); |
|||
|
|||
void WriteConfig( WINDOW_SETTINGS& aCfg ); |
|||
|
|||
void UpdateScaleFactor(); |
|||
|
|||
DPI_SCALING_COMMON m_dpi; |
|||
}; |
|||
|
|||
#endif |
Write
Preview
Loading…
Cancel
Save
Reference in new issue