X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fvisuals%2Fvisual-base-impl.cpp;h=e8ed4a32f950f85a3637813717db1193fd70d75c;hp=58e4d38f10d85b9ad8842daf4ab6080cd1a79cda;hb=d1cfad4519366d33c73f7152451735e664ad241c;hpb=d46f6a3bf122f36f36e9c4e8ab048f9482984dfe diff --git a/dali-toolkit/internal/visuals/visual-base-impl.cpp b/dali-toolkit/internal/visuals/visual-base-impl.cpp index 58e4d38..e8ed4a3 100644 --- a/dali-toolkit/internal/visuals/visual-base-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-base-impl.cpp @@ -23,7 +23,7 @@ #include //INTERNAL HEARDER -#include +#include #include #include @@ -55,13 +55,13 @@ void Visual::Base::SetCustomShader( const Property::Map& shaderMap ) } else { - mImpl->mCustomShader = new Impl::CustomShader( shaderMap ); + mImpl->mCustomShader = new Impl::CustomShader( shaderMap ); } } -void Visual::Base::Initialize( Actor& actor, const Property::Map& propertyMap ) +void Visual::Base::SetProperties( const Property::Map& propertyMap ) { - Property::Value* customShaderValue = propertyMap.Find( Toolkit::Visual::Property::SHADER, CUSTOM_SHADER ); + Property::Value* customShaderValue = propertyMap.Find( VisualProperty::SHADER, CUSTOM_SHADER ); if( customShaderValue ) { Property::Map shaderMap; @@ -71,7 +71,27 @@ void Visual::Base::Initialize( Actor& actor, const Property::Map& propertyMap ) } } - DoInitialize( actor, propertyMap ); + Property::Value* transform = propertyMap.Find( Toolkit::Visual::DevelProperty::TRANSFORM, TRANSFORM ); + if( transform ) + { + Property::Map map; + if( transform->Get( map ) ) + { + mImpl->mTransform.SetPropertyMap( map ); + } + } + + DoSetProperties( propertyMap ); +} + +void Visual::Base::SetName( const std::string& name ) +{ + mImpl->mName = name; +} + +const std::string& Visual::Base::GetName() +{ + return mImpl->mName; } void Visual::Base::SetSize( const Vector2& size ) @@ -84,7 +104,12 @@ const Vector2& Visual::Base::GetSize() const return mImpl->mSize; } -void Visual::Base::GetNaturalSize( Vector2& naturalSize ) const +float Visual::Base::GetHeightForWidth( float width ) const +{ + return 0.f; +} + +void Visual::Base::GetNaturalSize( Vector2& naturalSize ) { naturalSize = Vector2::ZERO; } @@ -105,18 +130,24 @@ float Visual::Base::GetDepthIndex() const void Visual::Base::SetOnStage( Actor& actor ) { - DoSetOnStage( actor ); - - mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled()); - mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex ); - actor.AddRenderer( mImpl->mRenderer ); + if( !IsOnStage() ) + { + // To display the actor correctly, renderer should not be added to actor until all required resources are ready. + // Thus the calling of actor.AddRenderer() should happen inside derived class as base class does not know the exact timing. + DoSetOnStage( actor ); - mImpl->mFlags |= Impl::IS_ON_STAGE; + if( mImpl->mRenderer ) + { + mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled()); + mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex ); + mImpl->mFlags |= Impl::IS_ON_STAGE; // Only sets the flag if renderer exists + } + } } void Visual::Base::SetOffStage( Actor& actor ) { - if( GetIsOnStage() ) + if( IsOnStage() ) { DoSetOffStage( actor ); @@ -124,6 +155,20 @@ void Visual::Base::SetOffStage( Actor& actor ) } } +void Visual::Base::CreatePropertyMap( Property::Map& map ) const +{ + DoCreatePropertyMap( map ); + + if( mImpl->mCustomShader ) + { + mImpl->mCustomShader->CreatePropertyMap( map ); + } + + Property::Map transform; + mImpl->mTransform.GetPropertyMap( transform ); + map.Insert( Toolkit::Visual::DevelProperty::TRANSFORM, transform ); +} + void Visual::Base::EnablePreMultipliedAlpha( bool preMultipled ) { if(preMultipled) @@ -146,34 +191,72 @@ bool Visual::Base::IsPreMultipliedAlphaEnabled() const return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA; } -void Visual::Base::DoSetOnStage( Actor& actor ) -{ -} - void Visual::Base::DoSetOffStage( Actor& actor ) { actor.RemoveRenderer( mImpl->mRenderer ); mImpl->mRenderer.Reset(); } -void Visual::Base::CreatePropertyMap( Property::Map& map ) const +bool Visual::Base::IsOnStage() const { - DoCreatePropertyMap( map ); + return mImpl->mFlags & Impl::IS_ON_STAGE; +} - if( mImpl->mCustomShader ) - { - mImpl->mCustomShader->CreatePropertyMap( map ); - } +bool Visual::Base::IsFromCache() const +{ + return mImpl->mFlags & Impl::IS_FROM_CACHE; } -bool Visual::Base::GetIsOnStage() const +void Visual::Base::SetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue ) { - return mImpl->mFlags & Impl::IS_ON_STAGE; + DALI_ASSERT_ALWAYS( ( index > Property::INVALID_INDEX ) && + ( index > VISUAL_PROPERTY_BASE_START_INDEX ) && // Change the type of visual is not allowed. + "Property index is out of bounds" ); + + if( index < VISUAL_PROPERTY_START_INDEX ) + { + if( index == Dali::Toolkit::Visual::DevelProperty::TRANSFORM ) + { + Property::Map* map = propertyValue.GetMap(); + if( map ) + { + mImpl->mTransform.SetPropertyMap( *map ); + OnSetTransform(); + } + } + + // TODO set the properties of the visual base. + } + else + { + DoSetProperty( index, propertyValue ); + } } -bool Visual::Base::GetIsFromCache() const +Dali::Property::Value Visual::Base::GetProperty( Dali::Property::Index index ) { - return mImpl->mFlags & Impl::IS_FROM_CACHE; + DALI_ASSERT_ALWAYS( ( index > Property::INVALID_INDEX ) && + ( index >= VISUAL_PROPERTY_BASE_START_INDEX ) && + "Property index is out of bounds" ); + + Dali::Property::Value value; + + if( index < VISUAL_PROPERTY_START_INDEX ) + { + if( index == Dali::Toolkit::Visual::DevelProperty::TRANSFORM ) + { + Property::Map map; + mImpl->mTransform.GetPropertyMap( map ); + return map; + } + // TODO retrieve the properties of the visual base. + } + else + { + value = DoGetProperty( index ); + } + + return value; } } // namespace Internal