Merge "Previous model height return problem fixed" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-animation-data.cpp
1 /*
2  * Copyright (c) 2016 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 #include <dali/dali.h>
18 #include <test-animation-data.h>
19
20 using namespace Dali;
21
22 namespace Test
23 {
24
25 TestAnimationData::TestAnimationData()
26 {
27 }
28
29 TestAnimationData::~TestAnimationData()
30 {
31 }
32
33 TestAnimationData::AnimationDataElement::AnimationDataElement()
34 : alphaFunction( AlphaFunction::DEFAULT ),
35   timePeriodDelay( 0.0f ),
36   timePeriodDuration( 1.0f )
37 {
38 }
39
40 void TestAnimationData::Add( AnimationDataElement* animationDataElement )
41 {
42   mAnimationDataList.PushBack( animationDataElement );
43 }
44
45 std::size_t TestAnimationData::Size() const
46 {
47   return mAnimationDataList.Size();
48 }
49
50 void TestAnimationData::Clear()
51 {
52   AnimationDataList::Iterator end = mAnimationDataList.End();
53   for( AnimationDataList::Iterator iter = mAnimationDataList.Begin(); iter != end; ++iter )
54   {
55     delete ( *iter );
56   }
57   mAnimationDataList.Clear();
58 }
59
60
61 void NewAnimator( const Property::Map& map, TestAnimationData::AnimationDataElement& element )
62 {
63   // Now set the properties, or create children
64   for( unsigned int i = 0, animationMapCount = map.Count(); i < animationMapCount; ++i )
65   {
66     const StringValuePair& pair( map.GetPair( i ) );
67     const std::string& key( pair.first );
68     const Property::Value& value( pair.second );
69
70     if( key == "actor" || key == "target" )
71     {
72       element.target = value.Get< std::string >();
73     }
74     else if( key == "property" )
75     {
76       element.property = value.Get< std::string >();
77     }
78     else if( key == "value" )
79     {
80       element.value = value;
81     }
82     else if( key == "alphaFunction" )
83     {
84       std::string alphaFunctionValue = value.Get< std::string >();
85
86       if( alphaFunctionValue == "LINEAR" )
87       {
88         element.alphaFunction = AlphaFunction::LINEAR;
89       }
90       else if( alphaFunctionValue == "REVERSE" )
91       {
92         element.alphaFunction = AlphaFunction::REVERSE;
93       }
94       else if( alphaFunctionValue == "EASE_IN_SQUARE" )
95       {
96         element.alphaFunction = AlphaFunction::EASE_IN_SQUARE;
97       }
98       else if( alphaFunctionValue == "EASE_OUT_SQUARE" )
99       {
100         element.alphaFunction = AlphaFunction::EASE_OUT_SQUARE;
101       }
102       else if( alphaFunctionValue == "EASE_IN" )
103       {
104         element.alphaFunction = AlphaFunction::EASE_IN;
105       }
106       else if( alphaFunctionValue == "EASE_OUT" )
107       {
108         element.alphaFunction = AlphaFunction::EASE_OUT;
109       }
110       else if( alphaFunctionValue == "EASE_IN_OUT" )
111       {
112         element.alphaFunction = AlphaFunction::EASE_IN_OUT;
113       }
114       else if( alphaFunctionValue == "EASE_IN_SINE" )
115       {
116         element.alphaFunction = AlphaFunction::EASE_IN_SINE;
117       }
118       else if( alphaFunctionValue == "EASE_OUT_SINE" )
119       {
120         element.alphaFunction = AlphaFunction::EASE_OUT_SINE;
121       }
122       else if( alphaFunctionValue == "EASE_IN_OUT_SINE" )
123       {
124         element.alphaFunction = AlphaFunction::EASE_IN_OUT_SINE;
125       }
126       else if( alphaFunctionValue == "BOUNCE" )
127       {
128         element.alphaFunction = AlphaFunction::BOUNCE;
129       }
130       else if( alphaFunctionValue == "SIN" )
131       {
132         element.alphaFunction = AlphaFunction::SIN;
133       }
134       else if( alphaFunctionValue == "EASE_OUT_BACK" )
135       {
136         element.alphaFunction = AlphaFunction::EASE_OUT_BACK;
137       }
138     }
139     else if( key == "timePeriod" )
140     {
141       Property::Map timeMap = value.Get< Property::Map >();
142       for( unsigned int i = 0; i < timeMap.Count(); ++i )
143       {
144         const StringValuePair& pair( timeMap.GetPair( i ) );
145         if( pair.first == "delay" )
146         {
147           element.timePeriodDelay = pair.second.Get< float >();
148         }
149         else if( pair.first == "duration" )
150         {
151           element.timePeriodDuration = pair.second.Get< float >();
152         }
153       }
154     }
155     else if( key == "animator" )
156     {
157       if( value.GetType() == Property::MAP )
158       {
159         Property::Map* map = value.GetMap();
160         const Property::Map& mapref = *map;
161         NewAnimator( mapref, element ); // Merge the map into element
162       }
163     }
164   }
165 }
166
167 void NewAnimation( const Property::Map& map, TestAnimationData& outputAnimationData )
168 {
169   TestAnimationData::AnimationDataElement* element = new TestAnimationData::AnimationDataElement();
170   NewAnimator( map, *element );
171
172   outputAnimationData.Add( element );
173 }
174
175 void NewAnimation( const Property::Array& array, TestAnimationData& outputAnimationData )
176 {
177   for(unsigned int i=0; i<array.Size(); ++i )
178   {
179     TestAnimationData::AnimationDataElement* element = new TestAnimationData::AnimationDataElement();
180     const Property::Value& value = array.GetElementAt(i);
181     if( value.GetType() == Property::MAP )
182     {
183       Property::Map* map = value.GetMap();
184       NewAnimator( *map, *element );
185       outputAnimationData.Add( element );
186     }
187   }
188 }
189
190 } // Test