Commit 6c3534bd authored by Maciej Suminski's avatar Maciej Suminski

Dynamic color setting for netnames.

parent 32db0d46
...@@ -132,6 +132,17 @@ public: ...@@ -132,6 +132,17 @@ public:
a ); 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 /// @brief Equality operator, are two colors equal
const bool operator==( const COLOR4D& aColor ); const bool operator==( const COLOR4D& aColor );
......
...@@ -263,9 +263,7 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) ...@@ -263,9 +263,7 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer )
VECTOR2D end( aTrack->GetEnd() ); VECTOR2D end( aTrack->GetEnd() );
int width = aTrack->GetWidth(); int width = aTrack->GetWidth();
int netNumber = aTrack->GetNet(); int netNumber = aTrack->GetNet();
COLOR4D color = getLayerColor( aLayer, netNumber ); COLOR4D color;
m_gal->SetStrokeColor( color );
if( IsNetnameLayer( aLayer ) ) if( IsNetnameLayer( aLayer ) )
{ {
...@@ -285,6 +283,13 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) ...@@ -285,6 +283,13 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer )
double textOrientation = -atan( line.y / line.x ); double textOrientation = -atan( line.y / line.x );
double textSize = std::min( static_cast<double>( width ), length / netName.length() ); double textSize = std::min( static_cast<double>( 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->SetLineWidth( width / 10.0 );
m_gal->SetBold( false ); m_gal->SetBold( false );
m_gal->SetItalic( false ); m_gal->SetItalic( false );
...@@ -298,6 +303,8 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) ...@@ -298,6 +303,8 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer )
else if( IsCopperLayer( aLayer )) else if( IsCopperLayer( aLayer ))
{ {
// Draw a regular track // Draw a regular track
color = getLayerColor( aLayer, netNumber );
m_gal->SetStrokeColor( color );
m_gal->SetIsStroke( true ); m_gal->SetIsStroke( true );
if( m_pcbSettings->m_sketchModeSelect[TRACKS_VISIBLE] ) if( m_pcbSettings->m_sketchModeSelect[TRACKS_VISIBLE] )
...@@ -368,8 +375,6 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) ...@@ -368,8 +375,6 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
NORMALIZE_ANGLE_90( orientation ); // do not display descriptions upside down NORMALIZE_ANGLE_90( orientation ); // do not display descriptions upside down
orientation = orientation * M_PI / 1800.0; orientation = orientation * M_PI / 1800.0;
color = getLayerColor( aLayer, aPad->GetNet() );
// Draw description layer // Draw description layer
if( aLayer == ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ) ) if( aLayer == ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ) )
{ {
...@@ -409,7 +414,13 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) ...@@ -409,7 +414,13 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
m_gal->SetBold( false ); m_gal->SetBold( false );
m_gal->SetItalic( false ); m_gal->SetItalic( false );
m_gal->SetMirrored( 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 // Let's make some space for a netname too, if there's one to display
if( !aPad->GetNetname().empty() ) if( !aPad->GetNetname().empty() )
...@@ -435,6 +446,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) ...@@ -435,6 +446,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
return; return;
} }
color = getLayerColor( aLayer, aPad->GetNet() );
if( m_pcbSettings->m_sketchModeSelect[PADS_VISIBLE] ) if( m_pcbSettings->m_sketchModeSelect[PADS_VISIBLE] )
{ {
// Outline mode // Outline mode
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment