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:
parent
0dcf95ee1a
commit
38227161bf
|
@ -41,7 +41,7 @@ extern COLOR4D DisplayColorFrame( wxWindow* aParent, COLOR4D aOldColor );
|
|||
/**
|
||||
* 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 );
|
||||
wxBrush brush;
|
||||
|
@ -49,11 +49,13 @@ static wxBitmap makeBitmap( COLOR4D aColor )
|
|||
|
||||
iconDC.SelectObject( bitmap );
|
||||
|
||||
brush.SetColour( aColor.ToColour() );
|
||||
brush.SetStyle( wxBRUSHSTYLE_SOLID );
|
||||
|
||||
brush.SetColour( aBackground.WithAlpha(1.0).ToColour() );
|
||||
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 );
|
||||
|
||||
return bitmap;
|
||||
|
@ -65,10 +67,10 @@ static wxBitmap makeBitmap( COLOR4D aColor )
|
|||
* creates a wxStaticBitmap and assigns it a solid color and a control ID
|
||||
*/
|
||||
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
|
||||
wxBitmap bitmap = makeBitmap( aColor );
|
||||
wxBitmap bitmap = makeBitmap( aColor, aBackground );
|
||||
auto ret = std::make_unique<wxStaticBitmap>( aParent, aID, bitmap );
|
||||
|
||||
return ret;
|
||||
|
@ -76,15 +78,16 @@ static std::unique_ptr<wxStaticBitmap> makeColorSwatch(
|
|||
|
||||
|
||||
COLOR_SWATCH::COLOR_SWATCH( wxWindow* aParent, COLOR4D aColor, int aID,
|
||||
bool aArbitraryColors ):
|
||||
bool aArbitraryColors, COLOR4D aBackground ):
|
||||
wxPanel( aParent, aID ),
|
||||
m_arbitraryColors( aArbitraryColors ),
|
||||
m_color( aColor )
|
||||
m_color( aColor ),
|
||||
m_background( aBackground )
|
||||
{
|
||||
auto sizer = new wxBoxSizer( wxHORIZONTAL );
|
||||
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
|
||||
|
||||
sizer->Add( m_swatch, 0, 0 );
|
||||
|
@ -126,7 +129,7 @@ void COLOR_SWATCH::SetSwatchColor( COLOR4D aColor, bool sendEvent )
|
|||
{
|
||||
m_color = aColor;
|
||||
|
||||
wxBitmap bm = makeBitmap( aColor );
|
||||
wxBitmap bm = makeBitmap( m_color, m_background );
|
||||
m_swatch->SetBitmap( bm );
|
||||
|
||||
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
|
||||
{
|
||||
return m_color;
|
||||
|
@ -160,7 +171,7 @@ void COLOR_SWATCH::GetNewSwatchColor()
|
|||
{
|
||||
m_color = newColor;
|
||||
|
||||
wxBitmap bm = makeBitmap( newColor );
|
||||
wxBitmap bm = makeBitmap( newColor, m_background );
|
||||
m_swatch->SetBitmap( bm );
|
||||
|
||||
sendSwatchChangeEvent( *this );
|
||||
|
|
|
@ -49,13 +49,18 @@ public:
|
|||
* 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,
|
||||
bool aArbitraryColors );
|
||||
bool aArbitraryColors, KIGFX::COLOR4D aBackground );
|
||||
|
||||
/**
|
||||
* Set the current swatch color directly.
|
||||
*/
|
||||
void SetSwatchColor( KIGFX::COLOR4D aColor, bool sendEvent );
|
||||
|
||||
/**
|
||||
* Set the swatch background color.
|
||||
*/
|
||||
void SetSwatchBackground( KIGFX::COLOR4D aBackground );
|
||||
|
||||
/**
|
||||
* @return the current swatch color
|
||||
*/
|
||||
|
@ -81,6 +86,9 @@ private:
|
|||
///> The current colour of the swatch
|
||||
KIGFX::COLOR4D m_color;
|
||||
|
||||
///> The background colour to show the swatch over
|
||||
KIGFX::COLOR4D m_background;
|
||||
|
||||
///> Handle of the actual swatch shown
|
||||
wxStaticBitmap* m_swatch;
|
||||
};
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
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->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); // useful to update rastnest
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -143,6 +143,8 @@ protected:
|
|||
|
||||
virtual bool AreArbitraryColorsAllowed() override;
|
||||
|
||||
virtual COLOR4D getBackgroundLayerColor() override;
|
||||
|
||||
/**
|
||||
* Function isAllowedInFpMode
|
||||
* @return true if item aId has meaning in footprint editor mode.
|
||||
|
|
|
@ -208,6 +208,29 @@ void LAYER_WIDGET::OnRenderSwatchChanged( wxCommandEvent& aEvent )
|
|||
|
||||
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.
|
||||
OnRenderColorChange( id, newColor );
|
||||
|
||||
|
@ -313,7 +336,7 @@ void LAYER_WIDGET::insertLayerRow( int aRow, const ROW& aSpec )
|
|||
col = COLUMN_COLORBM;
|
||||
|
||||
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( COLOR_SWATCH_CHANGED, &LAYER_WIDGET::OnLayerSwatchChanged, this );
|
||||
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 )
|
||||
{
|
||||
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->SetToolTip( _( "Left double click or middle click for color change" ) );
|
||||
m_RenderFlexGridSizer->wxSizer::Insert( index+col, bmb, 0, flags );
|
||||
|
|
|
@ -135,6 +135,12 @@ protected:
|
|||
*/
|
||||
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
|
||||
* is here to allow saving a layer index within a control as its wxControl id,
|
||||
|
|
|
@ -89,14 +89,14 @@ void PCB_RENDER_SETTINGS::ImportLegacyColors( const COLORS_DESIGN_SETTINGS* aSet
|
|||
|
||||
// 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_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_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_DRC] = COLOR4D( 1.0, 0.0, 0.0, 0.8 );
|
||||
|
||||
// LAYER_PADS_TH, LAYER_NON_PLATEDHOLES, LAYER_ANCHOR],LAYER_RATSNEST,
|
||||
// LAYER_VIA_THROUGH], LAYER_VIA_BBLIND, LAYER_VIA_MICROVIA
|
||||
// LAYER_PADS_TH, LAYER_NON_PLATEDHOLES, LAYER_ANCHOR ,LAYER_RATSNEST,
|
||||
// LAYER_VIA_THROUGH, LAYER_VIA_BBLIND, LAYER_VIA_MICROVIA
|
||||
// are initialized from aSettings
|
||||
|
||||
// These colors are not actually used. Set just in case...
|
||||
|
|
Loading…
Reference in New Issue