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

This commit is contained in:
Maciej Suminski 2013-09-11 11:39:46 +02:00
parent c5d3376c26
commit afe2e27b0a
4 changed files with 66 additions and 65 deletions

View File

@ -370,7 +370,7 @@ struct VIEW::updateItemsColor
void operator()( VIEW_ITEM* aItem )
{
// 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 );
if( group >= 0 )
@ -672,7 +672,8 @@ struct VIEW::recacheLayer
{
int group = gal->BeginGroup();
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();
}
else
@ -836,7 +837,7 @@ void VIEW::updateItemColor( VIEW_ITEM* aItem, int aLayer )
wxASSERT( (unsigned) aLayer < m_layers.size() );
// 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 );
// Change the color, only if it has group assigned

View File

@ -113,6 +113,16 @@ public:
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:
/**
* Function update
@ -217,16 +227,6 @@ public:
*/
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:
/// Instance of graphic abstraction layer that gives an interface to call
/// commands used to draw (eg. DrawLine, DrawCircle, etc.)

View File

@ -137,6 +137,41 @@ void PCB_RENDER_SETTINGS::LoadDisplayOptions( const DISPLAY_OPTIONS& aOptions )
}
const COLOR4D& PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) const
{
int netCode = -1;
if( aItem )
{
if( static_cast<const EDA_ITEM*>( aItem )->IsSelected() )
{
return m_layerColorsSel[aLayer];
}
// Try to obtain the netcode for the item
const BOARD_CONNECTED_ITEM* item = dynamic_cast<const BOARD_CONNECTED_ITEM*>( aItem );
if( item )
netCode = item->GetNet();
}
// Return grayish color for non-highlighted layers in the high contrast mode
if( m_hiContrastEnabled && m_activeLayers.count( aLayer ) == 0 )
return m_hiContrastColor;
// Single net highlight mode
if( m_highlightEnabled )
{
if( netCode == m_highlightNetcode )
return m_layerColorsHi[aLayer];
else
return m_layerColorsDark[aLayer];
}
// No special modificators enabled
return m_layerColors[aLayer];
}
void PCB_RENDER_SETTINGS::update()
{
// Calculate darkened/highlighted variants of layer colors
@ -159,41 +194,6 @@ PCB_PAINTER::PCB_PAINTER( GAL* aGal ) :
}
const COLOR4D& PCB_PAINTER::GetColor( const VIEW_ITEM* aItem, int aLayer )
{
int netCode = -1;
if( aItem )
{
if( static_cast<const EDA_ITEM*>( aItem )->IsSelected() )
{
return m_pcbSettings->m_layerColorsSel[aLayer];
}
// Try to obtain the netcode for the item
const BOARD_CONNECTED_ITEM* item = dynamic_cast<const BOARD_CONNECTED_ITEM*>( aItem );
if( item )
netCode = item->GetNet();
}
// Return grayish color for non-highlighted layers in the high contrast mode
if( m_pcbSettings->m_hiContrastEnabled && m_pcbSettings->m_activeLayers.count( aLayer ) == 0 )
return m_pcbSettings->m_hiContrastColor;
// Single net highlight mode
if( m_pcbSettings->m_highlightEnabled )
{
if( netCode == m_pcbSettings->m_highlightNetcode )
return m_pcbSettings->m_layerColorsHi[aLayer];
else
return m_pcbSettings->m_layerColorsDark[aLayer];
}
// No special modificators enabled
return m_pcbSettings->m_layerColors[aLayer];
}
bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer )
{
const BOARD_ITEM* item = static_cast<const BOARD_ITEM*>( aItem );
@ -280,8 +280,8 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer )
double textSize = std::min( static_cast<double>( width ), length / netName.length() );
// Set a proper color for the label
color = GetColor( aTrack, aTrack->GetLayer() );
COLOR4D labelColor = GetColor( NULL, aLayer );
color = m_pcbSettings->GetColor( aTrack, aTrack->GetLayer() );
COLOR4D labelColor = m_pcbSettings->GetColor( NULL, aLayer );
if( color.GetBrightness() > 0.5 )
m_gal->SetStrokeColor( labelColor.Inverted() );
@ -301,7 +301,7 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer )
else if( IsCopperLayer( aLayer ))
{
// Draw a regular track
color = GetColor( aTrack, aLayer );
color = m_pcbSettings->GetColor( aTrack, aLayer );
m_gal->SetStrokeColor( color );
m_gal->SetIsStroke( true );
@ -340,7 +340,7 @@ void PCB_PAINTER::draw( const SEGVIA* aVia, int aLayer )
else
return;
color = GetColor( aVia, aLayer );
color = m_pcbSettings->GetColor( aVia, aLayer );
if( m_pcbSettings->m_sketchModeSelect[VIAS_VISIBLE] )
{
@ -419,8 +419,8 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
m_gal->SetMirrored( false );
// Set a proper color for the label
color = GetColor( aPad, aPad->GetLayer() );
COLOR4D labelColor = GetColor( NULL, aLayer );
color = m_pcbSettings->GetColor( aPad, aPad->GetLayer() );
COLOR4D labelColor = m_pcbSettings->GetColor( NULL, aLayer );
if( color.GetBrightness() > 0.5 )
m_gal->SetStrokeColor( labelColor.Inverted() );
@ -466,7 +466,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
}
// Pad drawing
color = GetColor( aPad, aLayer );
color = m_pcbSettings->GetColor( aPad, aLayer );
if( m_pcbSettings->m_sketchModeSelect[PADS_VISIBLE] )
{
// Outline mode
@ -619,7 +619,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
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->SetIsStroke( true );
@ -708,7 +708,7 @@ void PCB_PAINTER::draw( const TEXTE_PCB* aText, int aLayer )
if( aText->GetText().Length() == 0 )
return;
COLOR4D strokeColor = GetColor( NULL, aText->GetLayer() );
COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, aText->GetLayer() );
VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y );
double orientation = aText->GetOrientation() * M_PI / 1800.0;
@ -732,8 +732,8 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer )
if( aText->GetLength() == 0 )
return;
COLOR4D strokeColor = GetColor( NULL, aLayer );
VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y);
COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, aLayer );
VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y );
double orientation = aText->GetDrawRotation() * M_PI / 1800.0;
m_gal->SetStrokeColor( strokeColor );
@ -747,7 +747,7 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer )
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;
PCB_RENDER_SETTINGS::DisplayZonesMode displayMode = m_pcbSettings->m_displayZoneMode;
@ -824,7 +824,7 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer )
else
{
int layer = aDimension->GetLayer();
COLOR4D strokeColor = GetColor( NULL, layer );
COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, layer );
m_gal->SetStrokeColor( strokeColor );
m_gal->SetIsFill( false );
@ -850,7 +850,7 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer )
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() );
double size, radius;

View File

@ -85,6 +85,9 @@ public:
*/
void LoadDisplayOptions( const DISPLAY_OPTIONS& aOptions );
/// @copydoc RENDER_SETTINGS::GetColor()
virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const;
protected:
/// @copydoc RENDER_SETTINGS::Update()
void update();
@ -130,9 +133,6 @@ public:
m_pcbSettings = dynamic_cast<PCB_RENDER_SETTINGS*>( aSettings );
}
/// @copydoc PAINTER::GetColor()
virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer );
protected:
PCB_RENDER_SETTINGS* m_pcbSettings;