From c9f9db906964df6951a4c9ea42bdfbd57599eac4 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 8 Jul 2013 20:42:46 +0200 Subject: [PATCH] Dynamic color setting for netnames. --- include/gal/color4d.h | 11 +++++++++++ pcbnew/pcb_painter.cpp | 24 ++++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/include/gal/color4d.h b/include/gal/color4d.h index f11f6487db..64616239e6 100644 --- a/include/gal/color4d.h +++ b/include/gal/color4d.h @@ -132,6 +132,17 @@ public: a ); } + /** + * Function GetBrightness + * Returns the brightness value of the color ranged from 0.0 to 1.0. + * @return The brightness value. + */ + double GetBrightness() const + { + // Weighted W3C formula + return ( r * 0.299 + g * 0.587 + b * 0.117 ); + } + /// @brief Equality operator, are two colors equal const bool operator==( const COLOR4D& aColor ); diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 9c08ee2251..1efc19d092 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -263,9 +263,7 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) VECTOR2D end( aTrack->GetEnd() ); int width = aTrack->GetWidth(); int netNumber = aTrack->GetNet(); - COLOR4D color = getLayerColor( aLayer, netNumber ); - - m_gal->SetStrokeColor( color ); + COLOR4D color; if( IsNetnameLayer( aLayer ) ) { @@ -285,6 +283,13 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) double textOrientation = -atan( line.y / line.x ); double textSize = std::min( static_cast( width ), length / netName.length() ); + // Set a proper color for the label + color = getLayerColor( aTrack->GetLayer(), aTrack->GetNet() ); + if( color.GetBrightness() > 0.5 ) + m_gal->SetStrokeColor( color.Darkened( 0.8 ) ); + else + m_gal->SetStrokeColor( color.Highlighted( 0.8 ) ); + m_gal->SetLineWidth( width / 10.0 ); m_gal->SetBold( false ); m_gal->SetItalic( false ); @@ -298,6 +303,8 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) else if( IsCopperLayer( aLayer )) { // Draw a regular track + color = getLayerColor( aLayer, netNumber ); + m_gal->SetStrokeColor( color ); m_gal->SetIsStroke( true ); if( m_pcbSettings->m_sketchModeSelect[TRACKS_VISIBLE] ) @@ -368,8 +375,6 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) NORMALIZE_ANGLE_90( orientation ); // do not display descriptions upside down orientation = orientation * M_PI / 1800.0; - color = getLayerColor( aLayer, aPad->GetNet() ); - // Draw description layer if( aLayer == ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ) ) { @@ -409,7 +414,13 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) m_gal->SetBold( false ); m_gal->SetItalic( false ); m_gal->SetMirrored( false ); - m_gal->SetStrokeColor( color ); + + // Set a proper color for the label + color = getLayerColor( aPad->GetParent()->GetLayer(), aPad->GetNet() ); + if( color.GetBrightness() > 0.5 ) + m_gal->SetStrokeColor( color.Darkened( 0.8 ) ); + else + m_gal->SetStrokeColor( color.Highlighted( 0.8 ) ); // Let's make some space for a netname too, if there's one to display if( !aPad->GetNetname().empty() ) @@ -435,6 +446,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) return; } + color = getLayerColor( aLayer, aPad->GetNet() ); if( m_pcbSettings->m_sketchModeSelect[PADS_VISIBLE] ) { // Outline mode