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::SetProperties( 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 DoSetProperties( propertyMap );
77 void Visual::Base::SetName( const std::string& name )
82 const std::string& Visual::Base::GetName()
87 void Visual::Base::SetSize( const Vector2& size )
92 const Vector2& Visual::Base::GetSize() const
97 float Visual::Base::GetHeightForWidth( float width ) const
102 void Visual::Base::GetNaturalSize( Vector2& naturalSize ) const
104 naturalSize = Vector2::ZERO;
107 void Visual::Base::SetDepthIndex( float index )
109 mImpl->mDepthIndex = index;
110 if( mImpl->mRenderer )
112 mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
116 float Visual::Base::GetDepthIndex() const
118 return mImpl->mDepthIndex;
121 void Visual::Base::SetOnStage( Actor& actor )
123 // To display the actor correctly, renderer should not be added to actor until all required resources are ready.
124 // Thus the calling of actor.AddRenderer() should happen inside derived class as base class does not know the exact timing.
125 DoSetOnStage( actor );
127 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
128 mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
129 mImpl->mFlags |= Impl::IS_ON_STAGE;
132 void Visual::Base::SetOffStage( Actor& actor )
136 DoSetOffStage( actor );
138 mImpl->mFlags &= ~Impl::IS_ON_STAGE;
142 void Visual::Base::CreatePropertyMap( Property::Map& map ) const
144 DoCreatePropertyMap( map );
146 if( mImpl->mCustomShader )
148 mImpl->mCustomShader->CreatePropertyMap( map );
152 void Visual::Base::EnablePreMultipliedAlpha( bool preMultipled )
156 mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
160 mImpl->mFlags &= ~Impl::IS_PREMULTIPLIED_ALPHA;
163 if( mImpl->mRenderer )
165 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, preMultipled);
169 bool Visual::Base::IsPreMultipliedAlphaEnabled() const
171 return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA;
174 void Visual::Base::DoSetOffStage( Actor& actor )
176 actor.RemoveRenderer( mImpl->mRenderer );
177 mImpl->mRenderer.Reset();
180 bool Visual::Base::IsOnStage() const
182 return mImpl->mFlags & Impl::IS_ON_STAGE;
185 bool Visual::Base::IsFromCache() const
187 return mImpl->mFlags & Impl::IS_FROM_CACHE;
190 void Visual::Base::SetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue )
192 DALI_ASSERT_ALWAYS( ( index > Property::INVALID_INDEX ) &&
193 ( index > VISUAL_PROPERTY_BASE_START_INDEX ) && // Change the type of visual is not allowed.
194 "Property index is out of bounds" );
196 if( index < VISUAL_PROPERTY_START_INDEX )
198 // TODO set the properties of the visual base.
202 DoSetProperty( index, propertyValue );
206 Dali::Property::Value Visual::Base::GetProperty( Dali::Property::Index index )
208 DALI_ASSERT_ALWAYS( ( index > Property::INVALID_INDEX ) &&
209 ( index >= VISUAL_PROPERTY_BASE_START_INDEX ) &&
210 "Property index is out of bounds" );
212 Dali::Property::Value value;
214 if( index < VISUAL_PROPERTY_START_INDEX )
216 // TODO retrieve the properties of the visual base.
220 value = DoGetProperty( index );
226 } // namespace Internal
228 } // namespace Toolkit