API  1.0.0
CAMediaTimingFunction.j
Go to the documentation of this file.
1 /*
2  * CAMediaTimingFunction.j
3  * AppKit
4  *
5  * Created by Francisco Tolmasky.
6  * Copyright 2008, 280 North, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 
24 
25 kCAMediaTimingFunctionLinear = @"kCAMediaTimingFunctionLinear";
26 kCAMediaTimingFunctionEaseIn = @"kCAMediaTimingFunctionEaseIn";
27 kCAMediaTimingFunctionEaseOut = @"kCAMediaTimingFunctionEaseOut";
28 kCAMediaTimingFunctionEaseInEaseOut = @"kCAMediaTimingFunctionEaseInEaseOut";
29 
31 
32 @implementation CAMediaTimingFunction : CPObject
33 {
34  float _c1x;
35  float _c1y;
36  float _c2x;
37  float _c2y;
38 }
39 
40 + (id)functionWithName:(CPString)aName
41 {
43  {
45 
46  [CAMediaNamedTimingFunctions setObject:[CAMediaTimingFunction functionWithControlPoints:0.0 :0.0 :1.0 :1.0] forKey:kCAMediaTimingFunctionLinear];
47  [CAMediaNamedTimingFunctions setObject:[CAMediaTimingFunction functionWithControlPoints:0.42 :0.0 :1.0 :1.0] forKey:kCAMediaTimingFunctionEaseIn];
48  [CAMediaNamedTimingFunctions setObject:[CAMediaTimingFunction functionWithControlPoints:0.0 :0.0 :0.58 :1.0] forKey:kCAMediaTimingFunctionEaseOut];
49  [CAMediaNamedTimingFunctions setObject:[CAMediaTimingFunction functionWithControlPoints:0.42 :0.0 :0.58 :1.0] forKey:kCAMediaTimingFunctionEaseInEaseOut];
50  }
51 
52  return [CAMediaNamedTimingFunctions objectForKey:aName];
53 }
54 
55 + (id)functionWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y
56 {
57  return [[self alloc] initWithControlPoints:c1x :c1y :c2x :c2y];
58 }
59 
60 - (id)initWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y
61 {
62  self = [super init];
63 
64  if (self)
65  {
66  _c1x = c1x;
67  _c1y = c1y;
68  _c2x = c2x;
69  _c2y = c2y;
70  }
71 
72  return self;
73 }
74 
75 - (void)getControlPointAtIndex:(CPUInteger)anIndex values:(float/*[2]*/)reference
76 {
77  if (anIndex == 0)
78  {
79  reference[0] = 0;
80  reference[1] = 0;
81  }
82  else if (anIndex == 1)
83  {
84  reference[0] = _c1x;
85  reference[1] = _c1y;
86  }
87  else if (anIndex == 2)
88  {
89  reference[0] = _c2x;
90  reference[1] = _c2y;
91  }
92  else
93  {
94  reference[0] = 1.0;
95  reference[1] = 1.0;
96  }
97 }
98 
99 @end
An immutable string (collection of characters).
Definition: CPString.h:2
kCAMediaTimingFunctionEaseOut
kCAMediaTimingFunctionEaseIn
id init()
Definition: CPObject.j:145
var CAMediaNamedTimingFunctions
kCAMediaTimingFunctionEaseInEaseOut
id alloc()
Definition: CPObject.j:130
kCAMediaTimingFunctionLinear