]>
Commit | Line | Data |
---|---|---|
6a2c1874 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: canvas.h | |
3 | // Author: Robert Roebling | |
4 | // Created: XX/XX/XX | |
5 | // Copyright: 2000 (c) Robert Roebling | |
6 | // Licence: wxWindows Licence | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | #ifndef __WXCANVAS_H__ | |
10 | #define __WXCANVAS_H__ | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma interface "canvas.cpp" | |
14 | #endif | |
15 | ||
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/wx.h" | |
18 | #endif | |
19 | ||
20 | #include "wx/image.h" | |
21 | #include "wx/txtstrm.h" | |
5143c96b KH |
22 | #include "wx/geometry.h" |
23 | ||
dc16900b | 24 | |
33ebcd80 RR |
25 | //---------------------------------------------------------------------------- |
26 | // decls | |
27 | //---------------------------------------------------------------------------- | |
28 | ||
29 | #define IMAGE_CANVAS 0 | |
6a2c1874 | 30 | |
33ebcd80 | 31 | class wxCanvas; |
6a2c1874 RR |
32 | |
33 | //---------------------------------------------------------------------------- | |
34 | // wxCanvasObject | |
35 | //---------------------------------------------------------------------------- | |
36 | ||
37 | class wxCanvasObject: public wxEvtHandler | |
38 | { | |
39 | public: | |
4dbd4ee6 | 40 | wxCanvasObject(); |
dc16900b | 41 | |
4dbd4ee6 RR |
42 | // Area occupied by object. Used for clipping, intersection, |
43 | // mouse enter etc. Screen coordinates | |
44 | void SetArea( int x, int y, int width, int height ); | |
45 | void SetArea( wxRect rect ); | |
dc16900b | 46 | |
1e1af41e RR |
47 | // These are for screen output only therefore use |
48 | // int as coordinates. | |
239c1f50 | 49 | virtual bool IsHit( int x, int y, int margin = 0 ); |
fcbb6b37 | 50 | virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height ); |
dc16900b | 51 | |
4dbd4ee6 RR |
52 | // use doubles later |
53 | virtual void Move( int x, int y ); | |
dc16900b | 54 | |
1e1af41e RR |
55 | // Once we have world coordinates in doubles, this will get |
56 | // called for every object if the world coordinate system | |
57 | // changes (zooming). | |
4dbd4ee6 | 58 | virtual void Recreate(); |
1e1af41e RR |
59 | |
60 | // Later... | |
6a2c1874 | 61 | virtual void WriteSVG( wxTextOutputStream &stream ); |
dc16900b KH |
62 | |
63 | wxCanvas *GetOwner() { return m_owner; } | |
fcbb6b37 | 64 | virtual void SetOwner( wxCanvas *owner ) { m_owner = owner; } |
dc16900b | 65 | |
6a2c1874 RR |
66 | bool IsControl() { return m_isControl; } |
67 | bool IsVector() { return m_isVector; } | |
68 | bool IsImage() { return m_isImage; } | |
69 | inline int GetX() { return m_area.x; } | |
70 | inline int GetY() { return m_area.y; } | |
71 | inline int GetWidth() { return m_area.width; } | |
72 | inline int GetHeight() { return m_area.height; } | |
73 | ||
dc16900b KH |
74 | void CaptureMouse(); |
75 | void ReleaseMouse(); | |
76 | bool IsCapturedMouse(); | |
77 | ||
6a2c1874 RR |
78 | protected: |
79 | wxCanvas *m_owner; | |
80 | bool m_isControl; | |
81 | bool m_isVector; | |
82 | bool m_isImage; | |
fcbb6b37 KH |
83 | |
84 | //relative boundingbox in parent in pixels | |
6a2c1874 | 85 | wxRect m_area; |
dc16900b | 86 | |
6a2c1874 RR |
87 | friend class wxCanvas; |
88 | }; | |
89 | ||
fcbb6b37 KH |
90 | //---------------------------------------------------------------------------- |
91 | // wxCanvasObjectGroup | |
92 | //---------------------------------------------------------------------------- | |
93 | ||
94 | class wxCanvasObjectGroup | |
95 | { | |
96 | public: | |
97 | wxCanvasObjectGroup(); | |
21840a6c | 98 | virtual ~wxCanvasObjectGroup(); |
fcbb6b37 KH |
99 | |
100 | void SetOwner(wxCanvas* canvas); | |
101 | wxCanvas *GetOwner() { return m_owner; } | |
102 | ||
103 | virtual void Prepend( wxCanvasObject* obj ); | |
104 | virtual void Append( wxCanvasObject* obj ); | |
105 | virtual void Insert( size_t before, wxCanvasObject* obj ); | |
106 | virtual void Remove( wxCanvasObject* obj ); | |
107 | ||
108 | virtual void Recreate(); | |
109 | void DeleteContents( bool ); | |
110 | virtual void Render(int xabs, int yabs,int x, int y, int width, int height ); | |
111 | virtual void WriteSVG( wxTextOutputStream &stream ); | |
112 | virtual bool IsHit( int x, int y, int margin ); | |
113 | virtual wxCanvasObject* IsHitObject( int x, int y, int margin ); | |
114 | ||
5143c96b | 115 | void ExtendArea(double x, double y); |
fcbb6b37 | 116 | |
96f5fca9 RR |
117 | inline double GetXMin() { return m_minx; } |
118 | inline double GetYMin() { return m_miny; } | |
119 | inline double GetXMax() { return m_maxx; } | |
120 | inline double GetYMax() { return m_maxy; } | |
fcbb6b37 KH |
121 | |
122 | protected: | |
123 | wxCanvas *m_owner; | |
124 | ||
125 | //bounding box | |
126 | double m_minx; | |
127 | double m_miny; | |
128 | double m_maxx; | |
129 | double m_maxy; | |
130 | bool m_validbounds; | |
131 | ||
132 | wxList m_objects; | |
133 | ||
134 | friend class wxCanvas; | |
135 | }; | |
136 | ||
137 | //---------------------------------------------------------------------------- | |
138 | // wxCanvasObjectGroupRef | |
139 | //---------------------------------------------------------------------------- | |
140 | ||
141 | class wxCanvasObjectGroupRef: public wxCanvasObject | |
142 | { | |
143 | public: | |
144 | wxCanvasObjectGroupRef(double x, double y,wxCanvasObjectGroup* group); | |
145 | ||
146 | void SetOwner(wxCanvas* canvas); | |
147 | ||
148 | virtual void Recreate(); | |
149 | virtual void Render(int xabs, int yabs,int x, int y, int width, int height ); | |
150 | virtual void WriteSVG( wxTextOutputStream &stream ); | |
151 | virtual bool IsHit( int x, int y, int margin ); | |
152 | void Move( int x, int y ); | |
153 | ||
96f5fca9 RR |
154 | inline double GetPosX() { return m_x; } |
155 | inline double GetPosY() { return m_y; } | |
fcbb6b37 | 156 | |
5143c96b | 157 | void ExtendArea(double x, double y); |
fcbb6b37 KH |
158 | virtual wxCanvasObject* IsHitObject( int x, int y, int margin ); |
159 | ||
160 | protected: | |
161 | //position of the group | |
162 | double m_x; | |
163 | double m_y; | |
164 | ||
165 | //reference to the group | |
166 | wxCanvasObjectGroup* m_group; | |
167 | ||
168 | //bounding box | |
169 | double m_minx; | |
170 | double m_miny; | |
171 | double m_maxx; | |
172 | double m_maxy; | |
173 | bool m_validbounds; | |
174 | ||
175 | }; | |
176 | ||
5143c96b KH |
177 | //---------------------------------------------------------------------------- |
178 | // wxCanvasPolygon | |
179 | //---------------------------------------------------------------------------- | |
180 | ||
181 | class wxCanvasPolygon: public wxCanvasObject | |
182 | { | |
183 | public: | |
27d1065d | 184 | wxCanvasPolygon( int n, wxPoint2DDouble points[] ); |
5143c96b | 185 | ~wxCanvasPolygon(); |
27d1065d RR |
186 | void SetBrush(wxBrush& brush) { m_brush = brush; }; |
187 | void SetPen(wxPen& pen) { m_pen = pen; }; | |
5143c96b KH |
188 | |
189 | virtual void Recreate(); | |
190 | ||
191 | virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height ); | |
192 | virtual void WriteSVG( wxTextOutputStream &stream ); | |
193 | ||
194 | private: | |
195 | void ExtendArea(double x, double y); | |
196 | ||
197 | wxBrush m_brush; | |
198 | wxPen m_pen; | |
199 | ||
200 | int m_n; | |
201 | wxPoint2DDouble* m_points; | |
202 | ||
203 | //bounding box | |
204 | double m_minx; | |
205 | double m_miny; | |
206 | double m_maxx; | |
207 | double m_maxy; | |
208 | bool m_validbounds; | |
209 | ||
210 | }; | |
211 | ||
212 | //---------------------------------------------------------------------------- | |
213 | // wxCanvasPolyline | |
214 | //---------------------------------------------------------------------------- | |
215 | ||
216 | class wxCanvasPolyline: public wxCanvasObject | |
217 | { | |
218 | public: | |
219 | wxCanvasPolyline(int n, wxPoint2DDouble points[]); | |
220 | ~wxCanvasPolyline(); | |
27d1065d | 221 | void SetPen(wxPen& pen) { m_pen = pen; }; |
5143c96b KH |
222 | |
223 | virtual void Recreate(); | |
224 | ||
225 | virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height ); | |
226 | virtual void WriteSVG( wxTextOutputStream &stream ); | |
227 | ||
228 | private: | |
229 | void ExtendArea(double x, double y); | |
230 | ||
231 | wxPen m_pen; | |
232 | ||
233 | int m_n; | |
234 | wxPoint2DDouble* m_points; | |
235 | ||
236 | //bounding box | |
237 | double m_minx; | |
238 | double m_miny; | |
239 | double m_maxx; | |
240 | double m_maxy; | |
241 | bool m_validbounds; | |
242 | ||
243 | }; | |
244 | ||
245 | ||
246 | ||
21544859 RR |
247 | //---------------------------------------------------------------------------- |
248 | // wxCanvasRect | |
249 | //---------------------------------------------------------------------------- | |
250 | ||
251 | class wxCanvasRect: public wxCanvasObject | |
252 | { | |
253 | public: | |
27d1065d RR |
254 | wxCanvasRect( double x, double y, double w, double h ); |
255 | void SetBrush(wxBrush& brush) { m_brush = brush; }; | |
256 | void SetPen(wxPen& pen) { m_pen = pen; }; | |
dc16900b | 257 | |
4dbd4ee6 | 258 | virtual void Recreate(); |
dc16900b | 259 | |
fcbb6b37 | 260 | virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height ); |
21544859 | 261 | virtual void WriteSVG( wxTextOutputStream &stream ); |
dc16900b | 262 | |
21544859 | 263 | private: |
27d1065d RR |
264 | wxPen m_pen; |
265 | wxBrush m_brush; | |
266 | ||
4dbd4ee6 RR |
267 | double m_x; |
268 | double m_y; | |
269 | double m_width; | |
dc16900b | 270 | double m_height; |
21544859 RR |
271 | }; |
272 | ||
239c1f50 RR |
273 | //---------------------------------------------------------------------------- |
274 | // wxCanvasLine | |
275 | //---------------------------------------------------------------------------- | |
276 | ||
277 | class wxCanvasLine: public wxCanvasObject | |
278 | { | |
279 | public: | |
27d1065d RR |
280 | wxCanvasLine( double x1, double y1, double x2, double y2 ); |
281 | void SetPen(wxPen& pen) { m_pen = pen; }; | |
dc16900b | 282 | |
4dbd4ee6 | 283 | virtual void Recreate(); |
dc16900b | 284 | |
fcbb6b37 | 285 | virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height ); |
239c1f50 RR |
286 | virtual void WriteSVG( wxTextOutputStream &stream ); |
287 | ||
288 | private: | |
27d1065d RR |
289 | wxPen m_pen; |
290 | ||
4dbd4ee6 RR |
291 | double m_x1; |
292 | double m_y1; | |
293 | double m_x2; | |
294 | double m_y2; | |
239c1f50 RR |
295 | }; |
296 | ||
6a2c1874 RR |
297 | //---------------------------------------------------------------------------- |
298 | // wxCanvasImage | |
299 | //---------------------------------------------------------------------------- | |
300 | ||
301 | class wxCanvasImage: public wxCanvasObject | |
302 | { | |
303 | public: | |
4dbd4ee6 RR |
304 | wxCanvasImage( const wxImage &image, double x, double y, double w, double h ); |
305 | ||
306 | virtual void Recreate(); | |
6a2c1874 | 307 | |
fcbb6b37 | 308 | virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height ); |
6a2c1874 RR |
309 | virtual void WriteSVG( wxTextOutputStream &stream ); |
310 | ||
311 | private: | |
4dbd4ee6 RR |
312 | double m_x; |
313 | double m_y; | |
314 | double m_width; | |
315 | double m_height; | |
316 | ||
6a2c1874 | 317 | wxImage m_image; |
33ebcd80 | 318 | #if IMAGE_CANVAS |
4dbd4ee6 | 319 | wxImage m_tmp; |
33ebcd80 RR |
320 | #else |
321 | wxBitmap m_tmp; | |
322 | #endif | |
6a2c1874 RR |
323 | }; |
324 | ||
3b111dbe RR |
325 | //---------------------------------------------------------------------------- |
326 | // wxCanvasControl | |
327 | //---------------------------------------------------------------------------- | |
328 | ||
329 | class wxCanvasControl: public wxCanvasObject | |
330 | { | |
331 | public: | |
332 | wxCanvasControl( wxWindow *control ); | |
333 | ~wxCanvasControl(); | |
334 | ||
4dbd4ee6 RR |
335 | virtual void Recreate(); |
336 | ||
3b111dbe | 337 | virtual void Move( int x, int y ); |
3b111dbe RR |
338 | |
339 | private: | |
340 | wxWindow *m_control; | |
341 | }; | |
342 | ||
d1f9b206 RR |
343 | //---------------------------------------------------------------------------- |
344 | // wxCanvasText | |
345 | //---------------------------------------------------------------------------- | |
346 | ||
347 | class wxCanvasText: public wxCanvasObject | |
348 | { | |
349 | public: | |
4dbd4ee6 | 350 | wxCanvasText( const wxString &text, double x, double y, const wxString &foneFile, int size ); |
d1f9b206 | 351 | ~wxCanvasText(); |
dc16900b | 352 | |
4dbd4ee6 | 353 | void Recreate(); |
dc16900b | 354 | |
fcbb6b37 | 355 | virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height ); |
d1f9b206 RR |
356 | virtual void WriteSVG( wxTextOutputStream &stream ); |
357 | ||
d1f9b206 RR |
358 | void SetRGB( unsigned char red, unsigned char green, unsigned char blue ); |
359 | void SetFlag( int flag ); | |
239c1f50 | 360 | int GetFlag() { return m_flag; } |
dc16900b | 361 | |
d1f9b206 RR |
362 | private: |
363 | wxString m_text; | |
4dbd4ee6 RR |
364 | double m_x; |
365 | double m_y; | |
d1f9b206 RR |
366 | unsigned char *m_alpha; |
367 | void *m_faceData; | |
368 | int m_flag; | |
369 | int m_red; | |
370 | int m_green; | |
371 | int m_blue; | |
cb281cfc RR |
372 | wxString m_fontFileName; |
373 | int m_size; | |
d1f9b206 RR |
374 | }; |
375 | ||
6a2c1874 RR |
376 | //---------------------------------------------------------------------------- |
377 | // wxCanvas | |
378 | //---------------------------------------------------------------------------- | |
379 | ||
380 | class wxCanvas: public wxScrolledWindow | |
381 | { | |
382 | public: | |
383 | // constructors and destructors | |
384 | wxCanvas( wxWindow *parent, wxWindowID id = -1, | |
385 | const wxPoint& pos = wxDefaultPosition, | |
386 | const wxSize& size = wxDefaultSize, | |
387 | long style = wxScrolledWindowStyle ); | |
388 | virtual ~wxCanvas(); | |
dc16900b | 389 | |
6a2c1874 | 390 | virtual void SetArea( int width, int height ); |
cb281cfc | 391 | virtual void SetColour( unsigned char red, unsigned char green, unsigned char blue ); |
41328253 | 392 | virtual void Update( int x, int y, int width, int height, bool blit = TRUE ); |
6a2c1874 | 393 | virtual void UpdateNow(); |
dc16900b | 394 | |
239c1f50 RR |
395 | virtual void Freeze(); |
396 | virtual void Thaw(); | |
dc16900b | 397 | |
6a2c1874 RR |
398 | virtual void Prepend( wxCanvasObject* obj ); |
399 | virtual void Append( wxCanvasObject* obj ); | |
400 | virtual void Insert( size_t before, wxCanvasObject* obj ); | |
401 | virtual void Remove( wxCanvasObject* obj ); | |
dc16900b | 402 | |
4dbd4ee6 RR |
403 | // override these to change your coordiate system ... |
404 | virtual int GetDeviceX( double x ); | |
405 | virtual int GetDeviceY( double y ); | |
406 | virtual int GetDeviceWidth( double width ); | |
407 | virtual int GetDeviceHeight( double height ); | |
dc16900b | 408 | |
4dbd4ee6 RR |
409 | // ... and call this to tell all objets to recreate then |
410 | virtual void Recreate(); | |
411 | ||
33ebcd80 | 412 | #if IMAGE_CANVAS |
41328253 | 413 | inline wxImage *GetBuffer() { return &m_buffer; } |
33ebcd80 RR |
414 | #else |
415 | inline wxBitmap *GetBuffer() { return &m_buffer; } | |
416 | inline wxMemoryDC *GetDC() { return m_renderDC; } | |
417 | #endif | |
41328253 RR |
418 | inline int GetBufferX() { return m_bufferX; } |
419 | inline int GetBufferY() { return m_bufferY; } | |
420 | inline int GetBufferWidth() { return m_buffer.GetWidth(); } | |
421 | inline int GetBufferHeight() { return m_buffer.GetHeight(); } | |
422 | ||
6a2c1874 | 423 | bool NeedUpdate() { return m_needUpdate; } |
1e1af41e | 424 | bool IsFrozen() { return m_frozen; } |
dc16900b | 425 | |
3b111dbe | 426 | void BlitBuffer( wxDC &dc ); |
dc16900b KH |
427 | |
428 | void SetCaptureMouse( wxCanvasObject *obj ); | |
429 | ||
41328253 RR |
430 | virtual void ScrollWindow( int dx, int dy, |
431 | const wxRect* rect = (wxRect *) NULL ); | |
dc16900b | 432 | |
6a2c1874 | 433 | private: |
33ebcd80 | 434 | #if IMAGE_CANVAS |
239c1f50 | 435 | wxImage m_buffer; |
33ebcd80 RR |
436 | #else |
437 | wxBitmap m_buffer; | |
438 | wxMemoryDC *m_renderDC; | |
439 | #endif | |
41328253 RR |
440 | int m_bufferX; |
441 | int m_bufferY; | |
239c1f50 RR |
442 | bool m_needUpdate; |
443 | wxList m_updateRects; | |
fcbb6b37 KH |
444 | wxCanvasObjectGroup* m_root; |
445 | ||
239c1f50 RR |
446 | unsigned char m_green,m_red,m_blue; |
447 | bool m_frozen; | |
448 | wxCanvasObject *m_lastMouse; | |
4dbd4ee6 | 449 | wxCanvasObject *m_captureMouse; |
27d1065d RR |
450 | |
451 | int m_oldDeviceX,m_oldDeviceY; | |
dc16900b | 452 | |
6a2c1874 | 453 | friend class wxCanvasObject; |
dc16900b | 454 | |
6a2c1874 RR |
455 | private: |
456 | void OnChar( wxKeyEvent &event ); | |
457 | void OnPaint( wxPaintEvent &event ); | |
458 | void OnMouse( wxMouseEvent &event ); | |
459 | void OnSize( wxSizeEvent &event ); | |
460 | void OnIdle( wxIdleEvent &event ); | |
461 | void OnSetFocus( wxFocusEvent &event ); | |
462 | void OnKillFocus( wxFocusEvent &event ); | |
61b64bd9 | 463 | void OnEraseBackground( wxEraseEvent &event ); |
6a2c1874 RR |
464 | |
465 | private: | |
466 | DECLARE_CLASS(wxCanvas) | |
467 | DECLARE_EVENT_TABLE() | |
468 | }; | |
469 | ||
470 | ||
471 | #endif | |
472 | // WXCANVAS | |
473 |