]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: region.h | |
3 | // Purpose: wxRegion class | |
4 | // Author: Markus Holzem, Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
bbcdf8bc JS |
8 | // Copyright: (c) Julian Smart |
9 | // Licence: wxWindows licence | |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
bbcdf8bc JS |
12 | #ifndef _WX_REGION_H_ |
13 | #define _WX_REGION_H_ | |
2bda0e17 KB |
14 | |
15 | #ifdef __GNUG__ | |
16 | #pragma interface "region.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/list.h" | |
20 | #include "wx/gdiobj.h" | |
2432b92d | 21 | #include "wx/gdicmn.h" |
2bda0e17 KB |
22 | |
23 | class WXDLLEXPORT wxRect; | |
24 | class WXDLLEXPORT wxPoint; | |
25 | ||
26 | enum wxRegionContain { | |
27 | wxOutRegion = 0, wxPartRegion = 1, wxInRegion = 2 | |
28 | }; | |
29 | ||
30 | // So far, for internal use only | |
31 | enum wxRegionOp { | |
32 | wxRGN_AND, // Creates the intersection of the two combined regions. | |
33 | wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1. | |
34 | wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2. | |
35 | wxRGN_OR, // Creates the union of two combined regions. | |
36 | wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas. | |
37 | }; | |
38 | ||
39 | class WXDLLEXPORT wxRegion : public wxGDIObject { | |
40 | DECLARE_DYNAMIC_CLASS(wxRegion); | |
41 | friend class WXDLLEXPORT wxRegionIterator; | |
42 | public: | |
43 | wxRegion(long x, long y, long w, long h); | |
44 | wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight); | |
45 | wxRegion(const wxRect& rect); | |
81d66cf3 | 46 | wxRegion(WXHRGN hRegion); // Hangs on to this region |
2bda0e17 KB |
47 | |
48 | wxRegion(void); | |
49 | ~wxRegion(void); | |
50 | ||
51 | //# Copying | |
52 | inline wxRegion(const wxRegion& r) | |
53 | { Ref(r); } | |
54 | inline wxRegion& operator = (const wxRegion& r) | |
55 | { Ref(r); return (*this); } | |
56 | ||
57 | //# Modify region | |
58 | // Clear current region | |
59 | void Clear(void); | |
60 | ||
61 | // Union rectangle or region with this. | |
62 | inline bool Union(long x, long y, long width, long height) { return Combine(x, y, width, height, wxRGN_OR); } | |
63 | inline bool Union(const wxRect& rect) { return Combine(rect, wxRGN_OR); } | |
64 | inline bool Union(const wxRegion& region) { return Combine(region, wxRGN_OR); } | |
65 | ||
66 | // Intersect rectangle or region with this. | |
67 | inline bool Intersect(long x, long y, long width, long height) { return Combine(x, y, width, height, wxRGN_AND); } | |
68 | inline bool Intersect(const wxRect& rect) { return Combine(rect, wxRGN_AND); } | |
69 | inline bool Intersect(const wxRegion& region) { return Combine(region, wxRGN_AND); } | |
70 | ||
71 | // Subtract rectangle or region from this: | |
72 | // Combines the parts of 'this' that are not part of the second region. | |
73 | inline bool Subtract(long x, long y, long width, long height) { return Combine(x, y, width, height, wxRGN_DIFF); } | |
74 | inline bool Subtract(const wxRect& rect) { return Combine(rect, wxRGN_DIFF); } | |
75 | inline bool Subtract(const wxRegion& region) { return Combine(region, wxRGN_DIFF); } | |
76 | ||
77 | // XOR: the union of two combined regions except for any overlapping areas. | |
78 | inline bool Xor(long x, long y, long width, long height) { return Combine(x, y, width, height, wxRGN_XOR); } | |
79 | inline bool Xor(const wxRect& rect) { return Combine(rect, wxRGN_XOR); } | |
80 | inline bool Xor(const wxRegion& region) { return Combine(region, wxRGN_XOR); } | |
81 | ||
82 | //# Information on region | |
83 | // Outer bounds of region | |
84 | void GetBox(long& x, long& y, long&w, long &h) const; | |
85 | wxRect GetBox(void) const ; | |
86 | ||
87 | // Is region empty? | |
88 | bool Empty(void) const; | |
89 | inline bool IsEmpty(void) const { return Empty(); } | |
90 | ||
91 | //# Tests | |
92 | // Does the region contain the point (x,y)? | |
93 | wxRegionContain Contains(long x, long y) const; | |
94 | // Does the region contain the point pt? | |
95 | wxRegionContain Contains(const wxPoint& pt) const; | |
96 | // Does the region contain the rectangle (x, y, w, h)? | |
97 | wxRegionContain Contains(long x, long y, long w, long h) const; | |
98 | // Does the region contain the rectangle rect? | |
99 | wxRegionContain Contains(const wxRect& rect) const; | |
100 | ||
101 | // Internal | |
102 | bool Combine(long x, long y, long width, long height, wxRegionOp op); | |
103 | bool Combine(const wxRegion& region, wxRegionOp op); | |
104 | bool Combine(const wxRect& rect, wxRegionOp op); | |
a724d789 JS |
105 | |
106 | // Get internal region handle | |
107 | WXHRGN GetHRGN() const; | |
2bda0e17 KB |
108 | }; |
109 | ||
110 | class WXDLLEXPORT wxRegionIterator : public wxObject { | |
111 | DECLARE_DYNAMIC_CLASS(wxRegionIterator); | |
112 | public: | |
113 | wxRegionIterator(void); | |
114 | wxRegionIterator(const wxRegion& region); | |
115 | ~wxRegionIterator(void); | |
116 | ||
117 | void Reset(void) { m_current = 0; } | |
118 | void Reset(const wxRegion& region); | |
119 | ||
a3ef5bf5 JS |
120 | #ifndef __SALFORDC__ |
121 | operator bool (void) const { return (m_current < m_numRects); } | |
122 | #endif | |
123 | ||
124 | bool HaveRects(void) const { return (m_current < m_numRects); } | |
2bda0e17 KB |
125 | |
126 | void operator ++ (void); | |
127 | void operator ++ (int); | |
128 | ||
129 | long GetX(void) const; | |
130 | long GetY(void) const; | |
131 | long GetW(void) const; | |
132 | long GetWidth(void) const { return GetW(); } | |
133 | long GetH(void) const; | |
134 | long GetHeight(void) const { return GetH(); } | |
3572173c | 135 | wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); } |
2bda0e17 KB |
136 | |
137 | private: | |
138 | long m_current; | |
139 | long m_numRects; | |
140 | wxRegion m_region; | |
141 | wxRect* m_rects; | |
142 | }; | |
143 | ||
144 | #endif | |
bbcdf8bc | 145 | // _WX_REGION_H_ |