From 57a8622e9af6a3e6144859a3b5e8680991444954 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 24 Sep 2013 15:48:04 +0200 Subject: [PATCH] Added functions for refreshing the layer set occupied by a VIEW_ITEM. --- common/view/view.cpp | 41 +++++++++++++++++++++++++++++++++------ common/view/view_item.cpp | 1 - include/view/view.h | 3 +++ include/view/view_item.h | 1 + 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/common/view/view.cpp b/common/view/view.cpp index 5d529f4559..10d52c62d7 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -633,7 +633,7 @@ void VIEW::draw( VIEW_ITEM* aItem, bool aImmediate ) const { int layers[VIEW_MAX_LAYERS], layers_count; - aItem->getLayers( layers, layers_count ); + aItem->ViewGetLayers( layers, layers_count ); // Sorting is needed for drawing order dependent GALs (like Cairo) SortLayers( layers, layers_count ); @@ -813,19 +813,23 @@ void VIEW::clearGroupCache() void VIEW::invalidateItem( VIEW_ITEM* aItem, int aUpdateFlags ) { - int layers[VIEW_MAX_LAYERS], layers_count; - aItem->getLayers( layers, layers_count ); - - if( aUpdateFlags & VIEW_ITEM::GEOMETRY ) + // updateLayers updates geometry too, so we do not have to update both of them at the same time + if( aUpdateFlags & VIEW_ITEM::LAYERS ) + updateLayers( aItem ); + else if( aUpdateFlags & VIEW_ITEM::GEOMETRY ) updateBbox( aItem ); + int layers[VIEW_MAX_LAYERS], layers_count; + aItem->ViewGetLayers( layers, layers_count ); + // Iterate through layers used by the item and recache it immediately for( int i = 0; i < layers_count; i++ ) { int layerId = layers[i]; - if( aUpdateFlags & VIEW_ITEM::GEOMETRY ) + if( aUpdateFlags & ( VIEW_ITEM::GEOMETRY | VIEW_ITEM::LAYERS ) ) { + // Redraw if( IsCached( layerId ) ) updateItemGeometry( aItem, layerId ); } @@ -900,6 +904,31 @@ void VIEW::updateBbox( VIEW_ITEM* aItem ) } +void VIEW::updateLayers( VIEW_ITEM* aItem ) +{ + int layers[VIEW_MAX_LAYERS], layers_count; + + // Remove the item from previous layer set + aItem->getLayers( layers, layers_count ); + for( int i = 0; i < layers_count; i++ ) + { + VIEW_LAYER& l = m_layers[layers[i]]; + l.items->Remove( aItem ); + MarkTargetDirty( l.target ); + } + + // Add the item to new layer set + aItem->ViewGetLayers( layers, layers_count ); + aItem->saveLayers( layers, layers_count ); + for( int i = 0; i < layers_count; i++ ) + { + VIEW_LAYER& l = m_layers[layers[i]]; + l.items->Insert( aItem ); + MarkTargetDirty( l.target ); + } +} + + bool VIEW::areRequiredLayersEnabled( int aLayerId ) const { wxASSERT( (unsigned) aLayerId < m_layers.size() ); diff --git a/common/view/view_item.cpp b/common/view/view_item.cpp index d7e563109b..2daf2ec837 100644 --- a/common/view/view_item.cpp +++ b/common/view/view_item.cpp @@ -73,7 +73,6 @@ void VIEW_ITEM::getLayers( int* aLayers, int& aCount ) const { if( m_layers[i] ) *layersPtr++ = i; - } aCount = m_layers.count(); diff --git a/include/view/view.h b/include/view/view.h index b287ce5199..0dd12e803a 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -569,6 +569,9 @@ private: /// Updates bounding box of an item void updateBbox( VIEW_ITEM* aItem ); + /// Updates set of layers that an item occupies + void updateLayers( VIEW_ITEM* aItem ); + /// Determines rendering order of layers. Used in display order sorting function. static bool compareRenderingOrder( VIEW_LAYER* i, VIEW_LAYER* j ) { diff --git a/include/view/view_item.h b/include/view/view_item.h index cbf8be7967..13f7ec0d6b 100644 --- a/include/view/view_item.h +++ b/include/view/view_item.h @@ -165,6 +165,7 @@ public: APPEARANCE = 0x01, /// Visibility flag has changed COLOR = 0x02, /// Color has changed GEOMETRY = 0x04, /// Position or shape has changed + LAYERS = 0x08, /// Layers have changed ALL = 0xff };