Fix drawing of transparent layer swatches.

Also fixes a related bug to redraw holes when changing the
pcb background colour.

Fixes: lp:1741049
* https://bugs.launchpad.net/kicad/+bug/1741049

Fixes: lp:1741101
* https://bugs.launchpad.net/kicad/+bug/1741101
This commit is contained in:
Jeff Young 2018-01-03 22:38:25 +00:00 committed by Wayne Stambaugh
parent 0dcf95ee1a
commit 38227161bf
7 changed files with 77 additions and 16 deletions

View File

@ -41,7 +41,7 @@ extern COLOR4D DisplayColorFrame( wxWindow* aParent, COLOR4D aOldColor );
/** /**
* Make a simple color swatch bitmap * Make a simple color swatch bitmap
*/ */
static wxBitmap makeBitmap( COLOR4D aColor ) static wxBitmap makeBitmap( COLOR4D aColor, COLOR4D aBackground )
{ {
wxBitmap bitmap( SWATCH_SIZE_X, SWATCH_SIZE_Y ); wxBitmap bitmap( SWATCH_SIZE_X, SWATCH_SIZE_Y );
wxBrush brush; wxBrush brush;
@ -49,11 +49,13 @@ static wxBitmap makeBitmap( COLOR4D aColor )
iconDC.SelectObject( bitmap ); iconDC.SelectObject( bitmap );
brush.SetColour( aColor.ToColour() );
brush.SetStyle( wxBRUSHSTYLE_SOLID ); brush.SetStyle( wxBRUSHSTYLE_SOLID );
brush.SetColour( aBackground.WithAlpha(1.0).ToColour() );
iconDC.SetBrush( brush ); iconDC.SetBrush( brush );
iconDC.DrawRectangle( 0, 0, SWATCH_SIZE_X, SWATCH_SIZE_Y );
brush.SetColour( aColor.ToColour() );
iconDC.SetBrush( brush );
iconDC.DrawRectangle( 0, 0, SWATCH_SIZE_X, SWATCH_SIZE_Y ); iconDC.DrawRectangle( 0, 0, SWATCH_SIZE_X, SWATCH_SIZE_Y );
return bitmap; return bitmap;
@ -65,10 +67,10 @@ static wxBitmap makeBitmap( COLOR4D aColor )
* creates a wxStaticBitmap and assigns it a solid color and a control ID * creates a wxStaticBitmap and assigns it a solid color and a control ID
*/ */
static std::unique_ptr<wxStaticBitmap> makeColorSwatch( static std::unique_ptr<wxStaticBitmap> makeColorSwatch(
wxWindow* aParent, COLOR4D aColor, int aID ) wxWindow* aParent, COLOR4D aColor, COLOR4D aBackground, int aID )
{ {
// construct a bitmap of the right color and make the swatch from it // construct a bitmap of the right color and make the swatch from it
wxBitmap bitmap = makeBitmap( aColor ); wxBitmap bitmap = makeBitmap( aColor, aBackground );
auto ret = std::make_unique<wxStaticBitmap>( aParent, aID, bitmap ); auto ret = std::make_unique<wxStaticBitmap>( aParent, aID, bitmap );
return ret; return ret;
@ -76,15 +78,16 @@ static std::unique_ptr<wxStaticBitmap> makeColorSwatch(
COLOR_SWATCH::COLOR_SWATCH( wxWindow* aParent, COLOR4D aColor, int aID, COLOR_SWATCH::COLOR_SWATCH( wxWindow* aParent, COLOR4D aColor, int aID,
bool aArbitraryColors ): bool aArbitraryColors, COLOR4D aBackground ):
wxPanel( aParent, aID ), wxPanel( aParent, aID ),
m_arbitraryColors( aArbitraryColors ), m_arbitraryColors( aArbitraryColors ),
m_color( aColor ) m_color( aColor ),
m_background( aBackground )
{ {
auto sizer = new wxBoxSizer( wxHORIZONTAL ); auto sizer = new wxBoxSizer( wxHORIZONTAL );
SetSizer( sizer ); SetSizer( sizer );
auto swatch = makeColorSwatch( this, m_color, aID ); auto swatch = makeColorSwatch( this, m_color, m_background, aID );
m_swatch = swatch.release(); // hold a handle m_swatch = swatch.release(); // hold a handle
sizer->Add( m_swatch, 0, 0 ); sizer->Add( m_swatch, 0, 0 );
@ -126,7 +129,7 @@ void COLOR_SWATCH::SetSwatchColor( COLOR4D aColor, bool sendEvent )
{ {
m_color = aColor; m_color = aColor;
wxBitmap bm = makeBitmap( aColor ); wxBitmap bm = makeBitmap( m_color, m_background );
m_swatch->SetBitmap( bm ); m_swatch->SetBitmap( bm );
if( sendEvent ) if( sendEvent )
@ -136,6 +139,14 @@ void COLOR_SWATCH::SetSwatchColor( COLOR4D aColor, bool sendEvent )
} }
void COLOR_SWATCH::SetSwatchBackground( COLOR4D aBackground )
{
m_background = aBackground;
wxBitmap bm = makeBitmap( m_color, m_background );
m_swatch->SetBitmap( bm );
}
COLOR4D COLOR_SWATCH::GetSwatchColor() const COLOR4D COLOR_SWATCH::GetSwatchColor() const
{ {
return m_color; return m_color;
@ -160,7 +171,7 @@ void COLOR_SWATCH::GetNewSwatchColor()
{ {
m_color = newColor; m_color = newColor;
wxBitmap bm = makeBitmap( newColor ); wxBitmap bm = makeBitmap( newColor, m_background );
m_swatch->SetBitmap( bm ); m_swatch->SetBitmap( bm );
sendSwatchChangeEvent( *this ); sendSwatchChangeEvent( *this );

View File

@ -49,13 +49,18 @@ public:
* and false to allow a selection from a set of colors accepted by the legacy canvas. * and false to allow a selection from a set of colors accepted by the legacy canvas.
*/ */
COLOR_SWATCH( wxWindow* aParent, KIGFX::COLOR4D aColor, int aID, COLOR_SWATCH( wxWindow* aParent, KIGFX::COLOR4D aColor, int aID,
bool aArbitraryColors ); bool aArbitraryColors, KIGFX::COLOR4D aBackground );
/** /**
* Set the current swatch color directly. * Set the current swatch color directly.
*/ */
void SetSwatchColor( KIGFX::COLOR4D aColor, bool sendEvent ); void SetSwatchColor( KIGFX::COLOR4D aColor, bool sendEvent );
/**
* Set the swatch background color.
*/
void SetSwatchBackground( KIGFX::COLOR4D aBackground );
/** /**
* @return the current swatch color * @return the current swatch color
*/ */
@ -81,6 +86,9 @@ private:
///> The current colour of the swatch ///> The current colour of the swatch
KIGFX::COLOR4D m_color; KIGFX::COLOR4D m_color;
///> The background colour to show the swatch over
KIGFX::COLOR4D m_background;
///> Handle of the actual swatch shown ///> Handle of the actual swatch shown
wxStaticBitmap* m_swatch; wxStaticBitmap* m_swatch;
}; };

View File

@ -125,6 +125,12 @@ bool PCB_LAYER_WIDGET::AreArbitraryColorsAllowed()
} }
COLOR4D PCB_LAYER_WIDGET::getBackgroundLayerColor()
{
return myframe->Settings().Colors().GetLayerColor( LAYER_PCB_BACKGROUND );
}
bool PCB_LAYER_WIDGET::isAllowedInFpMode( int aId ) bool PCB_LAYER_WIDGET::isAllowedInFpMode( int aId )
{ {
for( unsigned ii = 0; ii < DIM( s_allowed_in_FpEditor ); ii++ ) for( unsigned ii = 0; ii < DIM( s_allowed_in_FpEditor ); ii++ )
@ -634,6 +640,11 @@ void PCB_LAYER_WIDGET::OnRenderColorChange( int aId, COLOR4D aColor )
view->GetPainter()->GetSettings()->ImportLegacyColors( &myframe->Settings().Colors() ); view->GetPainter()->GetSettings()->ImportLegacyColors( &myframe->Settings().Colors() );
view->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); // useful to update rastnest view->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); // useful to update rastnest
view->UpdateLayerColor( aId ); view->UpdateLayerColor( aId );
// plated-through-holes don't have their own color; they use the background color
if( aId == LAYER_PCB_BACKGROUND )
view->UpdateLayerColor( LAYER_PADS_PLATEDHOLES );
galCanvas->Refresh(); galCanvas->Refresh();
} }

View File

@ -143,6 +143,8 @@ protected:
virtual bool AreArbitraryColorsAllowed() override; virtual bool AreArbitraryColorsAllowed() override;
virtual COLOR4D getBackgroundLayerColor() override;
/** /**
* Function isAllowedInFpMode * Function isAllowedInFpMode
* @return true if item aId has meaning in footprint editor mode. * @return true if item aId has meaning in footprint editor mode.

View File

@ -208,6 +208,29 @@ void LAYER_WIDGET::OnRenderSwatchChanged( wxCommandEvent& aEvent )
LAYER_NUM id = getDecodedId( eventSource->GetId() ); LAYER_NUM id = getDecodedId( eventSource->GetId() );
if( id == LAYER_PCB_BACKGROUND )
{
// Update all swatch backgrounds
int count = GetLayerRowCount();
int row;
int col = 1; // bitmap button is column 1 in layers tab
for( row = 0; row < count; ++row )
{
COLOR_SWATCH* swatch = dynamic_cast<COLOR_SWATCH*>( getLayerComp( row, col ) );
if( swatch )
swatch->SetSwatchBackground( newColor );
}
count = GetRenderRowCount();
col = 0; // bitmap button is column 0 in render tab
for( row = 0; row < count; ++row )
{
COLOR_SWATCH* swatch = dynamic_cast<COLOR_SWATCH*>( getRenderComp( row, col ) );
if( swatch )
swatch->SetSwatchBackground( newColor );
}
}
// tell the client code. // tell the client code.
OnRenderColorChange( id, newColor ); OnRenderColorChange( id, newColor );
@ -313,7 +336,7 @@ void LAYER_WIDGET::insertLayerRow( int aRow, const ROW& aSpec )
col = COLUMN_COLORBM; col = COLUMN_COLORBM;
auto bmb = new COLOR_SWATCH( m_LayerScrolledWindow, aSpec.color, encodeId( col, aSpec.id ), auto bmb = new COLOR_SWATCH( m_LayerScrolledWindow, aSpec.color, encodeId( col, aSpec.id ),
AreArbitraryColorsAllowed() ); AreArbitraryColorsAllowed(), getBackgroundLayerColor() );
bmb->Bind( wxEVT_LEFT_DOWN, &LAYER_WIDGET::OnLeftDownLayers, this ); bmb->Bind( wxEVT_LEFT_DOWN, &LAYER_WIDGET::OnLeftDownLayers, this );
bmb->Bind( COLOR_SWATCH_CHANGED, &LAYER_WIDGET::OnLayerSwatchChanged, this ); bmb->Bind( COLOR_SWATCH_CHANGED, &LAYER_WIDGET::OnLayerSwatchChanged, this );
bmb->SetToolTip( _("Left double click or middle click for color change, right click for menu" ) ); bmb->SetToolTip( _("Left double click or middle click for color change, right click for menu" ) );
@ -378,7 +401,7 @@ void LAYER_WIDGET::insertRenderRow( int aRow, const ROW& aSpec )
if( aSpec.color != COLOR4D::UNSPECIFIED ) if( aSpec.color != COLOR4D::UNSPECIFIED )
{ {
auto bmb = new COLOR_SWATCH( m_RenderScrolledWindow, aSpec.color, encodeId( col, aSpec.id ), auto bmb = new COLOR_SWATCH( m_RenderScrolledWindow, aSpec.color, encodeId( col, aSpec.id ),
AreArbitraryColorsAllowed() ); AreArbitraryColorsAllowed(), getBackgroundLayerColor() );
bmb->Bind( COLOR_SWATCH_CHANGED, &LAYER_WIDGET::OnRenderSwatchChanged, this ); bmb->Bind( COLOR_SWATCH_CHANGED, &LAYER_WIDGET::OnRenderSwatchChanged, this );
bmb->SetToolTip( _( "Left double click or middle click for color change" ) ); bmb->SetToolTip( _( "Left double click or middle click for color change" ) );
m_RenderFlexGridSizer->wxSizer::Insert( index+col, bmb, 0, flags ); m_RenderFlexGridSizer->wxSizer::Insert( index+col, bmb, 0, flags );

View File

@ -135,6 +135,12 @@ protected:
*/ */
virtual bool AreArbitraryColorsAllowed() { return false; } virtual bool AreArbitraryColorsAllowed() { return false; }
/**
* Subclasses can override this to provide accurate representation
* of transparent colour swatches.
*/
virtual COLOR4D getBackgroundLayerColor() { return COLOR4D::BLACK; }
/** /**
* Function encodeId * Function encodeId
* is here to allow saving a layer index within a control as its wxControl id, * is here to allow saving a layer index within a control as its wxControl id,

View File

@ -89,14 +89,14 @@ void PCB_RENDER_SETTINGS::ImportLegacyColors( const COLORS_DESIGN_SETTINGS* aSet
// Default colors for specific layers (not really board layers). // Default colors for specific layers (not really board layers).
m_layerColors[LAYER_VIAS_HOLES] = COLOR4D( 0.5, 0.4, 0.0, 0.8 ); m_layerColors[LAYER_VIAS_HOLES] = COLOR4D( 0.5, 0.4, 0.0, 0.8 );
m_layerColors[LAYER_PADS_PLATEDHOLES] = COLOR4D( 0.0, 0.0, 0.0, 1.0 ); m_layerColors[LAYER_PADS_PLATEDHOLES] = aSettings->GetItemColor( LAYER_PCB_BACKGROUND );
m_layerColors[LAYER_PADS_NETNAMES] = COLOR4D( 1.0, 1.0, 1.0, 0.9 ); m_layerColors[LAYER_PADS_NETNAMES] = COLOR4D( 1.0, 1.0, 1.0, 0.9 );
m_layerColors[LAYER_PAD_FR_NETNAMES] = COLOR4D( 1.0, 1.0, 1.0, 0.9 ); m_layerColors[LAYER_PAD_FR_NETNAMES] = COLOR4D( 1.0, 1.0, 1.0, 0.9 );
m_layerColors[LAYER_PAD_BK_NETNAMES] = COLOR4D( 1.0, 1.0, 1.0, 0.9 ); m_layerColors[LAYER_PAD_BK_NETNAMES] = COLOR4D( 1.0, 1.0, 1.0, 0.9 );
m_layerColors[LAYER_DRC] = COLOR4D( 1.0, 0.0, 0.0, 0.8 ); m_layerColors[LAYER_DRC] = COLOR4D( 1.0, 0.0, 0.0, 0.8 );
// LAYER_PADS_TH, LAYER_NON_PLATEDHOLES, LAYER_ANCHOR],LAYER_RATSNEST, // LAYER_PADS_TH, LAYER_NON_PLATEDHOLES, LAYER_ANCHOR ,LAYER_RATSNEST,
// LAYER_VIA_THROUGH], LAYER_VIA_BBLIND, LAYER_VIA_MICROVIA // LAYER_VIA_THROUGH, LAYER_VIA_BBLIND, LAYER_VIA_MICROVIA
// are initialized from aSettings // are initialized from aSettings
// These colors are not actually used. Set just in case... // These colors are not actually used. Set just in case...