Desaturate the symbols in DNP for print/plot

The desaturation should match screen display

Fixes https://gitlab.com/kicad/code/kicad/issues/13481
This commit is contained in:
Seth Hillbrand 2023-01-11 12:53:09 -08:00
parent 89a6e55e58
commit a206f6717d
11 changed files with 91 additions and 13 deletions

View File

@ -527,6 +527,21 @@ COLOR4D& COLOR4D::Saturate( double aFactor )
}
COLOR4D& COLOR4D::Desaturate()
{
// One can desaturate a color only when r, v, b are not equal
if( r == g && r == b )
return *this;
double h, s, l;
ToHSL( h, s, l );
FromHSL( h, 0.0, l );
return *this;
}
const COLOR4D COLOR4D::UNSPECIFIED( 0, 0, 0, 0 );
const COLOR4D COLOR4D::WHITE( 1, 1, 1, 1 );
const COLOR4D COLOR4D::BLACK( 0, 0, 0, 1 );

View File

@ -146,7 +146,10 @@ void LIB_FIELD::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset
color = GetTextColor();
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
KIFONT::FONT* font = GetFont();
@ -369,7 +372,10 @@ void LIB_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffs
}
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
int penWidth = GetEffectivePenWidth( renderSettings );
KIFONT::FONT* font = GetFont();

View File

@ -237,7 +237,10 @@ void LIB_PIN::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
bg = COLOR4D::WHITE;
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
GRCircle( DC, pos1, TARGET_PIN_RADIUS, 0, color );
}
@ -261,7 +264,10 @@ void LIB_PIN::printPinSymbol( const RENDER_SETTINGS* aSettings, const VECTOR2I&
bg = aSettings->GetLayerColor( LAYER_HIDDEN );
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
MapX1 = MapY1 = 0;
x1 = posX;
@ -400,6 +406,8 @@ void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos
if( aDimmed )
{
nameColor.Desaturate();
numColor.Desaturate();
nameColor = nameColor.Mix( bg, 0.5f );
numColor = numColor.Mix( bg, 0.5f );
}
@ -565,7 +573,10 @@ void LIB_PIN::printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, VECT
bg = aSettings->GetLayerColor( LAYER_HIDDEN );
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
VECTOR2I txtpos = aPosition;
int offset = schIUScale.mmToIU( 0.4 );
@ -613,7 +624,10 @@ void LIB_PIN::PlotSymbol( PLOTTER *aPlotter, const VECTOR2I &aPosition, int aOri
bg = COLOR4D::WHITE;
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
aPlotter->SetColor( color );
aPlotter->SetCurrentLineWidth( penWidth );
@ -776,6 +790,8 @@ void LIB_PIN::PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, int aPin
if( aDimmed )
{
nameColor.Desaturate( );
numColor.Desaturate( );
nameColor = nameColor.Mix( bg, 0.5f );
numColor = numColor.Mix( bg, 0.5f );
}

View File

@ -226,7 +226,10 @@ void LIB_SHAPE::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffs
bg = COLOR4D::WHITE;
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
aPlotter->SetColor( color );
aPlotter->SetDash( penWidth, lineStyle );
@ -296,7 +299,10 @@ void LIB_SHAPE::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset
bg = COLOR4D::WHITE;
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
unsigned ptCount = 0;
VECTOR2I* buffer = nullptr;
@ -351,6 +357,12 @@ void LIB_SHAPE::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset
if( fillColor != COLOR4D::UNSPECIFIED )
{
if( aDimmed )
{
fillColor.Desaturate( );
fillColor = color.Mix( bg, 0.5f );
}
switch( GetShape() )
{
case SHAPE_T::ARC:

View File

@ -714,8 +714,10 @@ void LIB_SYMBOL::Plot( PLOTTER *aPlotter, int aUnit, int aConvert, bool aBackgro
bg = COLOR4D::WHITE;
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
aPlotter->SetColor( color );
for( const LIB_ITEM& item : m_drawings )
@ -753,7 +755,10 @@ void LIB_SYMBOL::PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert, bool
bg = COLOR4D::WHITE;
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
aPlotter->SetColor( color );

View File

@ -294,7 +294,10 @@ void LIB_TEXT::Plot( PLOTTER* plotter, bool aBackground, const VECTOR2I& offset,
bg = COLOR4D::WHITE;
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
int penWidth = std::max( GetEffectiveTextPenWidth(), settings->GetMinPenWidth() );
@ -346,7 +349,10 @@ void LIB_TEXT::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
bg = aSettings->GetLayerColor( LAYER_HIDDEN );
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
// Calculate the text orientation, according to the symbol orientation/mirror (needed when
// draw text in schematic)

View File

@ -253,7 +253,10 @@ void LIB_TEXTBOX::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffs
bg = COLOR4D::WHITE;
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
if( lineStyle == PLOT_DASH_TYPE::DEFAULT )
lineStyle = PLOT_DASH_TYPE::SOLID;
@ -295,7 +298,10 @@ void LIB_TEXTBOX::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffs
bg = COLOR4D::WHITE;
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
penWidth = std::max( GetEffectiveTextPenWidth(), aSettings->GetMinPenWidth() );
@ -411,7 +417,10 @@ void LIB_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOf
lineStyle = PLOT_DASH_TYPE::DASH;
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
aPlotter->SetColor( color );
aPlotter->SetDash( penWidth, lineStyle );
@ -432,7 +441,10 @@ void LIB_TEXTBOX::Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOf
color = renderSettings->GetLayerColor( LAYER_DEVICE );
if( aDimmed )
{
color.Desaturate( );
color = color.Mix( bg, 0.5f );
}
penWidth = std::max( GetEffectiveTextPenWidth(), aPlotter->RenderSettings()->GetMinPenWidth() );

View File

@ -375,7 +375,10 @@ void SCH_FIELD::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset
}
if( parentSymbol && parentSymbol->GetDNP() )
{
color.Desaturate();
color = color.Mix( bg, 0.5f );
}
}
KIFONT::FONT* font = GetFont();
@ -1002,7 +1005,10 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground ) const
SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
if( parentSymbol->GetDNP() )
{
color.Desaturate();
color = color.Mix( bg, 0.5f );
}
if( parentSymbol->GetTransform().y1 ) // Rotate symbol 90 deg.
{

View File

@ -472,13 +472,8 @@ COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM *aItem, int aLayer, bool aDr
if( aDimmed )
{
double hue;
double sat;
double light;
color.ToHSL( hue, sat, light );
color.FromHSL( hue, 0.0, light );
COLOR4D sheetColour = m_schSettings.GetLayerColor( LAYER_SCHEMATIC_BACKGROUND );
color.Desaturate();
color = color.Mix( sheetColour, 0.5f );
}
@ -745,12 +740,9 @@ bool SCH_PAINTER::setDeviceColors( const LIB_ITEM* aItem, int aLayer, bool aDimm
if( aDimmed )
{
double hue, sat, light;
fillColour.ToHSL( hue, sat, light );
fillColour.FromHSL( hue, 0.0, light );
fillColour = fillColour.Mix(
m_schSettings.GetLayerColor( LAYER_SCHEMATIC_BACKGROUND ), 0.5f );
fillColour.Desaturate( );
}
m_gal->SetFillColor( fillColour );
@ -1136,7 +1128,10 @@ void SCH_PAINTER::draw( const LIB_TEXTBOX* aTextBox, int aLayer, bool aDimmed )
}
if( aDimmed )
{
borderColor.Desaturate( );
borderColor = borderColor.Mix( bg, 0.5f );
}
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );

View File

@ -480,8 +480,7 @@ void SCH_SYMBOL::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffse
{
BOX2I bbox = GetBodyAndPinsBoundingBox();
wxDC* DC = aSettings->GetPrintDC();
COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
COLOR4D dnp_color = colors->GetColor( LAYER_ERC_ERR );
COLOR4D dnp_color = aSettings->GetLayerColor( LAYER_ERC_ERR );
GRFilledSegment( DC, bbox.GetOrigin(), bbox.GetEnd(),
3.0 * schIUScale.MilsToIU( DEFAULT_LINE_WIDTH_MILS ),

View File

@ -269,6 +269,12 @@ public:
*/
COLOR4D& Saturate( double aFactor );
/**
* Removes color (in HSL model)
* @return greyscale version of color
*/
COLOR4D& Desaturate();
/**
* Return a color that is brighter by a given factor, without modifying object.
*