PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/AppKit/CoreAnimation/CAMediaTimingFunction.j

http://github.com/cacaodev/cappuccino
Unknown | 102 lines | 88 code | 14 blank | 0 comment | 0 complexity | a3d1046ee7fd46dbc269732b8f1e3c68 MD5 | raw 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@import <Foundation/CPObject.j>
 24@import <Foundation/CPDictionary.j>
 25@import <Foundation/CPString.j>
 26
 27
 28kCAMediaTimingFunctionLinear        = @"kCAMediaTimingFunctionLinear";
 29kCAMediaTimingFunctionEaseIn        = @"kCAMediaTimingFunctionEaseIn";
 30kCAMediaTimingFunctionEaseOut       = @"kCAMediaTimingFunctionEaseOut";
 31kCAMediaTimingFunctionEaseInEaseOut = @"kCAMediaTimingFunctionEaseInEaseOut";
 32
 33var CAMediaNamedTimingFunctions = nil;
 34
 35@implementation CAMediaTimingFunction : CPObject
 36{
 37    float _c1x;
 38    float _c1y;
 39    float _c2x;
 40    float _c2y;
 41}
 42
 43+ (id)functionWithName:(CPString)aName
 44{
 45    if (!CAMediaNamedTimingFunctions)
 46    {
 47        CAMediaNamedTimingFunctions = @{};
 48
 49        [CAMediaNamedTimingFunctions setObject:[CAMediaTimingFunction functionWithControlPoints:0.0 :0.0 :1.0 :1.0] forKey:kCAMediaTimingFunctionLinear];
 50        [CAMediaNamedTimingFunctions setObject:[CAMediaTimingFunction functionWithControlPoints:0.42 :0.0 :1.0 :1.0] forKey:kCAMediaTimingFunctionEaseIn];
 51        [CAMediaNamedTimingFunctions setObject:[CAMediaTimingFunction functionWithControlPoints:0.0 :0.0 :0.58 :1.0] forKey:kCAMediaTimingFunctionEaseOut];
 52        [CAMediaNamedTimingFunctions setObject:[CAMediaTimingFunction functionWithControlPoints:0.42 :0.0 :0.58 :1.0] forKey:kCAMediaTimingFunctionEaseInEaseOut];
 53    }
 54
 55    return [CAMediaNamedTimingFunctions objectForKey:aName];
 56}
 57
 58+ (id)functionWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y
 59{
 60    return [[self alloc] initWithControlPoints:c1x :c1y :c2x :c2y];
 61}
 62
 63- (id)initWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y
 64{
 65    self = [super init];
 66
 67    if (self)
 68    {
 69        _c1x = c1x;
 70        _c1y = c1y;
 71        _c2x = c2x;
 72        _c2y = c2y;
 73    }
 74
 75    return self;
 76}
 77
 78- (void)getControlPointAtIndex:(CPUInteger)anIndex values:(float/*[2]*/)reference
 79{
 80    if (anIndex == 0)
 81    {
 82        reference[0] = 0;
 83        reference[1] = 0;
 84    }
 85    else if (anIndex == 1)
 86    {
 87        reference[0] = _c1x;
 88        reference[1] = _c1y;
 89    }
 90    else if (anIndex == 2)
 91    {
 92        reference[0] = _c2x;
 93        reference[1] = _c2y;
 94    }
 95    else
 96    {
 97        reference[0] = 1.0;
 98        reference[1] = 1.0;
 99    }
100}
101
102@end