]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/region.h
Improvements for building minimal builds and new ports: wxUSE_* usage and minor cleaning.
[wxWidgets.git] / include / wx / generic / region.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/region.h
3 // Purpose: generic wxRegion class
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2004/04/12
7 // RCS-ID: $Id$
8 // Copyright: (c) 2004 David Elliott
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GENERIC_REGION_H__
13 #define _WX_GENERIC_REGION_H__
14
15 #include "wx/gdiobj.h"
16 #include "wx/gdicmn.h"
17
18 class WXDLLEXPORT wxRect;
19 class WXDLLEXPORT wxPoint;
20
21 enum wxRegionContain
22 { wxOutRegion = 0
23 , wxPartRegion = 1
24 , wxInRegion = 2
25 };
26
27 class WXDLLEXPORT wxRegionGeneric : public wxGDIObject
28 {
29 // DECLARE_DYNAMIC_CLASS(wxRegionGeneric);
30 friend class WXDLLEXPORT wxRegionIteratorGeneric;
31 public:
32 wxRegionGeneric(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
33 wxRegionGeneric(const wxPoint& topLeft, const wxPoint& bottomRight);
34 wxRegionGeneric(const wxRect& rect);
35 wxRegionGeneric();
36 ~wxRegionGeneric();
37
38 bool Ok() const { return m_refData != NULL; }
39
40 bool operator == ( const wxRegionGeneric& region ) const;
41 bool operator != ( const wxRegionGeneric& region ) const { return !(*this == region); }
42
43 //# Modify region
44 // Clear current region
45 void Clear();
46
47 // Move the region
48 bool Offset(wxCoord x, wxCoord y);
49
50 // Union rectangle or region with this.
51 bool Union(long x, long y, long width, long height)
52 { return Union(wxRect(x,y,width,height)); }
53 bool Union(const wxRect& rect);
54 bool Union(const wxRegionGeneric& region);
55
56 // Intersect rectangle or region with this.
57 bool Intersect(long x, long y, long width, long height)
58 { return Intersect(wxRect(x,y,width,height)); }
59 bool Intersect(const wxRect& rect);
60 bool Intersect(const wxRegionGeneric& region);
61
62 // Subtract rectangle or region from this:
63 // Combines the parts of 'this' that are not part of the second region.
64 bool Subtract(long x, long y, long width, long height)
65 { return Subtract(wxRect(x,y,width,height)); }
66 bool Subtract(const wxRect& rect);
67 bool Subtract(const wxRegionGeneric& region);
68
69 // XOR: the union of two combined regions except for any overlapping areas.
70 bool Xor(long x, long y, long width, long height);
71 bool Xor(const wxRect& rect);
72 bool Xor(const wxRegionGeneric& region);
73
74 //# Information on region
75 // Outer bounds of region
76 void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
77 wxRect GetBox() const;
78
79 // Is region empty?
80 bool Empty() const;
81 inline bool IsEmpty() const { return Empty(); }
82
83 //# Tests
84 // Does the region contain the point (x,y)?
85 wxRegionContain Contains(long x, long y) const;
86 // Does the region contain the point pt?
87 wxRegionContain Contains(const wxPoint& pt) const;
88 // Does the region contain the rectangle (x, y, w, h)?
89 wxRegionContain Contains(long x, long y, long w, long h) const;
90 // Does the region contain the rectangle rect?
91 wxRegionContain Contains(const wxRect& rect) const;
92
93 // Use the non-transparent pixels of a wxBitmap for the region to combine
94 // with this region. First version takes transparency from bitmap's mask,
95 // second lets the user specify the colour to be treated as transparent
96 // along with an optional tolerance value.
97 // NOTE: implemented in common/rgncmn.cpp
98 bool Union(const wxBitmap& bmp);
99 bool Union(const wxBitmap& bmp,
100 const wxColour& transColour, int tolerance = 0);
101
102 // Convert the region to a B&W bitmap with the white pixels being inside
103 // the region.
104 wxBitmap ConvertToBitmap() const;
105
106 protected:
107 virtual wxObjectRefData *CreateRefData() const;
108 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
109 };
110
111 class WXDLLEXPORT wxRegionIteratorGeneric : public wxObject
112 {
113 // DECLARE_DYNAMIC_CLASS(wxRegionIteratorGeneric);
114 public:
115 wxRegionIteratorGeneric();
116 wxRegionIteratorGeneric(const wxRegionGeneric& region);
117 wxRegionIteratorGeneric(const wxRegionIteratorGeneric& iterator);
118 ~wxRegionIteratorGeneric();
119
120 wxRegionIteratorGeneric& operator=(const wxRegionIteratorGeneric& iterator);
121
122 void Reset() { m_current = 0; }
123 void Reset(const wxRegionGeneric& region);
124
125 operator bool () const { return HaveRects(); }
126 bool HaveRects() const;
127
128 wxRegionIteratorGeneric& operator++();
129 wxRegionIteratorGeneric operator++(int);
130
131 long GetX() const;
132 long GetY() const;
133 long GetW() const;
134 long GetWidth() const { return GetW(); }
135 long GetH() const;
136 long GetHeight() const { return GetH(); }
137 wxRect GetRect() const;
138 private:
139 long m_current;
140 wxRegionGeneric m_region;
141 };
142
143 #endif //ndef _WX_GENERIC_REGION_H__