Merge pull request #10 from gunyarakun/fix-invalid-return
[cocotron.git] / QuartzCore / CAMediaTimingFunction.m
blob9e4c1f2670aabc348f1ee95225fcf530fed19a8f
1 #import <QuartzCore/CAMediaTimingFunction.h>
2 #import <Foundation/NSString.h>
3 #import <Foundation/NSRaise.h>
5 NSString * const kCAMediaTimingFunctionLinear=@"kCAMediaTimingFunctionLinear";
6 NSString * const kCAMediaTimingFunctionEaseIn=@"kCAMediaTimingFunctionEaseIn";
7 NSString * const kCAMediaTimingFunctionEaseOut=@"kCAMediaTimingFunctionEaseOut";
8 NSString * const kCAMediaTimingFunctionEaseInEaseOut=@"kCAMediaTimingFunctionEaseInEaseOut";
9 NSString * const kCAMediaTimingFunctionDefault=@"kCAMediaTimingFunctionDefault";
11 @implementation CAMediaTimingFunction
13 -initWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y {
14    _c1x=c1x;
15    _c1y=c1y;
16    _c2x=c2x;
17    _c2y=c2y;
18    return self;
21 +functionWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y {
22    return [[[self alloc] initWithControlPoints:c1x:c1y:c2x:c2y] autorelease];
25 +functionWithName:(NSString *)name {
26    if([name isEqualToString:kCAMediaTimingFunctionLinear])
27     return [self functionWithControlPoints:0:0:1:1];
28    if([name isEqualToString:kCAMediaTimingFunctionEaseIn])
29     return [self functionWithControlPoints:0.5:0:1:1];
30    if([name isEqualToString:kCAMediaTimingFunctionEaseOut])
31     return [self functionWithControlPoints:0:0:0.5:1];
32    if([name isEqualToString:kCAMediaTimingFunctionEaseInEaseOut])
33     return [self functionWithControlPoints:0.5:0:0.5:1];
34    if([name isEqualToString:kCAMediaTimingFunctionDefault])
35     return [self functionWithControlPoints:0.25:0.1:0.25:1];
36     
37    return nil;
40 -(void)getControlPointAtIndex:(size_t)index values:(float[2])ptr {
42    switch(index){
43    
44     default:
45     case 0:
46      ptr[0]=0;
47      ptr[1]=0;
48      break;
49      
50     case 1:
51      ptr[0]=_c1x;
52      ptr[1]=_c1y;
53      break;
55     case 2:
56      ptr[0]=_c2x;
57      ptr[1]=_c2y;
58      break;
60     case 3:
61      ptr[0]=1;
62      ptr[1]=1;
63      break;
64      
65    }
68 @end