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.
19 #include "animation-wrapper.h"
23 #include <dali-wrapper.h>
24 #include <animation/animation-api.h>
25 #include <shared/api-function.h>
26 #include <shared/object-template-helper.h>
33 v8::Persistent<v8::ObjectTemplate> AnimationWrapper::mAnimationTemplate;
39 * Contains a list of all functions that can be called
41 const ApiFunction AnimationFunctionTable[]=
43 /**************************************
44 * Animation API (in order of animation.h)
45 **************************************/
47 { "SetDuration" , AnimationApi::SetDuration },
48 { "GetDuration" , AnimationApi::GetDuration },
49 { "SetLooping" , AnimationApi::SetLooping },
50 { "IsLooping" , AnimationApi::IsLooping },
51 { "SetEndAction" , AnimationApi::SetEndAction },
52 { "GetEndAction" , AnimationApi::GetEndAction },
53 { "SetDisconnectAction" , AnimationApi::SetDisconnectAction },
54 { "GetDisconnectAction" , AnimationApi::GetDisconnectAction },
55 { "SetDefaultAlphaFunction" , AnimationApi::SetDefaultAlphaFunction },
56 { "GetDefaultAlphaFunction" , AnimationApi::GetDefaultAlphaFunction },
57 { "GetCurrentProgress" , AnimationApi::GetCurrentProgress },
58 { "SetSpeedFactor" , AnimationApi::SetSpeedFactor },
59 { "GetSpeedFactor" , AnimationApi::GetSpeedFactor },
60 { "SetPlayRange" , AnimationApi::SetPlayRange },
61 { "GetPlayRange" , AnimationApi::GetPlayRange },
62 { "SetCurrentProgress" , AnimationApi::SetCurrentProgress },
63 { "Play" , AnimationApi::Play },
64 { "PlayFrom" , AnimationApi::PlayFrom },
65 { "Pause" , AnimationApi::Pause },
66 { "Stop" , AnimationApi::Stop },
67 { "Clear" , AnimationApi::Clear },
68 { "Animate" , AnimationApi::Animate },
69 { "AnimateBy" , AnimationApi::AnimateBy },
70 { "AnimateTo" , AnimationApi::AnimateTo },
71 { "AnimateBetween" , AnimationApi::AnimateBetween },
72 { "Show" , AnimationApi::Show },
73 { "Hide" , AnimationApi::Hide },
77 const unsigned int AnimationFunctionTableCount = sizeof(AnimationFunctionTable)/sizeof(AnimationFunctionTable[0]);
81 AnimationWrapper::AnimationWrapper( const Dali::Animation& animation, GarbageCollectorInterface& gc )
82 : BaseWrappedObject( BaseWrappedObject::ANIMATION , gc )
84 mAnimation = animation;
87 AnimationWrapper::~AnimationWrapper()
92 v8::Handle<v8::Object> AnimationWrapper::WrapAnimation(v8::Isolate* isolate, const Dali::Animation& animation )
94 v8::EscapableHandleScope handleScope( isolate );
95 v8::Local<v8::ObjectTemplate> objectTemplate;
97 objectTemplate = GetAnimationTemplate( isolate);
99 // create an instance of the template
100 v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
102 // create the Animation wrapper
103 AnimationWrapper* pointer = new AnimationWrapper( animation, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
105 // assign the JavaScript object to the wrapper.
106 pointer->SetJavascriptObject( isolate, localObject );
108 return handleScope.Escape( localObject );
111 v8::Local<v8::ObjectTemplate> AnimationWrapper::GetAnimationTemplate( v8::Isolate* isolate)
113 v8::EscapableHandleScope handleScope( isolate );
114 v8::Local<v8::ObjectTemplate> objectTemplate;
116 if( mAnimationTemplate.IsEmpty() )
118 objectTemplate = MakeAnimationTemplate( isolate );
119 mAnimationTemplate.Reset( isolate, objectTemplate );
123 // get the object template
124 objectTemplate = v8::Local<v8::ObjectTemplate>::New( isolate, mAnimationTemplate );
126 return handleScope.Escape( objectTemplate );
129 v8::Handle<v8::ObjectTemplate> AnimationWrapper::MakeAnimationTemplate( v8::Isolate* isolate )
131 v8::EscapableHandleScope handleScope( isolate );
133 v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
135 // add intercepts for Signals, we can't use HandleWrapper::AddIntercepts because Animation doesn't inherit
136 // from Handle ( just baseHandle)
137 ObjectTemplateHelper::AddSignalConnectAndDisconnect( isolate, objTemplate );
139 objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
141 // add our function properties
142 ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, AnimationFunctionTable, AnimationFunctionTableCount );
144 return handleScope.Escape( objTemplate );
147 void AnimationWrapper::NewAnimation( const v8::FunctionCallbackInfo< v8::Value >& args)
149 v8::Isolate* isolate = args.GetIsolate();
150 v8::HandleScope handleScope( isolate);
152 if( !args.IsConstructCall() )
154 DALI_SCRIPT_EXCEPTION( isolate, "Animation constructor called without 'new'" );
158 Dali::Animation animation = AnimationApi::New( args );
159 v8::Local<v8::Object> localObject = WrapAnimation( isolate, animation );
160 args.GetReturnValue().Set( localObject );
164 Animation AnimationWrapper::GetAnimation()
170 } // namespace V8Plugin