visual.md doc to use renamed images
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / visual-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/controls/visual-factory/visual-factory.h>
28 #include <dali-toolkit/internal/controls/renderers/visual-factory-cache.h>
29 #include "../../../devel-api/controls/visual-factory/visual.h"
30
31 namespace Dali
32 {
33
34 namespace Toolkit
35 {
36
37 namespace Internal
38 {
39
40 /**
41  * Base class for all Control rendering logic. A control may have multiple visuals.
42  *
43  * Note: The visual responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
44  *
45  * The following properties are optional
46  *
47  * | %Property Name          | Type             |
48  * |-------------------------|------------------|
49  * | customShader            | MAP              |
50  *
51  * where custom-shader is a map with the following properties:
52  * | %Property Name          | Type             |
53  * |-------------------------|------------------|
54  * | vertexShader            | STRING           |
55  * | fragmentShader          | STRING           |
56  * | subdivideGridX          | INT              |
57  * | subdivideGridY          | INT              |
58  * | shaderHints             | INT              |
59  */
60 class Visual : public BaseObject
61 {
62 public:
63
64   /**
65    * Initialisation of the visual, this API should only called by the VisualFactory:
66    *  request the geometry and shader from the cache, if not available, create and save to the cache for sharing;
67    *  record the property values.
68    *
69    * @param[in] actor The Actor the visual is applied to if, empty if the visual has not been applied to any Actor
70    * @param[in] propertyMap The properties for the requested Visual object.
71    */
72   void Initialize( Actor& actor, const Property::Map& propertyMap );
73
74   /**
75    * @copydoc Toolkit::Visual::SetSize
76    */
77   virtual void SetSize( const Vector2& size );
78
79   /**
80    * @copydoc Toolkit::Visual::GetSize
81    */
82   const Vector2& GetSize() const;
83
84   /**
85    * @copydoc Toolkit::Visual::GetNaturalSize
86    */
87   virtual void GetNaturalSize( Vector2& naturalSize ) const;
88
89   /**
90    * ToDo: Add this function to Toolkit::Visual when it is fully implemented.
91    *
92    * Set the clip rectangular of this visual.
93    * The contents of the visual will not be visible outside this rectangular.
94    *
95    * @param [in] clipRect The clipping rectangular.
96    */
97   virtual void SetClipRect( const Rect<int>& clipRect );
98
99   /**
100    *ToDo: Add this function to Toolkit::Visual when it is fully implemented.
101    *
102    * Reposition this visual with a 2D offset.
103    *
104    * @param[in] offset The offset to reposition the visual.
105    */
106   virtual void SetOffset( const Vector2& offset );
107
108   /**
109    * @copydoc Toolkit::Visual::SetDepthIndex
110    */
111   void SetDepthIndex( float index );
112
113   /**
114    * @copydoc Toolkit::Visual::GetDepthIndex
115    */
116   float GetDepthIndex() const;
117
118   /**
119    * @copydoc Toolkit::Visual::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::SetOffStage
126    */
127   void SetOffStage( Actor& actor );
128
129   /**
130    * @copydoc Toolkit::Visual::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 protected:
155
156   /**
157    * @brief Constructor.
158    *
159    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
160    */
161   Visual( VisualFactoryCache& factoryCache );
162
163   /**
164    * @brief A reference counted object may only be deleted by calling Unreference().
165    */
166   virtual ~Visual();
167
168 protected:
169   /**
170    * @brief Called by CreatePropertyMap() allowing sub classes to respond to the CreatePropertyMap event
171    *
172    * @param[out] map The visual property map.
173    */
174   virtual void DoCreatePropertyMap( Property::Map& map ) const = 0;
175
176   /**
177    * @brief Called by Initialize() allowing sub classes to respond to the Initialize event
178    *
179    * @param[in] actor The Actor the visual is applied to if, empty if the visual has not been applied to any Actor
180    * @param[in] propertyMap The properties for the requested Visual object.
181    */
182   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap ) {};
183
184 protected:
185
186   /**
187    * @brief Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
188    *
189    * @param[in] actor The actor applying this visual.
190    */
191   virtual void DoSetOnStage( Actor& actor );
192
193   /**
194    * @brief Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
195    *
196    * @param[in] actor The actor applying this visual.
197    */
198   virtual void DoSetOffStage( Actor& actor );
199
200 protected:
201   /**
202    * @brief Gets the on stage state for this Visual
203    *
204    * @return Returns true if this Visual is on stage, false if it is off the stage
205    */
206   bool GetIsOnStage() const;
207
208   /**
209    * @brief Gets whether the Dali::Renderer is from a shared cache (and therefore any modifications will affect other users of that renderer)
210    *
211    * @return Returns true if the renderer is from shared cache, false otherwise
212    */
213   bool GetIsFromCache() const;
214
215 private:
216
217   // Undefined
218   Visual( const Visual& visual );
219
220   // Undefined
221   Visual& operator=( const Visual& visual );
222
223 protected:
224   struct Impl;
225   Impl* mImpl;
226   VisualFactoryCache& mFactoryCache;
227 };
228
229 } // namespace Internal
230
231 inline const Internal::Visual& GetImplementation(const Toolkit::Visual& visual)
232 {
233   DALI_ASSERT_ALWAYS( visual && "Visual handle is empty" );
234
235   const BaseObject& handle = visual.GetBaseObject();
236
237   return static_cast<const Internal::Visual&>(handle);
238 }
239
240 inline Internal::Visual& GetImplementation(Toolkit::Visual& visual)
241 {
242   DALI_ASSERT_ALWAYS( visual && "Visual handle is empty" );
243
244   BaseObject& handle = visual.GetBaseObject();
245
246   return static_cast<Internal::Visual&>(handle);
247 }
248
249 } // namespace Toolkit
250
251 } // namespace Dali
252
253 #endif // DALI_TOOLKIT_INTERNAL_VISUAL_H