a1f8c4ca87e0f36d1c2a236caa42def9159ee0a1
[platform/core/uifw/dali-core.git] / dali / internal / event / animation / animation-playlist.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // CLASS HEADER
18 #include <dali/internal/event/animation/animation-playlist.h>
19
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/common/set-wrapper.h>
24 #include <dali/internal/event/animation/animation-impl.h>
25
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 AnimationPlaylist* AnimationPlaylist::New()
34 {
35   return new AnimationPlaylist();
36 }
37
38 AnimationPlaylist::AnimationPlaylist()
39 {
40 }
41
42 AnimationPlaylist::~AnimationPlaylist()
43 {
44 }
45
46 void AnimationPlaylist::AnimationCreated( Animation& animation )
47 {
48   mAnimations.insert( &animation );
49 }
50
51 void AnimationPlaylist::AnimationDestroyed( Animation& animation )
52 {
53   std::set< Animation* >::iterator iter = find( mAnimations.begin(), mAnimations.end(), &animation );
54   DALI_ASSERT_ALWAYS( iter != mAnimations.end() && "Animation not found" );
55
56   mAnimations.erase( iter );
57 }
58
59 void AnimationPlaylist::OnPlay( Animation& animation )
60 {
61   mPlaylist.insert( Dali::Animation(&animation) );
62 }
63
64 void AnimationPlaylist::OnClear( Animation& animation )
65 {
66   mPlaylist.erase( Dali::Animation(&animation) );
67 }
68
69 void AnimationPlaylist::NotifyFinishedAnimations()
70 {
71   std::vector< Dali::Animation > finishedAnimations;
72
73   // Since animations can be unreferenced during the signal emissions, iterators into animationPointers may be invalidated.
74   // First copy and reference the finished animations, then emit signals
75   for ( std::set< Animation* >::iterator iter = mAnimations.begin(); iter != mAnimations.end(); ++iter )
76   {
77     Animation* animation = *iter;
78
79     if ( animation->HasFinished() )
80     {
81       finishedAnimations.push_back( Dali::Animation(animation) );
82
83       // The animation may be present in mPlaylist - remove if necessary
84       // Note that the animation "Finish" signal is emitted after Stop() has been called
85       mPlaylist.erase( Dali::Animation(animation) );
86     }
87   }
88
89   // Now it's safe to emit the signals
90   for ( std::vector< Dali::Animation >::iterator iter = finishedAnimations.begin(); iter != finishedAnimations.end(); ++iter )
91   {
92     Dali::Animation& handle = *iter;
93
94     GetImplementation(handle).EmitSignalFinish();
95   }
96 }
97
98 } // namespace Internal
99
100 } // namespace Dali