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=86d2114168ce11740c628c6b7dbc6f56cd9bcfe0;hp=d9e19de012e5fa6c87e3a9d50829d6e744e73a38;hb=63f9b5207c2794cdc460d587723be89585872a51;hpb=99e2ea03e6d6059f5803d700932df1ff1c848cd3 diff --git a/dali-toolkit/internal/visuals/visual-base-impl.cpp b/dali-toolkit/internal/visuals/visual-base-impl.cpp index d9e19de..86d2114 100644 --- a/dali-toolkit/internal/visuals/visual-base-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-base-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,18 +23,9 @@ #include //INTERNAL HEARDER +#include #include - -namespace -{ -//custom shader -const char * const CUSTOM_SHADER( "shader" ); -const char * const CUSTOM_VERTEX_SHADER( "vertexShader" ); -const char * const CUSTOM_FRAGMENT_SHADER( "fragmentShader" ); -const char * const CUSTOM_SUBDIVIDE_GRID_X( "subdivideGridX" ); -const char * const CUSTOM_SUBDIVIDE_GRID_Y( "subdivideGridY" ); -const char * const CUSTOM_SHADER_HINTS( "hints" ); ///< type INTEGER; (bitfield) values from enum Shader::Hint -} +#include namespace Dali { @@ -45,21 +36,18 @@ namespace Toolkit namespace Internal { -namespace Visual -{ - -Base::Base( VisualFactoryCache& factoryCache ) +Visual::Base::Base( VisualFactoryCache& factoryCache ) : mImpl( new Impl() ), mFactoryCache( factoryCache ) { } -Base::~Base() +Visual::Base::~Base() { delete mImpl; } -void Base::SetCustomShader( const Property::Map& shaderMap ) +void Visual::Base::SetCustomShader( const Property::Map& shaderMap ) { if( mImpl->mCustomShader ) { @@ -71,9 +59,9 @@ void Base::SetCustomShader( const Property::Map& shaderMap ) } } -void Base::Initialize( Actor& actor, const Property::Map& propertyMap ) +void Visual::Base::Initialize( Actor& actor, const Property::Map& propertyMap ) { - Property::Value* customShaderValue = propertyMap.Find( CUSTOM_SHADER ); + Property::Value* customShaderValue = propertyMap.Find( Toolkit::Visual::Property::SHADER, CUSTOM_SHADER ); if( customShaderValue ) { Property::Map shaderMap; @@ -86,31 +74,27 @@ void Base::Initialize( Actor& actor, const Property::Map& propertyMap ) DoInitialize( actor, propertyMap ); } -void Base::SetSize( const Vector2& size ) +void Visual::Base::SetSize( const Vector2& size ) { mImpl->mSize = size; } -const Vector2& Base::GetSize() const +const Vector2& Visual::Base::GetSize() const { return mImpl->mSize; } -void Base::GetNaturalSize( Vector2& naturalSize ) const -{ - naturalSize = Vector2::ZERO; -} - -void Base::SetClipRect( const Rect& clipRect ) +float Visual::Base::GetHeightForWidth( float width ) const { + return 0.f; } -void Base::SetOffset( const Vector2& offset ) +void Visual::Base::GetNaturalSize( Vector2& naturalSize ) const { - mImpl->mOffset = offset; + naturalSize = Vector2::ZERO; } -void Base::SetDepthIndex( float index ) +void Visual::Base::SetDepthIndex( float index ) { mImpl->mDepthIndex = index; if( mImpl->mRenderer ) @@ -119,24 +103,25 @@ void Base::SetDepthIndex( float index ) } } -float Base::GetDepthIndex() const +float Visual::Base::GetDepthIndex() const { return mImpl->mDepthIndex; } -void Base::SetOnStage( Actor& actor ) +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 ); mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled()); mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex ); - actor.AddRenderer( mImpl->mRenderer ); mImpl->mFlags |= Impl::IS_ON_STAGE; } -void Base::SetOffStage( Actor& actor ) +void Visual::Base::SetOffStage( Actor& actor ) { - if( GetIsOnStage() ) + if( IsOnStage() ) { DoSetOffStage( actor ); @@ -144,7 +129,17 @@ void Base::SetOffStage( Actor& actor ) } } -void Base::EnablePreMultipliedAlpha( bool preMultipled ) +void Visual::Base::CreatePropertyMap( Property::Map& map ) const +{ + DoCreatePropertyMap( map ); + + if( mImpl->mCustomShader ) + { + mImpl->mCustomShader->CreatePropertyMap( map ); + } +} + +void Visual::Base::EnablePreMultipliedAlpha( bool preMultipled ) { if(preMultipled) { @@ -161,42 +156,62 @@ void Base::EnablePreMultipliedAlpha( bool preMultipled ) } } -bool Base::IsPreMultipliedAlphaEnabled() const +bool Visual::Base::IsPreMultipliedAlphaEnabled() const { return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA; } -void Base::DoSetOnStage( Actor& actor ) +void Visual::Base::DoSetOffStage( Actor& actor ) { + actor.RemoveRenderer( mImpl->mRenderer ); + mImpl->mRenderer.Reset(); } -void Base::DoSetOffStage( Actor& actor ) +bool Visual::Base::IsOnStage() const { - actor.RemoveRenderer( mImpl->mRenderer ); - mImpl->mRenderer.Reset(); + return mImpl->mFlags & Impl::IS_ON_STAGE; } -void Base::CreatePropertyMap( Property::Map& map ) const +bool Visual::Base::IsFromCache() const { - DoCreatePropertyMap( map ); + return mImpl->mFlags & Impl::IS_FROM_CACHE; +} - if( mImpl->mCustomShader ) +void Visual::Base::SetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue ) +{ + 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 ) { - mImpl->mCustomShader->CreatePropertyMap( map ); + // TODO set the properties of the visual base. + } + else + { + DoSetProperty( index, propertyValue ); } } -bool Base::GetIsOnStage() const +Dali::Property::Value Visual::Base::GetProperty( Dali::Property::Index index ) { - return mImpl->mFlags & Impl::IS_ON_STAGE; -} + DALI_ASSERT_ALWAYS( ( index > Property::INVALID_INDEX ) && + ( index >= VISUAL_PROPERTY_BASE_START_INDEX ) && + "Property index is out of bounds" ); -bool Base::GetIsFromCache() const -{ - return mImpl->mFlags & Impl::IS_FROM_CACHE; -} + Dali::Property::Value value; -} // namespace Visual + if( index < VISUAL_PROPERTY_START_INDEX ) + { + // TODO retrieve the properties of the visual base. + } + else + { + value = DoGetProperty( index ); + } + + return value; +} } // namespace Internal