Dali 3D User Interface Engine
animation-playlist.cpp
Go to the documentation of this file.
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
20 
21 
22 // INTERNAL INCLUDES
26 
27 
28 namespace Dali
29 {
30 
31 namespace Internal
32 {
33 
35 {
36  return new AnimationPlaylist();
37 }
38 
40 {
41 }
42 
44 {
45 }
46 
48 {
49  mAnimations.PushBack( &animation );
50 }
51 
53 {
54  Dali::Vector< Animation* >::Iterator iter = std::find( mAnimations.Begin(), mAnimations.End(), &animation );
55  DALI_ASSERT_ALWAYS( iter != mAnimations.End() && "Animation not found" );
56 
57  mAnimations.Remove( iter );
58 }
59 
61 {
62  mPlaylist.push_back( Dali::Animation(&animation) );
63 }
64 
66 {
67  std::vector< Dali::Animation >::iterator iter = std::find( mPlaylist.begin(), mPlaylist.end(), Dali::Animation(&animation) );
68  std::vector< Dali::Animation >::iterator last = mPlaylist.end();
69  if( iter != last )
70  {
71  --last; // move to real last
72  std::swap( *iter, *last ); // swap
73  mPlaylist.resize( mPlaylist.size() - 1u );
74  }
75 }
76 
78 {
79  std::vector< Dali::Animation > finishedAnimations;
80 
81  // Since animations can be unreferenced during the signal emissions, iterators into animationPointers may be invalidated.
82  // First copy and reference the finished animations, then emit signals
83  for ( Dali::Vector< Animation* >::Iterator iter = mAnimations.Begin(); iter != mAnimations.End(); ++iter )
84  {
85  Animation* animation = *iter;
86 
87  if ( animation->HasFinished() )
88  {
89  finishedAnimations.push_back( Dali::Animation(animation) );
90 
91  // The animation may be present in mPlaylist - remove if necessary
92  // Note that the animation "Finish" signal is emitted after Stop() has been called
93  std::vector< Dali::Animation >::iterator iter = std::find( mPlaylist.begin(), mPlaylist.end(), Dali::Animation(animation) );
94  DALI_ASSERT_DEBUG(iter != mPlaylist.end());
95  mPlaylist.erase( iter );
96  }
97  }
98 
99  // Now it's safe to emit the signals
100  for ( std::vector< Dali::Animation >::iterator iter = finishedAnimations.begin(); iter != finishedAnimations.end(); ++iter )
101  {
102  Dali::Animation& handle = *iter;
103 
104  GetImplementation(handle).EmitSignalFinish();
105  }
106 }
107 
108 } // namespace Internal
109 
110 } // namespace Dali
Dali Docs Home
Read more about Dali