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