1 #ifndef DALI_TOOLKIT_INTERNAL_CONTROL_RENDERER_H
2 #define DALI_TOOLKIT_INTERNAL_CONTROL_RENDERER_H
5 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/images/image-operations.h>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/rendering/shader.h>
27 #include <dali-toolkit/devel-api/controls/renderer-factory/control-renderer.h>
28 #include <dali-toolkit/devel-api/controls/renderer-factory/renderer-factory.h>
29 #include <dali-toolkit/internal/controls/renderers/renderer-factory-cache.h>
41 * Base class for all Control rendering logic. A control may have multiple control renderers.
43 * Note: The control renderer responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
45 * The following properties are optional
47 * | %Property Name | Type |
48 * |-------------------------|------------------|
49 * | customShader | MAP |
51 * where custom-shader is a map with the following properties:
52 * | %Property Name | Type |
53 * |-------------------------|------------------|
54 * | vertexShader | STRING |
55 * | fragmentShader | STRING |
56 * | subdivideGridX | INT |
57 * | subdivideGridY | INT |
58 * | shaderHints | INT |
60 class ControlRenderer : public BaseObject
65 * Initialisation of the renderer, this API should only called by the RendererFactory:
66 * request the geometry and shader from the cache, if not available, create and save to the cache for sharing;
67 * record the property values.
69 * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
70 * @param[in] propertyMap The properties for the requested ControlRenderer object.
72 void Initialize( Actor& actor, const Property::Map& propertyMap );
75 * @copydoc Toolkit::ControlRenderer::SetSize
77 virtual void SetSize( const Vector2& size );
80 * @copydoc Toolkit::ControlRenderer::GetSize
82 const Vector2& GetSize() const;
85 * @copydoc Toolkit::ControlRenderer::GetNaturalSize
87 virtual void GetNaturalSize( Vector2& naturalSize ) const;
90 * ToDo: Add this function to Toolkit::ControlRenderer when it is fully implemented.
92 * Set the clip rectangular of this renderer.
93 * The contents of the renderer will not be visible outside this rectangular.
95 * @param [in] clipRect The clipping rectangular.
97 virtual void SetClipRect( const Rect<int>& clipRect );
100 *ToDo: Add this function to Toolkit::ControlRenderer when it is fully implemented.
102 * Reposition this renderer with a 2D offset.
104 * @param[in] offset The offset to reposition the renderer.
106 virtual void SetOffset( const Vector2& offset );
109 * @copydoc Toolkit::ControlRenderer::SetDepthIndex
111 void SetDepthIndex( float index );
114 * @copydoc Toolkit::ControlRenderer::GetDepthIndex
116 float GetDepthIndex() const;
119 * @copydoc Toolkit::ControlRenderer::SetOnStage
120 * @pre Impl->mGeometry must be created before this method is called
122 void SetOnStage( Actor& actor );
125 * @copydoc Toolkit::ControlRenderer::SetOffStage
127 void SetOffStage( Actor& actor );
130 * @copydoc Toolkit::ControlRenderer::CreatePropertyMap
132 void CreatePropertyMap( Property::Map& map ) const;
135 * @brief Set whether the Pre-multiplied Alpha Blending is required
137 * @param[in] preMultipled whether alpha is pre-multiplied.
139 void EnablePreMultipliedAlpha( bool preMultipled );
142 * @brief Query whether alpha is pre-multiplied.
144 * @return True is alpha is pre-multiplied, false otherwise.
146 bool IsPreMultipliedAlphaEnabled() const;
149 * @brief Sets properties of custom shader
150 * @param[in] propertyMap Property map containing the custom shader data
152 void SetCustomShader( const Property::Map& propertyMap );
157 * @brief Constructor.
159 * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
161 ControlRenderer( RendererFactoryCache& factoryCache );
164 * @brief A reference counted object may only be deleted by calling Unreference().
166 virtual ~ControlRenderer();
170 * @brief Called by CreatePropertyMap() allowing sub classes to respond to the CreatePropertyMap event
172 * @param[out] map The renderer property map.
174 virtual void DoCreatePropertyMap( Property::Map& map ) const = 0;
177 * @brief Called by Initialize() allowing sub classes to respond to the Initialize event
179 * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
180 * @param[in] propertyMap The properties for the requested ControlRenderer object.
182 virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ) {};
187 * @brief Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
189 * @param[in] actor The actor applying this renderer.
191 virtual void DoSetOnStage( Actor& actor );
194 * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
196 * @param[in] actor The actor applying this renderer.
198 virtual void DoSetOffStage( Actor& actor );
202 * @brief Gets the on stage state for this ControlRenderer
204 * @return Returns true if this ControlRenderer is on stage, false if it is off the stage
206 bool GetIsOnStage() const;
209 * @brief Gets whether the Dali::Renderer is from a shared cache (and therefore any modifications will affect other users of that renderer)
211 * @return Returns true if the renderer is from shared cache, false otherwise
213 bool GetIsFromCache() const;
218 ControlRenderer( const ControlRenderer& renderer );
221 ControlRenderer& operator=( const ControlRenderer& renderer );
226 RendererFactoryCache& mFactoryCache;
229 } // namespace Internal
231 inline const Internal::ControlRenderer& GetImplementation(const Toolkit::ControlRenderer& renderer)
233 DALI_ASSERT_ALWAYS( renderer && "ControlRenderer handle is empty" );
235 const BaseObject& handle = renderer.GetBaseObject();
237 return static_cast<const Internal::ControlRenderer&>(handle);
240 inline Internal::ControlRenderer& GetImplementation(Toolkit::ControlRenderer& renderer)
242 DALI_ASSERT_ALWAYS( renderer && "ControlRenderer handle is empty" );
244 BaseObject& handle = renderer.GetBaseObject();
246 return static_cast<Internal::ControlRenderer&>(handle);
249 } // namespace Toolkit
253 #endif // DALI_TOOLKIT_INTERNAL_CONTROL_RENDERER_H