RSS

(root)/iphone/common : 27 : Jigs/source/ElAnimation.m

To get this branch, use:
bzr branch /browse/iphone/common

« back to all changes in this revision

Viewing changes to Jigs/source/ElAnimation.m

Dömötör Gulyás
2009-08-13 12:31:20
Revision ID: dognotdog@gmail.com-20090813103120-y0yoc55s14agedur
improvements in Jigs GUI

Show diffs side-by-side

added added

removed removed

34
34
 
35
35
@interface ElAnimationController : NSObject
36
36
{
37
 
        NSMutableSet*                           queuedAnimations;
 
37
        NSMutableDictionary*            queuedAnimations;
38
38
        NSTimeInterval                          lastTime;
 
39
 
39
40
        mach_timebase_info_data_t       timebase;
40
41
        uint64_t                                        machTimingStart;
41
42
}
42
43
+ (ElAnimationController*) sharedController;
43
44
 
44
 
- (void) queueAnimation: (ElAnimation*) anim forKey: (NSString*) key;
 
45
- (void) queueAnimation: (ElAnimation*) anim forKey: (id) key atBeginning: (BOOL) atBegin cancelPending: (BOOL) cancelPending;
45
46
- (NSTimeInterval) now;
46
47
 
47
48
@end;
49
50
 
50
51
@implementation ElAnimation
51
52
 
52
 
- (void) queueWithKey: (NSString*) key
 
53
- (void) queueForKey: (NSString*) key atBeginning: (BOOL) atBeginning cancelPending: (BOOL) cancelPending;
53
54
{
54
 
        [[ElAnimationController sharedController] queueAnimation: self forKey: key];
 
55
        [[ElAnimationController sharedController] queueAnimation: self forKey: key atBeginning: atBeginning cancelPending: cancelPending];
55
56
}
56
57
 
57
58
- (BOOL) animateForTime: (NSTimeInterval) time delta: (NSTimeInterval) deltaTime
67
68
        return [[ElAnimationController sharedController] now];
68
69
}
69
70
 
70
 
 
71
 
@synthesize startTime, duration, interpolation;
 
71
- (void) setStartTime: (NSTimeInterval) time
 
72
{
 
73
        startTime = time;
 
74
}
 
75
- (NSTimeInterval) startTime
 
76
{
 
77
        return startTime;
 
78
}
 
79
 
 
80
+ (ElAnimation*) delayedAnimationWithDelay: (float) seconds
 
81
{
 
82
        ElAnimation* anim = [[[ElAnimation alloc] init] autorelease];
 
83
        [anim setDuration: seconds];
 
84
        return anim;
 
85
}
 
86
 
 
87
@synthesize duration, interpolation;
72
88
 
73
89
@end
74
90
 
102
118
        return result;
103
119
}
104
120
 
 
121
- (void) dealloc
 
122
{
 
123
        [target release];
 
124
        [super dealloc];
 
125
}
105
126
 
106
127
@synthesize startValue, endValue, target, property;
107
128
 
114
135
        if (!(self = [super init]))
115
136
                return nil;
116
137
 
117
 
        queuedAnimations = [[NSMutableSet alloc] init];
 
138
        queuedAnimations = [[NSMutableDictionary alloc] init];
118
139
 
119
140
        mach_timebase_info(&timebase);
120
141
        machTimingStart = mach_absolute_time();
146
167
        
147
168
//      NSLog(@"%f %f", time, delta);
148
169
        
149
 
        NSMutableSet* objectsToRemove = [NSMutableSet set];
150
 
        for (ElAnimation* anim in queuedAnimations)
 
170
        NSMutableArray* keysToRemove = [NSMutableArray array];
 
171
        for (id key in queuedAnimations)
151
172
        {
152
 
                if ([anim startTime] < time)
153
 
                        if (![anim animateForTime: time delta: delta])
154
 
                                [objectsToRemove addObject: anim];
 
173
                NSMutableArray* animArray = [queuedAnimations objectForKey: key];
 
174
                if (![animArray count])
 
175
                {
 
176
                        [keysToRemove addObject: key];
 
177
                        continue;
 
178
                }
 
179
                
 
180
                ElAnimation* anim = [animArray objectAtIndex: 0];
 
181
                
 
182
                if ([anim startTime] == 0.0)
 
183
                        [anim setStartTime: lastTime];
 
184
                        
 
185
                [anim animateForTime: time delta: delta];
 
186
 
 
187
                if ([anim startTime] + [anim duration] < time)
 
188
                {
 
189
                        [animArray removeObjectAtIndex: 0];
 
190
                        //NSLog(@"dequeued animation");
 
191
                }
155
192
        }
156
 
        [queuedAnimations minusSet: objectsToRemove];
 
193
        [queuedAnimations removeObjectsForKeys: keysToRemove];
157
194
        lastTime = time;
158
195
}
159
196
 
160
 
- (void) queueAnimation: (ElAnimation*) anim forKey: (NSString*) key
 
197
- (void) queueAnimation: (ElAnimation*) anim forKey: (id) key atBeginning: (BOOL) atBeginning cancelPending: (BOOL) cancelPending
161
198
{
162
199
        static NSTimer* animationTimer = nil;
163
200
        if (!animationTimer)
166
203
                lastTime = [self currentTime];
167
204
        }
168
205
        
169
 
        [queuedAnimations addObject: anim];
 
206
        if (!key)
 
207
                key = [NSNull null];
 
208
        
 
209
        NSMutableArray* animArray = [queuedAnimations objectForKey: key];
 
210
        if (!animArray)
 
211
        {
 
212
                animArray = [NSMutableArray array];
 
213
                [queuedAnimations setObject: animArray forKey: key];
 
214
        }
 
215
        
 
216
        if (!cancelPending && !atBeginning)
 
217
                [animArray addObject: anim];
 
218
        else if (cancelPending && !atBeginning)
 
219
        {
 
220
                if ([animArray count] > 1)
 
221
                        [animArray removeObjectsInRange: (NSRange){1, [animArray count]-1}];
 
222
                [animArray addObject: anim];
 
223
        }
 
224
        else if (!cancelPending && atBeginning)
 
225
        {
 
226
                if ([animArray count])
 
227
                        [animArray replaceObjectAtIndex: 0 withObject: anim];
 
228
                else
 
229
                        [animArray addObject: anim];
 
230
        }
 
231
        else
 
232
        {
 
233
                [animArray removeAllObjects];
 
234
                [animArray addObject: anim];
 
235
        }
170
236
}
171
237
 
172
238
- (NSTimeInterval) now

Loggerhead 1.17 is a web-based interface for Bazaar branches