]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/region.h
centralized Esc key handling for closing the dialogs in wxDialogBase:
[wxWidgets.git] / include / wx / generic / region.h
CommitLineData
4c3c3844
DE
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
ca65c044 9// Licence: wxWindows licence
4c3c3844
DE
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
18class WXDLLEXPORT wxRect;
19class WXDLLEXPORT wxPoint;
20
4c3c3844
DE
21class WXDLLEXPORT wxRegionGeneric : public wxGDIObject
22{
23// DECLARE_DYNAMIC_CLASS(wxRegionGeneric);
24 friend class WXDLLEXPORT wxRegionIteratorGeneric;
25public:
26 wxRegionGeneric(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
27 wxRegionGeneric(const wxPoint& topLeft, const wxPoint& bottomRight);
28 wxRegionGeneric(const wxRect& rect);
29 wxRegionGeneric();
30 ~wxRegionGeneric();
31
4c3c3844
DE
32 bool Ok() const { return m_refData != NULL; }
33
fbfb8bcc
VZ
34 bool operator == ( const wxRegionGeneric& region ) const;
35 bool operator != ( const wxRegionGeneric& region ) const { return !(*this == region); }
4c3c3844
DE
36
37 //# Modify region
38 // Clear current region
39 void Clear();
40
41 // Move the region
42 bool Offset(wxCoord x, wxCoord y);
43
44 // Union rectangle or region with this.
45 bool Union(long x, long y, long width, long height)
46 { return Union(wxRect(x,y,width,height)); }
47 bool Union(const wxRect& rect);
48 bool Union(const wxRegionGeneric& region);
49
50 // Intersect rectangle or region with this.
51 bool Intersect(long x, long y, long width, long height)
52 { return Intersect(wxRect(x,y,width,height)); }
53 bool Intersect(const wxRect& rect);
54 bool Intersect(const wxRegionGeneric& region);
55
56 // Subtract rectangle or region from this:
57 // Combines the parts of 'this' that are not part of the second region.
58 bool Subtract(long x, long y, long width, long height)
59 { return Subtract(wxRect(x,y,width,height)); }
60 bool Subtract(const wxRect& rect);
61 bool Subtract(const wxRegionGeneric& region);
62
63 // XOR: the union of two combined regions except for any overlapping areas.
64 bool Xor(long x, long y, long width, long height);
65 bool Xor(const wxRect& rect);
66 bool Xor(const wxRegionGeneric& region);
67
68 //# Information on region
69 // Outer bounds of region
70 void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
71 wxRect GetBox() const;
72
73 // Is region empty?
74 bool Empty() const;
75 inline bool IsEmpty() const { return Empty(); }
76
77 //# Tests
78 // Does the region contain the point (x,y)?
79 wxRegionContain Contains(long x, long y) const;
80 // Does the region contain the point pt?
81 wxRegionContain Contains(const wxPoint& pt) const;
82 // Does the region contain the rectangle (x, y, w, h)?
83 wxRegionContain Contains(long x, long y, long w, long h) const;
84 // Does the region contain the rectangle rect?
85 wxRegionContain Contains(const wxRect& rect) const;
86
9a6384ca
WS
87 // Use the non-transparent pixels of a wxBitmap for the region to combine
88 // with this region. First version takes transparency from bitmap's mask,
89 // second lets the user specify the colour to be treated as transparent
90 // along with an optional tolerance value.
91 // NOTE: implemented in common/rgncmn.cpp
92 bool Union(const wxBitmap& bmp);
93 bool Union(const wxBitmap& bmp,
94 const wxColour& transColour, int tolerance = 0);
95
96 // Convert the region to a B&W bitmap with the white pixels being inside
97 // the region.
98 wxBitmap ConvertToBitmap() const;
99
4c3c3844
DE
100protected:
101 virtual wxObjectRefData *CreateRefData() const;
102 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
103};
104
105class WXDLLEXPORT wxRegionIteratorGeneric : public wxObject
106{
107// DECLARE_DYNAMIC_CLASS(wxRegionIteratorGeneric);
108public:
109 wxRegionIteratorGeneric();
110 wxRegionIteratorGeneric(const wxRegionGeneric& region);
111 wxRegionIteratorGeneric(const wxRegionIteratorGeneric& iterator);
112 ~wxRegionIteratorGeneric();
113
114 wxRegionIteratorGeneric& operator=(const wxRegionIteratorGeneric& iterator);
115
116 void Reset() { m_current = 0; }
117 void Reset(const wxRegionGeneric& region);
118
119 operator bool () const { return HaveRects(); }
120 bool HaveRects() const;
121
122 wxRegionIteratorGeneric& operator++();
123 wxRegionIteratorGeneric operator++(int);
124
125 long GetX() const;
126 long GetY() const;
127 long GetW() const;
128 long GetWidth() const { return GetW(); }
129 long GetH() const;
130 long GetHeight() const { return GetH(); }
131 wxRect GetRect() const;
132private:
133 long m_current;
134 wxRegionGeneric m_region;
135};
136
137#endif //ndef _WX_GENERIC_REGION_H__