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 "control-renderer-impl.h"
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/integration-api/debug.h>
26 #include <dali-toolkit/internal/controls/renderers/control-renderer-data-impl.h>
31 const char * const CUSTOM_SHADER( "shader" );
32 const char * const CUSTOM_VERTEX_SHADER( "vertex-shader" );
33 const char * const CUSTOM_FRAGMENT_SHADER( "fragment-shader" );
34 const char * const CUSTOM_SUBDIVIDE_GRID_X( "subdivide-grid-x" );
35 const char * const CUSTOM_SUBDIVIDE_GRID_Y( "subdivide-grid-y" );
36 const char * const CUSTOM_SHADER_HINTS( "hints" ); ///< type INTEGER; (bitfield) values from enum Shader::Hints
48 ControlRenderer::ControlRenderer()
53 ControlRenderer::~ControlRenderer()
58 void ControlRenderer::Initialize( RendererFactoryCache& factoryCache, const Property::Map& propertyMap )
60 if( mImpl->mCustomShader )
62 mImpl->mCustomShader->SetPropertyMap( propertyMap );
66 Property::Value* customShaderValue = propertyMap.Find( CUSTOM_SHADER );
67 if( customShaderValue )
69 Property::Map customShader;
70 if( customShaderValue->Get( customShader ) )
72 mImpl->mCustomShader = new Impl::CustomShader( propertyMap );
76 DoInitialize( factoryCache, propertyMap );
79 void ControlRenderer::SetSize( const Vector2& size )
84 const Vector2& ControlRenderer::GetSize() const
89 void ControlRenderer::GetNaturalSize( Vector2& naturalSize ) const
91 naturalSize = Vector2::ZERO;
94 void ControlRenderer::SetClipRect( const Rect<int>& clipRect )
96 mImpl->mClipRect = clipRect;
99 void ControlRenderer::SetOffset( const Vector2& offset )
101 mImpl->mOffset = offset;
104 void ControlRenderer::SetDepthIndex( float index )
106 mImpl->mDepthIndex = index;
107 if( mImpl->mRenderer )
109 mImpl->mRenderer.SetDepthIndex( mImpl->mDepthIndex );
113 float ControlRenderer::GetDepthIndex() const
115 return mImpl->mDepthIndex;
118 void ControlRenderer::SetOnStage( Actor& actor )
120 Material material = Material::New( mImpl->mShader );
121 mImpl->mRenderer = Renderer::New( mImpl->mGeometry, material );
122 mImpl->mRenderer.SetDepthIndex( mImpl->mDepthIndex );
123 actor.AddRenderer( mImpl->mRenderer );
124 mImpl->mIsOnStage = true;
126 DoSetOnStage( actor );
129 void ControlRenderer::SetOffStage( Actor& actor )
131 if( mImpl->mIsOnStage )
133 DoSetOffStage( actor );
135 actor.RemoveRenderer( mImpl->mRenderer );
136 mImpl->mRenderer.Reset();
138 mImpl->mIsOnStage = false;
142 void ControlRenderer::DoSetOnStage( Actor& actor )
146 void ControlRenderer::DoSetOffStage( Actor& actor )
150 void ControlRenderer::CreatePropertyMap( Property::Map& map ) const
152 if( mImpl->mCustomShader )
154 mImpl->mCustomShader->CreatePropertyMap( map );
156 DoCreatePropertyMap( map );
159 } // namespace Internal
161 } // namespace Toolkit