1 #ifndef DALI_TOOLKIT_INTERNAL_GRADIENT_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_GRADIENT_VISUAL_H
5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/common/intrusive-ptr.h>
25 #include <dali-toolkit/internal/visuals/gradient/gradient.h>
26 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
38 typedef IntrusivePtr<GradientVisual> GradientVisualPtr;
41 * The visual which renders smooth transition of colors to the control's quad.
42 * It supports two types of gradients: linear and radial.
44 * The following properties are essential for create a LINEAR GradientRender
46 * | %Property Name | Type |
47 * |-------------------------|------------------|
48 * | startPosition | VECTOR2 |
49 * | endPosition | VECTOR2 |
50 * | stopColor | ARRAY of VECTOR4 |
52 * The following properties are essential for create a RADIAL GradientRender
54 * | %Property Name | Type |
55 * |-------------------------|------------------|
56 * | center | VECTOR2 |
58 * | stopColor | ARRAY of VECTOR4 |
60 * The following properties are optional for both LINEAR and RADIAL GradientRender.
62 * | %Property Name | Type |
63 * |-------------------------|------------------|
64 * | stopOffset | ARRAY of FLOAT |
66 * | spreadMethod | STRING |
68 * Valid values for units are 'userSpace' and 'objectBoundingBox'.
69 * Valid values for spreadMethod are 'pad', 'repeat' and 'reflect.'
70 * If not provided, 'objectBoundingBox' is used as default gradient units, and 'pad' is used as default spread method.
72 class GradientVisual : public Visual::Base
76 * Types of the gradient
85 * @brief Create a new gradient visual.
87 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
88 * @param[in] properties A Property::Map containing settings for this visual
89 * @return A smart-pointer to the newly allocated visual.
91 static GradientVisualPtr New(VisualFactoryCache& factoryCache, const Property::Map& properties);
93 public: // from Visual
95 * @copydoc Visual::Base::CreatePropertyMap
97 void DoCreatePropertyMap(Property::Map& map) const override;
100 * @copydoc Visual::Base::CreateInstancePropertyMap
102 void DoCreateInstancePropertyMap(Property::Map& map) const override;
105 * @copydoc Visual::Base::EnablePreMultipliedAlpha
107 void EnablePreMultipliedAlpha(bool preMultiplied) override;
111 * @brief Constructor.
113 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
115 GradientVisual(VisualFactoryCache& factoryCache);
118 * @brief A reference counted object may only be deleted by calling Unreference().
120 virtual ~GradientVisual();
123 * @copydoc Visual::Base::OnInitialize
125 void OnInitialize() override;
128 * @copydoc Visual::Base::DoSetProperties
130 void DoSetProperties(const Property::Map& propertyMap) override;
133 * @copydoc Visual::Base::OnSetTransform
135 void OnSetTransform() override;
138 * @copydoc Visual::Base::DoSetOnScene
140 void DoSetOnScene(Actor& actor) override;
143 * @copydoc Visual::Base::UpdateShader
145 void UpdateShader() override;
148 * @copydoc Visual::Base::GenerateShader
150 Shader GenerateShader() const override;
154 * New a gradient object with the given property map.
156 * @return True if the property map provides valid properties to create a gradient. Otherwise, returns false.
158 bool NewGradient(Type gradientType, const Property::Map& propertyMap);
161 * Get the stop-offsets from the property.
162 * The valid property type are ARRAY, VECTOR2, VECTOR3, VECTOR4.
164 * @param[in] value The property value of stop-offsets
165 * @param[out] stopOffsets The vector contains the stop offset values.
167 static void GetStopOffsets(const Property::Value* value, Vector<float>& stopOffsets);
170 GradientVisual(const GradientVisual& gradientVisual);
173 GradientVisual& operator=(const GradientVisual& gradientVisual);
176 Matrix3 mGradientTransform;
177 IntrusivePtr<Gradient> mGradient;
179 bool mIsOpaque; ///< Set to false if any of the stop colors are not opaque
182 } // namespace Internal
184 } // namespace Toolkit
188 #endif /* DALI_TOOLKIT_INTERNAL_GRADIENT_VISUAL_H */