mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 15:11:37 +00:00
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:
parent
f7850daa26
commit
3f9af34a0f
5 changed files with 1076 additions and 751 deletions
14
ChangeLog
14
ChangeLog
|
@ -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>
|
||||
|
||||
* Source/NSView.m: When transforming a size ensure that the
|
||||
|
@ -23,7 +35,7 @@
|
|||
2007-04-05 Xavier Glattard <xavier.glattard@online.fr>
|
||||
|
||||
* Headers/AppKit/NSAnimation.h
|
||||
* Source/NSAnimation.m
|
||||
* Source/NSAnimation.m
|
||||
* Headers/Additions/GNUstepGUI/GSAnimator.h
|
||||
* Source/GSAnimator.m
|
||||
Implementation of NSAnimation and NSViewAnimation classes :
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
*
|
||||
* Copyright (c) 2007 Free Software Foundation, Inc.
|
||||
*
|
||||
* This file used to be part of the mySTEP Library.
|
||||
* This file now is part of the GNUstep GUI Library.
|
||||
* This file is part of the GNUstep GUI Library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
|
@ -31,7 +30,7 @@
|
|||
@class NSRunLoop;
|
||||
@class NSEvent;
|
||||
@class NSTimer;
|
||||
@class NSThread;
|
||||
@class NSString;
|
||||
|
||||
#include <Foundation/NSObject.h>
|
||||
#include <Foundation/NSDate.h>
|
||||
|
@ -42,8 +41,6 @@
|
|||
* be animated by a GSAnimator.
|
||||
*/
|
||||
@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
|
||||
* animation loop. */
|
||||
- (void) animatorDidStart;
|
||||
|
@ -51,64 +48,56 @@
|
|||
* animation loop. */
|
||||
- (void) animatorDidStop;
|
||||
/** Call back method called for each animation loop. */
|
||||
- (void) animatorStep: (NSTimeInterval) elapsedTime;
|
||||
- (void) animatorStep: (NSTimeInterval)elapsedTime;
|
||||
@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 manages the timing of an animation.
|
||||
* GSAnimator manage the timing of an animation.
|
||||
*/
|
||||
@interface GSAnimator : NSObject
|
||||
{
|
||||
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
|
||||
|
||||
NSTimeInterval _elapsed; // Elapsed time since the animator started
|
||||
NSTimeInterval _lastFrame; // The time of the last animation loop
|
||||
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;
|
||||
}
|
||||
|
||||
/** 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
|
||||
* to be animated. */
|
||||
+ (GSAnimator*) animatorWithAnimation: (id<GSAnimation>)anAnimation
|
||||
mode: (GSAnimationBlockingMode)aMode
|
||||
frameRate: (float)fps;
|
||||
|
||||
/** Returns a GSAnimator object allocated in the given NSZone and
|
||||
* initialized with the specified object to be animated. */
|
||||
+ (GSAnimator*) animatorWithAnimation: (id<GSAnimation>)anAnimation
|
||||
mode: (GSAnimationBlockingMode)aMode
|
||||
frameRate: (float)fps
|
||||
zone: (NSZone*)aZone;
|
||||
|
||||
/** 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
|
||||
frameRate: (float)aFrameRate
|
||||
runLoop: (NSRunLoop*)aRunLoop;
|
||||
frameRate: (float)aFrameRate;
|
||||
|
||||
- (GSAnimator*) initWithAnimation: (id<GSAnimation>)anAnimation;
|
||||
|
||||
- (unsigned int) frameCount;
|
||||
- (void) resetCounters;
|
||||
- (float) frameRate;
|
||||
- (NSRunLoop*) runLoopForAnimating;
|
||||
- (NSArray*) runLoopModesForAnimating;
|
||||
- (void) setRunLoopModesForAnimating: (NSArray*)modes;
|
||||
|
||||
- (void) startAnimation;
|
||||
- (void) stopAnimation;
|
||||
|
|
|
@ -39,109 +39,10 @@
|
|||
#include <Foundation/NSString.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 NSArray;
|
||||
@class NSNumber;
|
||||
@class NSRecursiveLock;
|
||||
|
||||
/** These constants describe the curve of an animation—that is, the relative speed of an animation from start to finish. */
|
||||
typedef enum _NSAnimationCurve
|
||||
|
@ -156,16 +57,46 @@ typedef enum _NSAnimationCurve
|
|||
/** These constants indicate the blocking mode of an NSAnimation object when it is running. */
|
||||
typedef enum _NSAnimationBlockingMode
|
||||
{
|
||||
NSAnimationBlocking = GSBlockingCocoaAnimation,
|
||||
NSAnimationNonblocking = GSNonblockingCocoaAnimation,
|
||||
NSAnimationNonblockingThreaded = GSNonblockingCocoaThreadedAnimation
|
||||
NSAnimationBlocking,
|
||||
NSAnimationNonblocking,
|
||||
NSAnimationNonblockingThreaded
|
||||
} NSAnimationBlockingMode;
|
||||
|
||||
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. */
|
||||
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
|
||||
* animations in the user interface. The class also lets you link together
|
||||
|
@ -195,7 +126,7 @@ APPKIT_EXPORT NSString *NSAnimationProgressMarkNotification;
|
|||
|
||||
NSAnimationBlockingMode _blockingMode; // Blocking mode
|
||||
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...
|
||||
void (*_delegate_animationDidReachProgressMark)(id,SEL,NSAnimation*,NSAnimationProgress);
|
||||
|
@ -203,6 +134,10 @@ APPKIT_EXPORT NSString *NSAnimationProgressMarkNotification;
|
|||
void (*_delegate_animationDidEnd )(id,SEL,NSAnimation*);
|
||||
void (*_delegate_animationDidStop )(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. */
|
||||
|
@ -245,44 +180,63 @@ APPKIT_EXPORT NSString *NSAnimationProgressMarkNotification;
|
|||
/** Returns the receiver’s progress marks. */
|
||||
- (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;
|
||||
|
||||
/** 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;
|
||||
|
||||
/** 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;
|
||||
|
||||
/** Sets the receiver’s animation curve. */
|
||||
/** Sets the receiver’s 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;
|
||||
|
||||
/** 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;
|
||||
|
||||
/** 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;
|
||||
|
||||
/** 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;
|
||||
|
||||
/** 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;
|
||||
|
||||
/** Sets the receiver’s progress marks to the values specified in the passed-in array. */
|
||||
/** Sets the receiver’s progress marks to the values specified in the
|
||||
passed-in array. The new marks are t*/
|
||||
- (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;
|
||||
|
||||
/** 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
|
||||
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;
|
||||
|
||||
/** 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
|
||||
reachesProgress: (NSAnimationProgress)stop;
|
||||
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
|
||||
#include <AppKit/NSEvent.h>
|
||||
|
||||
#include <Foundation/NSDebug.h>
|
||||
|
||||
typedef enum {
|
||||
NullEvent,
|
||||
GSAnimationNextFrameEvent,
|
||||
|
@ -56,80 +58,63 @@ typedef enum {
|
|||
{ }
|
||||
@end
|
||||
|
||||
@interface GSThreadedTimerBasedAnimator : GSAnimator
|
||||
{
|
||||
NSThread* _thread;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation GSAnimator
|
||||
|
||||
+ (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
|
||||
zone: (NSZone*)aZone
|
||||
{
|
||||
GSAnimator* animator;
|
||||
NSRunLoop* runLoop;
|
||||
|
||||
switch(aMode)
|
||||
{//FIXME
|
||||
case GSTimerBasedAnimation:
|
||||
case GSPerformerBasedAnimation:
|
||||
case GSBlockingCocoaAnimation:
|
||||
case GSNonblockingCocoaAnimation:
|
||||
case GSNonblockingCocoaThreadedAnimation:
|
||||
runLoop = [NSRunLoop currentRunLoop];
|
||||
animator = [[GSTimerBasedAnimator allocWithZone: aZone]
|
||||
initWithAnimation: anAnimation
|
||||
frameRate: fps
|
||||
runLoop: runLoop];
|
||||
}
|
||||
animator = [[GSTimerBasedAnimator allocWithZone: aZone]
|
||||
initWithAnimation: anAnimation
|
||||
frameRate: fps];
|
||||
AUTORELEASE(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
|
||||
frameRate: (float)aFrameRate
|
||||
runLoop: (NSRunLoop*)aRunLoop
|
||||
frameRate: (float)fps
|
||||
{
|
||||
if((self = [super init]))
|
||||
{
|
||||
_running = NO;
|
||||
|
||||
_animation = anAnimation; TEST_RETAIN(_animation);
|
||||
_runLoop = aRunLoop; TEST_RETAIN(_runLoop);
|
||||
_timerInterval = (aFrameRate==0.0)?0.0:(1.0/aFrameRate);
|
||||
{
|
||||
_running = NO;
|
||||
|
||||
_animation = anAnimation; TEST_RETAIN(_animation);
|
||||
_runLoopModes = [NSArray arrayWithObject: NSDefaultRunLoopMode];
|
||||
RETAIN(_runLoopModes);
|
||||
_timerInterval = (fps==0.0)?0.0:(1.0/fps);
|
||||
|
||||
[self resetCounters];
|
||||
}
|
||||
[self resetCounters];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (GSAnimator*) initWithAnimation: (id<GSAnimation>)anAnimation
|
||||
{
|
||||
return [self initWithAnimation: anAnimation
|
||||
frameRate: 0.0
|
||||
runLoop: [NSRunLoop currentRunLoop]];
|
||||
frameRate: 0.0];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[self stopAnimation];
|
||||
TEST_RELEASE(_animation);
|
||||
TEST_RELEASE(_runLoop);
|
||||
TEST_RELEASE(_startTime);
|
||||
TEST_RELEASE(_runLoopModes);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -146,32 +131,33 @@ typedef enum {
|
|||
- (float) frameRate
|
||||
{ return ((float)[self frameCount]) / ((float)_elapsed); }
|
||||
|
||||
- (NSRunLoop*) runLoopForAnimating
|
||||
{ return _runLoop; }
|
||||
|
||||
- (NSArray*) runLoopModesForAnimating
|
||||
{ return [_animation runLoopModesForAnimating]; }
|
||||
{ return _runLoopModes; }
|
||||
|
||||
- (void) setRunLoopModesForAnimating: (NSArray*)modes
|
||||
{ ASSIGN (_runLoopModes,modes); }
|
||||
|
||||
- (void) startAnimation
|
||||
{
|
||||
if(!_running)
|
||||
{
|
||||
_running = YES;
|
||||
[self resetCounters];
|
||||
[_animation animatorDidStart];
|
||||
[self _animationBegin];
|
||||
[self _animationLoop];
|
||||
}
|
||||
{
|
||||
_running = YES;
|
||||
[self resetCounters];
|
||||
[_animation animatorDidStart];
|
||||
[self _animationBegin];
|
||||
[self _animationLoop];
|
||||
NSDebugFLLog (@"GSAnimator",@"%@ Started !",self);
|
||||
}
|
||||
}
|
||||
|
||||
- (void) stopAnimation
|
||||
{
|
||||
if(_running)
|
||||
{
|
||||
_running = NO;
|
||||
[self _animationEnd];
|
||||
[_animation animatorDidStop];
|
||||
}
|
||||
{
|
||||
_running = NO;
|
||||
[self _animationEnd];
|
||||
[_animation animatorDidStop];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) startStopAnimation
|
||||
|
@ -220,7 +206,7 @@ static int _GSTimerBasedAnimator_animator_count = 0;
|
|||
+ (void) loopsAnimators
|
||||
{
|
||||
switch(_GSTimerBasedAnimator_animator_count)
|
||||
{
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
|
@ -229,103 +215,120 @@ static int _GSTimerBasedAnimator_animator_count = 0;
|
|||
default:
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName: @"GSTimerBasedAnimator_loop" object: self];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+ (void) registerAnimator: (GSTimerBasedAnimator*) anAnimator
|
||||
+ (void) registerAnimator: (GSTimerBasedAnimator*)anAnimator
|
||||
{
|
||||
if(anAnimator->_timerInterval == 0.0)
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver: anAnimator
|
||||
selector: @selector(_animationLoop)
|
||||
name: @"GSTimerBasedAnimator_loop"
|
||||
object: self];
|
||||
|
||||
if(!_GSTimerBasedAnimator_animator_count++)
|
||||
_GSTimerBasedAnimator_the_one_animator = anAnimator;
|
||||
NSTimer* newTimer = nil;
|
||||
|
||||
if(nil==_GSTimerBasedAnimator_animators)
|
||||
_GSTimerBasedAnimator_animators = [[NSMutableSet alloc] initWithCapacity: 5];
|
||||
[_GSTimerBasedAnimator_animators addObject: anAnimator];
|
||||
|
||||
if(nil==_GSTimerBasedAnimator_timer)
|
||||
if(anAnimator->_timerInterval == 0.0)
|
||||
{
|
||||
_GSTimerBasedAnimator_timer = [NSTimer
|
||||
scheduledTimerWithTimeInterval: 0.0
|
||||
target: self
|
||||
selector: @selector(loopsAnimators)
|
||||
userInfo: nil
|
||||
repeats: YES
|
||||
];
|
||||
TEST_RETAIN(_GSTimerBasedAnimator_timer);
|
||||
NSDebugFLLog (@"GSAnimator",@"%@ AFAP",anAnimator);
|
||||
[[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)
|
||||
_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
|
||||
{
|
||||
anAnimator->_timer = [NSTimer
|
||||
scheduledTimerWithTimeInterval: anAnimator->_timerInterval
|
||||
target: anAnimator
|
||||
selector: @selector(_animationLoop)
|
||||
userInfo: nil
|
||||
repeats: YES
|
||||
];
|
||||
TEST_RETAIN(anAnimator->_timer);
|
||||
}
|
||||
{
|
||||
NSDebugFLLog (@"GSAnimator",@"%@ Fixed frame rate",anAnimator);
|
||||
newTimer =
|
||||
anAnimator->_timer = [NSTimer
|
||||
timerWithTimeInterval: anAnimator->_timerInterval
|
||||
target: anAnimator
|
||||
selector: @selector(_animationLoop)
|
||||
userInfo: nil
|
||||
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)
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
removeObserver: anAnimator
|
||||
name: @"GSTimerBasedAnimator_loop"
|
||||
object: self];
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
removeObserver: anAnimator
|
||||
name: @"GSTimerBasedAnimator_loop"
|
||||
object: self];
|
||||
|
||||
[_GSTimerBasedAnimator_animators removeObject: anAnimator];
|
||||
|
||||
if(!--_GSTimerBasedAnimator_animator_count)
|
||||
{
|
||||
[_GSTimerBasedAnimator_timer invalidate];
|
||||
DESTROY(_GSTimerBasedAnimator_timer);
|
||||
_GSTimerBasedAnimator_the_one_animator = nil;
|
||||
[_GSTimerBasedAnimator_animators removeObject: anAnimator];
|
||||
|
||||
if(!--_GSTimerBasedAnimator_animator_count)
|
||||
{
|
||||
[_GSTimerBasedAnimator_timer invalidate];
|
||||
DESTROY(_GSTimerBasedAnimator_timer);
|
||||
_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
|
||||
{
|
||||
if(anAnimator->_timer != nil)
|
||||
{
|
||||
[anAnimator->_timer invalidate];
|
||||
DESTROY(anAnimator->_timer);
|
||||
if(anAnimator->_timer != nil)
|
||||
{
|
||||
[anAnimator->_timer invalidate];
|
||||
DESTROY(anAnimator->_timer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) _animationBegin
|
||||
{
|
||||
NSDebugFLLog (@"GSAnimator",@"%@",self);
|
||||
[[self class] registerAnimator: self];
|
||||
}
|
||||
|
||||
- (void) _animationLoop
|
||||
{
|
||||
NSDebugFLLog (@"GSAnimator",@"%@",self);
|
||||
[self stepAnimation];
|
||||
}
|
||||
|
||||
- (void) _animationEnd
|
||||
{
|
||||
NSDebugFLLog (@"GSAnimator",@"%@",self);
|
||||
[[self class] unregisterAnimator: self];
|
||||
}
|
||||
|
||||
@end
|
||||
@end // implementation GSTimerBasedAnimator
|
||||
|
||||
static void _sendAnimationPerformer( GSAnimator* animator )
|
||||
{
|
||||
[[animator runLoopForAnimating]
|
||||
[[NSRunLoop currentRunLoop]
|
||||
performSelector: @selector(_animationLoop)
|
||||
target: animator
|
||||
argument: nil
|
||||
|
@ -336,7 +339,7 @@ static void _sendAnimationPerformer( GSAnimator* animator )
|
|||
|
||||
static void _cancelAnimationPerformer( GSAnimator* animator )
|
||||
{
|
||||
[[animator runLoopForAnimating] cancelPerformSelectorsWithTarget: animator];
|
||||
[[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: animator];
|
||||
}
|
||||
|
||||
@implementation GSPerformerBasedAnimator
|
||||
|
|
1331
Source/NSAnimation.m
1331
Source/NSAnimation.m
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue