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