From 1dd4af2972acc37097ede1d1871c170cd6df937f Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sun, 25 Mar 2018 11:10:51 -0400 Subject: [PATCH] Sort VIEW_GROUP drawing by layer order Fixes: lp:1757146 * https://bugs.launchpad.net/kicad/+bug/1757146 --- common/view/view_group.cpp | 48 +++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/common/view/view_group.cpp b/common/view/view_group.cpp index f2a024a5ae..b38577d4d8 100644 --- a/common/view/view_group.cpp +++ b/common/view/view_group.cpp @@ -105,28 +105,54 @@ void VIEW_GROUP::ViewDraw( int aLayer, VIEW* aView ) const const auto drawList = updateDrawList(); - // Draw all items immediately (without caching) + std::unordered_map> layer_item_map; + + // Build a list of layers used by the items in the group for( auto item : drawList ) { - gal->PushDepth(); + int item_layers[VIEW::VIEW_MAX_LAYERS], item_layers_count; + item->ViewGetLayers( item_layers, item_layers_count ); - int layers[VIEW::VIEW_MAX_LAYERS], layers_count; - item->ViewGetLayers( layers, layers_count ); - aView->SortLayers( layers, layers_count ); - - for( int i = 0; i < layers_count; i++ ) + for( int i = 0; i < item_layers_count; i++ ) { - if( aView->IsLayerVisible( layers[i] ) ) + if( layer_item_map.count( item_layers[i] ) == 0 ) { - gal->AdvanceDepth(); + layer_item_map.emplace( std::make_pair( item_layers[i], + std::vector() ) ); + } + layer_item_map[ item_layers[i] ].push_back( item ); + } + } + + int layers[VIEW::VIEW_MAX_LAYERS], layers_count = 0; + + for( const auto& entry : layer_item_map ) + { + layers[ layers_count++ ] = entry.first; + } + + aView->SortLayers( layers, layers_count ); + + // Now draw the layers in sorted order + + gal->PushDepth(); + + for( int i = 0; i < layers_count; i++ ) + { + if( aView->IsLayerVisible( layers[i] ) ) + { + gal->AdvanceDepth(); + + for( auto item : layer_item_map[ layers[i] ] ) + { if( !painter->Draw( item, layers[i] ) ) item->ViewDraw( layers[i], aView ); // Alternative drawing method } } - - gal->PopDepth(); } + + gal->PopDepth(); }