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>
42 Base::Base( VisualFactoryCache& factoryCache )
43 : mImpl( new Impl() ),
44 mFactoryCache( factoryCache )
53 void Base::SetCustomShader( const Property::Map& shaderMap )
55 if( mImpl->mCustomShader )
57 mImpl->mCustomShader->SetPropertyMap( shaderMap );
61 mImpl->mCustomShader = new Impl::CustomShader( shaderMap );
65 void Base::Initialize( Actor& actor, const Property::Map& propertyMap )
67 Property::Value* customShaderValue = propertyMap.Find( Toolkit::Visual::Property::SHADER, CUSTOM_SHADER );
68 if( customShaderValue )
70 Property::Map shaderMap;
71 if( customShaderValue->Get( shaderMap ) )
73 SetCustomShader( shaderMap );
77 DoInitialize( actor, propertyMap );
80 void Base::SetSize( const Vector2& size )
85 const Vector2& Base::GetSize() const
90 void Base::GetNaturalSize( Vector2& naturalSize ) const
92 naturalSize = Vector2::ZERO;
95 void Base::SetClipRect( const Rect<int>& clipRect )
99 void Base::SetOffset( const Vector2& offset )
101 mImpl->mOffset = offset;
104 void Base::SetDepthIndex( float index )
106 mImpl->mDepthIndex = index;
107 if( mImpl->mRenderer )
109 mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
113 float Base::GetDepthIndex() const
115 return mImpl->mDepthIndex;
118 void Base::SetOnStage( Actor& actor )
120 // To display the actor correctly, renderer should not be added to actor until all required resources are ready.
121 // Thus the calling of actor.AddRenderer() should happen inside derived class as base class does not know the exact timing.
122 DoSetOnStage( actor );
124 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
125 mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
126 mImpl->mFlags |= Impl::IS_ON_STAGE;
129 void Base::SetOffStage( Actor& actor )
133 DoSetOffStage( actor );
135 mImpl->mFlags &= ~Impl::IS_ON_STAGE;
139 void Base::EnablePreMultipliedAlpha( bool preMultipled )
143 mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
147 mImpl->mFlags &= ~Impl::IS_PREMULTIPLIED_ALPHA;
150 if( mImpl->mRenderer )
152 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, preMultipled);
156 bool Base::IsPreMultipliedAlphaEnabled() const
158 return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA;
161 void Base::DoSetOffStage( Actor& actor )
163 actor.RemoveRenderer( mImpl->mRenderer );
164 mImpl->mRenderer.Reset();
167 void Base::CreatePropertyMap( Property::Map& map ) const
169 DoCreatePropertyMap( map );
171 if( mImpl->mCustomShader )
173 mImpl->mCustomShader->CreatePropertyMap( map );
177 bool Base::GetIsOnStage() const
179 return mImpl->mFlags & Impl::IS_ON_STAGE;
182 bool Base::GetIsFromCache() const
184 return mImpl->mFlags & Impl::IS_FROM_CACHE;
187 } // namespace Visual
189 } // namespace Internal
191 } // namespace Toolkit