]> git.saurik.com Git - wxWidgets.git/blame - include/wx/motif/region.h
API adaptions to MSW EnhMetafile
[wxWidgets.git] / include / wx / motif / region.h
CommitLineData
9b6dbb09
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: region.h
3// Purpose: wxRegion class
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_REGION_H_
13#define _WX_REGION_H_
14
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
9b6dbb09
JS
16#pragma interface "region.h"
17#endif
18
19#include "wx/list.h"
20#include "wx/gdiobj.h"
3dd4e4e0 21#include "wx/gdicmn.h"
9b6dbb09 22
25f47127
JS
23// ----------------------------------------------------------------------------
24// A list of rectangles type used by wxRegion and wxWindow
25// ----------------------------------------------------------------------------
26
27WX_DECLARE_LIST(wxRect, wxRectList);
28
9b6dbb09
JS
29
30enum wxRegionContain {
83df96d6 31 wxOutRegion = 0, wxPartRegion = 1, wxInRegion = 2
9b6dbb09
JS
32};
33
34// So far, for internal use only
35enum wxRegionOp {
83df96d6
JS
36 wxRGN_AND, // Creates the intersection of the two combined regions.
37 wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1.
38 wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
39 wxRGN_OR, // Creates the union of two combined regions.
40 wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas.
9b6dbb09
JS
41};
42
43class WXDLLEXPORT wxRegion : public wxGDIObject {
f052d487 44 DECLARE_DYNAMIC_CLASS(wxRegion)
83df96d6 45 friend class WXDLLEXPORT wxRegionIterator;
9b6dbb09 46public:
3ccf6cd7 47 wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
9b6dbb09
JS
48 wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
49 wxRegion(const wxRect& rect);
83df96d6 50 wxRegion();
1542ea39
RD
51 wxRegion( const wxBitmap& bmp,
52 const wxColour& transColour = wxNullColour,
53 int tolerance = 0)
54 {
55 Union(bmp, transColour, tolerance);
56 }
83df96d6 57 ~wxRegion();
1542ea39 58
83df96d6
JS
59 //# Copying
60 inline wxRegion(const wxRegion& r)
61 { Ref(r); }
62 inline wxRegion& operator = (const wxRegion& r)
63 { Ref(r); return (*this); }
1542ea39 64
83df96d6
JS
65 //# Modify region
66 // Clear current region
67 void Clear();
1542ea39 68
83df96d6
JS
69 // Union rectangle or region with this.
70 inline bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_OR); }
71 inline bool Union(const wxRect& rect) { return Combine(rect, wxRGN_OR); }
72 inline bool Union(const wxRegion& region) { return Combine(region, wxRGN_OR); }
1542ea39 73
83df96d6
JS
74 // Intersect rectangle or region with this.
75 inline bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_AND); }
76 inline bool Intersect(const wxRect& rect) { return Combine(rect, wxRGN_AND); }
77 inline bool Intersect(const wxRegion& region) { return Combine(region, wxRGN_AND); }
1542ea39 78
83df96d6 79 // Subtract rectangle or region from this:
9b6dbb09 80 // Combines the parts of 'this' that are not part of the second region.
83df96d6
JS
81 inline bool Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_DIFF); }
82 inline bool Subtract(const wxRect& rect) { return Combine(rect, wxRGN_DIFF); }
83 inline bool Subtract(const wxRegion& region) { return Combine(region, wxRGN_DIFF); }
1542ea39 84
83df96d6
JS
85 // XOR: the union of two combined regions except for any overlapping areas.
86 inline bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_XOR); }
87 inline bool Xor(const wxRect& rect) { return Combine(rect, wxRGN_XOR); }
88 inline bool Xor(const wxRegion& region) { return Combine(region, wxRGN_XOR); }
1542ea39 89
83df96d6
JS
90 //# Information on region
91 // Outer bounds of region
92 void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
93 wxRect GetBox() const ;
1542ea39 94
83df96d6
JS
95 // Is region empty?
96 bool Empty() const;
97 inline bool IsEmpty() const { return Empty(); }
98 bool Ok() const { return (m_refData != NULL) ; }
1542ea39 99
83df96d6
JS
100 //# Tests
101 // Does the region contain the point (x,y)?
102 wxRegionContain Contains(wxCoord x, wxCoord y) const;
103 // Does the region contain the point pt?
104 wxRegionContain Contains(const wxPoint& pt) const;
105 // Does the region contain the rectangle (x, y, w, h)?
106 wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const;
107 // Does the region contain the rectangle rect?
108 wxRegionContain Contains(const wxRect& rect) const;
1542ea39 109
819451b6 110 // Convert the region to a B&W bitmap with the white pixels being inside
1542ea39
RD
111 // the region.
112 wxBitmap ConvertToBitmap() const;
113
114 // Use the non-transparent pixels of a wxBitmap for the region to combine
115 // with this region. If the bitmap has a mask then it will be used,
116 // otherwise the colour to be treated as transparent may be specified,
117 // along with an optional tolerance value.
118 bool Union(const wxBitmap& bmp,
119 const wxColour& transColour = wxNullColour,
120 int tolerance = 0);
121
83df96d6
JS
122 // Internal
123 bool Combine(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxRegionOp op);
124 bool Combine(const wxRegion& region, wxRegionOp op);
125 bool Combine(const wxRect& rect, wxRegionOp op);
1542ea39 126
55acd85e 127 // Get the internal Region handle
45d49251 128 WXRegion GetXRegion() const;
1542ea39 129
83df96d6
JS
130 // 'Naughty' functions that allow wxWindows to use a list of rects
131 // instead of the region, in certain circumstances (e.g. when
132 // making a region out of the update rectangles).
133 // These are used by wxPaintDC::wxPaintDC and wxRegionIterator::Reset.
25f47127
JS
134 bool UsingRects() const;
135 wxRect* GetRects();
136 int GetRectCount() const;
137 void SetRects(const wxRectList& rectList);
138 void SetRects(int count, const wxRect* rects);
9b6dbb09
JS
139};
140
141class WXDLLEXPORT wxRegionIterator : public wxObject {
f052d487 142 DECLARE_DYNAMIC_CLASS(wxRegionIterator)
9b6dbb09 143public:
83df96d6
JS
144 wxRegionIterator();
145 wxRegionIterator(const wxRegion& region);
146 ~wxRegionIterator();
1542ea39 147
83df96d6
JS
148 void Reset() { m_current = 0; }
149 void Reset(const wxRegion& region);
1542ea39 150
83df96d6
JS
151 operator bool () const { return m_current < m_numRects; }
152 bool HaveRects() const { return m_current < m_numRects; }
1542ea39 153
83df96d6
JS
154 void operator ++ ();
155 void operator ++ (int);
1542ea39 156
83df96d6
JS
157 wxCoord GetX() const;
158 wxCoord GetY() const;
159 wxCoord GetW() const;
160 wxCoord GetWidth() const { return GetW(); }
161 wxCoord GetH() const;
162 wxCoord GetHeight() const { return GetH(); }
163 wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
1542ea39 164
9b6dbb09 165private:
83df96d6
JS
166 size_t m_current;
167 size_t m_numRects;
168 wxRegion m_region;
169 wxRect* m_rects;
9b6dbb09
JS
170};
171
172#endif
83df96d6 173// _WX_REGION_H_