WMGaugeViewStyle.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * WMGaugeViewStyle.h
  3. *
  4. * Copyright (C) 2015 William Markezana <william.markezana@me.com>
  5. *
  6. */
  7. #import <Foundation/Foundation.h>
  8. #import <UIKit/UIKit.h>
  9. /* Degrees to radians conversion macro */
  10. #define DEGREES_TO_RADIANS(degrees) (degrees) / 180.0 * M_PI
  11. /* Colors creation macros */
  12. #define RGB(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0]
  13. #define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a/255.0]
  14. #define CGRGB(r,g,b) RGB(r,g,b).CGColor
  15. #define iCGRGB(r,g,b) (id)CGRGB(r,g,b)
  16. #define CGRGBA(r,g,b,a) RGBA(r,g,b,a).CGColor
  17. #define iCGRGBA(r,g,b,a) (id)CGRGBA(r,g,b,a)
  18. static inline
  19. NSArray* CGColorArray(NSArray<UIColor*>*c) {
  20. NSMutableArray* _c = [NSMutableArray array];
  21. for(UIColor* col in c) {
  22. [_c addObject: (id)col.CGColor];
  23. }
  24. return _c.copy;
  25. }
  26. static inline
  27. CGFloat* CGFloatCArray(NSArray<NSNumber*>*a) {
  28. CGFloat* ar = malloc(sizeof(*ar) * a.count);
  29. [a enumerateObjectsUsingBlock:^(NSNumber* obj, NSUInteger idx, BOOL * _Nonnull stop) {
  30. ar[idx] = (CGFloat)obj.doubleValue;
  31. }];
  32. return ar;
  33. }
  34. /* Position macros */
  35. #define FULL_RECT CGRectMake(0.0, 0.0, 1.0, 1.0)
  36. #define kCenterX 0.5
  37. #define kCenterY 0.5
  38. #define kCenterPoint CGPointMake(kCenterX, kCenterY)
  39. /* Scale conversion macro from [0-1] range to view real size range */
  40. #define FULLSCALE(x,y) (x)*rect.size.width, (y)*rect.size.height
  41. /**
  42. * WMGaugeView style protocol
  43. */
  44. @protocol WMGaugeViewStyle <NSObject>
  45. @required
  46. - (void)drawNeedleOnLayer:(CALayer*)layer inRect:(CGRect)rect;
  47. - (void)drawFaceWithContext:(CGContextRef)context inRect:(CGRect)rect;
  48. - (BOOL)needleLayer:(CALayer*)layer willMoveAnimated:(BOOL)animated duration:(NSTimeInterval)duration animation:(CAKeyframeAnimation*)animation;
  49. @end