2 * Copyright (c) 2015 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.
18 // #include "animation-wrapper.h"
21 #include "emscripten/emscripten.h"
22 #include <dali/devel-api/scripting/scripting.h>
25 #include "property-value-wrapper.h"
34 void KeyFramesAddWithAlpha(Dali::KeyFrames& keyFrames, float progress, Property::Value& value,
35 const std::string& alphaFunction)
37 Dali::AlphaFunction func(AlphaFunction::LINEAR);
39 if( alphaFunction == "LINEAR" )
41 func = Dali::AlphaFunction(AlphaFunction::LINEAR);
43 else if( alphaFunction == "REVERSE" )
45 func = Dali::AlphaFunction(AlphaFunction::REVERSE);
47 else if( alphaFunction == "EASE_IN_SQUARE" )
49 func = Dali::AlphaFunction(AlphaFunction::EASE_IN_SQUARE);
51 else if( alphaFunction == "EASE_OUT_SQUARE" )
53 func = Dali::AlphaFunction(AlphaFunction::EASE_OUT_SQUARE);
55 else if( alphaFunction == "EASE_IN" )
57 func = Dali::AlphaFunction(AlphaFunction::EASE_IN);
59 else if( alphaFunction == "EASE_OUT" )
61 func = Dali::AlphaFunction(AlphaFunction::EASE_OUT);
63 else if( alphaFunction == "EASE_IN_OUT" )
65 func = Dali::AlphaFunction(AlphaFunction::EASE_IN_OUT);
67 else if( alphaFunction == "EASE_IN_SINE" )
69 func = Dali::AlphaFunction(AlphaFunction::EASE_IN_SINE);
71 else if( alphaFunction == "EASE_OUT_SINE" )
73 func = Dali::AlphaFunction(AlphaFunction::EASE_OUT_SINE);
75 else if( alphaFunction == "EASE_IN_OUT_SINE" )
77 func = Dali::AlphaFunction(AlphaFunction::EASE_IN_OUT_SINE);
79 else if( alphaFunction == "BOUNCE" )
81 func = Dali::AlphaFunction(AlphaFunction::BOUNCE);
83 else if( alphaFunction == "SIN" )
85 func = Dali::AlphaFunction(AlphaFunction::SIN);
87 else if( alphaFunction == "EASE_OUT_BACK" )
89 func = Dali::AlphaFunction(AlphaFunction::EASE_OUT_BACK);
93 EM_ASM( console.log( "KeyFramesAddWithAlpha: Unknown alpha function" ) );
96 keyFrames.Add(progress, value, func);
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,
105 const float duration)
107 DALI_ASSERT_ALWAYS(self);
109 Dali::Property::Index propertyIndex = handle.GetPropertyIndex(property);
111 Dali::Property::Type propertyType = handle.GetPropertyType(propertyIndex);
113 if( propertyType != destinationValue.GetType() )
115 EM_ASM( throw "animateTo property types are not the same" );
117 else if( propertyIndex != Dali::Property::INVALID_INDEX )
119 Dali::Property target( handle, propertyIndex );
120 self.AnimateTo( target, destinationValue, alphaFunction, Dali::TimePeriod(delay, duration) );
124 EM_ASM( throw "unknown property" );
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,
134 const float duration)
136 DALI_ASSERT_ALWAYS(self);
138 Dali::Property::Index propertyIndex = handle.GetPropertyIndex(property);
140 Dali::Property::Type propertyType = handle.GetPropertyType(propertyIndex);
142 if( propertyType != destinationValue.GetType() )
144 EM_ASM( throw "animateTo property types are not the same" );
146 else if( propertyIndex != Dali::Property::INVALID_INDEX )
148 Dali::Property target( handle, propertyIndex );
149 self.AnimateBy( target, destinationValue, alphaFunction, Dali::TimePeriod(delay,duration));
153 EM_ASM( throw "unknown property" );
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,
163 const float duration,
164 const Dali::Animation::Interpolation& interpolation)
166 DALI_ASSERT_ALWAYS(self);
168 Dali::Property::Index propertyIndex = handle.GetPropertyIndex(property);
170 if( propertyIndex != Dali::Property::INVALID_INDEX )
172 Dali::Property target( handle, propertyIndex );
173 self.AnimateBetween(target, keyFrames, alphaFunction, Dali::TimePeriod(delay, duration), interpolation);
177 EM_ASM( throw "unknown property" );
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,
187 const float duration)
189 DALI_ASSERT_ALWAYS(self);
193 printf("Unable to add animation, bad path object\n");
197 Dali::Actor actor = Dali::Actor::DownCast(target);
200 printf("Unable to add path animation, bad actor\n");
204 self.Animate( actor, path, forward, alphaFunction, Dali::TimePeriod( delay, duration ) );
209 }; // namespace Emscripten
210 }; // namespace Internal