OpenCPN Partial API docs
Loading...
Searching...
No Matches
ocpn_region.h
Go to the documentation of this file.
1
2// Author: Robert Roebling
3// Copyright: (c) 1998 Robert Roebling
4// Copyright: (c) 2010 David S Register
5// Licence: wxWindows licence
7
14#ifndef _OCPN_REGION_H_
15#define _OCPN_REGION_H_
16
17#include <wx/wxprec.h>
18
19#ifndef WX_PRECOMP
20#include <wx/wx.h>
21#endif
22
23#define USE_NEW_REGION
24
31class OCPNRegion : public
32#ifdef USE_NEW_REGION
33 wxObject
34#else
35 wxRegion
36#endif
37{
38public:
39 OCPNRegion() {}
40
41 OCPNRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
42 OCPNRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
43 OCPNRegion(const wxRect& rect);
44 OCPNRegion(const wxRegion& region);
45 OCPNRegion(size_t n, const wxPoint* points, int fillStyle = wxODDEVEN_RULE);
46
47 virtual ~OCPNRegion();
48
49 wxRegion* GetNew_wxRegion() const;
50
51#ifdef USE_NEW_REGION
52
53 // common part of ctors for a rectangle region
54 void InitRect(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
55
56 // operators
57 // ---------
58 bool operator==(const OCPNRegion& region) const { return ODoIsEqual(region); }
59 bool operator!=(const OCPNRegion& region) const { return !(*this == region); }
60
61 bool IsOk() const { return m_refData != NULL; }
62 bool Ok() const { return IsOk(); }
63
64 // Get the bounding box
65 bool GetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const {
66 return ODoGetBox(x, y, w, h);
67 }
68 wxRect GetBox() const {
69 wxCoord x, y, w, h;
70 return ODoGetBox(x, y, w, h) ? wxRect(x, y, w, h) : wxRect();
71 }
72
73 // Test if the given point or rectangle is inside this region
74 wxRegionContain Contains(wxCoord x, wxCoord y) const {
75 return ODoContainsPoint(x, y);
76 }
77 wxRegionContain Contains(const wxPoint& pt) const {
78 return ODoContainsPoint(pt.x, pt.y);
79 }
80 wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const {
81 return ODoContainsRect(wxRect(x, y, w, h));
82 }
83 wxRegionContain Contains(const wxRect& rect) const {
84 return ODoContainsRect(rect);
85 }
86
87 // Is region equal (i.e. covers the same area as another one)?
88 bool IsEqual(const OCPNRegion& region) const;
89
90 // OCPNRegionBase methods
91 virtual void Clear();
92 virtual bool IsEmpty() const;
93 bool Empty() const { return IsEmpty(); }
94
95public:
96 // OCPNRegion( OGdkRegion *region );
97
98 void* GetRegion() const;
99
100 bool Offset(wxCoord x, wxCoord y) { return ODoOffset(x, y); }
101 bool Offset(const wxPoint& pt) { return ODoOffset(pt.x, pt.y); }
102 bool Intersect(const OCPNRegion& region) { return ODoIntersect(region); }
103 bool Union(const OCPNRegion& region) { return ODoUnionWithRegion(region); }
104 bool Union(wxCoord x, wxCoord y, wxCoord w, wxCoord h) {
105 return ODoUnionWithRect(wxRect(x, y, w, h));
106 }
107 bool Union(const wxRect& rect) { return ODoUnionWithRect(rect); }
108 bool Subtract(const OCPNRegion& region) { return ODoSubtract(region); }
109
110protected:
111 // ref counting code
112 virtual wxObjectRefData* CreateRefData() const;
113 virtual wxObjectRefData* CloneRefData(const wxObjectRefData* data) const;
114
115 // wxRegionBase pure virtuals
116 virtual bool ODoIsEqual(const OCPNRegion& region) const;
117 virtual bool ODoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const;
118 virtual wxRegionContain ODoContainsPoint(wxCoord x, wxCoord y) const;
119 virtual wxRegionContain ODoContainsRect(const wxRect& rect) const;
120
121 virtual bool ODoOffset(wxCoord x, wxCoord y);
122 virtual bool ODoUnionWithRect(const wxRect& rect);
123 virtual bool ODoUnionWithRegion(const OCPNRegion& region);
124 virtual bool ODoIntersect(const OCPNRegion& region);
125 virtual bool ODoSubtract(const OCPNRegion& region);
126 // virtual bool DoXor(const OCPNRegion& region);
127
128#endif
129};
130
138public:
140 OCPNRegionIterator(const OCPNRegion& region);
141 virtual ~OCPNRegionIterator();
142
143 void Reset();
144 void Reset(const OCPNRegion& region);
145
146 bool HaveRects() const;
147 void NextRect(void);
148 wxRect GetRect() const;
149
150private:
151#ifdef USE_NEW_REGION
152 void Init();
153 void CreateRects(const OCPNRegion& r);
154
155 size_t m_current;
156 OCPNRegion m_region;
157
158 wxRect* m_rects;
159 size_t m_numRects;
160#else
161 wxRegionIterator* m_ri;
162#endif
163};
164
165#endif
166// _OCPN_REGION_H_
An iterator class for OCPNRegion.
A wrapper class for wxRegion with additional functionality.
Definition ocpn_region.h:37