2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali/devel-api/animation/path-constrainer.h>
23 #include <dali-test-suite-utils.h>
26 using namespace Dali::Internal;
30 static void SetupLinearConstrainerUniformProgress( Dali::LinearConstrainer& linearConstrainer)
32 Dali::Property::Array points;
37 linearConstrainer.SetProperty( Dali::LinearConstrainer::Property::VALUE, points );
40 static void SetupLinearConstrainerNonUniformProgress( Dali::LinearConstrainer& linearConstrainer)
42 Dali::Property::Array points;
47 linearConstrainer.SetProperty( Dali::LinearConstrainer::Property::VALUE, points );
52 linearConstrainer.SetProperty( Dali::LinearConstrainer::Property::PROGRESS, points );
55 } // anonymous namespace
57 int UtcLinearConstrainerApply(void)
59 TestApplication application;
61 Dali::Actor actor = Dali::Actor::New();
63 // Register a float property
64 Property::Index index = actor.RegisterProperty( "t", 0.0f );
66 Dali::Stage::GetCurrent().Add(actor);
69 //Create a LinearConstrainer without specifying progress for values
70 Dali::LinearConstrainer linearConstrainer = Dali::LinearConstrainer::New();
71 SetupLinearConstrainerUniformProgress( linearConstrainer );
73 //Apply the linear constraint to the actor's position. The source property for the constraint will be the custom property "t"
74 Vector2 range( 0.0f, 1.0f );
75 linearConstrainer.Apply( Property(actor,Dali::Actor::Property::POSITION_X), Property(actor,index), range );
77 //Create an animation to animate the custom property
78 float durationSeconds(1.0f);
79 Dali::Animation animation = Dali::Animation::New(durationSeconds);
80 animation.AnimateTo(Dali::Property(actor,index),1.0f);
83 application.SendNotification();
84 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
86 DALI_TEST_EQUALS( actor.GetCurrentPosition().x, 0.5f, TEST_LOCATION );
88 application.SendNotification();
89 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
90 DALI_TEST_EQUALS( actor.GetCurrentPosition().x, 1.0f, TEST_LOCATION );
92 application.SendNotification();
93 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
94 DALI_TEST_EQUALS( actor.GetCurrentPosition().x, 0.5f, TEST_LOCATION );
96 application.SendNotification();
97 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
98 DALI_TEST_EQUALS( actor.GetCurrentPosition().x, 0.0f, TEST_LOCATION );
100 application.SendNotification();
101 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* beyond the animation duration*/);
102 DALI_TEST_EQUALS( actor.GetCurrentPosition().x, 0.0f, TEST_LOCATION );
104 //Setup a LinearConstrainer specifying the progress for each value
105 linearConstrainer.Remove(actor);
106 SetupLinearConstrainerNonUniformProgress( linearConstrainer );
107 linearConstrainer.Apply( Property(actor,Dali::Actor::Property::POSITION_X), Property(actor,index), range );
109 actor.SetProperty(index,0.0f);
111 application.SendNotification();
112 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
114 DALI_TEST_EQUALS( actor.GetCurrentPosition().x, 1.0f, TEST_LOCATION );
116 application.SendNotification();
117 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
118 DALI_TEST_EQUALS( actor.GetCurrentPosition().x, 2.0f/3.0f, Math::MACHINE_EPSILON_1, TEST_LOCATION );
120 application.SendNotification();
121 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
122 DALI_TEST_EQUALS( actor.GetCurrentPosition().x, 1.0f/3.0f, Math::MACHINE_EPSILON_1, TEST_LOCATION );
124 application.SendNotification();
125 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
126 DALI_TEST_EQUALS( actor.GetCurrentPosition().x, 0.0f, TEST_LOCATION );
128 application.SendNotification();
129 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* beyond the animation duration*/);
130 DALI_TEST_EQUALS( actor.GetCurrentPosition().x, 0.0f, TEST_LOCATION );