Updated Gradient renderer to use SetTexture
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / control-renderer-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_CONTROL_RENDERER_H__
2 #define __DALI_TOOLKIT_INTERNAL_CONTROL_RENDERER_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21
22 // EXTERNAL INCLUDES
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/public-api/images/image-operations.h>
25 #include <dali/devel-api/rendering/shader.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/devel-api/controls/renderer-factory/renderer-factory.h>
29 #include <dali-toolkit/devel-api/controls/renderer-factory/control-renderer.h>
30 #include <dali-toolkit/internal/controls/renderers/renderer-factory-cache.h>
31
32 namespace Dali
33 {
34
35 namespace Toolkit
36 {
37
38 namespace Internal
39 {
40
41 /**
42  * Base class for all Control rendering logic. A control may have multiple control renderers.
43  *
44  * Note: The control renderer responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
45  *
46  * The following properties are optional
47  *
48  * | %Property Name          | Type             |
49  * |-------------------------|------------------|
50  * | customShader            | MAP              |
51  *
52  * where custom-shader is a map with the following properties:
53  * | %Property Name          | Type             |
54  * |-------------------------|------------------|
55  * | vertexShader            | STRING           |
56  * | fragmentShader          | STRING           |
57  * | subdivideGridX          | INT              |
58  * | subdivideGridY          | INT              |
59  * | shaderHints             | INT              |
60  */
61 class ControlRenderer : public BaseObject
62 {
63 public:
64
65   /**
66    * Initialisation of the renderer, this API should only called by the RendererFactory:
67    *  request the geometry and shader from the cache, if not available, create and save to the cache for sharing;
68    *  record the property values.
69    *
70    * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
71    * @param[in] propertyMap The properties for the requested ControlRenderer object.
72    */
73   void Initialize( Actor& actor, const Property::Map& propertyMap );
74
75   /**
76    * @copydoc Toolkit::ControlRenderer::SetSize
77    */
78   virtual void SetSize( const Vector2& size );
79
80   /**
81    * @copydoc Toolkit::ControlRenderer::GetSize
82    */
83   const Vector2& GetSize() const;
84
85   /**
86    * @copydoc Toolkit::ControlRenderer::GetNaturalSize
87    */
88   virtual void GetNaturalSize( Vector2& naturalSize ) const;
89
90   /**
91    * ToDo: Add this function to Toolkit::ControlRenderer when it is fully implemented.
92    *
93    * Set the clip rectangular of this renderer.
94    * The contents of the renderer will not be visible outside this rectangular.
95    *
96    * @param [in] clipRect The clipping rectangular.
97    */
98   virtual void SetClipRect( const Rect<int>& clipRect );
99
100   /**
101    *ToDo: Add this function to Toolkit::ControlRenderer when it is fully implemented.
102    *
103    * Reposition this renderer with a 2D offset.
104    *
105    * @param[in] offset The offset to reposition the renderer.
106    */
107   virtual void SetOffset( const Vector2& offset );
108
109   /**
110    * @copydoc Toolkit::ControlRenderer::SetDepthIndex
111    */
112   void SetDepthIndex( float index );
113
114   /**
115    * @copydoc Toolkit::ControlRenderer::GetDepthIndex
116    */
117   float GetDepthIndex() const;
118
119   /**
120    * @copydoc Toolkit::ControlRenderer::SetOnStage
121    * @pre Impl->mGeometry must be created before this method is called
122    */
123   void SetOnStage( Actor& actor );
124
125   /**
126    * @copydoc Toolkit::ControlRenderer::SetOffStage
127    */
128   void SetOffStage( Actor& actor );
129
130   /**
131    * @copydoc Toolkit::ControlRenderer::CreatePropertyMap
132    */
133   void CreatePropertyMap( Property::Map& map ) const;
134
135   /**
136    * @brief Set whether the Pre-multiplied Alpha Blending is required
137    *
138    * @param[in] preMultipled whether alpha is pre-multiplied.
139    */
140   void EnablePreMultipliedAlpha(  bool preMultipled );
141
142   /**
143    * @brief Query whether alpha is pre-multiplied.
144    *
145    * @return True is alpha is pre-multiplied, false otherwise.
146    */
147   bool IsPreMultipliedAlphaEnabled() const;
148
149   /**
150    * @brief Sets properties of custom shader
151    * @param[in] propertyMap Property map containing the custom shader data
152    */
153   void SetCustomShader( const Property::Map& propertyMap );
154
155 protected:
156
157   /**
158    * @brief Constructor.
159    *
160    * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
161    */
162   ControlRenderer( RendererFactoryCache& factoryCache );
163
164   /**
165    * @brief A reference counted object may only be deleted by calling Unreference().
166    */
167   virtual ~ControlRenderer();
168
169 protected:
170   /**
171    * @brief Called by CreatePropertyMap() allowing sub classes to respond to the CreatePropertyMap event
172    *
173    * @param[out] map The renderer property map.
174    */
175   virtual void DoCreatePropertyMap( Property::Map& map ) const = 0;
176
177   /**
178    * @brief Called by Initialize() allowing sub classes to respond to the Initialize event
179    *
180    * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
181    * @param[in] propertyMap The properties for the requested ControlRenderer object.
182    */
183   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ) {};
184
185 protected:
186
187   /**
188    * @brief Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
189    *
190    * @param[in] actor The actor applying this renderer.
191    */
192   virtual void DoSetOnStage( Actor& actor );
193
194   /**
195    * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
196    *
197    * @param[in] actor The actor applying this renderer.
198    */
199   virtual void DoSetOffStage( Actor& actor );
200
201 protected:
202   /**
203    * @brief Gets the on stage state for this ControlRenderer
204    *
205    * @return Returns true if this ControlRenderer is on stage, false if it is off the stage
206    */
207   bool GetIsOnStage() const;
208
209   /**
210    * @brief Gets whether the Dali::Renderer is from a shared cache (and therefore any modifications will affect other users of that renderer)
211    *
212    * @return Returns true if the renderer is from shared cache, false otherwise
213    */
214   bool GetIsFromCache() const;
215
216 private:
217
218   // Undefined
219   ControlRenderer( const ControlRenderer& renderer );
220
221   // Undefined
222   ControlRenderer& operator=( const ControlRenderer& renderer );
223
224 protected:
225   struct Impl;
226   Impl* mImpl;
227   RendererFactoryCache& mFactoryCache;
228 };
229
230 } // namespace Internal
231
232 inline const Internal::ControlRenderer& GetImplementation(const Toolkit::ControlRenderer& renderer)
233 {
234   DALI_ASSERT_ALWAYS( renderer && "ControlRenderer handle is empty" );
235
236   const BaseObject& handle = renderer.GetBaseObject();
237
238   return static_cast<const Internal::ControlRenderer&>(handle);
239 }
240
241 inline Internal::ControlRenderer& GetImplementation(Toolkit::ControlRenderer& renderer)
242 {
243   DALI_ASSERT_ALWAYS( renderer && "ControlRenderer handle is empty" );
244
245   BaseObject& handle = renderer.GetBaseObject();
246
247   return static_cast<Internal::ControlRenderer&>(handle);
248 }
249
250 } // namespace Toolkit
251
252 } // namespace Dali
253
254 #endif /* __DALI_TOOLKIT_INTERNAL_CONTROL_RENDERER_H___ */