Commit afe2e27b authored by Maciej Suminski's avatar Maciej Suminski

Moved GetColor() from PAINTER to RENDER_SETTINGS. Fixed recaching of custom items.

parent c5d3376c
...@@ -370,7 +370,7 @@ struct VIEW::updateItemsColor ...@@ -370,7 +370,7 @@ struct VIEW::updateItemsColor
void operator()( VIEW_ITEM* aItem ) void operator()( VIEW_ITEM* aItem )
{ {
// Obtain the color that should be used for coloring the item // Obtain the color that should be used for coloring the item
const COLOR4D color = painter->GetColor( aItem, layer ); const COLOR4D color = painter->GetSettings()->GetColor( aItem, layer );
int group = aItem->getGroup( layer ); int group = aItem->getGroup( layer );
if( group >= 0 ) if( group >= 0 )
...@@ -672,7 +672,8 @@ struct VIEW::recacheLayer ...@@ -672,7 +672,8 @@ struct VIEW::recacheLayer
{ {
int group = gal->BeginGroup(); int group = gal->BeginGroup();
aItem->setGroup( layer, group ); aItem->setGroup( layer, group );
view->m_painter->Draw( static_cast<EDA_ITEM*>( aItem ), layer ); if( !view->m_painter->Draw( aItem, layer ) )
aItem->ViewDraw( layer, gal, BOX2I() ); // Alternative drawing method
gal->EndGroup(); gal->EndGroup();
} }
else else
...@@ -836,7 +837,7 @@ void VIEW::updateItemColor( VIEW_ITEM* aItem, int aLayer ) ...@@ -836,7 +837,7 @@ void VIEW::updateItemColor( VIEW_ITEM* aItem, int aLayer )
wxASSERT( (unsigned) aLayer < m_layers.size() ); wxASSERT( (unsigned) aLayer < m_layers.size() );
// Obtain the color that should be used for coloring the item on the specific layerId // Obtain the color that should be used for coloring the item on the specific layerId
const COLOR4D color = m_painter->GetColor( aItem, aLayer ); const COLOR4D color = m_painter->GetSettings()->GetColor( aItem, aLayer );
int group = aItem->getGroup( aLayer ); int group = aItem->getGroup( aLayer );
// Change the color, only if it has group assigned // Change the color, only if it has group assigned
......
...@@ -113,6 +113,16 @@ public: ...@@ -113,6 +113,16 @@ public:
m_hiContrastEnabled = aEnabled; m_hiContrastEnabled = aEnabled;
} }
/**
* Function GetColor
* Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer
* using currently used render settings.
* @param aItem is the VIEW_ITEM.
* @param aLayer is the layer.
* @return The color.
*/
virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0;
protected: protected:
/** /**
* Function update * Function update
...@@ -217,16 +227,6 @@ public: ...@@ -217,16 +227,6 @@ public:
*/ */
virtual void DrawBrightened( const VIEW_ITEM* aItem ); virtual void DrawBrightened( const VIEW_ITEM* aItem );
/**
* Function GetColor
* Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer
* using currently used render settings.
* @param aItem is the VIEW_ITEM.
* @param aLayer is the layer.
* @return The color.
*/
virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) = 0;
protected: protected:
/// Instance of graphic abstraction layer that gives an interface to call /// Instance of graphic abstraction layer that gives an interface to call
/// commands used to draw (eg. DrawLine, DrawCircle, etc.) /// commands used to draw (eg. DrawLine, DrawCircle, etc.)
......
...@@ -137,29 +137,7 @@ void PCB_RENDER_SETTINGS::LoadDisplayOptions( const DISPLAY_OPTIONS& aOptions ) ...@@ -137,29 +137,7 @@ void PCB_RENDER_SETTINGS::LoadDisplayOptions( const DISPLAY_OPTIONS& aOptions )
} }
void PCB_RENDER_SETTINGS::update() const COLOR4D& PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) const
{
// Calculate darkened/highlighted variants of layer colors
for( int i = 0; i < TOTAL_LAYER_COUNT; i++ )
{
m_layerColors[i].a = m_layerOpacity;
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 );
}
m_hiContrastColor = COLOR4D( m_hiContrastFactor, m_hiContrastFactor, m_hiContrastFactor,
m_layerOpacity );
}
PCB_PAINTER::PCB_PAINTER( GAL* aGal ) :
PAINTER( aGal )
{
}
const COLOR4D& PCB_PAINTER::GetColor( const VIEW_ITEM* aItem, int aLayer )
{ {
int netCode = -1; int netCode = -1;
...@@ -167,7 +145,7 @@ const COLOR4D& PCB_PAINTER::GetColor( const VIEW_ITEM* aItem, int aLayer ) ...@@ -167,7 +145,7 @@ const COLOR4D& PCB_PAINTER::GetColor( const VIEW_ITEM* aItem, int aLayer )
{ {
if( static_cast<const EDA_ITEM*>( aItem )->IsSelected() ) if( static_cast<const EDA_ITEM*>( aItem )->IsSelected() )
{ {
return m_pcbSettings->m_layerColorsSel[aLayer]; return m_layerColorsSel[aLayer];
} }
// Try to obtain the netcode for the item // Try to obtain the netcode for the item
...@@ -177,20 +155,42 @@ const COLOR4D& PCB_PAINTER::GetColor( const VIEW_ITEM* aItem, int aLayer ) ...@@ -177,20 +155,42 @@ const COLOR4D& PCB_PAINTER::GetColor( const VIEW_ITEM* aItem, int aLayer )
} }
// Return grayish color for non-highlighted layers in the high contrast mode // Return grayish color for non-highlighted layers in the high contrast mode
if( m_pcbSettings->m_hiContrastEnabled && m_pcbSettings->m_activeLayers.count( aLayer ) == 0 ) if( m_hiContrastEnabled && m_activeLayers.count( aLayer ) == 0 )
return m_pcbSettings->m_hiContrastColor; return m_hiContrastColor;
// Single net highlight mode // Single net highlight mode
if( m_pcbSettings->m_highlightEnabled ) if( m_highlightEnabled )
{ {
if( netCode == m_pcbSettings->m_highlightNetcode ) if( netCode == m_highlightNetcode )
return m_pcbSettings->m_layerColorsHi[aLayer]; return m_layerColorsHi[aLayer];
else else
return m_pcbSettings->m_layerColorsDark[aLayer]; return m_layerColorsDark[aLayer];
} }
// No special modificators enabled // No special modificators enabled
return m_pcbSettings->m_layerColors[aLayer]; return m_layerColors[aLayer];
}
void PCB_RENDER_SETTINGS::update()
{
// Calculate darkened/highlighted variants of layer colors
for( int i = 0; i < TOTAL_LAYER_COUNT; i++ )
{
m_layerColors[i].a = m_layerOpacity;
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 );
}
m_hiContrastColor = COLOR4D( m_hiContrastFactor, m_hiContrastFactor, m_hiContrastFactor,
m_layerOpacity );
}
PCB_PAINTER::PCB_PAINTER( GAL* aGal ) :
PAINTER( aGal )
{
} }
...@@ -280,8 +280,8 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) ...@@ -280,8 +280,8 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer )
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 // Set a proper color for the label
color = GetColor( aTrack, aTrack->GetLayer() ); color = m_pcbSettings->GetColor( aTrack, aTrack->GetLayer() );
COLOR4D labelColor = GetColor( NULL, aLayer ); COLOR4D labelColor = m_pcbSettings->GetColor( NULL, aLayer );
if( color.GetBrightness() > 0.5 ) if( color.GetBrightness() > 0.5 )
m_gal->SetStrokeColor( labelColor.Inverted() ); m_gal->SetStrokeColor( labelColor.Inverted() );
...@@ -301,7 +301,7 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) ...@@ -301,7 +301,7 @@ 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 = GetColor( aTrack, aLayer ); color = m_pcbSettings->GetColor( aTrack, aLayer );
m_gal->SetStrokeColor( color ); m_gal->SetStrokeColor( color );
m_gal->SetIsStroke( true ); m_gal->SetIsStroke( true );
...@@ -340,7 +340,7 @@ void PCB_PAINTER::draw( const SEGVIA* aVia, int aLayer ) ...@@ -340,7 +340,7 @@ void PCB_PAINTER::draw( const SEGVIA* aVia, int aLayer )
else else
return; return;
color = GetColor( aVia, aLayer ); color = m_pcbSettings->GetColor( aVia, aLayer );
if( m_pcbSettings->m_sketchModeSelect[VIAS_VISIBLE] ) if( m_pcbSettings->m_sketchModeSelect[VIAS_VISIBLE] )
{ {
...@@ -419,8 +419,8 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) ...@@ -419,8 +419,8 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
m_gal->SetMirrored( false ); m_gal->SetMirrored( false );
// Set a proper color for the label // Set a proper color for the label
color = GetColor( aPad, aPad->GetLayer() ); color = m_pcbSettings->GetColor( aPad, aPad->GetLayer() );
COLOR4D labelColor = GetColor( NULL, aLayer ); COLOR4D labelColor = m_pcbSettings->GetColor( NULL, aLayer );
if( color.GetBrightness() > 0.5 ) if( color.GetBrightness() > 0.5 )
m_gal->SetStrokeColor( labelColor.Inverted() ); m_gal->SetStrokeColor( labelColor.Inverted() );
...@@ -466,7 +466,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) ...@@ -466,7 +466,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
} }
// Pad drawing // Pad drawing
color = GetColor( aPad, aLayer ); color = m_pcbSettings->GetColor( aPad, aLayer );
if( m_pcbSettings->m_sketchModeSelect[PADS_VISIBLE] ) if( m_pcbSettings->m_sketchModeSelect[PADS_VISIBLE] )
{ {
// Outline mode // Outline mode
...@@ -619,7 +619,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) ...@@ -619,7 +619,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
void PCB_PAINTER::draw( const DRAWSEGMENT* aSegment ) void PCB_PAINTER::draw( const DRAWSEGMENT* aSegment )
{ {
COLOR4D color = GetColor( NULL, aSegment->GetLayer() ); COLOR4D color = m_pcbSettings->GetColor( NULL, aSegment->GetLayer() );
m_gal->SetIsFill( false ); m_gal->SetIsFill( false );
m_gal->SetIsStroke( true ); m_gal->SetIsStroke( true );
...@@ -708,7 +708,7 @@ void PCB_PAINTER::draw( const TEXTE_PCB* aText, int aLayer ) ...@@ -708,7 +708,7 @@ void PCB_PAINTER::draw( const TEXTE_PCB* aText, int aLayer )
if( aText->GetText().Length() == 0 ) if( aText->GetText().Length() == 0 )
return; return;
COLOR4D strokeColor = GetColor( NULL, aText->GetLayer() ); COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, aText->GetLayer() );
VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y ); VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y );
double orientation = aText->GetOrientation() * M_PI / 1800.0; double orientation = aText->GetOrientation() * M_PI / 1800.0;
...@@ -732,8 +732,8 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer ) ...@@ -732,8 +732,8 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer )
if( aText->GetLength() == 0 ) if( aText->GetLength() == 0 )
return; return;
COLOR4D strokeColor = GetColor( NULL, aLayer ); COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, aLayer );
VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y); VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y );
double orientation = aText->GetDrawRotation() * M_PI / 1800.0; double orientation = aText->GetDrawRotation() * M_PI / 1800.0;
m_gal->SetStrokeColor( strokeColor ); m_gal->SetStrokeColor( strokeColor );
...@@ -747,7 +747,7 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer ) ...@@ -747,7 +747,7 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer )
void PCB_PAINTER::draw( const ZONE_CONTAINER* aZone ) void PCB_PAINTER::draw( const ZONE_CONTAINER* aZone )
{ {
COLOR4D color = GetColor( NULL, aZone->GetLayer() ); COLOR4D color = m_pcbSettings->GetColor( NULL, aZone->GetLayer() );
std::deque<VECTOR2D> corners; std::deque<VECTOR2D> corners;
PCB_RENDER_SETTINGS::DisplayZonesMode displayMode = m_pcbSettings->m_displayZoneMode; PCB_RENDER_SETTINGS::DisplayZonesMode displayMode = m_pcbSettings->m_displayZoneMode;
...@@ -824,7 +824,7 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer ) ...@@ -824,7 +824,7 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer )
else else
{ {
int layer = aDimension->GetLayer(); int layer = aDimension->GetLayer();
COLOR4D strokeColor = GetColor( NULL, layer ); COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, layer );
m_gal->SetStrokeColor( strokeColor ); m_gal->SetStrokeColor( strokeColor );
m_gal->SetIsFill( false ); m_gal->SetIsFill( false );
...@@ -850,7 +850,7 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer ) ...@@ -850,7 +850,7 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer )
void PCB_PAINTER::draw( const PCB_TARGET* aTarget ) void PCB_PAINTER::draw( const PCB_TARGET* aTarget )
{ {
COLOR4D strokeColor = GetColor( NULL, aTarget->GetLayer() ); COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, aTarget->GetLayer() );
VECTOR2D position( aTarget->GetPosition() ); VECTOR2D position( aTarget->GetPosition() );
double size, radius; double size, radius;
......
...@@ -85,6 +85,9 @@ public: ...@@ -85,6 +85,9 @@ public:
*/ */
void LoadDisplayOptions( const DISPLAY_OPTIONS& aOptions ); void LoadDisplayOptions( const DISPLAY_OPTIONS& aOptions );
/// @copydoc RENDER_SETTINGS::GetColor()
virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const;
protected: protected:
/// @copydoc RENDER_SETTINGS::Update() /// @copydoc RENDER_SETTINGS::Update()
void update(); void update();
...@@ -130,9 +133,6 @@ public: ...@@ -130,9 +133,6 @@ public:
m_pcbSettings = dynamic_cast<PCB_RENDER_SETTINGS*>( aSettings ); m_pcbSettings = dynamic_cast<PCB_RENDER_SETTINGS*>( aSettings );
} }
/// @copydoc PAINTER::GetColor()
virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer );
protected: protected:
PCB_RENDER_SETTINGS* m_pcbSettings; PCB_RENDER_SETTINGS* m_pcbSettings;
......
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