2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "visual-base-impl.h"
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/integration-api/debug.h>
26 #include <dali-toolkit/public-api/visuals/visual-properties.h>
27 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
28 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
39 Visual::Base::Base( VisualFactoryCache& factoryCache )
40 : mImpl( new Impl() ),
41 mFactoryCache( factoryCache )
50 void Visual::Base::SetCustomShader( const Property::Map& shaderMap )
52 if( mImpl->mCustomShader )
54 mImpl->mCustomShader->SetPropertyMap( shaderMap );
58 mImpl->mCustomShader = new Impl::CustomShader( shaderMap );
62 void Visual::Base::Initialize( Actor& actor, const Property::Map& propertyMap )
64 Property::Value* customShaderValue = propertyMap.Find( Toolkit::Visual::Property::SHADER, CUSTOM_SHADER );
65 if( customShaderValue )
67 Property::Map shaderMap;
68 if( customShaderValue->Get( shaderMap ) )
70 SetCustomShader( shaderMap );
74 DoInitialize( actor, propertyMap );
77 void Visual::Base::SetSize( const Vector2& size )
82 const Vector2& Visual::Base::GetSize() const
87 void Visual::Base::GetNaturalSize( Vector2& naturalSize ) const
89 naturalSize = Vector2::ZERO;
92 void Visual::Base::SetDepthIndex( float index )
94 mImpl->mDepthIndex = index;
95 if( mImpl->mRenderer )
97 mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
101 float Visual::Base::GetDepthIndex() const
103 return mImpl->mDepthIndex;
106 void Visual::Base::SetOnStage( Actor& actor )
108 DoSetOnStage( actor );
110 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
111 mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
112 actor.AddRenderer( mImpl->mRenderer );
114 mImpl->mFlags |= Impl::IS_ON_STAGE;
117 void Visual::Base::SetOffStage( Actor& actor )
121 DoSetOffStage( actor );
123 mImpl->mFlags &= ~Impl::IS_ON_STAGE;
127 void Visual::Base::EnablePreMultipliedAlpha( bool preMultipled )
131 mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
135 mImpl->mFlags &= ~Impl::IS_PREMULTIPLIED_ALPHA;
138 if( mImpl->mRenderer )
140 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, preMultipled);
144 bool Visual::Base::IsPreMultipliedAlphaEnabled() const
146 return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA;
149 void Visual::Base::DoSetOnStage( Actor& actor )
153 void Visual::Base::DoSetOffStage( Actor& actor )
155 actor.RemoveRenderer( mImpl->mRenderer );
156 mImpl->mRenderer.Reset();
159 void Visual::Base::CreatePropertyMap( Property::Map& map ) const
161 DoCreatePropertyMap( map );
163 if( mImpl->mCustomShader )
165 mImpl->mCustomShader->CreatePropertyMap( map );
169 bool Visual::Base::GetIsOnStage() const
171 return mImpl->mFlags & Impl::IS_ON_STAGE;
174 bool Visual::Base::GetIsFromCache() const
176 return mImpl->mFlags & Impl::IS_FROM_CACHE;
179 } // namespace Internal
181 } // namespace Toolkit