Implements threaded and blocking NSAnimation modes and some other changes.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@24998 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
xgl 2007-04-12 17:01:23 +00:00
parent 5278c0cbe2
commit 9fe955c56d
5 changed files with 1076 additions and 751 deletions

View file

@ -1,3 +1,15 @@
2007-04-12 Xavier Glattard <xavier.glattard@online.fr>
* Headers/AppKit/NSAnimation.h
* Source/NSAnimation.m
* Headers/Additions/GNUstepGUI/GSAnimator.h
* Source/GSAnimator.m
- attempt to follow GNU coding standards
- implementation of NSAnimationBlockingMode and
NSAnimationNonBlockingThreaded modes
- fix some bugs and incompatibilities with Cocoa
- Add some more documentation
2007-04-11 Richard Frith-Macdonald <rfm@gnu.org> 2007-04-11 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSView.m: When transforming a size ensure that the * Source/NSView.m: When transforming a size ensure that the
@ -23,7 +35,7 @@
2007-04-05 Xavier Glattard <xavier.glattard@online.fr> 2007-04-05 Xavier Glattard <xavier.glattard@online.fr>
* Headers/AppKit/NSAnimation.h * Headers/AppKit/NSAnimation.h
* Source/NSAnimation.m * Source/NSAnimation.m
* Headers/Additions/GNUstepGUI/GSAnimator.h * Headers/Additions/GNUstepGUI/GSAnimator.h
* Source/GSAnimator.m * Source/GSAnimator.m
Implementation of NSAnimation and NSViewAnimation classes : Implementation of NSAnimation and NSViewAnimation classes :

View file

@ -5,8 +5,7 @@
* *
* Copyright (c) 2007 Free Software Foundation, Inc. * Copyright (c) 2007 Free Software Foundation, Inc.
* *
* This file used to be part of the mySTEP Library. * This file is part of the GNUstep GUI Library.
* This file now is part of the GNUstep GUI Library.
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public * modify it under the terms of the GNU Library General Public
@ -31,7 +30,7 @@
@class NSRunLoop; @class NSRunLoop;
@class NSEvent; @class NSEvent;
@class NSTimer; @class NSTimer;
@class NSThread; @class NSString;
#include <Foundation/NSObject.h> #include <Foundation/NSObject.h>
#include <Foundation/NSDate.h> #include <Foundation/NSDate.h>
@ -42,8 +41,6 @@
* be animated by a GSAnimator. * be animated by a GSAnimator.
*/ */
@protocol GSAnimation @protocol GSAnimation
/** Returns the run-loop modes useed to run the animation timer in. */
- (NSArray*) runLoopModesForAnimating;
/** Call back method indicating that the GSAnimator did start the /** Call back method indicating that the GSAnimator did start the
* animation loop. */ * animation loop. */
- (void) animatorDidStart; - (void) animatorDidStart;
@ -51,64 +48,56 @@
* animation loop. */ * animation loop. */
- (void) animatorDidStop; - (void) animatorDidStop;
/** Call back method called for each animation loop. */ /** Call back method called for each animation loop. */
- (void) animatorStep: (NSTimeInterval) elapsedTime; - (void) animatorStep: (NSTimeInterval)elapsedTime;
@end @end
typedef enum
{
GSTimerBasedAnimation,
GSPerformerBasedAnimation,
// Cocoa compatible animation modes :
GSBlockingCocoaAnimation,
GSNonblockingCocoaAnimation,
GSNonblockingCocoaThreadedAnimation
} GSAnimationBlockingMode;
/** /**
* GSAnimator is the front of a class cluster. Instances of a subclass of * GSAnimator is the front of a class cluster. Instances of a subclass of
* GSAnimator manages the timing of an animation. * GSAnimator manage the timing of an animation.
*/ */
@interface GSAnimator : NSObject @interface GSAnimator : NSObject
{ {
id<GSAnimation> _animation; // The Object to be animated id<GSAnimation> _animation; // The Object to be animated
NSDate *_startTime; // The time the animation did started NSDate* _startTime; // The time the animation did started
BOOL _running; // Indicates that the animator is looping BOOL _running; // Indicates that the animator is looping
NSTimeInterval _elapsed; // Elapsed time since the animator started NSTimeInterval _elapsed; // Elapsed time since the animator started
NSTimeInterval _lastFrame; // The time of the last animation loop NSTimeInterval _lastFrame; // The time of the last animation loop
unsigned int _frameCount; // The number of loops since the start unsigned int _frameCount; // The number of loops since the start
NSRunLoop *_runLoop; // The run-loop used for looping NSArray* _runLoopModes;
NSTimer *_timer; // Timer used for looping NSTimer* _timer; // Timer used for looping
NSTimeInterval _timerInterval; NSTimeInterval _timerInterval;
} }
/** Returns a GSAnimator object initialized with the specified object
* to be animated as fast as possible. */
+ (GSAnimator*) animatorWithAnimation: (id<GSAnimation>)anAnimation;
/** Returns a GSAnimator object initialized with the specified object /** Returns a GSAnimator object initialized with the specified object
* to be animated. */ * to be animated. */
+ (GSAnimator*) animatorWithAnimation: (id<GSAnimation>)anAnimation + (GSAnimator*) animatorWithAnimation: (id<GSAnimation>)anAnimation
mode: (GSAnimationBlockingMode)aMode
frameRate: (float)fps; frameRate: (float)fps;
/** Returns a GSAnimator object allocated in the given NSZone and /** Returns a GSAnimator object allocated in the given NSZone and
* initialized with the specified object to be animated. */ * initialized with the specified object to be animated. */
+ (GSAnimator*) animatorWithAnimation: (id<GSAnimation>)anAnimation + (GSAnimator*) animatorWithAnimation: (id<GSAnimation>)anAnimation
mode: (GSAnimationBlockingMode)aMode
frameRate: (float)fps frameRate: (float)fps
zone: (NSZone*)aZone; zone: (NSZone*)aZone;
/** Returns a GSAnimator object initialized with the specified object /** Returns a GSAnimator object initialized with the specified object
* to be animated. */ * to be animated. The given NSRunLoop is used in NSDefaultRunLoopMode.*/
- (GSAnimator*) initWithAnimation: (id<GSAnimation>)anAnimation - (GSAnimator*) initWithAnimation: (id<GSAnimation>)anAnimation
frameRate: (float)aFrameRate frameRate: (float)aFrameRate;
runLoop: (NSRunLoop*)aRunLoop;
- (GSAnimator*) initWithAnimation: (id<GSAnimation>)anAnimation; - (GSAnimator*) initWithAnimation: (id<GSAnimation>)anAnimation;
- (unsigned int) frameCount; - (unsigned int) frameCount;
- (void) resetCounters; - (void) resetCounters;
- (float) frameRate; - (float) frameRate;
- (NSRunLoop*) runLoopForAnimating;
- (NSArray*) runLoopModesForAnimating; - (NSArray*) runLoopModesForAnimating;
- (void) setRunLoopModesForAnimating: (NSArray*)modes;
- (void) startAnimation; - (void) startAnimation;
- (void) stopAnimation; - (void) stopAnimation;

View file

@ -39,109 +39,10 @@
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
#include <Foundation/NSArray.h> #include <Foundation/NSArray.h>
// Bezier curve parameters
typedef struct __GSBezierDesc
{
float p[4]; // control points
BOOL areCoefficientsComputed;
float a[4]; // coefficients
} _GSBezierDesc;
static inline void
_GSBezierComputeCoefficients( _GSBezierDesc *b )
{
b->a[0] = b->p[0];
b->a[1] =-3.0*b->p[0]+3.0*b->p[1];
b->a[2] = 3.0*b->p[0]-6.0*b->p[1]+3.0*b->p[2];
b->a[3] =- b->p[0]+3.0*b->p[1]-3.0*b->p[2]+b->p[3];
b->areCoefficientsComputed = YES;
}
static inline float
_GSBezierEval( _GSBezierDesc *b, float t )
{
if(!b->areCoefficientsComputed)
_GSBezierComputeCoefficients(b);
return b->a[0]+t*(b->a[1]+t*(b->a[2]+t*b->a[3]));
}
static inline float
_GSBezierDerivEval( _GSBezierDesc *b, float t )
{
if(!b->areCoefficientsComputed)
_GSBezierComputeCoefficients(b);
return b->a[1]+t*(2.0*b->a[2]+t*3.0*b->a[3]);
}
// Rational Bezier curve parameters
typedef struct __GSRationalBezierDesc
{
float w[4]; // weights
float p[4]; // control points
BOOL areBezierDescComputed;
_GSBezierDesc n; // numerator
_GSBezierDesc d; // denumerator
} _GSRationalBezierDesc;
static inline void
_GSRationalBezierComputeBezierDesc( _GSRationalBezierDesc *rb )
{
unsigned i;
for(i=0;i<4;i++)
rb->n.p[i] = (rb->d.p[i] = rb->w[i]) * rb->p[i];
_GSBezierComputeCoefficients(&rb->n);
_GSBezierComputeCoefficients(&rb->d);
rb->areBezierDescComputed = YES;
}
static inline float
_GSRationalBezierEval( _GSRationalBezierDesc *rb, float t)
{
if(!rb->areBezierDescComputed)
_GSRationalBezierComputeBezierDesc(rb);
return _GSBezierEval(&(rb->n),t)/_GSBezierEval(&(rb->d),t);
}
static inline float
_GSRationalBezierDerivEval( _GSRationalBezierDesc *rb, float t)
{
if(!rb->areBezierDescComputed)
_GSRationalBezierComputeBezierDesc(rb);
float h = _GSBezierEval(&(rb->d),t);
return ( _GSBezierDerivEval(&(rb->n),t) * h
- _GSBezierEval (&(rb->n),t) * _GSBezierDerivEval(&(rb->d),t) )
/ (h*h);
}
typedef struct __NSAnimationCurveDesc
{
float s,e; // start & end values
float sg,eg; // start & end gradients
_GSRationalBezierDesc rb;
BOOL isRBezierComputed;
} _NSAnimationCurveDesc;
extern
_NSAnimationCurveDesc *_gs_animationCurveDesc;
static inline float
_gs_animationValueForCurve( _NSAnimationCurveDesc *c, float t, float t0 )
{
if(!c->isRBezierComputed)
{
c->rb.p[0] = c->s;
c->rb.p[1] = c->s + (c->sg*c->rb.w[0])/(3*c->rb.w[1]);
c->rb.p[2] = c->e - (c->eg*c->rb.w[3])/(3*c->rb.w[2]);
c->rb.p[3] = c->e;
_GSRationalBezierComputeBezierDesc(&c->rb);
c->isRBezierComputed = YES;
}
return _GSRationalBezierEval( &(c->rb),(t-t0)/(1.0-t0) );
}
@class NSString; @class NSString;
@class NSArray; @class NSArray;
@class NSNumber; @class NSNumber;
@class NSRecursiveLock;
/** These constants describe the curve of an animation—that is, the relative speed of an animation from start to finish. */ /** These constants describe the curve of an animation—that is, the relative speed of an animation from start to finish. */
typedef enum _NSAnimationCurve typedef enum _NSAnimationCurve
@ -156,16 +57,46 @@ typedef enum _NSAnimationCurve
/** These constants indicate the blocking mode of an NSAnimation object when it is running. */ /** These constants indicate the blocking mode of an NSAnimation object when it is running. */
typedef enum _NSAnimationBlockingMode typedef enum _NSAnimationBlockingMode
{ {
NSAnimationBlocking = GSBlockingCocoaAnimation, NSAnimationBlocking,
NSAnimationNonblocking = GSNonblockingCocoaAnimation, NSAnimationNonblocking,
NSAnimationNonblockingThreaded = GSNonblockingCocoaThreadedAnimation NSAnimationNonblockingThreaded
} NSAnimationBlockingMode; } NSAnimationBlockingMode;
typedef float NSAnimationProgress; typedef float NSAnimationProgress;
// Bezier curve parameters
typedef struct __GSBezierDesc
{
float p[4]; // control points
BOOL areCoefficientsComputed;
float a[4]; // coefficients
} _GSBezierDesc;
// Rational Bezier curve parameters
typedef struct __GSRationalBezierDesc
{
float w[4]; // weights
float p[4]; // control points
BOOL areBezierDescComputed;
_GSBezierDesc n; // numerator
_GSBezierDesc d; // denumerator
} _GSRationalBezierDesc;
// Animation curve parameters
typedef struct __NSAnimationCurveDesc
{
float s,e; // start & end values
float sg,eg; // start & end gradients
_GSRationalBezierDesc rb;
BOOL isRBezierComputed;
} _NSAnimationCurveDesc;
/** Posted when the current progress of a running animation reaches one of its progress marks. */ /** Posted when the current progress of a running animation reaches one of its progress marks. */
APPKIT_EXPORT NSString *NSAnimationProgressMarkNotification; APPKIT_EXPORT NSString *NSAnimationProgressMarkNotification;
/** Key used in the [NSNotification-userInfo] disctionary to access the current progress mark. */
APPKIT_EXPORT NSString *NSAnimationProgressMark;
/** /**
* Objects of the NSAnimation class manage the timing and progress of * Objects of the NSAnimation class manage the timing and progress of
* animations in the user interface. The class also lets you link together * animations in the user interface. The class also lets you link together
@ -195,7 +126,7 @@ APPKIT_EXPORT NSString *NSAnimationProgressMarkNotification;
NSAnimationBlockingMode _blockingMode; // Blocking mode NSAnimationBlockingMode _blockingMode; // Blocking mode
GSAnimator *_animator; // The animator GSAnimator *_animator; // The animator
BOOL _isANewAnimatorNeeded; // Some parameters have changed... BOOL _isANewAnimatorNeeded; // Some parameters have changed...
id _delegate; // The delegate, and the cached delegation methods... id _delegate; // The delegate, and the cached delegation methods...
void (*_delegate_animationDidReachProgressMark)(id,SEL,NSAnimation*,NSAnimationProgress); void (*_delegate_animationDidReachProgressMark)(id,SEL,NSAnimation*,NSAnimationProgress);
@ -203,6 +134,10 @@ APPKIT_EXPORT NSString *NSAnimationProgressMarkNotification;
void (*_delegate_animationDidEnd )(id,SEL,NSAnimation*); void (*_delegate_animationDidEnd )(id,SEL,NSAnimation*);
void (*_delegate_animationDidStop )(id,SEL,NSAnimation*); void (*_delegate_animationDidStop )(id,SEL,NSAnimation*);
BOOL (*_delegate_animationShouldStart )(id,SEL,NSAnimation*); BOOL (*_delegate_animationShouldStart )(id,SEL,NSAnimation*);
id _currentDelegate; // The delegate when the animation is running
BOOL _isThreaded;
NSRecursiveLock *_isAnimatingLock;
} }
/** Adds the progress mark to the receiver. */ /** Adds the progress mark to the receiver. */
@ -245,44 +180,63 @@ APPKIT_EXPORT NSString *NSAnimationProgressMarkNotification;
/** Returns the receivers progress marks. */ /** Returns the receivers progress marks. */
- (NSArray*) progressMarks; - (NSArray*) progressMarks;
/** Removes progress mark from the receiver. */ /** Removes a progress mark from the receiver.
A value that does not correspond to a progress mark is ignored.*/
- (void) removeProgressMark: (NSAnimationProgress)progress; - (void) removeProgressMark: (NSAnimationProgress)progress;
/** Overridden to return the run-loop modes that the receiver uses to run the animation timer in. */ /** Overridden to return the run-loop modes that the receiver uses to run the
animation timer in. */
- (NSArray*) runLoopModesForAnimating; - (NSArray*) runLoopModesForAnimating;
/** Sets the blocking mode of the receiver. */ /** Sets the blocking mode of the receiver.
The new blocking mode takes effect the next time the receiver is started. */
- (void) setAnimationBlockingMode: (NSAnimationBlockingMode)mode; - (void) setAnimationBlockingMode: (NSAnimationBlockingMode)mode;
/** Sets the receivers animation curve. */ /** Sets the receivers animation curve.
The new value affects the animation already in progress : the actual
curve smoothly changes from the old curve to the new one. */
- (void) setAnimationCurve: (NSAnimationCurve)curve; - (void) setAnimationCurve: (NSAnimationCurve)curve;
/** Sets the current progress of the receiver. */ /** Sets the current progress of the receiver.
In the case of a forward jump the marks between the previous progress value
and the new (excluded) progress value are ignored. In the case of a
backward jump (rewind) the marks will be reached again. */
- (void) setCurrentProgress: (NSAnimationProgress)progress; - (void) setCurrentProgress: (NSAnimationProgress)progress;
/** Sets the delegate of the receiver. */ /** Sets the delegate of the receiver.
The new delegate takes effect the next time the receiver is started. */
- (void) setDelegate: (id)delegate; - (void) setDelegate: (id)delegate;
/** Sets the duration of the animation to a specified number of seconds. */ /** Sets the duration of the animation to a specified number of seconds.
If the duration is changed while the animation is running the <i>speed</i>
of the animation is not changed but the current progress value is
(see [-setCurrentprogress]). The new value takes effect at the next
frame. */
- (void) setDuration: (NSTimeInterval)duration; - (void) setDuration: (NSTimeInterval)duration;
/** Sets the frame rate of the receiver. */ /** Sets the frame rate of the receiver.
The new frame rate takes effect at the next frame. */
- (void) setFrameRate: (float)fps; - (void) setFrameRate: (float)fps;
/** Sets the receivers progress marks to the values specified in the passed-in array. */ /** Sets the receivers progress marks to the values specified in the
passed-in array. The new marks are t*/
- (void) setProgressMarks: (NSArray*)progress; - (void) setProgressMarks: (NSArray*)progress;
/** Starts the animation represented by the receiver. */ /** Starts the animation represented by the receiver.
If the animation is already running the method has no effect.*/
- (void) startAnimation; - (void) startAnimation;
/** Starts running the animation represented by the receiver when another animation reaches a specific progress mark. */ /** Starts running the animation represented by the receiver when another
animation reaches a specific progress mark. */
- (void) startWhenAnimation: (NSAnimation*)animation - (void) startWhenAnimation: (NSAnimation*)animation
reachesProgress: (NSAnimationProgress)start; reachesProgress: (NSAnimationProgress)start;
/** Stops the animation represented by the receiver. */ /** Stops the animation represented by the receiver.
If the animation is not running the method has no effect.*/
- (void) stopAnimation; - (void) stopAnimation;
/** Stops running the animation represented by the receiver when another animation reaches a specific progress mark. */ /** Stops running the animation represented by the receiver when another
animation reaches a specific progress mark. */
- (void) stopWhenAnimation: (NSAnimation*)animation - (void) stopWhenAnimation: (NSAnimation*)animation
reachesProgress: (NSAnimationProgress)stop; reachesProgress: (NSAnimationProgress)stop;

View file

@ -36,6 +36,8 @@
#include <AppKit/NSEvent.h> #include <AppKit/NSEvent.h>
#include <Foundation/NSDebug.h>
typedef enum { typedef enum {
NullEvent, NullEvent,
GSAnimationNextFrameEvent, GSAnimationNextFrameEvent,
@ -56,80 +58,63 @@ typedef enum {
{ } { }
@end @end
@interface GSThreadedTimerBasedAnimator : GSAnimator
{
NSThread* _thread;
}
@end
@implementation GSAnimator @implementation GSAnimator
+ (GSAnimator*) animatorWithAnimation: (id<GSAnimation>)anAnimation + (GSAnimator*) animatorWithAnimation: (id<GSAnimation>)anAnimation
mode: (GSAnimationBlockingMode)aMode
frameRate: (float)fps
{
return [self
animatorWithAnimation: anAnimation
mode: aMode
frameRate: fps
zone: NULL];
}
+ (GSAnimator*) animatorWithAnimation: (id<GSAnimation>)anAnimation
mode: (GSAnimationBlockingMode)aMode
frameRate: (float)fps frameRate: (float)fps
zone: (NSZone*)aZone zone: (NSZone*)aZone
{ {
GSAnimator* animator; GSAnimator* animator;
NSRunLoop* runLoop; animator = [[GSTimerBasedAnimator allocWithZone: aZone]
initWithAnimation: anAnimation
switch(aMode) frameRate: fps];
{//FIXME
case GSTimerBasedAnimation:
case GSPerformerBasedAnimation:
case GSBlockingCocoaAnimation:
case GSNonblockingCocoaAnimation:
case GSNonblockingCocoaThreadedAnimation:
runLoop = [NSRunLoop currentRunLoop];
animator = [[GSTimerBasedAnimator allocWithZone: aZone]
initWithAnimation: anAnimation
frameRate: fps
runLoop: runLoop];
}
AUTORELEASE(animator); AUTORELEASE(animator);
return animator; return animator;
} }
+ (GSAnimator*) animatorWithAnimation: (id<GSAnimation>)anAnimation
frameRate: (float)fps
{
return [self animatorWithAnimation: anAnimation
frameRate: fps
zone: NULL];
}
+ (GSAnimator*) animatorWithAnimation: (id<GSAnimation>)anAnimation
{
return [self animatorWithAnimation: anAnimation
frameRate: 0.0];
}
- (GSAnimator*) initWithAnimation: (id<GSAnimation>)anAnimation - (GSAnimator*) initWithAnimation: (id<GSAnimation>)anAnimation
frameRate: (float)aFrameRate frameRate: (float)fps
runLoop: (NSRunLoop*)aRunLoop
{ {
if((self = [super init])) if((self = [super init]))
{ {
_running = NO; _running = NO;
_animation = anAnimation; TEST_RETAIN(_animation); _animation = anAnimation; TEST_RETAIN(_animation);
_runLoop = aRunLoop; TEST_RETAIN(_runLoop); _runLoopModes = [NSArray arrayWithObject: NSDefaultRunLoopMode];
_timerInterval = (aFrameRate==0.0)?0.0:(1.0/aFrameRate); RETAIN(_runLoopModes);
_timerInterval = (fps==0.0)?0.0:(1.0/fps);
[self resetCounters]; [self resetCounters];
} }
return self; return self;
} }
- (GSAnimator*) initWithAnimation: (id<GSAnimation>)anAnimation - (GSAnimator*) initWithAnimation: (id<GSAnimation>)anAnimation
{ {
return [self initWithAnimation: anAnimation return [self initWithAnimation: anAnimation
frameRate: 0.0 frameRate: 0.0];
runLoop: [NSRunLoop currentRunLoop]];
} }
- (void) dealloc - (void) dealloc
{ {
[self stopAnimation]; [self stopAnimation];
TEST_RELEASE(_animation); TEST_RELEASE(_animation);
TEST_RELEASE(_runLoop);
TEST_RELEASE(_startTime); TEST_RELEASE(_startTime);
TEST_RELEASE(_runLoopModes);
[super dealloc]; [super dealloc];
} }
@ -146,32 +131,33 @@ typedef enum {
- (float) frameRate - (float) frameRate
{ return ((float)[self frameCount]) / ((float)_elapsed); } { return ((float)[self frameCount]) / ((float)_elapsed); }
- (NSRunLoop*) runLoopForAnimating
{ return _runLoop; }
- (NSArray*) runLoopModesForAnimating - (NSArray*) runLoopModesForAnimating
{ return [_animation runLoopModesForAnimating]; } { return _runLoopModes; }
- (void) setRunLoopModesForAnimating: (NSArray*)modes
{ ASSIGN (_runLoopModes,modes); }
- (void) startAnimation - (void) startAnimation
{ {
if(!_running) if(!_running)
{ {
_running = YES; _running = YES;
[self resetCounters]; [self resetCounters];
[_animation animatorDidStart]; [_animation animatorDidStart];
[self _animationBegin]; [self _animationBegin];
[self _animationLoop]; [self _animationLoop];
} NSDebugFLLog (@"GSAnimator",@"%@ Started !",self);
}
} }
- (void) stopAnimation - (void) stopAnimation
{ {
if(_running) if(_running)
{ {
_running = NO; _running = NO;
[self _animationEnd]; [self _animationEnd];
[_animation animatorDidStop]; [_animation animatorDidStop];
} }
} }
- (void) startStopAnimation - (void) startStopAnimation
@ -220,7 +206,7 @@ static int _GSTimerBasedAnimator_animator_count = 0;
+ (void) loopsAnimators + (void) loopsAnimators
{ {
switch(_GSTimerBasedAnimator_animator_count) switch(_GSTimerBasedAnimator_animator_count)
{ {
case 0: case 0:
break; break;
case 1: case 1:
@ -229,103 +215,120 @@ static int _GSTimerBasedAnimator_animator_count = 0;
default: default:
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
postNotificationName: @"GSTimerBasedAnimator_loop" object: self]; postNotificationName: @"GSTimerBasedAnimator_loop" object: self];
} }
} }
+ (void) registerAnimator: (GSTimerBasedAnimator*) anAnimator + (void) registerAnimator: (GSTimerBasedAnimator*)anAnimator
{ {
if(anAnimator->_timerInterval == 0.0) NSTimer* newTimer = nil;
{
[[NSNotificationCenter defaultCenter]
addObserver: anAnimator
selector: @selector(_animationLoop)
name: @"GSTimerBasedAnimator_loop"
object: self];
if(!_GSTimerBasedAnimator_animator_count++)
_GSTimerBasedAnimator_the_one_animator = anAnimator;
if(nil==_GSTimerBasedAnimator_animators) if(anAnimator->_timerInterval == 0.0)
_GSTimerBasedAnimator_animators = [[NSMutableSet alloc] initWithCapacity: 5];
[_GSTimerBasedAnimator_animators addObject: anAnimator];
if(nil==_GSTimerBasedAnimator_timer)
{ {
_GSTimerBasedAnimator_timer = [NSTimer NSDebugFLLog (@"GSAnimator",@"%@ AFAP",anAnimator);
scheduledTimerWithTimeInterval: 0.0 [[NSNotificationCenter defaultCenter]
target: self addObserver: anAnimator
selector: @selector(loopsAnimators) selector: @selector(_animationLoop)
userInfo: nil name: @"GSTimerBasedAnimator_loop"
repeats: YES object: self];
];
TEST_RETAIN(_GSTimerBasedAnimator_timer); if(!_GSTimerBasedAnimator_animator_count++)
_GSTimerBasedAnimator_the_one_animator = anAnimator;
if(nil==_GSTimerBasedAnimator_animators)
_GSTimerBasedAnimator_animators = [[NSMutableSet alloc] initWithCapacity: 5];
[_GSTimerBasedAnimator_animators addObject: anAnimator];
if(nil==_GSTimerBasedAnimator_timer)
{
newTimer =
_GSTimerBasedAnimator_timer = [NSTimer
timerWithTimeInterval: 0.0
target: self
selector: @selector(loopsAnimators)
userInfo: nil
repeats: YES
];
}
} }
}
else else
{ {
anAnimator->_timer = [NSTimer NSDebugFLLog (@"GSAnimator",@"%@ Fixed frame rate",anAnimator);
scheduledTimerWithTimeInterval: anAnimator->_timerInterval newTimer =
target: anAnimator anAnimator->_timer = [NSTimer
selector: @selector(_animationLoop) timerWithTimeInterval: anAnimator->_timerInterval
userInfo: nil target: anAnimator
repeats: YES selector: @selector(_animationLoop)
]; userInfo: nil
TEST_RETAIN(anAnimator->_timer); repeats: YES
} ];
}
if(newTimer!=nil)
{
unsigned i,c;
TEST_RETAIN(newTimer);
for (i=0,c=[anAnimator->_runLoopModes count]; i<c; i++)
[[NSRunLoop currentRunLoop]
addTimer: newTimer
forMode: [anAnimator->_runLoopModes objectAtIndex:i]];
NSDebugFLLog (@"GSAnimator",@"%@ addTimer in %d mode(s)",anAnimator,c);
}
} }
+ (void) unregisterAnimator: (GSTimerBasedAnimator*) anAnimator + (void) unregisterAnimator: (GSTimerBasedAnimator*)anAnimator
{ {
if(anAnimator->_timerInterval == 0.0) if(anAnimator->_timerInterval == 0.0)
{ {
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
removeObserver: anAnimator removeObserver: anAnimator
name: @"GSTimerBasedAnimator_loop" name: @"GSTimerBasedAnimator_loop"
object: self]; object: self];
[_GSTimerBasedAnimator_animators removeObject: anAnimator]; [_GSTimerBasedAnimator_animators removeObject: anAnimator];
if(!--_GSTimerBasedAnimator_animator_count) if(!--_GSTimerBasedAnimator_animator_count)
{ {
[_GSTimerBasedAnimator_timer invalidate]; [_GSTimerBasedAnimator_timer invalidate];
DESTROY(_GSTimerBasedAnimator_timer); DESTROY(_GSTimerBasedAnimator_timer);
_GSTimerBasedAnimator_the_one_animator = nil; _GSTimerBasedAnimator_the_one_animator = nil;
}
else
if(_GSTimerBasedAnimator_the_one_animator==anAnimator)
_GSTimerBasedAnimator_the_one_animator
= [_GSTimerBasedAnimator_animators anyObject];
} }
else
if(_GSTimerBasedAnimator_the_one_animator==anAnimator)
_GSTimerBasedAnimator_the_one_animator
= [_GSTimerBasedAnimator_animators anyObject];
}
else else
{
if(anAnimator->_timer != nil)
{ {
[anAnimator->_timer invalidate]; if(anAnimator->_timer != nil)
DESTROY(anAnimator->_timer); {
[anAnimator->_timer invalidate];
DESTROY(anAnimator->_timer);
}
} }
}
} }
- (void) _animationBegin - (void) _animationBegin
{ {
NSDebugFLLog (@"GSAnimator",@"%@",self);
[[self class] registerAnimator: self]; [[self class] registerAnimator: self];
} }
- (void) _animationLoop - (void) _animationLoop
{ {
NSDebugFLLog (@"GSAnimator",@"%@",self);
[self stepAnimation]; [self stepAnimation];
} }
- (void) _animationEnd - (void) _animationEnd
{ {
NSDebugFLLog (@"GSAnimator",@"%@",self);
[[self class] unregisterAnimator: self]; [[self class] unregisterAnimator: self];
} }
@end @end // implementation GSTimerBasedAnimator
static void _sendAnimationPerformer( GSAnimator* animator ) static void _sendAnimationPerformer( GSAnimator* animator )
{ {
[[animator runLoopForAnimating] [[NSRunLoop currentRunLoop]
performSelector: @selector(_animationLoop) performSelector: @selector(_animationLoop)
target: animator target: animator
argument: nil argument: nil
@ -336,7 +339,7 @@ static void _sendAnimationPerformer( GSAnimator* animator )
static void _cancelAnimationPerformer( GSAnimator* animator ) static void _cancelAnimationPerformer( GSAnimator* animator )
{ {
[[animator runLoopForAnimating] cancelPerformSelectorsWithTarget: animator]; [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: animator];
} }
@implementation GSPerformerBasedAnimator @implementation GSPerformerBasedAnimator

File diff suppressed because it is too large Load diff