Add VisualBase::GetType()
[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) 2018 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 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/dali-toolkit-common.h>
26 #include <dali-toolkit/public-api/visuals/visual-properties.h>
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 namespace Internal DALI_INTERNAL
35 {
36 namespace Visual
37 {
38 class Base;
39 }
40 }
41
42 namespace Visual
43 {
44
45 /**
46  * @brief A Visual provides a renderer for drawing a control component. A control may have multiple visuals.
47  *
48  * Visuals reuse geometry, shader etc. across controls. They ensure that the renderer and texture sets exist only when control is on-stage.
49  * Each visual also responds to actor size and color change, and provides clipping at the renderer level.
50  * Note: The visual responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
51  *
52  * The following properties are optional, but can be supplied in the property map to Dali::Toolkit::VisualFactory::CreateVisual().
53  *
54  * | %Property Name          | Type             |
55  * |-------------------------|------------------|
56  * | customShader            | MAP              |
57  * | transform               | MAP              |
58  *
59  * where \b customShader is a map with at least one of the following properties:
60  * | %Property Name          | Type                       | Required | Default | Description                             |
61  * |-------------------------|----------------------------|----------|---------|-----------------------------------------|
62  * | vertexShader            | STRING                     | No       | ""      | Vertex shader code                      |
63  * | fragmentShader          | STRING                     | No       | ""      | Fragment shader code                    |
64  * | subdivideGridX          | INTEGER                    | No       | 1       | How to subdivide the grid along X       |
65  * | subdivideGridY          | INTEGER                    | No       | 1       | How to subdivide the grid along Y       |
66  * | shaderHints             | INTEGER or ARRAY of STRING | No       | NONE    | Bitmask of hints @sa Dali::Shader::Hint |
67  *
68  * and \b transform is a map with the following properties:
69  * | %Property Name          | Type              | Required | Default                | Description                                         |
70  * |-------------------------|-------------------|----------|------------------------|-----------------------------------------------------|
71  * | offset                  | VECTOR2           | No       | (0,0)                  | Offset of visual from origin                        |
72  * | size                    | VECTOR2           | No       | (1,1)                  | size of visual                                      |
73  * | origin                  | INTEGER or STRING | No       | CENTER                 | origin of the visual @sa Dali::Toolkit::Align       |
74  * | anchorPoint             | INTEGER or STRING | No       | CENTER                 | anchor point of the visual @sa Dali::Toolkit::Align |
75  * | offsetPolicy            | VECTOR2           | No       | ( RELATIVE, RELATIVE ) | @sa Dali::Toolkit::Visual::Transform::Policy   |
76  * | sizePolicy              | VECTOR2           | No       | ( RELATIVE, RELATIVE ) | @sa Dali::Toolkit::Visual::Transform::Policy   |
77  *
78  * Relative means that the component describes a factor of the parent control size;
79  * size.x = 1 means full width; size.y = 0.5 means half height.
80  *
81  * Absolute means that the component describes world units (equivalent to pixels)
82  *
83  */
84 class DALI_TOOLKIT_API Base : public BaseHandle
85 {
86 public:
87
88   /**
89    * @brief Create an empty Visual Handle
90    */
91   Base();
92
93   /**
94    * @brief Destructor
95    *
96    * This is non-virtual since derived Handle types must not contain data or virtual methods.
97    */
98   ~Base();
99
100   /**
101    * @brief This copy constructor is required for (smart) pointer semantics.
102    *
103    * @param[in] handle A reference to the copied handle.
104    */
105   Base( const Base& handle );
106
107   /**
108    * @brief This assignment operator is required for (smart) pointer semantics.
109    *
110    * @param [in] handle  A reference to the copied handle.
111    * @return A reference to this.
112    */
113   Base& operator=( const Base& handle );
114
115   /**
116    * @brief Set the name of the visual
117    *
118    * Used by the styling system to animate properties
119    * @param[in] name The name to give the visual
120    */
121   void SetName( const std::string& name );
122
123   /**
124    * @brief Get the name of the visual
125    *
126    * Used by the styling system to animate properties
127    * @return The name of the visual
128    */
129   const std::string& GetName() const;
130
131   /**
132    * @brief Sets the transform and the control size
133    *
134    * @param[in] transform A property map describing the transform
135    * @param[in] controlSize The size of the parent control for visuals that need to scale internally.
136    */
137   void SetTransformAndSize( const Dali::Property::Map& transform, Size controlSize );
138
139   /**
140    * @brief Returns the height for a given width.
141    *
142    * @param[in] width Width to use.
143    *
144    * @return The height based on the width.
145    */
146   float GetHeightForWidth( float width );
147
148   /**
149    * @brief Returns the width for a given height.
150    *
151    * @param[in] height Height to use.
152    *
153    * @return The width based on the height.
154    */
155   float GetWidthForHeight( float height );
156
157   /**
158    * @brief Return the natural size of the visual.
159    *
160    * Deriving classes stipulate the natural size and by default a
161    * visual has a ZERO natural size.
162    *
163    * @note A visual may not actually have a natural size until it has
164    * been placed on stage and acquired all it's resources.
165    *
166    * @param[out] naturalSize The visual's natural size
167    */
168   void GetNaturalSize( Vector2& naturalSize );
169
170   /**
171    * @brief Set the depth index of this visual.
172    *
173    * Depth-index controls draw-order for overlapping visuals.
174    * Visuals with higher depth indices are rendered in front of other visual with smaller values
175    *
176    * @param[in] index The depth index of this visual.
177    */
178   void SetDepthIndex( int index );
179
180   /**
181    * @brief Get the depth index of this visual
182    *
183    * @return The depth index of this visual.
184    */
185   int GetDepthIndex() const;
186
187   /**
188    * @brief Create the property map representing this visual.
189    *
190    * @param[out] map The visual property map.
191    */
192   void CreatePropertyMap( Dali::Property::Map& map ) const;
193
194   /**
195    * @brief Get the type of this visual.
196    *
197    * @return The the type of this visual.
198    */
199   Visual::Type GetType() const;
200
201 public: // Not intended for application developers
202
203   explicit DALI_INTERNAL Base(Internal::Visual::Base *impl);
204
205 };
206
207 } // namespace Visual
208
209 } // namespace Toolkit
210
211 } // namespace Dali
212
213 #endif /*DALI_TOOLKIT_VISUAL_BASE_H*/