1 #ifndef DALI_TOOLKIT_VISUAL_BASE_H
2 #define DALI_TOOLKIT_VISUAL_BASE_H
4 * Copyright (c) 2020 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/actors/actor.h>
22 #include <dali/public-api/object/base-handle.h>
25 #include <dali-toolkit/public-api/dali-toolkit-common.h>
26 #include <dali-toolkit/public-api/visuals/visual-properties.h>
32 namespace Internal DALI_INTERNAL
38 } // namespace DALI_INTERNAL
43 * @brief A Visual provides a renderer for drawing a control component. A control may have multiple visuals.
45 * Visuals reuse geometry, shader etc. across controls. They ensure that the renderer and texture sets exist only when control is on-stage.
46 * Each visual also responds to actor size and color change, and provides clipping at the renderer level.
47 * Note: The visual responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
49 * The following properties are optional, but can be supplied in the property map to Dali::Toolkit::VisualFactory::CreateVisual().
51 * | %Property Name | Type |
52 * |-------------------------|------------------|
53 * | customShader | MAP |
56 * where \b customShader is a map with at least one of the following properties:
57 * | %Property Name | Type | Required | Default | Description |
58 * |-------------------------|----------------------------|----------|---------|-----------------------------------------|
59 * | vertexShader | STRING | No | "" | Vertex shader code |
60 * | fragmentShader | STRING | No | "" | Fragment shader code |
61 * | subdivideGridX | INTEGER | No | 1 | How to subdivide the grid along X |
62 * | subdivideGridY | INTEGER | No | 1 | How to subdivide the grid along Y |
63 * | shaderHints | INTEGER or ARRAY of STRING | No | NONE | Bitmask of hints @sa Dali::Shader::Hint |
65 * and \b transform is a map with the following properties:
66 * | %Property Name | Type | Required | Default | Description |
67 * |-------------------------|-------------------|----------|------------------------|-----------------------------------------------------|
68 * | offset | VECTOR2 | No | (0,0) | Offset of visual from origin |
69 * | size | VECTOR2 | No | (1,1) | size of visual |
70 * | origin | INTEGER or STRING | No | CENTER | origin of the visual @sa Dali::Toolkit::Align |
71 * | anchorPoint | INTEGER or STRING | No | CENTER | anchor point of the visual @sa Dali::Toolkit::Align |
72 * | offsetPolicy | VECTOR2 | No | ( RELATIVE, RELATIVE ) | @sa Dali::Toolkit::Visual::Transform::Policy |
73 * | sizePolicy | VECTOR2 | No | ( RELATIVE, RELATIVE ) | @sa Dali::Toolkit::Visual::Transform::Policy |
75 * Relative means that the component describes a factor of the parent control size;
76 * size.x = 1 means full width; size.y = 0.5 means half height.
78 * Absolute means that the component describes world units (equivalent to pixels)
81 class DALI_TOOLKIT_API Base : public BaseHandle
85 * @brief Create an empty Visual Handle
92 * This is non-virtual since derived Handle types must not contain data or virtual methods.
97 * @brief This copy constructor is required for (smart) pointer semantics.
99 * @param[in] handle A reference to the copied handle.
101 Base(const Base& handle);
104 * @brief This assignment operator is required for (smart) pointer semantics.
106 * @param [in] handle A reference to the copied handle.
107 * @return A reference to this.
109 Base& operator=(const Base& handle);
112 * @brief Set the name of the visual
114 * Used by the styling system to animate properties
115 * @param[in] name The name to give the visual
117 void SetName(const std::string& name);
120 * @brief Get the name of the visual
122 * Used by the styling system to animate properties
123 * @return The name of the visual
125 const std::string& GetName() const;
128 * @brief Sets the transform and the control size
130 * @param[in] transform A property map describing the transform
131 * @param[in] controlSize The size of the parent control for visuals that need to scale internally.
133 void SetTransformAndSize(const Dali::Property::Map& transform, Size controlSize);
136 * @brief Returns the height for a given width.
138 * @param[in] width Width to use.
140 * @return The height based on the width.
142 float GetHeightForWidth(float width);
145 * @brief Returns the width for a given height.
147 * @param[in] height Height to use.
149 * @return The width based on the height.
151 float GetWidthForHeight(float height);
154 * @brief Return the natural size of the visual.
156 * Deriving classes stipulate the natural size and by default a
157 * visual has a ZERO natural size.
159 * @note A visual may not actually have a natural size until it has
160 * been placed on stage and acquired all it's resources.
162 * @param[out] naturalSize The visual's natural size
164 void GetNaturalSize(Vector2& naturalSize);
167 * @brief Set the depth index of this visual.
169 * Depth-index controls draw-order for overlapping visuals.
170 * Visuals with higher depth indices are rendered in front of other visual with smaller values
172 * @param[in] index The depth index of this visual.
174 void SetDepthIndex(int index);
177 * @brief Get the depth index of this visual
179 * @return The depth index of this visual.
181 int GetDepthIndex() const;
184 * @brief Create the property map representing this visual.
186 * @param[out] map The visual property map.
188 void CreatePropertyMap(Dali::Property::Map& map) const;
191 * @brief Get the type of this visual.
193 * @return The the type of this visual.
195 Visual::Type GetType() const;
197 public: // Not intended for application developers
198 explicit DALI_INTERNAL Base(Internal::Visual::Base* impl);
201 } // namespace Visual
203 } // namespace Toolkit
207 #endif /*DALI_TOOLKIT_VISUAL_BASE_H*/