1 #ifndef DALI_TOOLKIT_INTERNAL_ANIMATED_GRADIENT_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_ANIMATED_GRADIENT_VISUAL_H
5 * Copyright (c) 2021 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-toolkit/devel-api/visuals/animated-gradient-visual-properties-devel.h>
23 #include <dali/devel-api/common/owner-container.h>
24 #include <dali/public-api/common/dali-vector.h>
25 #include <dali/public-api/common/intrusive-ptr.h>
28 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
29 #include <dali/devel-api/scripting/enum-helper.h>
30 #include <dali/devel-api/scripting/scripting.h>
38 class AnimatedGradientVisual;
39 typedef IntrusivePtr<AnimatedGradientVisual> AnimatedGradientVisualPtr;
42 * This visual which renders smooth transition of colors to the control's quad.
43 * There are two types of properties: non-animated property and animated property
45 * The following properties are non-animated property.
47 * | %Property Name | Type | Default |
48 * |----------------|--------------|---------------------------|
49 * | gradientType | GradientType | Linear |
50 * | unitType | UnitType | Object bounding box |
51 * | spreadType | SpreadType | Reflect |
53 * The following properties are animated property.
55 * | %Property Name | Type | Default |
56 * |----------------|------------------------------------------|---------------------------------|
57 * | startPosition | Vector2 or AnimationParameter< Vector2 > | (-0.5, 0) |
58 * | startColor | Vector4 or AnimationParameter< Vector4 > | (143., 170., 220., 255.) / 255. |
59 * | endPosition | Vector2 or AnimationParameter< Vector2 > | (0.5, 0) |
60 * | endColor | Vector4 or AnimationParameter< Vector4 > | (255., 163., 163., 255.) / 255. |
61 * | rotateCenter | Vector2 or AnimationParameter< Vector2 > | (0.0, 0.0) |
62 * | rotateAmount | Float or AnimationParameter< Float > | 0.0 |
63 * | offset | Float or AnimationParameter< Float > | (explain details below) |
65 * Each animated property can contain follow AnimationParameter
67 * | %AnimationParameter<T>::Propery Name | Type | Default |
68 * |--------------------------------------|---------------|----------|
69 * | start | T | Zero |
70 * | target | T | Zero |
71 * | direction | DirectionType | Forward |
72 * | duration | Float | 3.0 |
73 * | delay | Float | 0.0 |
74 * | repeat | Integer | 0 |
75 * | repeat_delay | Float | 0.0 |
76 * | motion_type | MotionType | Loop |
77 * | easing_type | EasingType | Linear |
79 * T is animated property value's type. If property type is AnimationParameter< Vector2 >, start and target type is Vector2.
82 * gradientType decide the form of gradient
83 * unitType decide the coordinate of all positions
84 * spreadType decide how to make color where gradient_point is not 0 ~ 1
85 * visualSize decide this visual's size hardly. only use when unitType is SCREEN
87 * startPoint and startColor decide position and color where gradient_point = 0. if gradientType is RADIAL, here is center of circle.
88 * endPoint and endColor decide position and color where gradient_point = 1.
89 * rotateCenter and rotateAmount are same job as its name
90 * rotateAmount is radian value
92 * offset is main feature of this visual.
93 * Image the points which has same gradient_point values. If gradientType is LINEAR, this form is line. If gradientTYPE IS RADIAL, this form is circle.
94 * without think about offset value, gradient_point = t color will be like this
96 * color(t) = startColor * (1-t) + endColor * t (0 <= t <= 1)
98 * so color be smooth changed when gradient_point change smooth.
99 * offset value change the color of gradient_point = t like this
101 * realColor(t) = color(t + offset)
103 * so If offset value increas (or decrease) gradient looks like "Flowing" effect
104 * default offset value is an unlimited simple loop animation from 0 to 2. duration is 3.0 second
106 * GradientType has two types : LINEAR / RADIAL
107 * LINEAR draw gradient linear form
108 * RADIAL draw gradietn circle form
109 * UnitType has two types : OBJECT_BOUNDING_BOX / USER_SPACE
110 * OBJECT_BOUNDING_BOX use normalized coordinate, relate by Actor bounding box. bottom-left ~ top-right : (-0.5,-0.5) ~ (0.5, 0.5)
111 * USER_SPACE use coordinate, relate by Actor Size. bottom-left ~ top-right : (ActorSize * -0.5) ~ (ActorSize * 0.5)
112 * SpreadType has three types : REFLECT / REPEAT / CLAMP
113 * REFLECT use mirror warping
114 * REPEAT use repeat warping
115 * CLAMP use clamp warping
117 * DirectionType has two types : FORWARD / BACKWARD
118 * FORWARD animate value from start to target
119 * BACKWARD animate value from target to start
120 * MotionType has two types : LOOP / MIRROR
121 * LOOP animate loopingmode restart
122 * MIRROR animate loopingmode auto_reverse
123 * EasingType has four types : LINEAR / IN / OUT / IN_OUT
124 * LINEAR easing animation linear
125 * IN easing in (slow start -> fast finish)
126 * OUT easing out (fast start -> slow finish)
127 * IN_OUT easing in and out (slow start -> slow finish)
129 class AnimatedGradientVisual : public Visual::Base
133 * Animation informations what this visual using
135 struct GradientAnimationData
137 GradientAnimationData()
138 : index(Property::INVALID_INDEX),
146 Toolkit::TransitionData transition;
148 Property::Index index;
149 int loop_count; ///< if < 0, loop unlimited. else, loop loop_count times.
150 float delay; ///< delay time. if > 0, wait 'delay' seconds. else, play animation at '-delay' seconds.
151 bool forward; ///< True if AnimationParameter::DirectionType::Type is FORWARD
152 bool auto_mirror; ///< True if AnimationParameter::LoopType::Type is MIRROR
155 using GradientAnimationDataList = Dali::OwnerContainer<GradientAnimationData*>;
159 * @brief Create a new animated gradient visual.
161 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
162 * @param[in] properties A Property::Map containing settings for this visual
163 * @return A smart-pointer to the newly allocated visual
165 static AnimatedGradientVisualPtr New(VisualFactoryCache& factoryCache, const Property::Map& properties);
167 private: //from Visual
169 * @copydoc Visual::Base::CreatePropertyMap
171 void DoCreatePropertyMap(Property::Map& map) const override;
174 * @copydoc Visual::Base::CreateInstancePropertyMap
176 void DoCreateInstancePropertyMap(Property::Map& map) const override;
180 * @brief Constructor.
182 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
184 AnimatedGradientVisual(VisualFactoryCache& factoryCache);
187 * @brief A reference counted object may only be deleted by calling Unrefecence()
189 virtual ~AnimatedGradientVisual();
191 protected: //from Visual
193 * @copydoc Visual::Base::OnInitialize
195 void OnInitialize() override;
198 * @copydoc Visual::Base::DoSetProperties
200 void DoSetProperties(const Property::Map& propertyMap) override;
203 * @copydoc Visual::Base::OnSetTransform
205 void OnSetTransform() override;
208 * @copydoc Visual::Base::DoSetOnScene
210 void DoSetOnScene(Actor& actor) override;
213 * @copydoc Visual::Base::DoSetOffScene
215 void DoSetOffScene(Actor& actor) override;
219 * @brief Initialize the default value of properies.
221 void SetupDefaultValue();
224 * @brief Make animations with GradientAnimationData
226 void SetupAnimation();
229 * @brief Play animations
231 void PlayAnimation();
234 * @brief Stop animations
236 void StopAnimation();
239 * @brief Clear all previous GradientAnimationData and Setup new GradientAnimationData information which made by animated properties
241 * param[in] propertyMap A Property::Map come from DoSetProperties
243 void SetupGradientAnimationData(const Property::Map& propertyMap);
246 * @brief Create new shader
248 * return A Shader which made by non-animated properties
250 Shader CreateShader();
253 AnimatedGradientVisual(const AnimatedGradientVisual& gradientRenderer);
256 AnimatedGradientVisual& operator=(const AnimatedGradientVisual& gradientRenderer);
259 GradientAnimationDataList mGradientAnimationDataList;
260 Property::Map mValueMap;
262 Dali::Toolkit::DevelAnimatedGradientVisual::GradientType::Type mGradientType;
263 Dali::Toolkit::DevelAnimatedGradientVisual::UnitType::Type mUnitType;
264 Dali::Toolkit::DevelAnimatedGradientVisual::SpreadType::Type mSpreadType;
267 } //namespace Internal
269 } //namespace Toolkit