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