1 #ifndef DALI_TOOLKIT_INTERNAL_ANIMATED_GRADIENT_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_ANIMATED_GRADIENT_VISUAL_H
5 * Copyright (c) 2019 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/dali-vector.h>
23 #include <dali/public-api/common/intrusive-ptr.h>
24 #include <dali/devel-api/common/owner-container.h>
25 #include <dali-toolkit/devel-api/visuals/animated-gradient-visual-properties-devel.h>
28 #include <dali/devel-api/scripting/enum-helper.h>
29 #include <dali/devel-api/scripting/scripting.h>
30 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
40 class AnimatedGradientVisual;
41 typedef IntrusivePtr< AnimatedGradientVisual > AnimatedGradientVisualPtr;
44 * This visual which renders smooth transition of colors to the control's quad.
45 * There are two types of properties: non-animated property and animated property
47 * The following properties are non-animated property.
49 * | %Property Name | Type | Default |
50 * |----------------|--------------|---------------------------|
51 * | gradientType | GradientType | Linear |
52 * | unitType | UnitType | Object bounding box |
53 * | spreadType | SpreadType | Reflect |
55 * The following properties are animated property.
57 * | %Property Name | Type | Default |
58 * |----------------|------------------------------------------|---------------------------------|
59 * | startPosition | Vector2 or AnimationParameter< Vector2 > | (-0.5, 0) |
60 * | startColor | Vector4 or AnimationParameter< Vector4 > | (143., 170., 220., 255.) / 255. |
61 * | endPosition | Vector2 or AnimationParameter< Vector2 > | (0.5, 0) |
62 * | endColor | Vector4 or AnimationParameter< Vector4 > | (255., 163., 163., 255.) / 255. |
63 * | rotateCenter | Vector2 or AnimationParameter< Vector2 > | (0.0, 0.0) |
64 * | rotateAmount | Float or AnimationParameter< Float > | 0.0 |
65 * | offset | Float or AnimationParameter< Float > | (explain details below) |
67 * Each animated property can contain follow AnimationParameter
69 * | %AnimationParameter<T>::Propery Name | Type | Default |
70 * |--------------------------------------|---------------|----------|
71 * | start | T | Zero |
72 * | target | T | Zero |
73 * | direction | DirectionType | Forward |
74 * | duration | Float | 3.0 |
75 * | delay | Float | 0.0 |
76 * | repeat | Integer | 0 |
77 * | repeat_delay | Float | 0.0 |
78 * | motion_type | MotionType | Loop |
79 * | easing_type | EasingType | Linear |
81 * T is animated property value's type. If property type is AnimationParameter< Vector2 >, start and target type is Vector2.
84 * gradientType decide the form of gradient
85 * unitType decide the coordinate of all positions
86 * spreadType decide how to make color where gradient_point is not 0 ~ 1
87 * visualSize decide this visual's size hardly. only use when unitType is SCREEN
89 * startPoint and startColor decide position and color where gradient_point = 0. if gradientType is RADIAL, here is center of circle.
90 * endPoint and endColor decide position and color where gradient_point = 1.
91 * rotateCenter and rotateAmount are same job as its name
92 * rotateAmount is radian value
94 * offset is main feature of this visual.
95 * 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.
96 * without think about offset value, gradient_point = t color will be like this
98 * color(t) = startColor * (1-t) + endColor * t (0 <= t <= 1)
100 * so color be smooth changed when gradient_point change smooth.
101 * offset value change the color of gradient_point = t like this
103 * realColor(t) = color(t + offset)
105 * so If offset value increas (or decrease) gradient looks like "Flowing" effect
106 * default offset value is an unlimited simple loop animation from 0 to 2. duration is 3.0 second
108 * GradientType has two types : LINEAR / RADIAL
109 * LINEAR draw gradient linear form
110 * RADIAL draw gradietn circle form
111 * UnitType has two types : OBJECT_BOUNDING_BOX / USER_SPACE
112 * OBJECT_BOUNDING_BOX use normalized coordinate, relate by Actor bounding box. bottom-left ~ top-right : (-0.5,-0.5) ~ (0.5, 0.5)
113 * USER_SPACE use coordinate, relate by Actor Size. bottom-left ~ top-right : (ActorSize * -0.5) ~ (ActorSize * 0.5)
114 * SpreadType has three types : REFLECT / REPEAT / CLAMP
115 * REFLECT use mirror warping
116 * REPEAT use repeat warping
117 * CLAMP use clamp warping
119 * DirectionType has two types : FORWARD / BACKWARD
120 * FORWARD animate value from start to target
121 * BACKWARD animate value from target to start
122 * MotionType has two types : LOOP / MIRROR
123 * LOOP animate loopingmode restart
124 * MIRROR animate loopingmode auto_reverse
125 * EasingType has four types : LINEAR / IN / OUT / IN_OUT
126 * LINEAR easing animation linear
127 * IN easing in (slow start -> fast finish)
128 * OUT easing out (fast start -> slow finish)
129 * IN_OUT easing in and out (slow start -> slow finish)
131 class AnimatedGradientVisual : public Visual::Base
136 * Animation informations what this visual using
138 struct GradientAnimationData
140 GradientAnimationData()
141 : index( Property::INVALID_INDEX ),
149 Toolkit::TransitionData transition;
151 Property::Index index;
152 int loop_count; ///< if < 0, loop unlimited. else, loop loop_count times.
153 float delay; ///< delay time. if > 0, wait 'delay' seconds. else, play animation at '-delay' seconds.
154 bool forward; ///< True if AnimationParameter::DirectionType::Type is FORWARD
155 bool auto_mirror; ///< True if AnimationParameter::LoopType::Type is MIRROR
158 using GradientAnimationDataList = Dali::OwnerContainer< GradientAnimationData* >;
163 * @brief Create a new animated gradient visual.
165 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
166 * @param[in] properties A Property::Map containing settings for this visual
167 * @return A smart-pointer to the newly allocated visual
169 static AnimatedGradientVisualPtr New( VisualFactoryCache& factoryCache, const Property::Map& properties );
171 private: //from Visual
174 * @copydoc Visual::Base::CreatePropertyMap
176 void DoCreatePropertyMap( Property::Map& map ) const override;
179 * @copydoc Visual::Base::CreateInstancePropertyMap
181 void DoCreateInstancePropertyMap( Property::Map& map ) const override;
186 * @brief Constructor.
188 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
190 AnimatedGradientVisual( VisualFactoryCache& factoryCache );
193 * @brief A reference counted object may only be deleted by calling Unrefecence()
195 virtual ~AnimatedGradientVisual();
197 protected: //from Visual
200 * @copydoc Visual::Base::DoSetProperties
202 void DoSetProperties( const Property::Map& propertyMap ) override;
205 * @copydoc Visual::Base::OnSetTransform
207 void OnSetTransform() override;
210 * @copydoc Visual::Base::DoSetOnStage
212 void DoSetOnStage( Actor& actor ) override;
215 * @copydoc Visual::Base::DoSetOffStage
217 void DoSetOffStage( Actor& actor ) override;
222 * @brief Initialize the default value of properies.
224 void SetupDefaultValue();
227 * @brief Initialize the rendere with the geometry from the cache, and shader which made by CreateShader()
229 void InitializeRenderer();
232 * @brief Make animations with GradientAnimationData
234 void SetupAnimation();
237 * @brief Play animations
239 void PlayAnimation();
242 * @brief Stop animations
244 void StopAnimation();
247 * @brief Clear all previous GradientAnimationData and Setup new GradientAnimationData information which made by animated properties
249 * param[in] propertyMap A Property::Map come from DoSetProperties
251 void SetupGradientAnimationData( const Property::Map& propertyMap );
254 * @brief Create new shader
256 * return A Shader which made by non-animated properties
258 Shader CreateShader();
261 AnimatedGradientVisual( const AnimatedGradientVisual& gradientRenderer );
264 AnimatedGradientVisual& operator=( const AnimatedGradientVisual& gradientRenderer );
267 GradientAnimationDataList mGradientAnimationDataList;
268 Property::Map mValueMap;
270 Dali::Toolkit::DevelAnimatedGradientVisual::GradientType::Type mGradientType;
271 Dali::Toolkit::DevelAnimatedGradientVisual::UnitType::Type mUnitType;
272 Dali::Toolkit::DevelAnimatedGradientVisual::SpreadType::Type mSpreadType;
275 }//namespace Internal