]> git.saurik.com Git - wxWidgets.git/blame - include/wx/x11/region.h
1. added support for bitmaps with alpha channel
[wxWidgets.git] / include / wx / x11 / region.h
CommitLineData
83df96d6
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$
1934d291 8// Copyright: (c) Julian Smart, Robert Roebling
65571936 9// Licence: wxWindows licence
83df96d6
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_REGION_H_
13#define _WX_REGION_H_
14
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
83df96d6
JS
16#pragma interface "region.h"
17#endif
18
19#include "wx/list.h"
20#include "wx/gdiobj.h"
21#include "wx/gdicmn.h"
22
1934d291
RR
23//-----------------------------------------------------------------------------
24// classes
25//-----------------------------------------------------------------------------
83df96d6 26
1934d291 27class wxRegion;
83df96d6 28
1934d291
RR
29//-----------------------------------------------------------------------------
30// constants
31//-----------------------------------------------------------------------------
83df96d6 32
1934d291
RR
33enum wxRegionContain
34{
35 wxOutRegion = 0,
36 wxPartRegion = 1,
37 wxInRegion = 2
83df96d6
JS
38};
39
40// So far, for internal use only
1934d291
RR
41enum wxRegionOp
42{
43 wxRGN_AND, // Creates the intersection of the two combined regions.
44 wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1.
45 wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
46 wxRGN_OR, // Creates the union of two combined regions.
47 wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas.
83df96d6
JS
48};
49
1934d291
RR
50// ----------------------------------------------------------------------------
51// wxRegion
52// ----------------------------------------------------------------------------
53
54class wxRegion : public wxGDIObject
55{
83df96d6 56public:
1934d291
RR
57 wxRegion() { }
58
59 wxRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h )
60 {
61 InitRect(x, y, w, h);
62 }
63
64 wxRegion( const wxPoint& topLeft, const wxPoint& bottomRight )
65 {
66 InitRect(topLeft.x, topLeft.y,
67 bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
68 }
69
70 wxRegion( const wxRect& rect )
71 {
72 InitRect(rect.x, rect.y, rect.width, rect.height);
73 }
74
75 wxRegion( size_t n, const wxPoint *points, int fillStyle = wxODDEVEN_RULE );
1542ea39 76
85f6b408
VS
77 wxRegion( const wxBitmap& bmp)
78 {
79 Union(bmp);
80 }
1542ea39 81 wxRegion( const wxBitmap& bmp,
85f6b408 82 const wxColour& transColour, int tolerance = 0)
1542ea39
RD
83 {
84 Union(bmp, transColour, tolerance);
85 }
86
83df96d6 87 ~wxRegion();
1934d291
RR
88
89 wxRegion( const wxRegion& region ) { Ref(region); }
90 wxRegion& operator = ( const wxRegion& region ) { Ref(region); return *this; }
91
92 bool Ok() const { return m_refData != NULL; }
93
94 bool operator == ( const wxRegion& region );
95 bool operator != ( const wxRegion& region ) { return !(*this == region); }
96
83df96d6 97 void Clear();
1934d291
RR
98
99 bool Offset( wxCoord x, wxCoord y );
100
101 bool Union( wxCoord x, wxCoord y, wxCoord width, wxCoord height );
102 bool Union( const wxRect& rect );
103 bool Union( const wxRegion& region );
104
105 bool Intersect( wxCoord x, wxCoord y, wxCoord width, wxCoord height );
106 bool Intersect( const wxRect& rect );
107 bool Intersect( const wxRegion& region );
108
109 bool Subtract( wxCoord x, wxCoord y, wxCoord width, wxCoord height );
110 bool Subtract( const wxRect& rect );
111 bool Subtract( const wxRegion& region );
112
113 bool Xor( wxCoord x, wxCoord y, wxCoord width, wxCoord height );
114 bool Xor( const wxRect& rect );
115 bool Xor( const wxRegion& region );
116
117 void GetBox( wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h ) const;
83df96d6 118 wxRect GetBox() const ;
1934d291 119
83df96d6 120 bool Empty() const;
1934d291
RR
121 bool IsEmpty() const { return Empty(); }
122
123 wxRegionContain Contains( wxCoord x, wxCoord y ) const;
124 wxRegionContain Contains( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) const;
83df96d6 125 wxRegionContain Contains(const wxPoint& pt) const;
83df96d6 126 wxRegionContain Contains(const wxRect& rect) const;
1934d291 127
819451b6 128 // Convert the region to a B&W bitmap with the white pixels being inside
1542ea39
RD
129 // the region.
130 wxBitmap ConvertToBitmap() const;
131
132 // Use the non-transparent pixels of a wxBitmap for the region to combine
85f6b408
VS
133 // with this region. First version takes transparency from bitmap's mask,
134 // second lets the user specify the colour to be treated as transparent
1542ea39 135 // along with an optional tolerance value.
85f6b408
VS
136 // NOTE: implemented in common/rgncmn.cpp
137 bool Union(const wxBitmap& bmp);
1542ea39 138 bool Union(const wxBitmap& bmp,
85f6b408 139 const wxColour& transColour, int tolerance = 0);
1542ea39
RD
140
141
1934d291
RR
142public:
143 WXRegion *GetX11Region() const;
144
145protected:
146 // ref counting code
147 virtual wxObjectRefData *CreateRefData() const;
148 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
1542ea39 149
1934d291
RR
150 // common part of ctors for a rectangle region
151 void InitRect(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
152
153private:
154 DECLARE_DYNAMIC_CLASS(wxRegion);
83df96d6
JS
155};
156
1934d291
RR
157// ----------------------------------------------------------------------------
158// wxRegionIterator: decomposes a region into rectangles
159// ----------------------------------------------------------------------------
160
161class wxRegionIterator: public wxObject
162{
83df96d6
JS
163public:
164 wxRegionIterator();
165 wxRegionIterator(const wxRegion& region);
1934d291
RR
166
167 void Reset() { m_current = 0u; }
83df96d6 168 void Reset(const wxRegion& region);
1934d291
RR
169
170 operator bool () const;
171 bool HaveRects() const;
172
83df96d6
JS
173 void operator ++ ();
174 void operator ++ (int);
1934d291 175
83df96d6
JS
176 wxCoord GetX() const;
177 wxCoord GetY() const;
178 wxCoord GetW() const;
179 wxCoord GetWidth() const { return GetW(); }
180 wxCoord GetH() const;
181 wxCoord GetHeight() const { return GetH(); }
1934d291
RR
182 wxRect GetRect() const;
183
83df96d6 184private:
1934d291 185 size_t m_current;
83df96d6 186 wxRegion m_region;
1934d291
RR
187
188private:
189 DECLARE_DYNAMIC_CLASS(wxRegionIterator);
83df96d6
JS
190};
191
192#endif
193// _WX_REGION_H_