Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TimelineItem.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2011, The Cinder Project, All rights reserved.
3  This code is intended for use with the Cinder C++ library: http://libcinder.org
4 
5  Based on the sc-Choreograph CinderBlock by David Wicks: http://sansumbrella.com/
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
8  the following conditions are met:
9 
10  * Redistributions of source code must retain the above copyright notice, this list of conditions and
11  the following disclaimer.
12  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
13  the following disclaimer in the documentation and/or other materials provided with the distribution.
14 
15  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
16  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22  POSSIBILITY OF SUCH DAMAGE.
23 */
24 
25 #pragma once
26 
27 #include "cinder/Cinder.h"
28 
29 namespace cinder
30 {
31 typedef std::shared_ptr<class TimelineItem> TimelineItemRef;
32 
34 class TimelineItem : public std::enable_shared_from_this<TimelineItem>
35 {
36  public:
37  TimelineItem( class Timeline *parent = 0 );
38  TimelineItem( class Timeline *parent, void *target, float startTime, float duration );
39  virtual ~TimelineItem() {}
40 
42  void* getTarget() const { return mTarget; }
43 
45  float getStartTime() const { return mStartTime; }
47  void setStartTime( float newTime );
48 
50  float getDuration() const { updateDuration(); return mDuration; }
52  void setDuration( float newDuration );
53 
55  bool getLoop() const { return mLoop; }
57  void setLoop( bool doLoop = true ) { mLoop = doLoop; }
58 
60  bool getPingPong() const { return mPingPong; }
62  void setPingPong( bool pingPong = true ) { mPingPong = pingPong; }
63 
65  bool getInfinite() const { return mLoop; }
67  void setInfinite( bool infinite = true ) { mInfinite = infinite; }
68 
70  float getEndTime() const { return mStartTime + getDuration(); }
71 
73  class Timeline* getParent() const { return mParent; }
75  void removeSelf();
77  virtual void reset( bool unsetStarted = false ) { if( unsetStarted ) mHasStarted = false; mComplete = false; }
78 
80  bool hasStarted() const { return mHasStarted; }
82  bool isComplete() { return mComplete; }
83 
85  bool getAutoRemove() const { return mAutoRemove; }
87  void setAutoRemove( bool autoRemove = true ) { mAutoRemove = autoRemove; }
88 
89  virtual void start( bool reverse ) = 0;
90  virtual void loopStart() {}
91  virtual void update( float relativeTime ) = 0;
92  virtual void complete( bool reverse ) = 0;
94  virtual bool updateAtLoopStart() { return false; }
95  virtual float calcDuration() const { return mDuration; }
96  virtual void reverse() = 0;
98  virtual TimelineItemRef clone() const = 0;
100  virtual TimelineItemRef cloneReverse() const = 0;
102  void stepTo( float time, bool reverse );
103 
104  TimelineItemRef thisRef() { return shared_from_this(); }
105 
106  protected:
107  void setDurationDirty() { mDirtyDuration = true; }
108  void updateDuration() const;
110  float loopTime( float absTime );
111  void setTarget( void *target ) { mTarget = target; }
112 
114 
115  void *mTarget;
116  float mStartTime;
120  bool mInfinite;
125 
126  friend class Timeline;
127  private:
128  mutable float mDuration, mInvDuration;
129  mutable bool mDirtyDuration; // marked if the virtual calcDuration() needs to be calculated
130 };
131 
132 } // namespace cinder
133 
bool isComplete()
Returns whether the item has completed.
Definition: TimelineItem.h:82
TimelineItemRef thisRef()
Definition: TimelineItem.h:104
virtual TimelineItemRef cloneReverse() const =0
Creates a cloned item which runs in reverse relative to a timeline of duration timelineDuration.
float loopTime(float absTime)
Converts time from absolute to absolute based on item's looping attributes.
Definition: TimelineItem.cpp:149
void setDurationDirty()
Definition: TimelineItem.h:107
virtual bool updateAtLoopStart()
Call update() only at the beginning of each loop (for example Cues exhibit require this behavior) ...
Definition: TimelineItem.h:94
void stepTo(float time, bool reverse)
go to a specific time, generally called by the parent Timeline only. If reverse then playhead is inte...
Definition: TimelineItem.cpp:50
void setLoop(bool doLoop=true)
Sets whether the item starts over when it is complete.
Definition: TimelineItem.h:57
virtual void reset(bool unsetStarted=false)
Marks the item as not completed, and if unsetStarted, marks the item as not started.
Definition: TimelineItem.h:77
GLenum target
Definition: GLee.h:13607
bool mLoop
Definition: TimelineItem.h:121
bool mAutoRemove
Definition: TimelineItem.h:123
TimelineItem(class Timeline *parent=0)
Definition: TimelineItem.cpp:31
void removeSelf()
Removes the item from its parent Timeline.
Definition: TimelineItem.cpp:45
virtual void loopStart()
Definition: TimelineItem.h:90
int32_t mLastLoopIteration
Definition: TimelineItem.h:124
virtual void complete(bool reverse)=0
virtual void reverse()=0
bool hasStarted() const
Returns whether the item has started.
Definition: TimelineItem.h:80
void * getTarget() const
Returns the item's target pointer.
Definition: TimelineItem.h:42
virtual ~TimelineItem()
Definition: TimelineItem.h:39
float getDuration() const
Returns the item's duration.
Definition: TimelineItem.h:50
void setAutoRemove(bool autoRemove=true)
Sets whether the item will remove itself from the Timeline when it is complete.
Definition: TimelineItem.h:87
Base interface for anything that can go on a Timeline.
Definition: TimelineItem.h:34
virtual TimelineItemRef clone() const =0
Creates a clone of the item.
bool mMarkedForRemoval
Definition: TimelineItem.h:119
float getEndTime() const
Returns the time of the item's competion, equivalent to getStartTime() + getDuration().
Definition: TimelineItem.h:70
bool mComplete
Definition: TimelineItem.h:118
bool mUseAbsoluteTime
Definition: TimelineItem.h:122
bool getPingPong() const
Returns whether the item alternates between forward and reverse. Overrides loop when true...
Definition: TimelineItem.h:60
virtual void update(float relativeTime)=0
class Timeline * getParent() const
Returns a pointer to the item's parent Timeline.
Definition: TimelineItem.h:73
virtual float calcDuration() const
Definition: TimelineItem.h:95
void setStartTime(float newTime)
Set the items's start time to newTime.
Definition: TimelineItem.cpp:125
void * mTarget
Definition: TimelineItem.h:115
bool getAutoRemove() const
Should the item remove itself from the Timeline when it is complete.
Definition: TimelineItem.h:85
void updateDuration() const
Definition: TimelineItem.cpp:132
bool mHasReverseStarted
Definition: TimelineItem.h:117
std::shared_ptr< class TimelineItem > TimelineItemRef
Definition: TimelineItem.h:31
void setDuration(float newDuration)
Sets the item's duration to newDuration.
Definition: TimelineItem.cpp:141
void setPingPong(bool pingPong=true)
Sets whether the item alternates between forward and reverse. Overrides loop when true...
Definition: TimelineItem.h:62
void setTarget(void *target)
Definition: TimelineItem.h:111
void setInfinite(bool infinite=true)
Sets whether the item ever is marked as complete.
Definition: TimelineItem.h:67
bool getLoop() const
Returns whether the item starts over when it is complete.
Definition: TimelineItem.h:55
bool mHasStarted
Definition: TimelineItem.h:117
float mStartTime
Definition: TimelineItem.h:116
virtual void start(bool reverse)=0
bool mPingPong
Definition: TimelineItem.h:121
Definition: Timeline.h:42
bool mInfinite
Definition: TimelineItem.h:120
bool getInfinite() const
Returns whether the item ever is marked as complete.
Definition: TimelineItem.h:65
class Timeline * mParent
Definition: TimelineItem.h:113
float getStartTime() const
Returns the item's start time.
Definition: TimelineItem.h:45
bool mReverseComplete
Definition: TimelineItem.h:118