Revert "[Tizen] Added 'make clean' on each profile build."
[platform/core/uifw/dali-adaptor.git] / adaptors / emscripten / wrappers / animation-wrapper.cpp
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 "animation-wrapper.h"
19
20 // EXTERNAL INCLUDES
21 #include "emscripten/emscripten.h"
22 #include <dali/devel-api/scripting/scripting.h>
23
24 // INTERNAL INCLUDES
25 #include "property-value-wrapper.h"
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 namespace Emscripten
32 {
33
34 void KeyFramesAddWithAlpha(Dali::KeyFrames& keyFrames, float progress, Property::Value& value,
35                            const std::string& alphaFunction)
36 {
37   Dali::AlphaFunction func(AlphaFunction::LINEAR);
38
39   if( alphaFunction == "LINEAR" )
40   {
41     func = Dali::AlphaFunction(AlphaFunction::LINEAR);
42   }
43   else if( alphaFunction == "REVERSE" )
44   {
45     func = Dali::AlphaFunction(AlphaFunction::REVERSE);
46   }
47   else if( alphaFunction == "EASE_IN_SQUARE" )
48   {
49     func = Dali::AlphaFunction(AlphaFunction::EASE_IN_SQUARE);
50   }
51   else if( alphaFunction == "EASE_OUT_SQUARE" )
52   {
53     func = Dali::AlphaFunction(AlphaFunction::EASE_OUT_SQUARE);
54   }
55   else if( alphaFunction == "EASE_IN" )
56   {
57     func = Dali::AlphaFunction(AlphaFunction::EASE_IN);
58   }
59   else if( alphaFunction == "EASE_OUT" )
60   {
61     func = Dali::AlphaFunction(AlphaFunction::EASE_OUT);
62   }
63   else if( alphaFunction == "EASE_IN_OUT" )
64   {
65     func = Dali::AlphaFunction(AlphaFunction::EASE_IN_OUT);
66   }
67   else if( alphaFunction == "EASE_IN_SINE" )
68   {
69     func = Dali::AlphaFunction(AlphaFunction::EASE_IN_SINE);
70   }
71   else if( alphaFunction == "EASE_OUT_SINE" )
72   {
73     func = Dali::AlphaFunction(AlphaFunction::EASE_OUT_SINE);
74   }
75   else if( alphaFunction == "EASE_IN_OUT_SINE" )
76   {
77     func = Dali::AlphaFunction(AlphaFunction::EASE_IN_OUT_SINE);
78   }
79   else if( alphaFunction == "BOUNCE" )
80   {
81     func = Dali::AlphaFunction(AlphaFunction::BOUNCE);
82   }
83   else if( alphaFunction == "SIN" )
84   {
85     func = Dali::AlphaFunction(AlphaFunction::SIN);
86   }
87   else if( alphaFunction == "EASE_OUT_BACK" )
88   {
89     func = Dali::AlphaFunction(AlphaFunction::EASE_OUT_BACK);
90   }
91   else
92   {
93     EM_ASM( console.log( "KeyFramesAddWithAlpha: Unknown alpha function" ) );
94   }
95
96   keyFrames.Add(progress, value, func);
97 }
98
99 void AnimateTo(Dali::Animation& self,
100                Dali::Handle& handle,
101                const std::string& property,
102                const Dali::Property::Value& destinationValue,
103                const Dali::AlphaFunction::BuiltinFunction& alphaFunction,
104                const float delay,
105                const float duration)
106 {
107   DALI_ASSERT_ALWAYS(self);
108
109   Dali::Property::Index propertyIndex = handle.GetPropertyIndex(property);
110
111   Dali::Property::Type propertyType = handle.GetPropertyType(propertyIndex);
112
113   if( propertyType != destinationValue.GetType() )
114   {
115     EM_ASM( throw "animateTo property types are not the same" );
116   }
117   else if( propertyIndex != Dali::Property::INVALID_INDEX )
118   {
119     Dali::Property target( handle, propertyIndex );
120     self.AnimateTo( target, destinationValue, alphaFunction, Dali::TimePeriod(delay, duration) );
121   }
122   else
123   {
124     EM_ASM( throw "unknown property" );
125   }
126 }
127
128 void AnimateBy(Dali::Animation& self,
129                Dali::Handle& handle,
130                const std::string& property,
131                const Dali::Property::Value& destinationValue,
132                const Dali::AlphaFunction::BuiltinFunction& alphaFunction,
133                const float delay,
134                const float duration)
135 {
136   DALI_ASSERT_ALWAYS(self);
137
138   Dali::Property::Index propertyIndex = handle.GetPropertyIndex(property);
139
140   Dali::Property::Type propertyType = handle.GetPropertyType(propertyIndex);
141
142   if( propertyType != destinationValue.GetType() )
143   {
144     EM_ASM( throw "animateTo property types are not the same" );
145   }
146   else if( propertyIndex != Dali::Property::INVALID_INDEX )
147   {
148     Dali::Property target( handle, propertyIndex );
149     self.AnimateBy( target, destinationValue, alphaFunction, Dali::TimePeriod(delay,duration));
150   }
151   else
152   {
153     EM_ASM( throw "unknown property" );
154   }
155 }
156
157 void AnimateBetween(Dali::Animation& self,
158                     Dali::Handle& handle,
159                     const std::string& property,
160                     Dali::KeyFrames& keyFrames,
161                     const Dali::AlphaFunction::BuiltinFunction& alphaFunction,
162                     const float delay,
163                     const float duration,
164                     const Dali::Animation::Interpolation& interpolation)
165 {
166   DALI_ASSERT_ALWAYS(self);
167
168   Dali::Property::Index propertyIndex = handle.GetPropertyIndex(property);
169
170   if( propertyIndex != Dali::Property::INVALID_INDEX )
171   {
172     Dali::Property target( handle, propertyIndex );
173     self.AnimateBetween(target, keyFrames, alphaFunction, Dali::TimePeriod(delay, duration), interpolation);
174   }
175   else
176   {
177     EM_ASM( throw "unknown property" );
178   }
179 }
180
181 void AnimatePath(Dali::Animation& self,
182                  Dali::Handle& target,
183                  const Dali::Path& path,
184                  const Dali::Vector3& forward,
185                  const Dali::AlphaFunction::BuiltinFunction& alphaFunction,
186                  const float delay,
187                  const float duration)
188 {
189   DALI_ASSERT_ALWAYS(self);
190
191   if(!path)
192   {
193     printf("Unable to add animation, bad path object\n");
194   }
195   else
196   {
197     Dali::Actor actor = Dali::Actor::DownCast(target);
198     if( !actor )
199     {
200       printf("Unable to add path animation, bad actor\n");
201     }
202     else
203     {
204       self.Animate( actor, path, forward, alphaFunction, Dali::TimePeriod( delay, duration ) );
205     }
206   }
207 }
208
209 }; // namespace Emscripten
210 }; // namespace Internal
211 }; // namespace Dali