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=0958afad58e62f22cddf9c15a26ebe09e2c9199d;hp=8356de5c42e9b77b6639e2c09900d96c2382fa19;hb=6fac6c064c9002b166b6292d0814fea8f16d7467;hpb=b81c20064def5a5017e77876effd01ddc5bb39d6 diff --git a/dali-toolkit/internal/visuals/visual-base-impl.cpp b/dali-toolkit/internal/visuals/visual-base-impl.cpp index 8356de5..0958afa 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,36 +55,96 @@ 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 ); - if( customShaderValue ) + for( size_t i = 0; i < propertyMap.Count(); ++i ) { - Property::Map shaderMap; - if( customShaderValue->Get( shaderMap ) ) + const KeyValuePair& pair = propertyMap.GetKeyValue( i ); + const Property::Key& key = pair.first; + const Property::Value& value = pair.second; + switch( key.indexKey ) { - SetCustomShader( shaderMap ); + case DevelVisual::Property::SHADER: + { + Property::Map shaderMap; + if( value.Get( shaderMap ) ) + { + SetCustomShader( shaderMap ); + } + break; + } + + case DevelVisual::Property::TRANSFORM: + { + Property::Map map; + if( value.Get( map ) ) + { + mImpl->mTransform.SetPropertyMap( map ); + } + break; + } + + case DevelVisual::Property::PREMULTIPLIED_ALPHA: + { + bool premultipliedAlpha = false; + if( value.Get( premultipliedAlpha ) ) + { + EnablePreMultipliedAlpha( premultipliedAlpha ); + } + break; + } } } - DoInitialize( actor, propertyMap ); + DoSetProperties( propertyMap ); } -void Visual::Base::SetSize( const Vector2& size ) +void Visual::Base::SetTransformAndSize( const Property::Map& transform, Size controlSize ) { - mImpl->mSize = size; + mImpl->mControlSize = controlSize; + mImpl->mTransform.SetPropertyMap( transform ); + OnSetTransform(); } -const Vector2& Visual::Base::GetSize() const +void Visual::Base::SetName( const std::string& name ) { - return mImpl->mSize; + mImpl->mName = name; } -void Visual::Base::GetNaturalSize( Vector2& naturalSize ) const +const std::string& Visual::Base::GetName() +{ + return mImpl->mName; +} + +float Visual::Base::GetHeightForWidth( float width ) +{ + float aspectCorrectedHeight = 0.f; + Vector2 naturalSize; + GetNaturalSize( naturalSize ); + if( naturalSize.width ) + { + aspectCorrectedHeight = naturalSize.height * width / naturalSize.width; + } + return aspectCorrectedHeight; +} + +float Visual::Base::GetWidthForHeight( float height ) +{ + float aspectCorrectedWidth = 0.f; + Vector2 naturalSize; + GetNaturalSize( naturalSize ); + if( naturalSize.height > 0.0f ) + { + aspectCorrectedWidth = naturalSize.width * height / naturalSize.height; + } + return aspectCorrectedWidth; +} + +void Visual::Base::GetNaturalSize( Vector2& naturalSize ) { naturalSize = Vector2::ZERO; } @@ -105,18 +165,24 @@ float Visual::Base::GetDepthIndex() const void Visual::Base::SetOnStage( Actor& actor ) { - // 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 ); + 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->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled()); - mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex ); - 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,9 +190,26 @@ 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( DevelVisual::Property::TRANSFORM, transform ); + + bool premultipliedAlpha( IsPreMultipliedAlphaEnabled() ); + map.Insert( DevelVisual::Property::PREMULTIPLIED_ALPHA, premultipliedAlpha ); +} + void Visual::Base::EnablePreMultipliedAlpha( bool preMultipled ) { - if(preMultipled) + if( preMultipled ) { mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA; } @@ -152,22 +235,12 @@ void Visual::Base::DoSetOffStage( Actor& actor ) mImpl->mRenderer.Reset(); } -void Visual::Base::CreatePropertyMap( Property::Map& map ) const -{ - DoCreatePropertyMap( map ); - - if( mImpl->mCustomShader ) - { - mImpl->mCustomShader->CreatePropertyMap( map ); - } -} - -bool Visual::Base::GetIsOnStage() const +bool Visual::Base::IsOnStage() const { return mImpl->mFlags & Impl::IS_ON_STAGE; } -bool Visual::Base::GetIsFromCache() const +bool Visual::Base::IsFromCache() const { return mImpl->mFlags & Impl::IS_FROM_CACHE; }