LOTFillRenderer.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // LOTFillRenderer.m
  3. // Lottie
  4. //
  5. // Created by brandon_withrow on 6/27/17.
  6. // Copyright © 2017 Airbnb. All rights reserved.
  7. //
  8. #import "LOTFillRenderer.h"
  9. #import "LOTColorInterpolator.h"
  10. #import "LOTNumberInterpolator.h"
  11. #import "LOTHelpers.h"
  12. @implementation LOTFillRenderer {
  13. LOTColorInterpolator *colorInterpolator_;
  14. LOTNumberInterpolator *opacityInterpolator_;
  15. BOOL _evenOddFillRule;
  16. CALayer *centerPoint_DEBUG;
  17. }
  18. - (instancetype)initWithInputNode:(LOTAnimatorNode *)inputNode
  19. shapeFill:(LOTShapeFill *)fill {
  20. self = [super initWithInputNode:inputNode keyName:fill.keyname];
  21. if (self) {
  22. colorInterpolator_ = [[LOTColorInterpolator alloc] initWithKeyframes:fill.color.keyframes];
  23. opacityInterpolator_ = [[LOTNumberInterpolator alloc] initWithKeyframes:fill.opacity.keyframes];
  24. centerPoint_DEBUG = [CALayer layer];
  25. centerPoint_DEBUG.bounds = CGRectMake(0, 0, 20, 20);
  26. if (ENABLE_DEBUG_SHAPES) {
  27. [self.outputLayer addSublayer:centerPoint_DEBUG];
  28. }
  29. _evenOddFillRule = fill.evenOddFillRule;
  30. self.outputLayer.fillRule = _evenOddFillRule ? @"even-odd" : @"non-zero";
  31. }
  32. return self;
  33. }
  34. - (NSDictionary *)valueInterpolators {
  35. return @{@"Color" : colorInterpolator_,
  36. @"Opacity" : opacityInterpolator_};
  37. }
  38. - (BOOL)needsUpdateForFrame:(NSNumber *)frame {
  39. return [colorInterpolator_ hasUpdateForFrame:frame] || [opacityInterpolator_ hasUpdateForFrame:frame];
  40. }
  41. - (void)performLocalUpdate {
  42. centerPoint_DEBUG.backgroundColor = [colorInterpolator_ colorForFrame:self.currentFrame];
  43. centerPoint_DEBUG.borderColor = [UIColor lightGrayColor].CGColor;
  44. centerPoint_DEBUG.borderWidth = 2.f;
  45. self.outputLayer.fillColor = [colorInterpolator_ colorForFrame:self.currentFrame];
  46. self.outputLayer.opacity = [opacityInterpolator_ floatValueForFrame:self.currentFrame];
  47. }
  48. - (void)rebuildOutputs {
  49. self.outputLayer.path = self.inputNode.outputPath.CGPath;
  50. }
  51. - (NSDictionary *)actionsForRenderLayer {
  52. return @{@"backgroundColor": [NSNull null],
  53. @"fillColor": [NSNull null],
  54. @"opacity" : [NSNull null]};
  55. }
  56. @end