![]() |
API 0.9.5
|
00001 /* 00002 * CAMediaTimingFunction.j 00003 * AppKit 00004 * 00005 * Created by Francisco Tolmasky. 00006 * Copyright 2008, 280 North, Inc. 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with this library; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 00024 00025 kCAMediaTimingFunctionLinear = @"kCAMediaTimingFunctionLinear"; 00026 kCAMediaTimingFunctionEaseIn = @"kCAMediaTimingFunctionEaseIn"; 00027 kCAMediaTimingFunctionEaseOut = @"kCAMediaTimingFunctionEaseOut"; 00028 kCAMediaTimingFunctionEaseInEaseOut = @"kCAMediaTimingFunctionEaseInEaseOut"; 00029 00030 var CAMediaNamedTimingFunctions = nil; 00031 00032 @implementation CAMediaTimingFunction : CPObject 00033 { 00034 float _c1x; 00035 float _c1y; 00036 float _c2x; 00037 float _c2y; 00038 } 00039 00040 + (id)functionWithName:(CPString)aName 00041 { 00042 if (!CAMediaNamedTimingFunctions) 00043 { 00044 CAMediaNamedTimingFunctions = [CPDictionary dictionary]; 00045 00046 [CAMediaNamedTimingFunctions setObject:[CAMediaTimingFunction functionWithControlPoints:0.0 :0.0 :1.0 :1.0] forKey:kCAMediaTimingFunctionLinear]; 00047 [CAMediaNamedTimingFunctions setObject:[CAMediaTimingFunction functionWithControlPoints:0.42 :0.0 :1.0 :1.0] forKey:kCAMediaTimingFunctionEaseIn]; 00048 [CAMediaNamedTimingFunctions setObject:[CAMediaTimingFunction functionWithControlPoints:0.0 :0.0 :0.58 :1.0] forKey:kCAMediaTimingFunctionEaseOut]; 00049 [CAMediaNamedTimingFunctions setObject:[CAMediaTimingFunction functionWithControlPoints:0.42 :0.0 :0.58 :1.0] forKey:kCAMediaTimingFunctionEaseInEaseOut]; 00050 } 00051 00052 return [CAMediaNamedTimingFunctions objectForKey:aName]; 00053 } 00054 00055 + (id)functionWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y 00056 { 00057 return [[self alloc] initWithControlPoints:c1x :c1y :c2x :c2y]; 00058 } 00059 00060 - (id)initWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y 00061 { 00062 self = [super init]; 00063 00064 if (self) 00065 { 00066 _c1x = c1x; 00067 _c1y = c1y; 00068 _c2x = c2x; 00069 _c2y = c2y; 00070 } 00071 00072 return self; 00073 } 00074 00075 - (void)getControlPointAtIndex:(unsigned)anIndex values:(float[2])reference 00076 { 00077 if (anIndex == 0) 00078 { 00079 reference[0] = 0; 00080 reference[1] = 0; 00081 } 00082 else if (anIndex == 1) 00083 { 00084 reference[0] = _c1x; 00085 reference[1] = _c1y; 00086 } 00087 else if (anIndex == 2) 00088 { 00089 reference[0] = _c2x; 00090 reference[1] = _c2y; 00091 } 00092 else 00093 { 00094 reference[0] = 1.0; 00095 reference[1] = 1.0; 00096 } 00097 } 00098 00099 @end