Dali 3D User Interface Engine
utc-Dali-AlphaFunction.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #include <iostream>
19 
20 #include <stdlib.h>
22 #include <dali-test-suite-utils.h>
23 
24 using namespace Dali;
25 
26 float customAlphaFunction( float progress )
27 {
28  return progress;
29 }
30 
32 {
34 }
35 
37 {
39 }
40 
42 {
43  TestApplication application;
44  AlphaFunction alpha;
45 
46  //Should return the default alpha function
48 
49  //Check the mode is BUILTIN_FUNCTION
51 
52  END_TEST;
53 }
54 
56 {
57  TestApplication application;
58 
59  //Construct the alpha function with a built-in function
61 
62  //Check if the built-in alpha function is EASE_IN_OUT
64 
65  //Check the mode is BUILTIN_FUNCTION
67 
68  END_TEST;
69 }
70 
72 {
73  TestApplication application;
74 
75  //Construct the alpha function with a function pointer
77 
78  //Check that the custom function points to the custom alpha function
80 
81  //Check the mode is CUSTOM_FUNCTION
83 
84 
85  END_TEST;
86 }
87 
89 {
90  TestApplication application;
91 
92  //Construct the alpha function with two control points
93  Vector2 controlPoint0 = Vector2(0.0f,1.0f);
94  Vector2 controlPoint1 = Vector2(1.0f,0.0f);
95  AlphaFunction alpha(controlPoint0,controlPoint1);
96 
97  //Check if the control points have the correct value
98  Vector4 controlPoints = alpha.GetBezierControlPoints();
99  DALI_TEST_EQUALS( Vector2(controlPoints.x,controlPoints.y), controlPoint0, TEST_LOCATION);
100  DALI_TEST_EQUALS( Vector2(controlPoints.z,controlPoints.w), controlPoint1, TEST_LOCATION);
101 
102  //Check the mode is BEZIER
104 
105  END_TEST;
106 }
107 
109 {
110  TestApplication application;
111 
112  //Construct the alpha function with two control points
113  Vector2 controlPoint0 = Vector2(-10.0f,1.0f);
114  Vector2 controlPoint1 = Vector2(10.0f,0.0f);
115  AlphaFunction alpha(controlPoint0,controlPoint1);
116 
117  //x components of the control points should have been clamped to [0,1] to ensure the curve is monotonic
118  Vector4 controlPoints = alpha.GetBezierControlPoints();
119  DALI_TEST_EQUALS( Vector2(controlPoints.x,controlPoints.y), Vector2(0.0f,1.0f), TEST_LOCATION);
120  DALI_TEST_EQUALS( Vector2(controlPoints.z,controlPoints.w), Vector2(1.0f,0.0f), TEST_LOCATION);
121 
122  //Check the mode is BEZIER
124 
125  END_TEST;
126 }
127 
129 {
130  TestApplication application;
132 
133  //Check if the builtin alpha function is EASE_IN
135 
136  //Check the mode is BUILTIN_FUNCTION
138 
139  END_TEST;
140 }
141 
143 {
144  TestApplication application;
146 
147  //Check that the custom function points to the custom alpha function
149 
150  //Check the mode is CUSTOM_FUNCTION
152 
153  END_TEST;
154 }
155 
157 {
158  TestApplication application;
159 
160  Vector2 controlPoint0 = Vector2(0.0f,1.0f);
161  Vector2 controlPoint1 = Vector2(1.0f,0.0f);
162  AlphaFunction alpha( controlPoint0,controlPoint1 );
163 
164  //Check if the control points have the correct value
165  Vector4 controlPoints = alpha.GetBezierControlPoints();
166  DALI_TEST_EQUALS( Vector2(controlPoints.x,controlPoints.y), controlPoint0, TEST_LOCATION);
167  DALI_TEST_EQUALS( Vector2(controlPoints.z,controlPoints.w), controlPoint1, TEST_LOCATION);
168 
169  //Check the mode is BEZIER
171 
172  END_TEST;
173 }
174 
176 {
177  TestApplication application;
178 
179  //Create alpha function using a built-in function
180  AlphaFunction alphaBuiltin( AlphaFunction::EASE_IN);
181 
182  //Check the mode is BUILTIN_FUNCTION
184 
185  //Create alpha function with pointer to function
186  AlphaFunction alphaCustom( &customAlphaFunction );
187  //Check the mode is CUSTOM_FUNCTION
189 
190  //Create alpha function with control points
191  Vector2 controlPoint0 = Vector2(0.0f,1.0f);
192  Vector2 controlPoint1 = Vector2(1.0f,0.0f);
193  AlphaFunction alphaBezier( controlPoint0,controlPoint1 );
194  //Check the mode is BEZIER
196 
197  END_TEST;
198 }
199 
201 {
202  TestApplication application;
203 
204  Actor actor = Actor::New();
205 
206  // Register a float property
207  float startValue(0.0f);
208  Property::Index index = actor.RegisterProperty( "testProperty", startValue );
209  Stage::GetCurrent().Add(actor);
210  DALI_TEST_EQUALS( actor.GetProperty<float>(index), startValue, TEST_LOCATION );
211 
212  // Build the animation
213  float durationSeconds(1.0f);
214  Animation animation = Animation::New(durationSeconds);
215  float targetValue(1.0f);
216 
217  Vector2 controlPoint0 = Vector2(0.25f,0.5f);
218  Vector2 controlPoint1 = Vector2(0.75f,0.5f);
219  animation.AnimateTo(Property(actor, "testProperty"), targetValue, AlphaFunction(controlPoint0,controlPoint1));
220 
221  // Start the animation
222  animation.Play();
223 
224  application.SendNotification();
225  application.Render(static_cast<unsigned int>(durationSeconds*200.0f)/* 20% progress */);
226  application.SendNotification();
227  float epsilon(0.01f);
228  DALI_TEST_EQUALS( actor.GetProperty<float>(index), 0.271964f, epsilon, TEST_LOCATION );
229 
230  application.SendNotification();
231  application.Render(static_cast<unsigned int>(durationSeconds*200.0f) + 1u/*40% progress*/);
232  application.SendNotification();
233  DALI_TEST_EQUALS( actor.GetProperty<float>(index), 0.432387f, epsilon, TEST_LOCATION );
234 
235  application.SendNotification();
236  application.Render(static_cast<unsigned int>(durationSeconds*200.0f) + 1u/*60% progress*/);
237  application.SendNotification();
238  DALI_TEST_EQUALS( actor.GetProperty<float>(index), 0.567613f, epsilon, TEST_LOCATION );
239 
240  application.SendNotification();
241  application.Render(static_cast<unsigned int>(durationSeconds*200.0f) + 1u/*80% progress*/);
242  application.SendNotification();
243  DALI_TEST_EQUALS( actor.GetProperty<float>(index), 0.728037f, epsilon, TEST_LOCATION );
244 
245  application.SendNotification();
246  application.Render(static_cast<unsigned int>(durationSeconds*200.0f) + 1u/*just beyond the animation duration*/);
247  application.SendNotification();
248  DALI_TEST_EQUALS( actor.GetProperty<float>(index), targetValue, TEST_LOCATION );
249 
250  END_TEST;
251 }
252 
Dali Docs Home
Read more about Dali