|
| 1 | +/* |
| 2 | + * Copyright (C) 2007-2008 Alacatia Labs |
| 3 | + * |
| 4 | + * This software is provided 'as-is', without any express or implied |
| 5 | + * warranty. In no event will the authors be held liable for any damages |
| 6 | + * arising from the use of this software. |
| 7 | + * |
| 8 | + * Permission is granted to anyone to use this software for any purpose, |
| 9 | + * including commercial applications, and to alter it and redistribute it |
| 10 | + * freely, subject to the following restrictions: |
| 11 | + * |
| 12 | + * 1. The origin of this software must not be misrepresented; you must not |
| 13 | + * claim that you wrote the original software. If you use this software |
| 14 | + * in a product, an acknowledgment in the product documentation would be |
| 15 | + * appreciated but is not required. |
| 16 | + * 2. Altered source versions must be plainly marked as such, and must not be |
| 17 | + * misrepresented as being the original software. |
| 18 | + * 3. This notice may not be removed or altered from any source distribution. |
| 19 | + * |
| 20 | + |
| 21 | + * |
| 22 | + */ |
| 23 | + |
| 24 | +#pragma once |
| 25 | + |
| 26 | +#pragma mark types |
| 27 | +#if MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED |
| 28 | + // on Leopard and up these are CFTypes |
| 29 | + typedef CFTypeRef CGSRegionObj; |
| 30 | + typedef CFTypeRef CGSRegionEnumeratorObj; |
| 31 | +#else |
| 32 | + // but opaque types under 10.4 |
| 33 | + typedef int CGSRegionObj; |
| 34 | + typedef int CGSRegionEnumeratorObj; |
| 35 | +#endif |
| 36 | + |
| 37 | +CG_EXTERN_C_BEGIN |
| 38 | + |
| 39 | +/*! Creates a region from a `CGRect`. */ |
| 40 | +CG_EXTERN CGError CGSNewRegionWithRect(const CGRect *rect, CGSRegionObj *outRegion); |
| 41 | + |
| 42 | +/*! Creates a region from a list of `CGRect`s. */ |
| 43 | +CG_EXTERN CGError CGSNewRegionWithRectList(const CGRect *rects, int rectCount, CGSRegionObj *outRegion); |
| 44 | + |
| 45 | +/*! Creates a new region from a QuickDraw region. */ |
| 46 | +CG_EXTERN CGError CGSNewRegionWithQDRgn(RgnHandle region, CGSRegionObj *outRegion); |
| 47 | + |
| 48 | +/*! Creates an empty region. */ |
| 49 | +CG_EXTERN CGError CGSNewEmptyRegion(CGSRegionObj *outRegion); |
| 50 | + |
| 51 | +/*! Releases a region. */ |
| 52 | +CG_EXTERN CGError CGSReleaseRegion(CGSRegionObj region); |
| 53 | + |
| 54 | +/*! Creates a `CGRect` from a region. */ |
| 55 | +CG_EXTERN CGError CGSGetRegionBounds(CGSRegionObj region, CGRect *outRect); |
| 56 | + |
| 57 | +/*! Determines if two regions are equal. */ |
| 58 | +CG_EXTERN bool CGSRegionsEqual(CGSRegionObj region1, CGSRegionObj region2); |
| 59 | + |
| 60 | +/* Created a new region by changing the origin an existing one. */ |
| 61 | +CG_EXTERN CGError CGSOffsetRegion(CGSRegionObj region, float offsetLeft, float offsetTop, CGSRegionObj *outRegion); |
| 62 | + |
| 63 | +/*! Creates a new region by copying an existing one. */ |
| 64 | +CG_EXTERN CGError CGSCopyRegion(CGSRegionObj region, CGSRegionObj *outRegion); |
| 65 | + |
| 66 | +/*! Creates a new region by combining two regions together. */ |
| 67 | +CG_EXTERN CGError CGSUnionRegion(CGSRegionObj region1, CGSRegionObj region2, CGSRegionObj *outRegion); |
| 68 | + |
| 69 | +/*! Creates a new region by combining a region and a rect. */ |
| 70 | +CG_EXTERN CGError CGSUnionRegionWithRect(CGSRegionObj region, CGRect *rect, CGSRegionObj *outRegion); |
| 71 | + |
| 72 | +/*! Creates a region by XORing two regions together. */ |
| 73 | +CG_EXTERN CGError CGSXorRegion(CGSRegionObj region1, CGSRegionObj region2, CGSRegionObj *outRegion); |
| 74 | + |
| 75 | +/*! Determines if the region is empty. */ |
| 76 | +CG_EXTERN bool CGSRegionIsEmpty(CGSRegionObj region); |
| 77 | + |
| 78 | +/*! Determines if the region is rectangular. */ |
| 79 | +CG_EXTERN bool CGSRegionIsRectangular(CGSRegionObj region); |
| 80 | + |
| 81 | +/*! Determines if a point in a region. */ |
| 82 | +CG_EXTERN bool CGSPointInRegion(CGSRegionObj region, const CGPoint *point); |
| 83 | + |
| 84 | +/*! Determines if a rect is in a region. */ |
| 85 | +CG_EXTERN bool CGSRectInRegion(CGSRegionObj region, const CGRect *rect); |
| 86 | + |
| 87 | +/*! Determines if a region is inside of a region. */ |
| 88 | +CG_EXTERN bool CGSRegionInRegion(CGSRegionObj region1, CGSRegionObj region2); |
| 89 | + |
| 90 | +/*! Determines if a rect intersects a region. */ |
| 91 | +CG_EXTERN bool CGSRegionIntersectsRect(CGSRegionObj obj, const CGRect *rect); |
| 92 | + |
| 93 | +/*! Determines if a region intersects a region. */ |
| 94 | +CG_EXTERN bool CGSRegionIntersectsRegion(CGSRegionObj region1, CGSRegionObj region2); |
| 95 | + |
| 96 | +/*! Creates a rect from the difference of two regions. */ |
| 97 | +CG_EXTERN CGError CGSDiffRegion(CGSRegionObj region1, CGSRegionObj region2, CGSRegionObj *outRegion); |
| 98 | + |
| 99 | + |
| 100 | +#pragma mark region enumerators |
| 101 | +/*! Gets the enumerator for a region. */ |
| 102 | +CG_EXTERN CGSRegionEnumeratorObj CGSRegionEnumerator(CGSRegionObj region); |
| 103 | + |
| 104 | +/*! Releases a region enumerator. */ |
| 105 | +CG_EXTERN void CGSReleaseRegionEnumerator(CGSRegionEnumeratorObj enumerator); |
| 106 | + |
| 107 | +/*! Gets the next rect of a region. */ |
| 108 | +CG_EXTERN CGRect* CGSNextRect(CGSRegionEnumeratorObj enumerator); |
| 109 | + |
| 110 | +CG_EXTERN_C_END |
0 commit comments