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