/ CoreGraphics / CGPath.m
CGPath.m
1 /* Copyright (c) 2007 Christopher J. W. Lloyd 2 3 Permission is hereby granted, free of charge, to any person obtaining a copy of 4 this software and associated documentation files (the "Software"), to deal in 5 the Software without restriction, including without limitation the rights to 6 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 the Software, and to permit persons to whom the Software is furnished to do so, 8 subject to the following conditions: 9 10 The above copyright notice and this permission notice shall be included in all 11 copies or substantial portions of the Software. 12 13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 19 20 #import "CGConversions.h" 21 #import <CoreGraphics/CGPath.h> 22 #import <Onyx2D/O2MutablePath.h> 23 #import <Onyx2D/O2Path.h> 24 25 #import <CoreGraphics/CGGeometry.h> 26 #include <stdio.h> 27 28 void CGPathRelease(CGPathRef self) { 29 O2PathRelease(self); 30 } 31 32 CGPathRef CGPathRetain(CGPathRef self) { 33 return (CGPathRef) O2PathRetain(self); 34 } 35 36 bool CGPathEqualToPath(CGPathRef self, CGPathRef other) { 37 return O2PathEqualToPath(self, other); 38 } 39 40 CGRect CGPathGetBoundingBox(CGPathRef self) { 41 return O2PathGetBoundingBox(self); 42 } 43 44 CGPoint CGPathGetCurrentPoint(CGPathRef self) { 45 return O2PathGetCurrentPoint(self); 46 } 47 48 bool CGPathIsEmpty(CGPathRef self) { 49 return O2PathIsEmpty(self); 50 } 51 52 bool CGPathIsRect(CGPathRef self, CGRect *rect) { 53 return O2PathIsRect(self, rect); 54 } 55 56 void CGPathApply(CGPathRef self, void *info, CGPathApplierFunction function) { 57 return O2PathApply(self, info, O2PathApplierFunctionFromCG(function)); 58 } 59 60 CGMutablePathRef CGPathCreateMutableCopy(CGPathRef self) { 61 return O2PathCreateMutableCopy(self); 62 } 63 64 CGPathRef CGPathCreateCopy(CGPathRef self) { 65 return (CGPathRef) O2PathCreateCopy(self); 66 } 67 68 bool CGPathContainsPoint(CGPathRef self, const CGAffineTransform *xform, 69 CGPoint point, bool evenOdd) 70 { 71 return O2PathContainsPoint(self, O2AffineTransformPtrFromCG(xform), point, 72 evenOdd); 73 } 74 75 CGMutablePathRef CGPathCreateMutable(void) { 76 return O2PathCreateMutable(); 77 } 78 79 void CGPathMoveToPoint(CGMutablePathRef self, const CGAffineTransform *xform, 80 CGFloat x, CGFloat y) 81 { 82 O2PathMoveToPoint(self, O2AffineTransformPtrFromCG(xform), x, y); 83 } 84 85 void CGPathAddLineToPoint(CGMutablePathRef self, const CGAffineTransform *xform, 86 CGFloat x, CGFloat y) 87 { 88 O2PathAddLineToPoint(self, O2AffineTransformPtrFromCG(xform), x, y); 89 } 90 91 void CGPathAddCurveToPoint(CGMutablePathRef self, 92 const CGAffineTransform *xform, CGFloat cp1x, 93 CGFloat cp1y, CGFloat cp2x, CGFloat cp2y, CGFloat x, 94 CGFloat y) 95 { 96 O2PathAddCurveToPoint(self, O2AffineTransformPtrFromCG(xform), cp1x, cp1y, 97 cp2x, cp2y, x, y); 98 } 99 100 void CGPathAddQuadCurveToPoint(CGMutablePathRef self, 101 const CGAffineTransform *xform, CGFloat cpx, 102 CGFloat cpy, CGFloat x, CGFloat y) 103 { 104 O2PathAddQuadCurveToPoint(self, O2AffineTransformPtrFromCG(xform), cpx, cpy, 105 x, y); 106 } 107 108 void CGPathCloseSubpath(CGMutablePathRef self) { 109 O2PathCloseSubpath(self); 110 } 111 112 void CGPathAddLines(CGMutablePathRef self, const CGAffineTransform *xform, 113 const CGPoint *points, size_t count) 114 { 115 O2PathAddLines(self, O2AffineTransformPtrFromCG(xform), points, count); 116 } 117 118 void CGPathAddRect(CGMutablePathRef self, const CGAffineTransform *xform, 119 CGRect rect) 120 { 121 O2PathAddRect(self, O2AffineTransformPtrFromCG(xform), rect); 122 } 123 124 void CGPathAddRects(CGMutablePathRef self, const CGAffineTransform *xform, 125 const CGRect *rects, size_t count) 126 { 127 O2PathAddRects(self, O2AffineTransformPtrFromCG(xform), rects, count); 128 } 129 130 void CGPathAddArc(CGMutablePathRef self, const CGAffineTransform *xform, 131 CGFloat x, CGFloat y, CGFloat radius, CGFloat startRadian, 132 CGFloat endRadian, bool clockwise) 133 { 134 O2PathAddArc(self, O2AffineTransformPtrFromCG(xform), x, y, radius, 135 startRadian, endRadian, clockwise); 136 } 137 138 void CGPathAddArcToPoint(CGMutablePathRef self, const CGAffineTransform *xform, 139 CGFloat tx1, CGFloat ty1, CGFloat tx2, CGFloat ty2, 140 CGFloat radius) 141 { 142 O2PathAddArcToPoint(self, O2AffineTransformPtrFromCG(xform), tx1, ty1, tx2, 143 ty2, radius); 144 } 145 146 void CGPathAddEllipseInRect(CGMutablePathRef self, 147 const CGAffineTransform *xform, CGRect rect) 148 { 149 O2PathAddEllipseInRect(self, O2AffineTransformPtrFromCG(xform), rect); 150 } 151 152 void CGPathAddPath(CGMutablePathRef self, const CGAffineTransform *xform, 153 CGPathRef other) 154 { 155 O2PathAddPath(self, O2AffineTransformPtrFromCG(xform), other); 156 } 157 158 CGPathRef CGPathCreateWithEllipseInRect(CGRect rect, 159 const CGAffineTransform *transform) 160 { 161 return (CGPathRef) O2PathCreateWithEllipseInRect( 162 rect, (O2AffineTransform *) transform); 163 } 164 165 CGPathRef CGPathCreateWithRect(CGRect rect, const CGAffineTransform *transform) 166 { 167 return (CGPathRef) O2PathCreateWithRect(rect, 168 (O2AffineTransform *) transform); 169 } 170 171 CGRect CGPathGetPathBoundingBox(CGPathRef path) { 172 return O2PathGetBoundingBox(path); 173 } 174 175 CGPathRef CGPathCreateCopyByTransformingPath(CGPathRef path, 176 CGAffineTransform *transform) 177 { 178 O2MutablePathRef copy = O2PathCreateMutableCopy(path); 179 O2PathApplyTransform(copy, *(O2AffineTransform *) transform); 180 return copy; 181 }