From 5a0869f2e20e6d083f9350e4e47000dabb258fc7 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 8 Jul 2013 09:28:58 +0200 Subject: [PATCH] Added 'required layers' option for drawn items. --- common/view/view.cpp | 28 ++++++++++++++++++++++++---- common/view/view_item.cpp | 7 +++++++ include/view/view.h | 3 +++ include/view/view_item.h | 10 ++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/common/view/view.cpp b/common/view/view.cpp index ab436c31fe..cf8678a254 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -454,13 +454,21 @@ struct VIEW::drawItem { GAL* gal = view->GetGAL(); + aItem->ViewGetRequiredLayers( layers, layersCount ); + + // Conditions that have te be fulfilled for an item to be drawn + bool drawCondition = aItem->ViewIsVisible() && + aItem->ViewGetLOD( currentLayer->id ) < view->m_scale && + view->isEveryLayerEnabled( layers, layersCount ); + if( !drawCondition ) + return; + if( currentLayer->cached ) { // Draw using cached information or create one int group = aItem->getGroup( currentLayer->id ); - if( group >= 0 && aItem->ViewIsVisible() && - aItem->ViewGetLOD( currentLayer->id ) < view->m_scale ) + if( group >= 0 ) { gal->DrawGroup( group ); } @@ -472,8 +480,7 @@ struct VIEW::drawItem gal->EndGroup(); } } - else if( aItem->ViewIsVisible() && - aItem->ViewGetLOD( currentLayer->id ) < view->m_scale ) + else { // Immediate mode view->m_painter->Draw( aItem, currentLayer->id ); @@ -482,6 +489,7 @@ struct VIEW::drawItem const VIEW_LAYER* currentLayer; VIEW* view; + int layersCount, layers[VIEW_MAX_LAYERS]; }; @@ -652,6 +660,18 @@ void VIEW::clearGroupCache() } +bool VIEW::isEveryLayerEnabled( const int aLayers[], int aCount ) const +{ + for( int i = 0; i < aCount; ++i ) + { + if( !m_layers.at( aLayers[i] ).enabled ) + return false; + } + + return true; +} + + void VIEW::RecacheAllItems( bool aImmediately ) { BOX2I r; diff --git a/common/view/view_item.cpp b/common/view/view_item.cpp index 266f7df186..8b53114a4c 100644 --- a/common/view/view_item.cpp +++ b/common/view/view_item.cpp @@ -48,6 +48,13 @@ void VIEW_ITEM::ViewSetVisible( bool aIsVisible ) } +void VIEW_ITEM::ViewGetRequiredLayers( int aLayers[], int& aCount ) const +{ + // By default there is no layer required + aCount = 0; +} + + void VIEW_ITEM::ViewUpdate( int aUpdateFlags, bool aForceImmediateRedraw ) { m_view->invalidateItem( this, aUpdateFlags ); diff --git a/include/view/view.h b/include/view/view.h index 7bb93fad15..c13ba6bf52 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -403,6 +403,9 @@ private: return i->renderingOrder > j->renderingOrder; } + /// Checks if every layer stored in aLayers array is enabled. + bool isEveryLayerEnabled( const int aLayers[], int aCount ) const; + /// Contains set of possible displayed layers and its properties LayerMap m_layers; diff --git a/include/view/view_item.h b/include/view/view_item.h index 7a3540ed38..00040e2455 100644 --- a/include/view/view_item.h +++ b/include/view/view_item.h @@ -207,6 +207,16 @@ public: */ virtual void ViewGetLayers( int aLayers[], int& aCount ) const = 0; + /** + * Function ViewGetRequiredLayers() + * Returns the all the layers that are required for an item to be drawn. Eg. there is no point + * to draw netnames, when the track is not visible - so track layer should be marked as + * required. + * @param aLayers[]: output layer index array + * @param aCount: number of layer indices in aLayers[] + */ + virtual void ViewGetRequiredLayers( int aLayers[], int& aCount ) const; + /** * Function ViewSetVisible() * Sets the item visibility.