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