Another attempt to fix the GTK uninitialized layer pair bitmap.

Fixes: lp:1838158
* https://bugs.launchpad.net/kicad/+bug/1838158
This commit is contained in:
Jeff Young 2019-07-28 16:19:25 -06:00
parent ee1be14b62
commit 7b5b807a8c
1 changed files with 58 additions and 57 deletions

View File

@ -86,11 +86,12 @@ static const char s_BitmapLayerIcon[BM_LAYERICON_SIZE][BM_LAYERICON_SIZE] =
void PCB_EDIT_FRAME::PrepareLayerIndicator()
{
static bool toolbarInitialized = false;
int ii, jj;
COLOR4D active_layer_color, top_color, bottom_color, via_color, background_color;
bool change = false;
bool changed = false;
static int previous_requested_scale;
static int previous_requested_scale = 0;
static COLOR4D previous_active_layer_color = COLOR4D::UNSPECIFIED;
static COLOR4D previous_Route_Layer_TOP_color = COLOR4D::UNSPECIFIED;
static COLOR4D previous_Route_Layer_BOTTOM_color = COLOR4D::UNSPECIFIED;
@ -103,7 +104,7 @@ void PCB_EDIT_FRAME::PrepareLayerIndicator()
if( requested_scale != previous_requested_scale )
{
previous_requested_scale = requested_scale;
change = true;
changed = true;
}
active_layer_color = Settings().Colors().GetLayerColor(GetActiveLayer());
@ -111,7 +112,7 @@ void PCB_EDIT_FRAME::PrepareLayerIndicator()
if( previous_active_layer_color != active_layer_color )
{
previous_active_layer_color = active_layer_color;
change = true;
changed = true;
}
top_color = Settings().Colors().GetLayerColor( GetScreen()->m_Route_Layer_TOP );
@ -119,7 +120,7 @@ void PCB_EDIT_FRAME::PrepareLayerIndicator()
if( previous_Route_Layer_TOP_color != top_color )
{
previous_Route_Layer_TOP_color = top_color;
change = true;
changed = true;
}
bottom_color = Settings().Colors().GetLayerColor( GetScreen()->m_Route_Layer_BOTTOM );
@ -127,7 +128,7 @@ void PCB_EDIT_FRAME::PrepareLayerIndicator()
if( previous_Route_Layer_BOTTOM_color != bottom_color )
{
previous_Route_Layer_BOTTOM_color = bottom_color;
change = true;
changed = true;
}
int via_type = GetDesignSettings().m_CurrentViaType;
@ -136,7 +137,7 @@ void PCB_EDIT_FRAME::PrepareLayerIndicator()
if( previous_via_color != via_color )
{
previous_via_color = via_color;
change = true;
changed = true;
}
background_color = Settings().Colors().GetItemColor( LAYER_PCB_BACKGROUND );
@ -144,17 +145,15 @@ void PCB_EDIT_FRAME::PrepareLayerIndicator()
if( previous_background_color != background_color )
{
previous_background_color = background_color;
change = true;
changed = true;
}
if( !change && LayerPairBitmap )
return;
if( changed || !LayerPairBitmap )
{
LayerPairBitmap = std::make_unique<wxBitmap>( 24, 24 );
/* Draw the icon, with colors according to the active layer and layer
* pairs for via command (change layer)
*/
// Draw the icon, with colors according to the active layer and layer pairs for via
// command (change layer)
wxMemoryDC iconDC;
iconDC.SelectObject( *LayerPairBitmap );
wxBrush brush;
@ -189,8 +188,8 @@ void PCB_EDIT_FRAME::PrepareLayerIndicator()
}
}
/* Deselect the Tool Bitmap from DC,
* in order to delete the MemoryDC safely without deleting the bitmap */
// Deselect the bitmap from the DC in order to delete the MemoryDC safely without
// deleting the bitmap
iconDC.SelectObject( wxNullBitmap );
// Scale the bitmap
@ -202,9 +201,11 @@ void PCB_EDIT_FRAME::PrepareLayerIndicator()
wxIMAGE_QUALITY_NEAREST );
LayerPairBitmap = std::make_unique<wxBitmap>( image );
}
if( m_mainToolBar )
if( m_mainToolBar && ( changed || !toolbarInitialized ) )
{
toolbarInitialized = true;
m_mainToolBar->SetToolBitmap( PCB_ACTIONS::selectLayerPair, *LayerPairBitmap );
m_mainToolBar->Refresh();
}