2cbb0b7b43b704747cf4ce89f9a4af71c1b87dec
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / visual-factory / visual-base.h
1 #ifndef DALI_TOOLKIT_VISUAL_BASE_H
2 #define DALI_TOOLKIT_VISUAL_BASE_H
3 /*
4  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/object/base-handle.h>
22 #include <dali/public-api/actors/actor.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 namespace Internal DALI_INTERNAL
31 {
32 namespace Visual
33 {
34 class Base;
35 }
36 }
37
38 namespace Visual
39 {
40 /**
41  * @brief Visual provides a renderer for rendering the controls. A control may have multiple visuals.
42  *
43  * Visuals reuses geometry, shader etc. across controls and manages the renderer and texture sets to exist only when control is on-stage.
44  * It also responds to actor size and color change, and provides the clipping at the renderer level.
45  * Note: The visual responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
46  */
47 class DALI_IMPORT_API Base : public BaseHandle
48 {
49 public:
50
51   /**
52    * @brief Create an empty Visual Handle
53    */
54   Base();
55
56   /**
57    * @brief Destructor
58    *
59    * This is non-virtual since derived Handle types must not contain data or virtual methods.
60    */
61   ~Base();
62
63   /**
64    * @brief This copy constructor is required for (smart) pointer semantics.
65    *
66    * @param[in] handle A reference to the copied handle.
67    */
68   Base( const Base& handle );
69
70   /**
71    * @brief This assignment operator is required for (smart) pointer semantics.
72    *
73    * @param [in] handle  A reference to the copied handle.
74    * @return A reference to this.
75    */
76   Base& operator=( const Base& handle );
77
78   /**
79    * @brief Set the name of the visual
80    *
81    * Used by the styling system to animate properties
82    * @param[in] name The name to give the visual
83    */
84   void SetName( const std::string& name );
85
86   /**
87    * @brief Get the name of the visual
88    *
89    * Used by the styling system to animate properties
90    * @return The name of the visual
91    */
92   const std::string& GetName();
93
94   /**
95    * @brief Set the size of the painting area.
96    *
97    * @param[in] size The size of the painting area.
98    */
99   void SetSize( const Vector2& size );
100
101   /**
102    * @brief Get the size of the painting area.
103    *
104    * @return The size of the visual's painting area.
105    */
106   const Vector2& GetSize() const;
107
108   /**
109    * @brief Returns the height for a given width.
110    *
111    * @param[in] width Width to use.
112    *
113    * @return The height based on the width.
114    */
115   float GetHeightForWidth( float width ) const;
116
117   /**
118    * @brief Return the natural size of the visual.
119    *
120    * Deriving classes stipulate the natural size and by default a visual has a ZERO natural size.
121    *
122    * @param[out] naturalSize The visual's natural size
123    */
124   void GetNaturalSize( Vector2& naturalSize ) const;
125
126   /**
127    * @brief Set the depth index of this visual.
128    *
129    * Depth-index controls draw-order for overlapping visuals.
130    * Visuals with higher depth indices are rendered in front of other visual with smaller values
131    *
132    * @param[in] index The depth index of this visual.
133    */
134   void SetDepthIndex( float index );
135
136   /**
137    * @brief Get the depth index of this visual
138    *
139    * @return The depth index of this visual.
140    */
141   float GetDepthIndex() const;
142
143   /**
144    * @brief Visual needs to know when the control is put on to the stage to add the renderer.
145    *
146    * This function should be called when the control is put on to the stage.
147    *
148    * @param[in] actor The actor using this visual.
149    * @post SetOffStage should be called with the same actor when the control is put off stage otherwise memory will be leaked
150    */
151   void SetOnStage( Actor& actor );
152
153   /**
154    * @brief Visual needs to know when the control is removed from the stage to remove the renderer.
155    *
156    * This function should be called when the control is removed from the stage
157    *
158    * @param[in] actor The actor using this visual.
159    */
160   void SetOffStage( Actor& actor );
161
162   /**
163    * @brief Remove the renderer from the actor and reset the visual self.
164    *
165    * This function can be called with an empty handle. If the visual is empty, this is a no-op.
166    *
167    * @param[in] actor The actor to be set off stage.
168    */
169   void RemoveAndReset( Actor& actor );
170
171   /**
172    * @brief Create the property map representing this visual.
173    *
174    * @param[out] map The visual property map.
175    */
176   void CreatePropertyMap( Dali::Property::Map& map ) const;
177
178   /**
179    * @brief Sets the value of an existing property.
180    *
181    * @param [in] index The index of the property.
182    * @param [in] propertyValue The new value of the property.
183    */
184   void SetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
185
186   /**
187    * @brief Retrieves a property value.
188    *
189    * @param [in] index The index of the property.
190    *
191    * @return The property value.
192    */
193   Dali::Property::Value GetProperty( Dali::Property::Index index );
194
195 public: // Not intended for application developers
196
197   explicit DALI_INTERNAL Base(Internal::Visual::Base *impl);
198
199 };
200
201 } // namespace Visual
202
203 } // namespace Toolkit
204
205 } // namespace Dali
206
207 #endif /*DALI_TOOLKIT_VISUAL_BASE_H*/