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