Fixed ItemView flicking to top now shows overshoot indicator
[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  * | custom-shader             | MAP              |
51  *
52  * where custom-shader is a map with the following properties:
53  * | %Property Name            | Type             |
54  * |---------------------------|------------------|
55  * | vertex-shader             | STRING           |
56  * | fragment-shader           | STRING           |
57  * | subdivide-grid-x          | INT              |
58  * | subdivide-grid-y          | INT              |
59  * | shader-hints              | 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 protected:
136
137   /**
138    * @brief Constructor.
139    *
140    * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
141    */
142   ControlRenderer( RendererFactoryCache& factoryCache );
143
144   /**
145    * @brief A reference counted object may only be deleted by calling Unreference().
146    */
147   virtual ~ControlRenderer();
148
149 protected:
150   /**
151    * @brief Called by CreatePropertyMap() allowing sub classes to respond to the CreatePropertyMap event
152    *
153    * @param[out] map The renderer property map.
154    */
155   virtual void DoCreatePropertyMap( Property::Map& map ) const = 0;
156
157   /**
158    * @brief Called by Initialize() allowing sub classes to respond to the Initialize event
159    *
160    * @param[in] actor The Actor the renderer is applied to if, empty if the renderer has not been applied to any Actor
161    * @param[in] propertyMap The properties for the requested ControlRenderer object.
162    */
163   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ) = 0;
164
165 protected:
166
167   /**
168    * @brief Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
169    *
170    * @param[in] actor The actor applying this renderer.
171    */
172   virtual void DoSetOnStage( Actor& actor );
173
174   /**
175    * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
176    *
177    * @param[in] actor The actor applying this renderer.
178    */
179   virtual void DoSetOffStage( Actor& actor );
180
181 protected:
182   /**
183    * @brief Gets the on stage state for this ControlRenderer
184    *
185    * @return Returns true if this ControlRenderer is on stage, false if it is off the stage
186    */
187   bool GetIsOnStage() const;
188
189   /**
190    * @brief Gets whether the Dali::Renderer is from a shared cache (and therefore any modifications will affect other users of that renderer)
191    *
192    * @return Returns true if the renderer is from shared cache, false otherwise
193    */
194   bool GetIsFromCache() const;
195
196 private:
197
198   // Undefined
199   ControlRenderer( const ControlRenderer& renderer );
200
201   // Undefined
202   ControlRenderer& operator=( const ControlRenderer& renderer );
203
204 protected:
205   struct Impl;
206   Impl* mImpl;
207   RendererFactoryCache& mFactoryCache;
208 };
209
210 } // namespace Internal
211
212 inline const Internal::ControlRenderer& GetImplementation(const Toolkit::ControlRenderer& renderer)
213 {
214   DALI_ASSERT_ALWAYS( renderer && "ControlRenderer handle is empty" );
215
216   const BaseObject& handle = renderer.GetBaseObject();
217
218   return static_cast<const Internal::ControlRenderer&>(handle);
219 }
220
221 inline Internal::ControlRenderer& GetImplementation(Toolkit::ControlRenderer& renderer)
222 {
223   DALI_ASSERT_ALWAYS( renderer && "ControlRenderer handle is empty" );
224
225   BaseObject& handle = renderer.GetBaseObject();
226
227   return static_cast<Internal::ControlRenderer&>(handle);
228 }
229
230 } // namespace Toolkit
231
232 } // namespace Dali
233
234 #endif /* __DALI_TOOLKIT_INTERNAL_CONTROL_RENDERER_H___ */