Dali 3D User Interface Engine
utc-Dali-Constrainer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 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>
23 #include <dali-test-suite-utils.h>
24 
25 using namespace Dali;
26 using namespace Dali::Internal;
27 
28 namespace
29 {
31 {
32  Dali::Property::Array points;
33  points.Resize(3);
34  points[0] = 0.0f;
35  points[1] = 1.0f;
36  points[2] = 0.0f;
37  linearConstrainer.SetProperty( Dali::LinearConstrainer::Property::VALUE, points );
38 }
39 
41 {
42  Dali::Property::Array points;
43  points.Resize(3);
44  points[0] = 0.0f;
45  points[1] = 1.0f;
46  points[2] = 0.0f;
47  linearConstrainer.SetProperty( Dali::LinearConstrainer::Property::VALUE, points );
48 
49  points[0] = 0.0f;
50  points[1] = 0.25f;
51  points[2] = 1.0f;
52  linearConstrainer.SetProperty( Dali::LinearConstrainer::Property::PROGRESS, points );
53 }
54 
55 } // anonymous namespace
56 
58 {
59  TestApplication application;
60 
61  Dali::Actor actor = Dali::Actor::New();
62 
63  // Register a float property
64  Property::Index index = actor.RegisterProperty( "t", 0.0f );
65 
67 
68 
69  //Create a LinearConstrainer without specifying progress for values
71  SetupLinearConstrainerUniformProgress( linearConstrainer );
72 
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 );
76 
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);
81  animation.Play();
82 
83  application.SendNotification();
84  application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
85 
87 
88  application.SendNotification();
89  application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
91 
92  application.SendNotification();
93  application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
95 
96  application.SendNotification();
97  application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
99 
100  application.SendNotification();
101  application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* beyond the animation duration*/);
103 
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 );
108 
109  actor.SetProperty(index,0.0f);
110  animation.Play();
111  application.SendNotification();
112  application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
113 
115 
116  application.SendNotification();
117  application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 50% progress */);
119 
120  application.SendNotification();
121  application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 75% progress */);
123 
124  application.SendNotification();
125  application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 100% progress */);
127 
128  application.SendNotification();
129  application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* beyond the animation duration*/);
131 
132  END_TEST;
133 }
134 
Dali Docs Home
Read more about Dali