bool GraphicsElementManager::InitElement( shared_ptr<GraphicsElement> pElement, int layer_index ) { int element_index = GetVacantSlotIndex(); m_vecpElement[element_index] = pElement; m_vecpElement[element_index]->SetGraphicsElementManager( this ); m_vecpElement[element_index]->ChangeScale( m_fScale ); m_vecpElement[element_index]->SetElementIndex( element_index ); pElement->m_pSelf = pElement; // if( pElement->GetElementType() != GraphicsElement::TYPE_GROUP ) if( pElement->BelongsToLayer() ) { // GraphicsElementGroup and CombinedPrimitiveElement do not belong to layer bool res = RegisterToLayer( element_index, layer_index ); if( !res ) return false; m_vecpElement[element_index]->SetLayerIndex( layer_index ); } return true; }
bool GraphicsElementManager::RemoveElement( shared_ptr<GraphicsElement> pElement ) { if( !pElement // invalid argument || !(pElement->m_pManager) ) // already released { return false; } pElement->OnRemovalRequested(); int element_id = pElement->GetElementIndex(); // callback triggered by element removal // - used by effect manager to remove effect which is currently being applied to removed element 'pElement' if( m_pCallbackPtr.get() ) m_pCallbackPtr->OnDestroyed( pElement ); // if( pElement->GetElementType() != GraphicsElement::TYPE_GROUP ) if( pElement->BelongsToLayer() ) { RemoveFromLayer( pElement ); } // remove the element from the group to which it currently belongs int group_id = pElement->GetGroupID(); shared_ptr<GraphicsElementGroup> pGroup; if( 0 <= group_id && GetElement(group_id)->GetElementType() == GraphicsElement::TYPE_GROUP && ( pGroup = dynamic_pointer_cast< GraphicsElementGroup, GraphicsElement >(GetElement(group_id)) ) ) { pGroup->RemoveElementFromGroup( pElement ); } // SAFE_DELETE( m_vecpElement[element_id] ); m_vecpElement[element_id].reset(); pElement->Release(); return true; }