Merge "Added code for stylable transitions" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-base-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_VISUAL_H
3
4 /*
5  * Copyright (c) 2016 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 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <dali/public-api/images/image-operations.h>
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/public-api/rendering/shader.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
29 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
30 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
31
32 namespace Dali
33 {
34
35 namespace Toolkit
36 {
37
38 namespace Internal
39 {
40
41 namespace Visual
42 {
43
44 /**
45  * Base class for all Control rendering logic. A control may have multiple visuals.
46  *
47  * Note: The visual responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
48  *
49  * The following properties are optional
50  *
51  * | %Property Name          | Type             |
52  * |-------------------------|------------------|
53  * | customShader            | MAP              |
54  *
55  * where custom-shader is a map with the following properties:
56  * | %Property Name          | Type             |
57  * |-------------------------|------------------|
58  * | vertexShader            | STRING           |
59  * | fragmentShader          | STRING           |
60  * | subdivideGridX          | INT              |
61  * | subdivideGridY          | INT              |
62  * | shaderHints             | INT              |
63  */
64 class Base : public BaseObject
65 {
66 public:
67
68   /**
69    *  Initialisation of the visual, this API should only called by the VisualFactory:
70    *  request the geometry and shader from the cache, if not available, create and save to the cache for sharing;
71    *  record the property values.
72    *
73    * @param[in] actor The Actor the visual is applied to if, empty if the visual has not been applied to any Actor
74    * @param[in] propertyMap The properties for the requested Visual object.
75    */
76   void Initialize( Actor& actor, const Property::Map& propertyMap );
77
78   /**
79    * @copydoc Toolkit::Visual::Base::SetName
80    */
81   void SetName( const std::string& name );
82
83   /**
84    * @copydoc Toolkit::Visual::Base::GetName
85    */
86   const std::string& GetName();
87
88   /**
89    * @copydoc Toolkit::Visual::Base::SetSize
90    */
91   virtual void SetSize( const Vector2& size );
92
93   /**
94    * @copydoc Toolkit::Visual::Base::GetSize
95    */
96   const Vector2& GetSize() const;
97
98   /**
99    * @copydoc Toolkit::Visual::Base::GetHeightForWidth
100    */
101   virtual float GetHeightForWidth( float width ) const;
102
103   /**
104    * @copydoc Toolkit::Visual::Base::GetNaturalSize
105    */
106   virtual void GetNaturalSize( Vector2& naturalSize ) const;
107
108   /**
109    * @copydoc Toolkit::Visual::Base::SetDepthIndex
110    */
111   void SetDepthIndex( float index );
112
113   /**
114    * @copydoc Toolkit::Visual::Base::GetDepthIndex
115    */
116   float GetDepthIndex() const;
117
118   /**
119    * @copydoc Toolkit::Visual::Base::SetOnStage
120    * @pre Impl->mGeometry must be created before this method is called
121    */
122   void SetOnStage( Actor& actor );
123
124   /**
125    * @copydoc Toolkit::Visual::Base::SetOffStage
126    */
127   void SetOffStage( Actor& actor );
128
129   /**
130    * @copydoc Toolkit::Visual::Base::CreatePropertyMap
131    */
132   void CreatePropertyMap( Property::Map& map ) const;
133
134   /**
135    * @brief Set whether the Pre-multiplied Alpha Blending is required
136    *
137    * @param[in] preMultipled whether alpha is pre-multiplied.
138    */
139   void EnablePreMultipliedAlpha( bool preMultipled );
140
141   /**
142    * @brief Query whether alpha is pre-multiplied.
143    *
144    * @return True is alpha is pre-multiplied, false otherwise.
145    */
146   bool IsPreMultipliedAlphaEnabled() const;
147
148   /**
149    * @brief Sets properties of custom shader
150    * @param[in] propertyMap Property map containing the custom shader data
151    */
152   void SetCustomShader( const Property::Map& propertyMap );
153
154   /**
155    * @copydoc Toolkit::Visual::Base::SetProperty
156    */
157   void SetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
158
159   /**
160    * @copydoc Toolkit::Visual::Base::GetProperty
161    */
162   Dali::Property::Value GetProperty( Dali::Property::Index index );
163
164 protected:
165
166   /**
167    * @brief Constructor.
168    *
169    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
170    */
171   Base( VisualFactoryCache& factoryCache );
172
173   /**
174    * @brief A reference counted object may only be deleted by calling Unreference().
175    */
176   virtual ~Base();
177
178 protected:
179   /**
180    * @brief Called by CreatePropertyMap() allowing sub classes to respond to the CreatePropertyMap event
181    *
182    * @param[out] map The visual property map.
183    */
184   virtual void DoCreatePropertyMap( Property::Map& map ) const = 0;
185
186   /**
187    * @brief Called by Initialize() allowing sub classes to respond to the Initialize event
188    *
189    * @param[in] actor The Actor the visual is applied to if, empty if the visual has not been applied to any Actor
190    * @param[in] propertyMap The properties for the requested Visual object.
191    */
192   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ) {}
193
194 protected:
195
196   /**
197    * @brief Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
198    *
199    * @note The derived class is required to create the renderer, and add it to the actor when all the resources are in place.
200    *
201    * @param[in] actor The actor applying this visual.
202    */
203   virtual void DoSetOnStage( Actor& actor )=0;
204
205   /**
206    * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
207    *
208    * @param[in] actor The actor applying this visual.
209    */
210   virtual void DoSetOffStage( Actor& actor );
211
212 protected:
213
214   /**
215    * @brief Gets the on stage state for this Visual
216    *
217    * @return Returns true if this Visual is on stage, false if it is off the stage
218    */
219   bool IsOnStage() const;
220
221   /**
222    * @brief Gets whether the Dali::Renderer is from a shared cache (and therefore any modifications will affect other users of that renderer)
223    *
224    * @return Returns true if the renderer is from shared cache, false otherwise
225    */
226   bool IsFromCache() const;
227
228 protected:
229   /**
230    * @brief Called by SetProperty(). To be overriden by derived clases in order to set properties.
231    *
232    * @param [in] index The index of the property.
233    * @param [in] propertyValue The new value of the property.
234    */
235   virtual void DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue ) = 0;
236
237   /**
238    * @brief Called by GetProperty(). To be overriden by derived classes in order to retrieve properties.
239    *
240    * @param [in] index The index of the property.
241    *
242    * @return The property value.
243    */
244   virtual Dali::Property::Value DoGetProperty( Dali::Property::Index index ) = 0;
245
246 private:
247
248   // Undefined
249   Base( const Visual::Base& visual );
250
251   // Undefined
252   Base& operator=( const Visual::Base& visual );
253
254 protected:
255   struct Impl;
256   Impl* mImpl;
257   VisualFactoryCache& mFactoryCache;
258 };
259
260 typedef IntrusivePtr<Base> BasePtr;
261
262 } // namspace Visual
263
264 } // namespace Internal
265
266 inline const Internal::Visual::Base& GetImplementation(const Toolkit::Visual::Base& visualBase )
267 {
268   DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
269
270   const BaseObject& handle = visualBase.GetBaseObject();
271
272   return static_cast<const Internal::Visual::Base&>(handle);
273 }
274
275 inline Internal::Visual::Base& GetImplementation(Toolkit::Visual::Base& visualBase)
276 {
277   DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
278
279   BaseObject& handle = visualBase.GetBaseObject();
280
281   return static_cast<Internal::Visual::Base&>(handle);
282 }
283
284 } // namespace Toolkit
285
286 } // namespace Dali
287
288 #endif // DALI_TOOLKIT_INTERNAL_VISUAL_H