2 * Copyright (C) 2007-2008 Alacatia Labs
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.
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:
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.
20 * Joe Ranieri joe@alacatia.com
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;
32 // but opaque types under 10.4
33 typedef int CGSRegionObj;
34 typedef int CGSRegionEnumeratorObj;
39 /*! Creates a region from a `CGRect`. */
40 CG_EXTERN CGError CGSNewRegionWithRect(const CGRect *rect, CGSRegionObj *outRegion);
42 /*! Creates a region from a list of `CGRect`s. */
43 CG_EXTERN CGError CGSNewRegionWithRectList(const CGRect *rects, int rectCount, CGSRegionObj *outRegion);
45 /*! Creates a new region from a QuickDraw region. */
46 CG_EXTERN CGError CGSNewRegionWithQDRgn(RgnHandle region, CGSRegionObj *outRegion);
48 /*! Creates an empty region. */
49 CG_EXTERN CGError CGSNewEmptyRegion(CGSRegionObj *outRegion);
51 /*! Releases a region. */
52 CG_EXTERN CGError CGSReleaseRegion(CGSRegionObj region);
54 /*! Creates a `CGRect` from a region. */
55 CG_EXTERN CGError CGSGetRegionBounds(CGSRegionObj region, CGRect *outRect);
57 /*! Determines if two regions are equal. */
58 CG_EXTERN bool CGSRegionsEqual(CGSRegionObj region1, CGSRegionObj region2);
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);
63 /*! Creates a new region by copying an existing one. */
64 CG_EXTERN CGError CGSCopyRegion(CGSRegionObj region, CGSRegionObj *outRegion);
66 /*! Creates a new region by combining two regions together. */
67 CG_EXTERN CGError CGSUnionRegion(CGSRegionObj region1, CGSRegionObj region2, CGSRegionObj *outRegion);
69 /*! Creates a new region by combining a region and a rect. */
70 CG_EXTERN CGError CGSUnionRegionWithRect(CGSRegionObj region, CGRect *rect, CGSRegionObj *outRegion);
72 /*! Creates a region by XORing two regions together. */
73 CG_EXTERN CGError CGSXorRegion(CGSRegionObj region1, CGSRegionObj region2, CGSRegionObj *outRegion);
75 /*! Determines if the region is empty. */
76 CG_EXTERN bool CGSRegionIsEmpty(CGSRegionObj region);
78 /*! Determines if the region is rectangular. */
79 CG_EXTERN bool CGSRegionIsRectangular(CGSRegionObj region);
81 /*! Determines if a point in a region. */
82 CG_EXTERN bool CGSPointInRegion(CGSRegionObj region, const CGPoint *point);
84 /*! Determines if a rect is in a region. */
85 CG_EXTERN bool CGSRectInRegion(CGSRegionObj region, const CGRect *rect);
87 /*! Determines if a region is inside of a region. */
88 CG_EXTERN bool CGSRegionInRegion(CGSRegionObj region1, CGSRegionObj region2);
90 /*! Determines if a rect intersects a region. */
91 CG_EXTERN bool CGSRegionIntersectsRect(CGSRegionObj obj, const CGRect *rect);
93 /*! Determines if a region intersects a region. */
94 CG_EXTERN bool CGSRegionIntersectsRegion(CGSRegionObj region1, CGSRegionObj region2);
96 /*! Creates a rect from the difference of two regions. */
97 CG_EXTERN CGError CGSDiffRegion(CGSRegionObj region1, CGSRegionObj region2, CGSRegionObj *outRegion);
100 #pragma mark region enumerators
101 /*! Gets the enumerator for a region. */
102 CG_EXTERN CGSRegionEnumeratorObj CGSRegionEnumerator(CGSRegionObj region);
104 /*! Releases a region enumerator. */
105 CG_EXTERN void CGSReleaseRegionEnumerator(CGSRegionEnumeratorObj enumerator);
107 /*! Gets the next rect of a region. */
108 CG_EXTERN CGRect* CGSNextRect(CGSRegionEnumeratorObj enumerator);