]> git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/canvas/polygon.h
Merges from Scitech Branch (George Davison):
[wxWidgets.git] / contrib / include / wx / canvas / polygon.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: polygon.h
3 // Author: Klaas Holwerda
4 // Created: XX/XX/XX
5 // Copyright: 2000 (c) Klaas Holwerda
6 // Licence: wxWindows Licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 #ifndef __WXPOLYGON_H__
10 #define __WXPOLYGON_H__
11
12 #ifdef __GNUG__
13 #pragma interface "polygon.cpp"
14 #endif
15
16 #ifndef WX_PRECOMP
17 #include "wx/wx.h"
18 #endif
19
20 #include "wx/matrix.h"
21 #include "wx/geometry.h"
22 #include "bbox.h"
23 #include "canvas.h"
24
25 enum INOUTPOLY {OUTSIDE_POLY,INSIDE_POLY,ON_POLY};
26
27 //----------------------------------------------------------------------------
28 // wxCanvasPolygon
29 //----------------------------------------------------------------------------
30
31 class wxCanvasPolygon: public wxCanvasObject
32 {
33 public:
34 wxCanvasPolygon( int n, wxPoint2DDouble points[], bool spline = FALSE );
35 ~wxCanvasPolygon();
36 void SetBrush( const wxBrush& brush) { m_brush = brush; }
37 void SetPen( const wxPen& pen) { m_pen = pen; CalcBoundingBox(); }
38
39 //set colour 1
40 //being the background color if filling with a monochrome bitmap
41 //or in case of gradient filling the starting colour for the fill
42 void SetColour1( const wxColour& fg) { m_textfg=fg;}
43 //set colour 1
44 //being the foreground color if filling with a monochrome bitmap
45 //or in case of gradient filling the ending colour for the fill
46 void SetColour2( const wxColour& bg) { m_textbg=bg;}
47 //transparent filling when bitmapbrush is monochrome
48 void SetTransParent(bool transp) { m_transp=transp;}
49 //gradient filling using lines chnging in colour from colour1 to colour2
50 void SetGradient(bool gradient, const wxPen& gpen, double distance)
51 { m_gradient=gradient;
52 m_gpen=gpen;
53 m_gdistance=distance;
54 }
55
56 double GetPosX() { return m_points[0].m_x; }
57 double GetPosY() { return m_points[0].m_y; }
58 void SetPosXY( double x, double y);
59
60 void TransLate( double x, double y );
61 void CalcBoundingBox();
62
63 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
64 virtual void WriteSVG( wxTextOutputStream &stream );
65
66 wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
67
68 INOUTPOLY PointInPolygon(const wxPoint2DDouble& P, double marge);
69
70 private:
71
72 bool MoveUp(double horline, int& index, int direction);
73 void DetectCriticalPoints();
74 void FillPolygon(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
75 wxList m_CRlist;
76 wxList m_AETlist;
77
78
79 wxBrush m_brush;
80 wxPen m_pen;
81 wxColour m_textbg;
82 wxColour m_textfg;
83
84 //if brush is of type bitmap with a mask fill with mask transparent
85 bool m_transp;
86 bool m_gradient;
87 wxPen m_gpen;
88 double m_gdistance;
89
90 bool m_spline;
91
92 int m_n;
93 wxPoint2DDouble* m_points;
94 };
95
96 //----------------------------------------------------------------------------
97 // wxCanvasPolyline
98 //----------------------------------------------------------------------------
99
100 class wxCanvasPolyline: public wxCanvasObject
101 {
102 public:
103 wxCanvasPolyline(int n, wxPoint2DDouble points[]);
104 ~wxCanvasPolyline();
105 void SetPen( const wxPen& pen) { m_pen = pen; CalcBoundingBox(); }
106
107 double GetPosX() { return m_points[0].m_x; }
108 double GetPosY() { return m_points[0].m_y; }
109 void SetPosXY( double x, double y);
110
111 void TransLate( double x, double y );
112 void CalcBoundingBox();
113
114 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
115 virtual void WriteSVG( wxTextOutputStream &stream );
116
117 wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
118
119 bool PointOnPolyline(const wxPoint2DDouble& P, double marge);
120
121 private:
122
123 wxPen m_pen;
124
125 int m_n;
126 wxPoint2DDouble* m_points;
127 };
128
129 //----------------------------------------------------------------------------
130 // wxCanvasPolygon
131 //----------------------------------------------------------------------------
132
133 class wxCanvasPolygonL: public wxCanvasObject
134 {
135 public:
136 wxCanvasPolygonL(wxList* points, bool spline = FALSE);
137 ~wxCanvasPolygonL();
138 void SetBrush( const wxBrush& brush) { m_brush = brush; }
139 void SetPen( const wxPen& pen) { m_pen = pen; CalcBoundingBox(); }
140 void SetColour1( const wxColour& fg) { m_textfg=fg;}
141 void SetColour2( const wxColour& bg) { m_textbg=bg;}
142 void SetTransParent(bool transp) { m_transp=transp;}
143
144 double GetPosX();
145 double GetPosY();
146 void SetPosXY( double x, double y);
147 void TransLate( double x, double y );
148 void CalcBoundingBox();
149
150 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
151 virtual void WriteSVG( wxTextOutputStream &stream );
152
153 wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
154
155 INOUTPOLY PointInPolygon(const wxPoint2DDouble& P, double marge);
156
157 private:
158
159 wxBrush m_brush;
160 wxPen m_pen;
161 bool m_spline;
162 wxColour m_textbg;
163 wxColour m_textfg;
164 //if brush is of type bitmap with a mask fill with mask transparent
165 bool m_transp;
166
167 wxList* m_lpoints;
168 };
169
170 //----------------------------------------------------------------------------
171 // wxCanvasPolyline
172 //----------------------------------------------------------------------------
173
174 class wxCanvasPolylineL: public wxCanvasObject
175 {
176 public:
177 wxCanvasPolylineL(wxList* points, bool spline );
178 ~wxCanvasPolylineL();
179 void SetPen( const wxPen& pen) { m_pen = pen; CalcBoundingBox(); }
180
181 double GetPosX();
182 double GetPosY();
183 void SetPosXY( double x, double y);
184
185 void TransLate( double x, double y );
186 void CalcBoundingBox();
187
188 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
189 virtual void WriteSVG( wxTextOutputStream &stream );
190
191 wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
192
193 bool PointOnPolyline(const wxPoint2DDouble& P, double marge);
194
195 private:
196 wxPen m_pen;
197 bool m_spline;
198
199 wxList* m_lpoints;
200 };
201
202 //active edge table
203 class wxAET
204 {
205 public:
206 inline void CalculateLineParameters( const wxPoint2DDouble& p1 , const wxPoint2DDouble& p2 );
207 inline void CalculateXs( double y );
208
209 //line paramters
210 bool m_horizontal;
211 double m_BdivA;
212 double m_CdivA;
213 int m_index;
214 int m_direction;
215 //intersection point with scanline;
216 double m_xs;
217 };
218
219 #endif
220