1 #ifndef DALI_TOOLKIT_VISUAL_BASE_H
2 #define DALI_TOOLKIT_VISUAL_BASE_H
4 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/object/base-handle.h>
22 #include <dali/public-api/actors/actor.h>
30 namespace Internal DALI_INTERNAL
41 * @brief A Visual provides a renderer for drawing a control component. A control may have multiple visuals.
43 * Visuals reuse geometry, shader etc. across controls. They ensure that the renderer and texture sets exist only when control is on-stage.
44 * Each visual also responds to actor size and color change, and provides clipping at the renderer level.
45 * Note: The visual responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
47 * The following properties are optional, but can be supplied in the property map to Dali::Toolkit::VisualFactory::CreateVisual().
49 * | %Property Name | Type |
50 * |-------------------------|------------------|
51 * | customShader | MAP |
54 * where \b customShader is a map with at least one of the following properties:
55 * | %Property Name | Type | Required | Default | Description |
56 * |-------------------------|----------------------------|----------|---------|-----------------------------------------|
57 * | vertexShader | STRING | No | "" | Vertex shader code |
58 * | fragmentShader | STRING | No | "" | Fragment shader code |
59 * | subdivideGridX | INTEGER | No | 1 | How to subdivide the grid along X |
60 * | subdivideGridY | INTEGER | No | 1 | How to subdivide the grid along Y |
61 * | shaderHints | INTEGER or ARRAY of STRING | No | NONE | Bitmask of hints @sa Dali::Shader::Hint |
63 * and \b transform is a map with the following properties:
64 * | %Property Name | Type | Required | Default | Description |
65 * |-------------------------|-------------------|----------|------------------------|-----------------------------------------------------|
66 * | offset | VECTOR2 | No | (0,0) | Offset of visual from origin |
67 * | size | VECTOR2 | No | (1,1) | size of visual |
68 * | origin | INTEGER or STRING | No | CENTER | origin of the visual @sa Dali::Toolkit::Align |
69 * | anchorPoint | INTEGER or STRING | No | CENTER | anchor point of the visual @sa Dali::Toolkit::Align |
70 * | offsetPolicy | VECTOR2 | No | ( RELATIVE, RELATIVE ) | @sa Dali::Toolkit::Visual::Transform::Policy |
71 * | sizePolicy | VECTOR2 | No | ( RELATIVE, RELATIVE ) | @sa Dali::Toolkit::Visual::Transform::Policy |
73 * Relative means that the component describes a factor of the parent control size;
74 * size.x = 1 means full width; size.y = 0.5 means half height.
76 * Absolute means that the component describes world units (equivalent to pixels)
79 class DALI_IMPORT_API Base : public BaseHandle
84 * @brief Create an empty Visual Handle
91 * This is non-virtual since derived Handle types must not contain data or virtual methods.
96 * @brief This copy constructor is required for (smart) pointer semantics.
98 * @param[in] handle A reference to the copied handle.
100 Base( const Base& handle );
103 * @brief This assignment operator is required for (smart) pointer semantics.
105 * @param [in] handle A reference to the copied handle.
106 * @return A reference to this.
108 Base& operator=( const Base& handle );
111 * @brief Set the name of the visual
113 * Used by the styling system to animate properties
114 * @param[in] name The name to give the visual
116 void SetName( const std::string& name );
119 * @brief Get the name of the visual
121 * Used by the styling system to animate properties
122 * @return The name of the visual
124 const std::string& GetName();
127 * @brief Sets the transform and the control size
129 * @param[in] transform A property map describing the transform
130 * @param[in] controlSize The size of the parent control for visuals that need to scale internally.
132 void SetTransformAndSize( const Dali::Property::Map& transform, Size controlSize );
135 * @brief Returns the height for a given width.
137 * @param[in] width Width to use.
139 * @return The height based on the width.
141 float GetHeightForWidth( float width );
144 * @brief Returns the width for a given height.
146 * @param[in] height Height to use.
148 * @return The width based on the height.
150 float GetWidthForHeight( float height );
153 * @brief Return the natural size of the visual.
155 * Deriving classes stipulate the natural size and by default a
156 * visual has a ZERO natural size.
158 * @note A visual may not actually have a natural size until it has
159 * been placed on stage and acquired all it's resources.
161 * @param[out] naturalSize The visual's natural size
163 void GetNaturalSize( Vector2& naturalSize );
166 * @brief Set the depth index of this visual.
168 * Depth-index controls draw-order for overlapping visuals.
169 * Visuals with higher depth indices are rendered in front of other visual with smaller values
171 * @param[in] index The depth index of this visual.
173 void SetDepthIndex( int index );
176 * @brief Get the depth index of this visual
178 * @return The depth index of this visual.
180 int GetDepthIndex() const;
183 * @brief Create the property map representing this visual.
185 * @param[out] map The visual property map.
187 void CreatePropertyMap( Dali::Property::Map& map ) const;
189 public: // Not intended for application developers
191 explicit DALI_INTERNAL Base(Internal::Visual::Base *impl);
195 } // namespace Visual
197 } // namespace Toolkit
201 #endif /*DALI_TOOLKIT_VISUAL_BASE_H*/