mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 22:00:46 +00:00
Implementation of NSAnimation and NSViewAnimation classes :
- only NSAnimationNonBlocking mode is implemented - runLoopModesForAnimating is not used GSAnimator class is in alpha stage : interface may be changed git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@24968 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
66fcff3b42
commit
b7c5595766
6 changed files with 1622 additions and 126 deletions
123
Headers/Additions/GNUstepGUI/GSAnimator.h
Normal file
123
Headers/Additions/GNUstepGUI/GSAnimator.h
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
/*
|
||||||
|
* GSAnimator.h
|
||||||
|
*
|
||||||
|
* Author: Xavier Glattard (xgl) <xavier.glattard@online.fr>
|
||||||
|
*
|
||||||
|
* 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 library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; see the file COPYING.LIB.
|
||||||
|
* If not, write to the Free Software Foundation,
|
||||||
|
* 51 Franklin Street, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _GNUstep_H_GSAnimator_
|
||||||
|
#define _GNUstep_H_GSAnimator_
|
||||||
|
|
||||||
|
@class NSRunLoop;
|
||||||
|
@class NSEvent;
|
||||||
|
@class NSTimer;
|
||||||
|
@class NSThread;
|
||||||
|
|
||||||
|
#include <Foundation/NSObject.h>
|
||||||
|
#include <Foundation/NSDate.h>
|
||||||
|
#include <Foundation/NSTimer.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Protocol that needs to be adopted by classes that want to
|
||||||
|
* 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;
|
||||||
|
/** Call back method indicating that the GSAnimator did stop the
|
||||||
|
* animation loop. */
|
||||||
|
- (void) animatorDidStop;
|
||||||
|
/** Call back method called for each animation loop. */
|
||||||
|
- (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.
|
||||||
|
*/
|
||||||
|
@interface GSAnimator : NSObject
|
||||||
|
{
|
||||||
|
id<GSAnimation> _animation; // The Object to be animated
|
||||||
|
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
|
||||||
|
|
||||||
|
NSTimer *_timer; // Timer used for looping
|
||||||
|
NSTimeInterval _timerInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 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. */
|
||||||
|
- (GSAnimator*) initWithAnimation: (id<GSAnimation>)anAnimation
|
||||||
|
frameRate: (float)aFrameRate
|
||||||
|
runLoop: (NSRunLoop*)aRunLoop;
|
||||||
|
- (GSAnimator*) initWithAnimation: (id<GSAnimation>)anAnimation;
|
||||||
|
|
||||||
|
- (unsigned int) frameCount;
|
||||||
|
- (void) resetCounters;
|
||||||
|
- (float) frameRate;
|
||||||
|
- (NSRunLoop*) runLoopForAnimating;
|
||||||
|
- (NSArray*) runLoopModesForAnimating;
|
||||||
|
|
||||||
|
- (void) startAnimation;
|
||||||
|
- (void) stopAnimation;
|
||||||
|
- (BOOL) isAnimationRunning;
|
||||||
|
- (void) startStopAnimation;
|
||||||
|
|
||||||
|
- (void) stepAnimation;
|
||||||
|
|
||||||
|
- (void) animationLoopEvent: (NSEvent*)e;
|
||||||
|
@end
|
||||||
|
|
||||||
|
#endif /* _GNUstep_H_GSAnimator_ */
|
|
@ -45,6 +45,7 @@
|
||||||
#include <AppKit/NSGraphics.h>
|
#include <AppKit/NSGraphics.h>
|
||||||
|
|
||||||
#include <AppKit/NSActionCell.h>
|
#include <AppKit/NSActionCell.h>
|
||||||
|
#include <AppKit/NSAnimation.h>
|
||||||
#include <AppKit/NSApplication.h>
|
#include <AppKit/NSApplication.h>
|
||||||
#include <AppKit/NSAttributedString.h>
|
#include <AppKit/NSAttributedString.h>
|
||||||
#include <AppKit/NSBitmapImageRep.h>
|
#include <AppKit/NSBitmapImageRep.h>
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
* NSAnimation.h
|
* NSAnimation.h
|
||||||
*
|
*
|
||||||
* Created by Dr. H. Nikolaus Schaller on Sat Jan 07 2006.
|
* Created by Dr. H. Nikolaus Schaller on Sat Jan 07 2006.
|
||||||
* Copyright (c) 2005 DSITRI.
|
* Copyright (c) 2007 Free Software Foundation, Inc.
|
||||||
|
*
|
||||||
|
* Author: Xavier Glattard (xgl) <xavier.glattard@online.fr>
|
||||||
*
|
*
|
||||||
* This file used to be part of the mySTEP Library.
|
* This file used to be part of the mySTEP Library.
|
||||||
* This file now is part of the GNUstep GUI Library.
|
* This file now is part of the GNUstep GUI Library.
|
||||||
|
@ -24,106 +26,339 @@
|
||||||
* Boston, MA 02110-1301, USA.
|
* Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _NSAnimation_h_GNUstep_
|
#ifndef _GNUstep_H_NSAnimation_
|
||||||
#define _NSAnimation_h_GNUstep_
|
#define _GNUstep_H_NSAnimation_
|
||||||
|
|
||||||
#include <Foundation/Foundation.h>
|
#include <GNUstepBase/GSVersionMacros.h>
|
||||||
|
|
||||||
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
|
||||||
|
|
||||||
|
#include <Foundation/NSObject.h>
|
||||||
|
#include <AppKit/AppKitDefines.h>
|
||||||
|
#include <GNUstepGUI/GSAnimator.h>
|
||||||
|
#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;
|
||||||
|
|
||||||
|
/** 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
|
||||||
{
|
{
|
||||||
NSAnimationEaseInOut = 0, // default
|
NSAnimationEaseInOut = 0, // default
|
||||||
NSAnimationEaseIn,
|
NSAnimationEaseIn,
|
||||||
NSAnimationEaseOut,
|
NSAnimationEaseOut,
|
||||||
NSAnimationLinear
|
NSAnimationLinear,
|
||||||
|
NSAnimationSpeedInOut // GNUstep only
|
||||||
} NSAnimationCurve;
|
} NSAnimationCurve;
|
||||||
|
|
||||||
|
/** These constants indicate the blocking mode of an NSAnimation object when it is running. */
|
||||||
typedef enum _NSAnimationBlockingMode
|
typedef enum _NSAnimationBlockingMode
|
||||||
{
|
{
|
||||||
NSAnimationBlocking,
|
NSAnimationBlocking = GSBlockingCocoaAnimation,
|
||||||
NSAnimationNonblocking,
|
NSAnimationNonblocking = GSNonblockingCocoaAnimation,
|
||||||
NSAnimationNonblockingThreaded
|
NSAnimationNonblockingThreaded = GSNonblockingCocoaThreadedAnimation
|
||||||
} NSAnimationBlockingMode;
|
} NSAnimationBlockingMode;
|
||||||
|
|
||||||
typedef float NSAnimationProgress;
|
typedef float NSAnimationProgress;
|
||||||
|
|
||||||
extern NSString *NSAnimationProgressMarkNotification;
|
/** Posted when the current progress of a running animation reaches one of its progress marks. */
|
||||||
|
APPKIT_EXPORT NSString *NSAnimationProgressMarkNotification;
|
||||||
|
|
||||||
@interface NSAnimation : NSObject < NSCopying, NSCoding >
|
/**
|
||||||
|
* Objects of the NSAnimation class manage the timing and progress of
|
||||||
|
* animations in the user interface. The class also lets you link together
|
||||||
|
* multiple animations so that when one animation ends another one starts.
|
||||||
|
* It does not provide any drawing support for animation and does not directly
|
||||||
|
* deal with views, targets, or actions.
|
||||||
|
*/
|
||||||
|
@interface NSAnimation : NSObject < NSCopying, NSCoding, GSAnimation >
|
||||||
{
|
{
|
||||||
NSAnimationBlockingMode _animationBlockingMode;
|
NSTimeInterval _duration; // Duration of the animation
|
||||||
NSAnimationCurve _animationCurve;
|
float _frameRate; // Wanted frame rate
|
||||||
NSAnimationProgress _currentProgress;
|
NSAnimationCurve _curve; // Id of progres->value function
|
||||||
NSMutableArray *_progressMarks;
|
_NSAnimationCurveDesc _curveDesc; // The curve as a rat. Bezier
|
||||||
id _delegate;
|
NSAnimationProgress _curveProgressShift;// Shift used for switching
|
||||||
NSTimeInterval _duration;
|
// from a curve to an other
|
||||||
float _currentValue;
|
NSAnimationProgress _currentProgress; // Progress of the animation
|
||||||
float _frameRate;
|
|
||||||
BOOL _isAnimating; // ?or the NSThread *
|
/* GSIArray<NSAnimationProgress> */ void *_progressMarks; // Array
|
||||||
|
unsigned int _nextMark; // The next mark to be reached
|
||||||
|
// = count if no next mark
|
||||||
|
NSNumber **_cachedProgressMarkNumbers; // Cached values used by
|
||||||
|
unsigned _cachedProgressMarkNumberCount;// [-progressMarks]
|
||||||
|
BOOL _isCachedProgressMarkNumbersValid;
|
||||||
|
|
||||||
|
NSAnimation *_startAnimation, *_stopAnimation; // Animations used as
|
||||||
|
NSAnimationProgress _startMark, _stopMark; // trigger, and marks
|
||||||
|
|
||||||
|
NSAnimationBlockingMode _blockingMode; // Blocking mode
|
||||||
|
GSAnimator *_animator; // The animator
|
||||||
|
BOOL _isANewAnimatorNeeded; // Some parameters have changed...
|
||||||
|
|
||||||
|
id _delegate; // The delegate, and the cached delegation methods...
|
||||||
|
void (*_delegate_animationDidReachProgressMark)(id,SEL,NSAnimation*,NSAnimationProgress);
|
||||||
|
float (*_delegate_animationValueForProgress )(id,SEL,NSAnimation*,NSAnimationProgress);
|
||||||
|
void (*_delegate_animationDidEnd )(id,SEL,NSAnimation*);
|
||||||
|
void (*_delegate_animationDidStop )(id,SEL,NSAnimation*);
|
||||||
|
BOOL (*_delegate_animationShouldStart )(id,SEL,NSAnimation*);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) addProgressMark: (NSAnimationProgress) progress;
|
/** Adds the progress mark to the receiver. */
|
||||||
|
- (void) addProgressMark: (NSAnimationProgress)progress;
|
||||||
|
|
||||||
|
/** Returns the blocking mode the receiver is next scheduled to run under. */
|
||||||
- (NSAnimationBlockingMode) animationBlockingMode;
|
- (NSAnimationBlockingMode) animationBlockingMode;
|
||||||
|
|
||||||
|
/** Returns the animation curve the receiver is running under. */
|
||||||
- (NSAnimationCurve) animationCurve;
|
- (NSAnimationCurve) animationCurve;
|
||||||
|
|
||||||
|
/** Clears linkage to another animation that causes the receiver to start. */
|
||||||
- (void) clearStartAnimation;
|
- (void) clearStartAnimation;
|
||||||
|
|
||||||
|
/** Clears linkage to another animation that causes the receiver to stop. */
|
||||||
- (void) clearStopAnimation;
|
- (void) clearStopAnimation;
|
||||||
|
|
||||||
|
/** Returns the current progress of the receiver. */
|
||||||
- (NSAnimationProgress) currentProgress;
|
- (NSAnimationProgress) currentProgress;
|
||||||
|
|
||||||
|
/** Returns the current value of the effect based on the current progress. */
|
||||||
- (float) currentValue;
|
- (float) currentValue;
|
||||||
|
|
||||||
|
/** Returns the delegate of the receiver. */
|
||||||
- (id) delegate;
|
- (id) delegate;
|
||||||
|
|
||||||
|
/** Returns the duration of the animation, in seconds. */
|
||||||
- (NSTimeInterval) duration;
|
- (NSTimeInterval) duration;
|
||||||
|
|
||||||
|
/** Returns the frame rate of the animation. */
|
||||||
- (float) frameRate;
|
- (float) frameRate;
|
||||||
- (id) initWithDuration: (NSTimeInterval) duration animationCurve:
|
|
||||||
(NSAnimationCurve) curve;
|
/** Returns an NSAnimation object initialized with the specified duration and animation-curve values. */
|
||||||
|
- (id) initWithDuration: (NSTimeInterval)duration
|
||||||
|
animationCurve: (NSAnimationCurve)curve;
|
||||||
|
|
||||||
|
/** Returns a Boolean value that indicates whether the receiver is currently animating. */
|
||||||
- (BOOL) isAnimating;
|
- (BOOL) isAnimating;
|
||||||
- (NSArray *) progressMarks;
|
|
||||||
- (void) removeProgressMark: (NSAnimationProgress) progress;
|
/** Returns the receiver’s progress marks. */
|
||||||
- (NSArray *) runLoopModesForAnimating;
|
- (NSArray*) progressMarks;
|
||||||
- (void) setAnimationBlockingMode: (NSAnimationBlockingMode) mode;
|
|
||||||
- (void) setAnimationCurve: (NSAnimationCurve) curve;
|
/** Removes progress mark from the receiver. */
|
||||||
- (void) setCurrentProgress: (NSAnimationProgress) progress;
|
- (void) removeProgressMark: (NSAnimationProgress)progress;
|
||||||
- (void) setDelegate: (id) delegate;
|
|
||||||
- (void) setDuration: (NSTimeInterval) duration;
|
/** Overridden to return the run-loop modes that the receiver uses to run the animation timer in. */
|
||||||
- (void) setFrameRate: (float) fps;
|
- (NSArray*) runLoopModesForAnimating;
|
||||||
- (void) setProgressMarks: (NSArray *) progress;
|
|
||||||
|
/** Sets the blocking mode of the receiver. */
|
||||||
|
- (void) setAnimationBlockingMode: (NSAnimationBlockingMode)mode;
|
||||||
|
|
||||||
|
/** Sets the receiver’s animation curve. */
|
||||||
|
- (void) setAnimationCurve: (NSAnimationCurve)curve;
|
||||||
|
|
||||||
|
/** Sets the current progress of the receiver. */
|
||||||
|
- (void) setCurrentProgress: (NSAnimationProgress)progress;
|
||||||
|
|
||||||
|
/** Sets the delegate of the receiver. */
|
||||||
|
- (void) setDelegate: (id)delegate;
|
||||||
|
|
||||||
|
/** Sets the duration of the animation to a specified number of seconds. */
|
||||||
|
- (void) setDuration: (NSTimeInterval)duration;
|
||||||
|
|
||||||
|
/** Sets the frame rate of the receiver. */
|
||||||
|
- (void) setFrameRate: (float)fps;
|
||||||
|
|
||||||
|
/** Sets the receiver’s progress marks to the values specified in the passed-in array. */
|
||||||
|
- (void) setProgressMarks: (NSArray*)progress;
|
||||||
|
|
||||||
|
/** Starts the animation represented by the receiver. */
|
||||||
- (void) startAnimation;
|
- (void) startAnimation;
|
||||||
- (void) startWhenAnimation: (NSAnimation *) animation reachesProgress:
|
|
||||||
(NSAnimationProgress) start;
|
/** 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. */
|
||||||
- (void) stopAnimation;
|
- (void) stopAnimation;
|
||||||
- (void) stopWhenAnimation: (NSAnimation *) animation reachesProgress:
|
|
||||||
(NSAnimationProgress) stop;
|
/** Stops running the animation represented by the receiver when another animation reaches a specific progress mark. */
|
||||||
|
- (void) stopWhenAnimation: (NSAnimation*)animation
|
||||||
|
reachesProgress: (NSAnimationProgress)stop;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@interface NSAnimation (GNUstep)
|
||||||
|
|
||||||
|
/** Returns the current value of the frame counter */
|
||||||
|
- (unsigned int) frameCount;
|
||||||
|
|
||||||
|
/** Resets all stats */
|
||||||
|
- (void) resetCounters;
|
||||||
|
|
||||||
|
/** Returns the current the actual (mesured) frame rate value */
|
||||||
|
- (float) actualFrameRate;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@interface NSObject (NSAnimation)
|
@interface NSObject (NSAnimation)
|
||||||
|
|
||||||
- (void) animation: (NSAnimation *) animation didReachProgressMark:
|
/** NSAnimation delegate method.
|
||||||
(NSAnimationProgress) progress;
|
* Sent to the delegate when an animation reaches a specific progress mark. */
|
||||||
- (float) animation: (NSAnimation *) animation valueForProgress:
|
- (void) animation: (NSAnimation*)animation
|
||||||
(NSAnimationProgress) progress;
|
didReachProgressMark: (NSAnimationProgress)progress;
|
||||||
- (void) animationDidEnd: (NSAnimation *) animation;
|
|
||||||
- (void) animationDidStop: (NSAnimation *) animation;
|
/** NSAnimation delegate method.
|
||||||
- (BOOL) animationShouldStart: (NSAnimation *) animation;
|
* Requests a custom curve value for the current progress value. */
|
||||||
|
- (float) animation: (NSAnimation*)animation
|
||||||
|
valueForProgress: (NSAnimationProgress)progress;
|
||||||
|
|
||||||
|
/** NSAnimation delegate method.
|
||||||
|
* Sent to the delegate when the specified animation completes its run. */
|
||||||
|
- (void) animationDidEnd: (NSAnimation*)animation;
|
||||||
|
|
||||||
|
/** NSAnimation delegate method.
|
||||||
|
* Sent to the delegate when the specified animation is stopped before it completes its run. */
|
||||||
|
- (void) animationDidStop: (NSAnimation*)animation;
|
||||||
|
|
||||||
|
/** NSAnimation delegate method.
|
||||||
|
* Sent to the delegate just after an animation is started. */
|
||||||
|
- (BOOL) animationShouldStart: (NSAnimation*)animation;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
APPKIT_EXPORT NSString *NSViewAnimationTargetKey;
|
||||||
|
APPKIT_EXPORT NSString *NSViewAnimationStartFrameKey;
|
||||||
|
APPKIT_EXPORT NSString *NSViewAnimationEndFrameKey;
|
||||||
|
APPKIT_EXPORT NSString *NSViewAnimationEffectKey;
|
||||||
|
|
||||||
extern NSString *NSViewAnimationTargetKey;
|
APPKIT_EXPORT NSString *NSViewAnimationFadeInEffect;
|
||||||
extern NSString *NSViewAnimationStartFrameKey;
|
APPKIT_EXPORT NSString *NSViewAnimationFadeOutEffect;
|
||||||
extern NSString *NSViewAnimationEndFrameKey;
|
|
||||||
extern NSString *NSViewAnimationEffectKey;
|
|
||||||
extern NSString *NSViewAnimationFadeInEffect;
|
|
||||||
extern NSString *NSViewAnimationFadeOutEffect;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The NSViewAnimation class, a public subclass of NSAnimation,
|
||||||
|
* offers a convenient way to animate multiple views and windows.
|
||||||
|
* The animation effects you can achieve are limited to changes in
|
||||||
|
* frame location and size, and to fade-in and fade-out effects.
|
||||||
|
*/
|
||||||
@interface NSViewAnimation : NSAnimation
|
@interface NSViewAnimation : NSAnimation
|
||||||
{
|
{
|
||||||
NSArray *_viewAnimations;
|
NSArray *_viewAnimations;
|
||||||
|
NSMutableArray *_viewAnimationDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithViewAnimations: (NSArray *) animations;
|
/** Returns an NSViewAnimation object initialized with the supplied information. */
|
||||||
- (void) setWithViewAnimations: (NSArray *) animations;
|
- (id) initWithViewAnimations: (NSArray*)animations;
|
||||||
- (NSArray *) viewAnimations;
|
|
||||||
|
/** Sets the dictionaries defining the objects to animate. */
|
||||||
|
- (void) setViewAnimations: (NSArray*)animations;
|
||||||
|
|
||||||
|
/** Returns the array of dictionaries defining the objects to animate. */
|
||||||
|
- (NSArray*) viewAnimations;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#endif /* _NSAnimation_h_GNUstep_ */
|
#endif /* OS_API_VERSION */
|
||||||
|
|
||||||
|
#endif /* _GNUstep_H_NSAnimation_ */
|
||||||
|
|
||||||
|
|
|
@ -170,6 +170,7 @@ NSWindow+Toolbar.m \
|
||||||
NSWindow.m \
|
NSWindow.m \
|
||||||
NSWindowController.m \
|
NSWindowController.m \
|
||||||
NSWorkspace.m \
|
NSWorkspace.m \
|
||||||
|
GSAnimator.m \
|
||||||
GSDisplayServer.m \
|
GSDisplayServer.m \
|
||||||
GSFusedSilica.m \
|
GSFusedSilica.m \
|
||||||
GSFusedSilicaContext.m \
|
GSFusedSilicaContext.m \
|
||||||
|
@ -368,6 +369,7 @@ GUI_HEADERS = \
|
||||||
GSVersion.h \
|
GSVersion.h \
|
||||||
GMAppKit.h \
|
GMAppKit.h \
|
||||||
GMArchiver.h \
|
GMArchiver.h \
|
||||||
|
GSAnimator.h \
|
||||||
GSTheme.h \
|
GSTheme.h \
|
||||||
GSFontInfo.h \
|
GSFontInfo.h \
|
||||||
GSMemoryPanel.h \
|
GSMemoryPanel.h \
|
||||||
|
|
359
Source/GSAnimator.m
Normal file
359
Source/GSAnimator.m
Normal file
|
@ -0,0 +1,359 @@
|
||||||
|
/*
|
||||||
|
* GSAnimator.m
|
||||||
|
*
|
||||||
|
* Author: Xavier Glattard (xgl) <xavier.glattard@online.fr>
|
||||||
|
*
|
||||||
|
* 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 library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Library General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Library General Public
|
||||||
|
* License along with this library; see the file COPYING.LIB.
|
||||||
|
* If not, write to the Free Software Foundation,
|
||||||
|
* 51 Franklin Street, Fifth Floor,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <GNUstepGUI/GSAnimator.h>
|
||||||
|
|
||||||
|
#include <Foundation/NSTimer.h>
|
||||||
|
#include <Foundation/NSRunLoop.h>
|
||||||
|
#include <Foundation/NSThread.h>
|
||||||
|
#include <Foundation/NSString.h>
|
||||||
|
#include <Foundation/NSSet.h>
|
||||||
|
#include <Foundation/NSNotification.h>
|
||||||
|
|
||||||
|
#include <AppKit/NSEvent.h>
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
NullEvent,
|
||||||
|
GSAnimationNextFrameEvent,
|
||||||
|
GSAnimationEventTypeNumber
|
||||||
|
} GSAnimationEventType;
|
||||||
|
|
||||||
|
@interface GSAnimator(private)
|
||||||
|
- (void) _animationBegin;
|
||||||
|
- (void) _animationLoop;
|
||||||
|
- (void) _animationEnd;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface GSTimerBasedAnimator : GSAnimator
|
||||||
|
{ }
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface GSPerformerBasedAnimator : GSAnimator
|
||||||
|
{ }
|
||||||
|
@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];
|
||||||
|
}
|
||||||
|
AUTORELEASE(animator);
|
||||||
|
return animator;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (GSAnimator*) initWithAnimation: (id<GSAnimation>)anAnimation
|
||||||
|
frameRate: (float)aFrameRate
|
||||||
|
runLoop: (NSRunLoop*)aRunLoop
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
[self resetCounters];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (GSAnimator*) initWithAnimation: (id<GSAnimation>)anAnimation
|
||||||
|
{
|
||||||
|
return [self initWithAnimation: anAnimation
|
||||||
|
frameRate: 0.0
|
||||||
|
runLoop: [NSRunLoop currentRunLoop]];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) dealloc
|
||||||
|
{
|
||||||
|
[self stopAnimation];
|
||||||
|
TEST_RELEASE(_animation);
|
||||||
|
TEST_RELEASE(_runLoop);
|
||||||
|
TEST_RELEASE(_startTime);
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (unsigned int) frameCount
|
||||||
|
{ return _frameCount; }
|
||||||
|
|
||||||
|
- (void) resetCounters
|
||||||
|
{
|
||||||
|
_elapsed = 0.0;
|
||||||
|
_frameCount = 0;
|
||||||
|
_lastFrame = [NSDate timeIntervalSinceReferenceDate];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (float) frameRate
|
||||||
|
{ return ((float)[self frameCount]) / ((float)_elapsed); }
|
||||||
|
|
||||||
|
- (NSRunLoop*) runLoopForAnimating
|
||||||
|
{ return _runLoop; }
|
||||||
|
|
||||||
|
- (NSArray*) runLoopModesForAnimating
|
||||||
|
{ return [_animation runLoopModesForAnimating]; }
|
||||||
|
|
||||||
|
- (void) startAnimation
|
||||||
|
{
|
||||||
|
if(!_running)
|
||||||
|
{
|
||||||
|
_running = YES;
|
||||||
|
[self resetCounters];
|
||||||
|
[_animation animatorDidStart];
|
||||||
|
[self _animationBegin];
|
||||||
|
[self _animationLoop];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) stopAnimation
|
||||||
|
{
|
||||||
|
if(_running)
|
||||||
|
{
|
||||||
|
_running = NO;
|
||||||
|
[self _animationEnd];
|
||||||
|
[_animation animatorDidStop];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) startStopAnimation
|
||||||
|
{
|
||||||
|
if(_running)
|
||||||
|
[self stopAnimation];
|
||||||
|
else
|
||||||
|
[self startAnimation];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) isAnimationRunning
|
||||||
|
{ return _running; }
|
||||||
|
|
||||||
|
- (void) _animationBegin
|
||||||
|
{ [self subclassResponsibility: _cmd]; }
|
||||||
|
|
||||||
|
- (void) _animationLoop
|
||||||
|
{ [self subclassResponsibility: _cmd]; }
|
||||||
|
|
||||||
|
- (void) _animationEnd
|
||||||
|
{ [self subclassResponsibility: _cmd]; }
|
||||||
|
|
||||||
|
- (void) stepAnimation
|
||||||
|
{
|
||||||
|
NSTimeInterval thisFrame = [NSDate timeIntervalSinceReferenceDate];
|
||||||
|
NSTimeInterval sinceLastFrame = (thisFrame - _lastFrame);
|
||||||
|
_elapsed += sinceLastFrame;
|
||||||
|
_lastFrame = thisFrame;
|
||||||
|
|
||||||
|
[_animation animatorStep: _elapsed];
|
||||||
|
_frameCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) animationLoopEvent: (NSEvent*) e
|
||||||
|
{ [self subclassResponsibility: _cmd]; }
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
static NSTimer* _GSTimerBasedAnimator_timer = nil;
|
||||||
|
static NSMutableSet* _GSTimerBasedAnimator_animators = nil;
|
||||||
|
static GSTimerBasedAnimator* _GSTimerBasedAnimator_the_one_animator = nil;
|
||||||
|
static int _GSTimerBasedAnimator_animator_count = 0;
|
||||||
|
|
||||||
|
@implementation GSTimerBasedAnimator
|
||||||
|
|
||||||
|
+ (void) loopsAnimators
|
||||||
|
{
|
||||||
|
switch(_GSTimerBasedAnimator_animator_count)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
[_GSTimerBasedAnimator_the_one_animator _animationLoop];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
[[NSNotificationCenter defaultCenter]
|
||||||
|
postNotificationName: @"GSTimerBasedAnimator_loop" object: self];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (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;
|
||||||
|
|
||||||
|
if(nil==_GSTimerBasedAnimator_animators)
|
||||||
|
_GSTimerBasedAnimator_animators = [[NSMutableSet alloc] initWithCapacity: 5];
|
||||||
|
[_GSTimerBasedAnimator_animators addObject: anAnimator];
|
||||||
|
|
||||||
|
if(nil==_GSTimerBasedAnimator_timer)
|
||||||
|
{
|
||||||
|
_GSTimerBasedAnimator_timer = [NSTimer
|
||||||
|
scheduledTimerWithTimeInterval: 0.0
|
||||||
|
target: self
|
||||||
|
selector: @selector(loopsAnimators)
|
||||||
|
userInfo: nil
|
||||||
|
repeats: YES
|
||||||
|
];
|
||||||
|
TEST_RETAIN(_GSTimerBasedAnimator_timer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
anAnimator->_timer = [NSTimer
|
||||||
|
scheduledTimerWithTimeInterval: anAnimator->_timerInterval
|
||||||
|
target: anAnimator
|
||||||
|
selector: @selector(_animationLoop)
|
||||||
|
userInfo: nil
|
||||||
|
repeats: YES
|
||||||
|
];
|
||||||
|
TEST_RETAIN(anAnimator->_timer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (void) unregisterAnimator: (GSTimerBasedAnimator*) anAnimator
|
||||||
|
{
|
||||||
|
if(anAnimator->_timerInterval == 0.0)
|
||||||
|
{
|
||||||
|
[[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;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) _animationBegin
|
||||||
|
{
|
||||||
|
[[self class] registerAnimator: self];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) _animationLoop
|
||||||
|
{
|
||||||
|
[self stepAnimation];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) _animationEnd
|
||||||
|
{
|
||||||
|
[[self class] unregisterAnimator: self];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
static void _sendAnimationPerformer( GSAnimator* animator )
|
||||||
|
{
|
||||||
|
[[animator runLoopForAnimating]
|
||||||
|
performSelector: @selector(_animationLoop)
|
||||||
|
target: animator
|
||||||
|
argument: nil
|
||||||
|
order: 1000000
|
||||||
|
modes: [animator runLoopModesForAnimating]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _cancelAnimationPerformer( GSAnimator* animator )
|
||||||
|
{
|
||||||
|
[[animator runLoopForAnimating] cancelPerformSelectorsWithTarget: animator];
|
||||||
|
}
|
||||||
|
|
||||||
|
@implementation GSPerformerBasedAnimator
|
||||||
|
|
||||||
|
- (void) _animationBegin
|
||||||
|
{ [self _animationLoop]; }
|
||||||
|
|
||||||
|
- (void) _animationLoop
|
||||||
|
{
|
||||||
|
[self stepAnimation];
|
||||||
|
if(_running)
|
||||||
|
_sendAnimationPerformer(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) _animationEnd
|
||||||
|
{ _cancelAnimationPerformer(self); }
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue