OpenCPN Partial API docs
Loading...
Searching...
No Matches
OCPNRegion.h
1/***************************************************************************
2 *
3 * Project: OpenCPN
4 *
5 ***************************************************************************
6 * Portions Copyright (C) 2010 by David S. Register *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
22 ***************************************************************************
23 */
24
26// Author: Robert Roebling
27// Copyright: (c) 1998 Robert Roebling
28// Licence: wxWindows licence
30
31#ifndef _OCPN_REGION_H_
32#define _OCPN_REGION_H_
33
34#include <wx/wxprec.h>
35
36#ifndef WX_PRECOMP
37#include <wx/wx.h>
38#endif // precompiled headers
39
40// #if defined(__WXOSX__)
41#define USE_NEW_REGION
42// #endif
43
50class OCPNRegion : public
51#ifdef USE_NEW_REGION
52 wxObject
53#else
54 wxRegion
55#endif
56{
57public:
58 OCPNRegion() {}
59
60 OCPNRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
61 OCPNRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
62 OCPNRegion(const wxRect& rect);
63 OCPNRegion(const wxRegion& region);
64 OCPNRegion(size_t n, const wxPoint* points, int fillStyle = wxODDEVEN_RULE);
65
66 virtual ~OCPNRegion();
67
68 wxRegion* GetNew_wxRegion() const;
69
70#ifdef USE_NEW_REGION
71
72 // common part of ctors for a rectangle region
73 void InitRect(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
74
75 // operators
76 // ---------
77 bool operator==(const OCPNRegion& region) const { return ODoIsEqual(region); }
78 bool operator!=(const OCPNRegion& region) const { return !(*this == region); }
79
80 bool IsOk() const { return m_refData != NULL; }
81 bool Ok() const { return IsOk(); }
82
83 // Get the bounding box
84 bool GetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const {
85 return ODoGetBox(x, y, w, h);
86 }
87 wxRect GetBox() const {
88 wxCoord x, y, w, h;
89 return ODoGetBox(x, y, w, h) ? wxRect(x, y, w, h) : wxRect();
90 }
91
92 // Test if the given point or rectangle is inside this region
93 wxRegionContain Contains(wxCoord x, wxCoord y) const {
94 return ODoContainsPoint(x, y);
95 }
96 wxRegionContain Contains(const wxPoint& pt) const {
97 return ODoContainsPoint(pt.x, pt.y);
98 }
99 wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const {
100 return ODoContainsRect(wxRect(x, y, w, h));
101 }
102 wxRegionContain Contains(const wxRect& rect) const {
103 return ODoContainsRect(rect);
104 }
105
106 // Is region equal (i.e. covers the same area as another one)?
107 bool IsEqual(const OCPNRegion& region) const;
108
109 // OCPNRegionBase methods
110 virtual void Clear();
111 virtual bool IsEmpty() const;
112 bool Empty() const { return IsEmpty(); }
113
114public:
115 // OCPNRegion( OGdkRegion *region );
116
117 void* GetRegion() const;
118
119 bool Offset(wxCoord x, wxCoord y) { return ODoOffset(x, y); }
120 bool Offset(const wxPoint& pt) { return ODoOffset(pt.x, pt.y); }
121 bool Intersect(const OCPNRegion& region) { return ODoIntersect(region); }
122 bool Union(const OCPNRegion& region) { return ODoUnionWithRegion(region); }
123 bool Union(wxCoord x, wxCoord y, wxCoord w, wxCoord h) {
124 return ODoUnionWithRect(wxRect(x, y, w, h));
125 }
126 bool Union(const wxRect& rect) { return ODoUnionWithRect(rect); }
127 bool Subtract(const OCPNRegion& region) { return ODoSubtract(region); }
128
129protected:
130 // ref counting code
131 virtual wxObjectRefData* CreateRefData() const;
132 virtual wxObjectRefData* CloneRefData(const wxObjectRefData* data) const;
133
134 // wxRegionBase pure virtuals
135 virtual bool ODoIsEqual(const OCPNRegion& region) const;
136 virtual bool ODoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const;
137 virtual wxRegionContain ODoContainsPoint(wxCoord x, wxCoord y) const;
138 virtual wxRegionContain ODoContainsRect(const wxRect& rect) const;
139
140 virtual bool ODoOffset(wxCoord x, wxCoord y);
141 virtual bool ODoUnionWithRect(const wxRect& rect);
142 virtual bool ODoUnionWithRegion(const OCPNRegion& region);
143 virtual bool ODoIntersect(const OCPNRegion& region);
144 virtual bool ODoSubtract(const OCPNRegion& region);
145 // virtual bool DoXor(const OCPNRegion& region);
146
147#endif
148};
149
157public:
159 OCPNRegionIterator(const OCPNRegion& region);
160 virtual ~OCPNRegionIterator();
161
162 void Reset();
163 void Reset(const OCPNRegion& region);
164
165 bool HaveRects() const;
166 void NextRect(void);
167 wxRect GetRect() const;
168
169private:
170#ifdef USE_NEW_REGION
171 void Init();
172 void CreateRects(const OCPNRegion& r);
173
174 size_t m_current;
175 OCPNRegion m_region;
176
177 wxRect* m_rects;
178 size_t m_numRects;
179#else
180 wxRegionIterator* m_ri;
181#endif
182};
183
184#endif
185// _OCPN_REGION_H_
An iterator class for OCPNRegion.
Definition OCPNRegion.h:156
A wrapper class for wxRegion with additional functionality.
Definition OCPNRegion.h:56