POPCGUtils.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**
  2. Copyright (c) 2014-present, Facebook, Inc.
  3. All rights reserved.
  4. This source code is licensed under the BSD-style license found in the
  5. LICENSE file in the root directory of this source tree. An additional grant
  6. of patent rights can be found in the PATENTS file in the same directory.
  7. */
  8. #import <CoreGraphics/CoreGraphics.h>
  9. #if TARGET_OS_IPHONE
  10. #import <UIKit/UIKit.h>
  11. #else
  12. #import <AppKit/AppKit.h>
  13. #endif
  14. #import "POPDefines.h"
  15. #if SCENEKIT_SDK_AVAILABLE
  16. #import <SceneKit/SceneKit.h>
  17. #endif
  18. POP_EXTERN_C_BEGIN
  19. NS_INLINE CGPoint values_to_point(const CGFloat values[])
  20. {
  21. return CGPointMake(values[0], values[1]);
  22. }
  23. NS_INLINE CGSize values_to_size(const CGFloat values[])
  24. {
  25. return CGSizeMake(values[0], values[1]);
  26. }
  27. NS_INLINE CGRect values_to_rect(const CGFloat values[])
  28. {
  29. return CGRectMake(values[0], values[1], values[2], values[3]);
  30. }
  31. #if SCENEKIT_SDK_AVAILABLE
  32. NS_INLINE SCNVector3 values_to_vec3(const CGFloat values[])
  33. {
  34. return SCNVector3Make(values[0], values[1], values[2]);
  35. }
  36. NS_INLINE SCNVector4 values_to_vec4(const CGFloat values[])
  37. {
  38. return SCNVector4Make(values[0], values[1], values[2], values[3]);
  39. }
  40. #endif
  41. #if TARGET_OS_IPHONE
  42. NS_INLINE UIEdgeInsets values_to_edge_insets(const CGFloat values[])
  43. {
  44. return UIEdgeInsetsMake(values[0], values[1], values[2], values[3]);
  45. }
  46. #endif
  47. NS_INLINE void values_from_point(CGFloat values[], CGPoint p)
  48. {
  49. values[0] = p.x;
  50. values[1] = p.y;
  51. }
  52. NS_INLINE void values_from_size(CGFloat values[], CGSize s)
  53. {
  54. values[0] = s.width;
  55. values[1] = s.height;
  56. }
  57. NS_INLINE void values_from_rect(CGFloat values[], CGRect r)
  58. {
  59. values[0] = r.origin.x;
  60. values[1] = r.origin.y;
  61. values[2] = r.size.width;
  62. values[3] = r.size.height;
  63. }
  64. #if SCENEKIT_SDK_AVAILABLE
  65. NS_INLINE void values_from_vec3(CGFloat values[], SCNVector3 v)
  66. {
  67. values[0] = v.x;
  68. values[1] = v.y;
  69. values[2] = v.z;
  70. }
  71. NS_INLINE void values_from_vec4(CGFloat values[], SCNVector4 v)
  72. {
  73. values[0] = v.x;
  74. values[1] = v.y;
  75. values[2] = v.z;
  76. values[3] = v.w;
  77. }
  78. #endif
  79. #if TARGET_OS_IPHONE
  80. NS_INLINE void values_from_edge_insets(CGFloat values[], UIEdgeInsets i)
  81. {
  82. values[0] = i.top;
  83. values[1] = i.left;
  84. values[2] = i.bottom;
  85. values[3] = i.right;
  86. }
  87. #endif
  88. /**
  89. Takes a CGColorRef and converts it into RGBA components, if necessary.
  90. */
  91. extern void POPCGColorGetRGBAComponents(CGColorRef color, CGFloat components[]);
  92. /**
  93. Takes RGBA components and returns a CGColorRef.
  94. */
  95. extern CGColorRef POPCGColorRGBACreate(const CGFloat components[]) CF_RETURNS_RETAINED;
  96. /**
  97. Takes a color reference and returns a CGColor.
  98. */
  99. extern CGColorRef POPCGColorWithColor(id color) CF_RETURNS_NOT_RETAINED;
  100. #if TARGET_OS_IPHONE
  101. /**
  102. Takes a UIColor and converts it into RGBA components, if necessary.
  103. */
  104. extern void POPUIColorGetRGBAComponents(UIColor *color, CGFloat components[]);
  105. /**
  106. Takes RGBA components and returns a UIColor.
  107. */
  108. extern UIColor *POPUIColorRGBACreate(const CGFloat components[]) NS_RETURNS_RETAINED;
  109. #else
  110. /**
  111. Takes a NSColor and converts it into RGBA components, if necessary.
  112. */
  113. extern void POPNSColorGetRGBAComponents(NSColor *color, CGFloat components[]);
  114. /**
  115. Takes RGBA components and returns a NSColor.
  116. */
  117. extern NSColor *POPNSColorRGBACreate(const CGFloat components[]) NS_RETURNS_RETAINED;
  118. #endif
  119. POP_EXTERN_C_END