2 * Copyright (c) 2015 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/internal/visuals/visual-base-data-impl.h>
31 const char * const CUSTOM_SHADER( "shader" );
32 const char * const CUSTOM_VERTEX_SHADER( "vertexShader" );
33 const char * const CUSTOM_FRAGMENT_SHADER( "fragmentShader" );
34 const char * const CUSTOM_SUBDIVIDE_GRID_X( "subdivideGridX" );
35 const char * const CUSTOM_SUBDIVIDE_GRID_Y( "subdivideGridY" );
36 const char * const CUSTOM_SHADER_HINTS( "hints" ); ///< type INTEGER; (bitfield) values from enum Shader::Hint
51 Base::Base( VisualFactoryCache& factoryCache )
52 : mImpl( new Impl() ),
53 mFactoryCache( factoryCache )
62 void Base::SetCustomShader( const Property::Map& shaderMap )
64 if( mImpl->mCustomShader )
66 mImpl->mCustomShader->SetPropertyMap( shaderMap );
70 mImpl->mCustomShader = new Impl::CustomShader( shaderMap );
74 void Base::Initialize( Actor& actor, const Property::Map& propertyMap )
76 Property::Value* customShaderValue = propertyMap.Find( CUSTOM_SHADER );
77 if( customShaderValue )
79 Property::Map shaderMap;
80 if( customShaderValue->Get( shaderMap ) )
82 SetCustomShader( shaderMap );
86 DoInitialize( actor, propertyMap );
89 void Base::SetSize( const Vector2& size )
94 const Vector2& Base::GetSize() const
99 void Base::GetNaturalSize( Vector2& naturalSize ) const
101 naturalSize = Vector2::ZERO;
104 void Base::SetClipRect( const Rect<int>& clipRect )
108 void Base::SetOffset( const Vector2& offset )
110 mImpl->mOffset = offset;
113 void Base::SetDepthIndex( float index )
115 mImpl->mDepthIndex = index;
116 if( mImpl->mRenderer )
118 mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
122 float Base::GetDepthIndex() const
124 return mImpl->mDepthIndex;
127 void Base::SetOnStage( Actor& actor )
129 DoSetOnStage( actor );
131 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
132 mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
133 actor.AddRenderer( mImpl->mRenderer );
134 mImpl->mFlags |= Impl::IS_ON_STAGE;
137 void Base::SetOffStage( Actor& actor )
141 DoSetOffStage( actor );
143 mImpl->mFlags &= ~Impl::IS_ON_STAGE;
147 void Base::EnablePreMultipliedAlpha( bool preMultipled )
151 mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
155 mImpl->mFlags &= ~Impl::IS_PREMULTIPLIED_ALPHA;
158 if( mImpl->mRenderer )
160 mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, preMultipled);
164 bool Base::IsPreMultipliedAlphaEnabled() const
166 return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA;
169 void Base::DoSetOnStage( Actor& actor )
173 void Base::DoSetOffStage( Actor& actor )
175 actor.RemoveRenderer( mImpl->mRenderer );
176 mImpl->mRenderer.Reset();
179 void Base::CreatePropertyMap( Property::Map& map ) const
181 DoCreatePropertyMap( map );
183 if( mImpl->mCustomShader )
185 mImpl->mCustomShader->CreatePropertyMap( map );
189 bool Base::GetIsOnStage() const
191 return mImpl->mFlags & Impl::IS_ON_STAGE;
194 bool Base::GetIsFromCache() const
196 return mImpl->mFlags & Impl::IS_FROM_CACHE;
199 } // namespace Visual
201 } // namespace Internal
203 } // namespace Toolkit