]> git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/canvas/canvas.h
3c12ffa07960f7b8c82a8e42692cec0e3259dc38
[wxWidgets.git] / contrib / include / wx / canvas / canvas.h
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"
22 #include "wx/geometry.h"
23
24
25 //----------------------------------------------------------------------------
26 // decls
27 //----------------------------------------------------------------------------
28
29 #define IMAGE_CANVAS 0
30
31 class wxCanvas;
32
33 //----------------------------------------------------------------------------
34 // wxCanvasObject
35 //----------------------------------------------------------------------------
36
37 class wxCanvasObject: public wxEvtHandler
38 {
39 public:
40 wxCanvasObject();
41
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 );
46
47 // These are for screen output only therefore use
48 // int as coordinates.
49 virtual bool IsHit( int x, int y, int margin = 0 );
50 virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
51
52 // use doubles later
53 virtual void Move( int x, int y );
54
55 // Once we have world coordinates in doubles, this will get
56 // called for every object if the world coordinate system
57 // changes (zooming).
58 virtual void Recreate();
59
60 // Later...
61 virtual void WriteSVG( wxTextOutputStream &stream );
62
63 wxCanvas *GetOwner() { return m_owner; }
64 virtual void SetOwner( wxCanvas *owner ) { m_owner = owner; }
65
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
74 void CaptureMouse();
75 void ReleaseMouse();
76 bool IsCapturedMouse();
77
78 protected:
79 wxCanvas *m_owner;
80 bool m_isControl;
81 bool m_isVector;
82 bool m_isImage;
83
84 //relative boundingbox in parent in pixels
85 wxRect m_area;
86
87 friend class wxCanvas;
88 };
89
90 //----------------------------------------------------------------------------
91 // wxCanvasObjectGroup
92 //----------------------------------------------------------------------------
93
94 class wxCanvasObjectGroup
95 {
96 public:
97 wxCanvasObjectGroup();
98 virtual ~wxCanvasObjectGroup();
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
115 void ExtendArea(double x, double y);
116
117 inline int GetXMin() { return m_minx; }
118 inline int GetYMin() { return m_miny; }
119 inline int GetXMax() { return m_maxx; }
120 inline int GetYMax() { return m_maxy; }
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
154 inline int GetPosX() { return m_x; }
155 inline int GetPosY() { return m_y; }
156
157 void ExtendArea(double x, double y);
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
177 //----------------------------------------------------------------------------
178 // wxCanvasPolygon
179 //----------------------------------------------------------------------------
180
181 class wxCanvasPolygon: public wxCanvasObject
182 {
183 public:
184 wxCanvasPolygon(int n, wxPoint2DDouble points[]);
185 ~wxCanvasPolygon();
186 SetBrush(wxBrush& brush){m_brush = brush;};
187 SetPen(wxPen& pen){m_pen = pen;};
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();
221 SetPen(wxPen& pen){m_pen = pen;};
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
247 //----------------------------------------------------------------------------
248 // wxCanvasRect
249 //----------------------------------------------------------------------------
250
251 class wxCanvasRect: public wxCanvasObject
252 {
253 public:
254 wxCanvasRect( double x, double y, double w, double h,
255 unsigned char red, unsigned char green, unsigned char blue );
256
257 virtual void Recreate();
258
259 virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
260 virtual void WriteSVG( wxTextOutputStream &stream );
261
262 private:
263 double m_x;
264 double m_y;
265 double m_width;
266 double m_height;
267
268 unsigned char m_red;
269 unsigned char m_green;
270 unsigned char m_blue;
271 };
272
273 //----------------------------------------------------------------------------
274 // wxCanvasLine
275 //----------------------------------------------------------------------------
276
277 class wxCanvasLine: public wxCanvasObject
278 {
279 public:
280 wxCanvasLine( double x1, double y1, double x2, double y2,
281 unsigned char red, unsigned char green, unsigned char blue );
282
283 virtual void Recreate();
284
285 virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
286 virtual void WriteSVG( wxTextOutputStream &stream );
287
288 private:
289 double m_x1;
290 double m_y1;
291 double m_x2;
292 double m_y2;
293
294 unsigned char m_red;
295 unsigned char m_green;
296 unsigned char m_blue;
297 };
298
299 //----------------------------------------------------------------------------
300 // wxCanvasImage
301 //----------------------------------------------------------------------------
302
303 class wxCanvasImage: public wxCanvasObject
304 {
305 public:
306 wxCanvasImage( const wxImage &image, double x, double y, double w, double h );
307
308 virtual void Recreate();
309
310 virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
311 virtual void WriteSVG( wxTextOutputStream &stream );
312
313 private:
314 double m_x;
315 double m_y;
316 double m_width;
317 double m_height;
318
319 wxImage m_image;
320 #if IMAGE_CANVAS
321 wxImage m_tmp;
322 #else
323 wxBitmap m_tmp;
324 #endif
325 };
326
327 //----------------------------------------------------------------------------
328 // wxCanvasControl
329 //----------------------------------------------------------------------------
330
331 class wxCanvasControl: public wxCanvasObject
332 {
333 public:
334 wxCanvasControl( wxWindow *control );
335 ~wxCanvasControl();
336
337 virtual void Recreate();
338
339 virtual void Move( int x, int y );
340
341 private:
342 wxWindow *m_control;
343 };
344
345 //----------------------------------------------------------------------------
346 // wxCanvasText
347 //----------------------------------------------------------------------------
348
349 class wxCanvasText: public wxCanvasObject
350 {
351 public:
352 wxCanvasText( const wxString &text, double x, double y, const wxString &foneFile, int size );
353 ~wxCanvasText();
354
355 void Recreate();
356
357 virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
358 virtual void WriteSVG( wxTextOutputStream &stream );
359
360 void SetRGB( unsigned char red, unsigned char green, unsigned char blue );
361 void SetFlag( int flag );
362 int GetFlag() { return m_flag; }
363
364 private:
365 wxString m_text;
366 double m_x;
367 double m_y;
368 unsigned char *m_alpha;
369 void *m_faceData;
370 int m_flag;
371 int m_red;
372 int m_green;
373 int m_blue;
374 wxString m_fontFileName;
375 int m_size;
376 };
377
378 //----------------------------------------------------------------------------
379 // wxCanvas
380 //----------------------------------------------------------------------------
381
382 class wxCanvas: public wxScrolledWindow
383 {
384 public:
385 // constructors and destructors
386 wxCanvas( wxWindow *parent, wxWindowID id = -1,
387 const wxPoint& pos = wxDefaultPosition,
388 const wxSize& size = wxDefaultSize,
389 long style = wxScrolledWindowStyle );
390 virtual ~wxCanvas();
391
392 virtual void SetArea( int width, int height );
393 virtual void SetColour( unsigned char red, unsigned char green, unsigned char blue );
394 virtual void Update( int x, int y, int width, int height, bool blit = TRUE );
395 virtual void UpdateNow();
396
397 virtual void Freeze();
398 virtual void Thaw();
399
400 virtual void Prepend( wxCanvasObject* obj );
401 virtual void Append( wxCanvasObject* obj );
402 virtual void Insert( size_t before, wxCanvasObject* obj );
403 virtual void Remove( wxCanvasObject* obj );
404
405 // override these to change your coordiate system ...
406 virtual int GetDeviceX( double x );
407 virtual int GetDeviceY( double y );
408 virtual int GetDeviceWidth( double width );
409 virtual int GetDeviceHeight( double height );
410
411 // ... and call this to tell all objets to recreate then
412 virtual void Recreate();
413
414 #if IMAGE_CANVAS
415 inline wxImage *GetBuffer() { return &m_buffer; }
416 #else
417 inline wxBitmap *GetBuffer() { return &m_buffer; }
418 inline wxMemoryDC *GetDC() { return m_renderDC; }
419 #endif
420 inline int GetBufferX() { return m_bufferX; }
421 inline int GetBufferY() { return m_bufferY; }
422 inline int GetBufferWidth() { return m_buffer.GetWidth(); }
423 inline int GetBufferHeight() { return m_buffer.GetHeight(); }
424
425 bool NeedUpdate() { return m_needUpdate; }
426 bool IsFrozen() { return m_frozen; }
427
428 void BlitBuffer( wxDC &dc );
429
430 void SetCaptureMouse( wxCanvasObject *obj );
431
432 virtual void ScrollWindow( int dx, int dy,
433 const wxRect* rect = (wxRect *) NULL );
434
435 private:
436 #if IMAGE_CANVAS
437 wxImage m_buffer;
438 #else
439 wxBitmap m_buffer;
440 wxMemoryDC *m_renderDC;
441 #endif
442 int m_bufferX;
443 int m_bufferY;
444 bool m_needUpdate;
445 wxList m_updateRects;
446 wxCanvasObjectGroup* m_root;
447
448 unsigned char m_green,m_red,m_blue;
449 bool m_frozen;
450 wxCanvasObject *m_lastMouse;
451 wxCanvasObject *m_captureMouse;
452
453 friend class wxCanvasObject;
454
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 );
463 void OnEraseBackground( wxEraseEvent &event );
464
465 private:
466 DECLARE_CLASS(wxCanvas)
467 DECLARE_EVENT_TABLE()
468 };
469
470
471 #endif
472 // WXCANVAS
473