From 4a52062a54193461075b0fb6223cd499152464ea Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sun, 9 Jun 2019 08:13:50 -0700 Subject: [PATCH] GAL: Make high-contrast meld into background This mixes the de-emphasized layers into the background color rather than merely a black color. This also keeps some of the original layer color. Fixes: lp:1831316 * https://bugs.launchpad.net/kicad/+bug/1831316 --- common/painter.cpp | 7 +++---- gerbview/gerbview_painter.cpp | 2 +- include/gal/color4d.h | 16 ++++++++++++++++ include/painter.h | 4 +++- pcbnew/pcb_painter.cpp | 2 +- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/common/painter.cpp b/common/painter.cpp index caa7a3e47a..26990602ae 100644 --- a/common/painter.cpp +++ b/common/painter.cpp @@ -37,7 +37,7 @@ RENDER_SETTINGS::RENDER_SETTINGS() m_layerOpacity = 0.8; m_highlightEnabled = false; m_hiContrastEnabled = false; - m_hiContrastFactor = 0.2; + m_hiContrastFactor = 0.2; //TODO: Make this user-configurable m_highlightNetcode = -1; m_outlineWidth = 1; m_worksheetLineWidth = 100000; @@ -52,12 +52,11 @@ RENDER_SETTINGS::~RENDER_SETTINGS() void RENDER_SETTINGS::update() { - m_hiContrastColor = COLOR4D( m_hiContrastFactor, m_hiContrastFactor, m_hiContrastFactor, - m_layerOpacity ); - // Calculate darkened/highlighted variants of layer colors for( int i = 0; i < LAYER_ID_COUNT; i++ ) { + m_hiContrastColor[i] = m_layerColors[i].Mix( m_layerColors[LAYER_PCB_BACKGROUND], + m_hiContrastFactor ); m_layerColorsHi[i] = m_layerColors[i].Brightened( m_highlightFactor ); m_layerColorsDark[i] = m_layerColors[i].Darkened( 1.0 - m_highlightFactor ); m_layerColorsSel[i] = m_layerColors[i].Brightened( m_selectFactor ); diff --git a/gerbview/gerbview_painter.cpp b/gerbview/gerbview_painter.cpp index 7920d30b25..a8e3455bff 100644 --- a/gerbview/gerbview_painter.cpp +++ b/gerbview/gerbview_painter.cpp @@ -133,7 +133,7 @@ const COLOR4D& GERBVIEW_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int a // Return grayish color for non-highlighted layers in the high contrast mode if( m_hiContrastEnabled && m_activeLayers.count( aLayer ) == 0) - return m_hiContrastColor; + return m_hiContrastColor[aLayer]; // Catch the case when highlight and high-contraste modes are enabled // and we are drawing a not highlighted track diff --git a/include/gal/color4d.h b/include/gal/color4d.h index 94eed1730e..1b3932623d 100644 --- a/include/gal/color4d.h +++ b/include/gal/color4d.h @@ -222,6 +222,22 @@ public: a ); } + /** + * Function Mix + * Returns a color that is mixed with the input by a factor + * @param aFactor Specifies how much of the original color to keep (valid values: 0.0 .. 1.0). + * @return COLOR4D Mixed color. + */ + COLOR4D Mix( const COLOR4D& aColor, double aFactor ) const + { + assert( aFactor >= 0.0 && aFactor <= 1.0 ); + + return COLOR4D( aColor.r * ( 1.0 - aFactor ) + r * aFactor, + aColor.g * ( 1.0 - aFactor ) + g * aFactor, + aColor.b * ( 1.0 - aFactor ) + b * aFactor, + a ); + } + /** * Function WithAlpha * Returns a colour with the same colour, but the given alpha diff --git a/include/painter.h b/include/painter.h index 4fdb5eebdc..9aa8100d2d 100644 --- a/include/painter.h +++ b/include/painter.h @@ -271,9 +271,11 @@ protected: ///> Colors for all layers (darkened) COLOR4D m_layerColorsDark[LAYER_ID_COUNT]; + ///< Colora used for high contrast display mode + COLOR4D m_hiContrastColor[LAYER_ID_COUNT]; + /// Parameters for display modes bool m_hiContrastEnabled; ///< High contrast display mode on/off - COLOR4D m_hiContrastColor; ///< Color used for high contrast display mode float m_hiContrastFactor; ///< Factor used for computing high contrast color bool m_highlightEnabled; ///< Highlight display mode on/off diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index ba9b1eeb6a..341299c812 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -254,7 +254,7 @@ const COLOR4D& PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer // Return grayish color for non-highlighted layers in the high contrast mode if( m_hiContrastEnabled && m_activeLayers.count( aLayer ) == 0 ) - return m_hiContrastColor; + return m_hiContrastColor[aLayer]; // Catch the case when highlight and high-contraste modes are enabled // and we are drawing a not highlighted track