Merge "Add descriptions and example codes" 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/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::SetSize
79    */
80   virtual void SetSize( const Vector2& size );
81
82   /**
83    * @copydoc Toolkit::Visual::Base::GetSize
84    */
85   const Vector2& GetSize() const;
86
87   /**
88    * @copydoc Toolkit::Visual::Base::GetNaturalSize
89    */
90   virtual void GetNaturalSize( Vector2& naturalSize ) const;
91
92   /**
93    * @copydoc Toolkit::Visual::Base::SetDepthIndex
94    */
95   void SetDepthIndex( float index );
96
97   /**
98    * @copydoc Toolkit::Visual::Base::GetDepthIndex
99    */
100   float GetDepthIndex() const;
101
102   /**
103    * @copydoc Toolkit::Visual::Base::SetOnStage
104    * @pre Impl->mGeometry must be created before this method is called
105    */
106   void SetOnStage( Actor& actor );
107
108   /**
109    * @copydoc Toolkit::Visual::Base::SetOffStage
110    */
111   void SetOffStage( Actor& actor );
112
113   /**
114    * @copydoc Toolkit::Visual::Base::CreatePropertyMap
115    */
116   void CreatePropertyMap( Property::Map& map ) const;
117
118   /**
119    * @brief Set whether the Pre-multiplied Alpha Blending is required
120    *
121    * @param[in] preMultipled whether alpha is pre-multiplied.
122    */
123   void EnablePreMultipliedAlpha(  bool preMultipled );
124
125   /**
126    * @brief Query whether alpha is pre-multiplied.
127    *
128    * @return True is alpha is pre-multiplied, false otherwise.
129    */
130   bool IsPreMultipliedAlphaEnabled() const;
131
132   /**
133    * @brief Sets properties of custom shader
134    * @param[in] propertyMap Property map containing the custom shader data
135    */
136   void SetCustomShader( const Property::Map& propertyMap );
137
138 protected:
139
140   /**
141    * @brief Constructor.
142    *
143    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
144    */
145   Base( VisualFactoryCache& factoryCache );
146
147   /**
148    * @brief A reference counted object may only be deleted by calling Unreference().
149    */
150   virtual ~Base();
151
152 protected:
153   /**
154    * @brief Called by CreatePropertyMap() allowing sub classes to respond to the CreatePropertyMap event
155    *
156    * @param[out] map The visual property map.
157    */
158   virtual void DoCreatePropertyMap( Property::Map& map ) const = 0;
159
160   /**
161    * @brief Called by Initialize() allowing sub classes to respond to the Initialize event
162    *
163    * @param[in] actor The Actor the visual is applied to if, empty if the visual has not been applied to any Actor
164    * @param[in] propertyMap The properties for the requested Visual object.
165    */
166   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ) {}
167
168 protected:
169
170   /**
171    * @brief Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
172    *
173    * @param[in] actor The actor applying this visual.
174    */
175   virtual void DoSetOnStage( Actor& actor );
176
177   /**
178    * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
179    *
180    * @param[in] actor The actor applying this visual.
181    */
182   virtual void DoSetOffStage( Actor& actor );
183
184 protected:
185   /**
186    * @brief Gets the on stage state for this Visual
187    *
188    * @return Returns true if this Visual is on stage, false if it is off the stage
189    */
190   bool GetIsOnStage() const;
191
192   /**
193    * @brief Gets whether the Dali::Renderer is from a shared cache (and therefore any modifications will affect other users of that renderer)
194    *
195    * @return Returns true if the renderer is from shared cache, false otherwise
196    */
197   bool GetIsFromCache() const;
198
199 private:
200
201   // Undefined
202   Base( const Visual::Base& visual );
203
204   // Undefined
205   Base& operator=( const Visual::Base& visual );
206
207 protected:
208   struct Impl;
209   Impl* mImpl;
210   VisualFactoryCache& mFactoryCache;
211 };
212
213 } // namspace Visual
214
215 } // namespace Internal
216
217 inline const Internal::Visual::Base& GetImplementation(const Toolkit::Visual::Base& visualBase )
218 {
219   DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
220
221   const BaseObject& handle = visualBase.GetBaseObject();
222
223   return static_cast<const Internal::Visual::Base&>(handle);
224 }
225
226 inline Internal::Visual::Base& GetImplementation(Toolkit::Visual::Base& visualBase)
227 {
228   DALI_ASSERT_ALWAYS( visualBase && "visual base handle is empty" );
229
230   BaseObject& handle = visualBase.GetBaseObject();
231
232   return static_cast<Internal::Visual::Base&>(handle);
233 }
234
235 } // namespace Toolkit
236
237 } // namespace Dali
238
239 #endif // DALI_TOOLKIT_INTERNAL_VISUAL_H