]> git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/canvas/canvas.h
removed loading from in-memory document (illicit idea)
[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 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; }
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 double GetPosX() { return m_x; }
155 inline double 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 void SetBrush(wxBrush& brush) { m_brush = brush; };
187 void 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 void 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 void SetBrush(wxBrush& brush) { m_brush = brush; };
256 void SetPen(wxPen& pen) { m_pen = pen; };
257
258 virtual void Recreate();
259
260 virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
261 virtual void WriteSVG( wxTextOutputStream &stream );
262
263 private:
264 wxPen m_pen;
265 wxBrush m_brush;
266
267 double m_x;
268 double m_y;
269 double m_width;
270 double m_height;
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 void SetPen(wxPen& pen) { m_pen = pen; };
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 wxPen m_pen;
290
291 double m_x1;
292 double m_y1;
293 double m_x2;
294 double m_y2;
295 };
296
297 //----------------------------------------------------------------------------
298 // wxCanvasImage
299 //----------------------------------------------------------------------------
300
301 class wxCanvasImage: public wxCanvasObject
302 {
303 public:
304 wxCanvasImage( const wxImage &image, double x, double y, double w, double h );
305
306 virtual void Recreate();
307
308 virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
309 virtual void WriteSVG( wxTextOutputStream &stream );
310
311 private:
312 double m_x;
313 double m_y;
314 double m_width;
315 double m_height;
316
317 wxImage m_image;
318 #if IMAGE_CANVAS
319 wxImage m_tmp;
320 #else
321 wxBitmap m_tmp;
322 #endif
323 };
324
325 //----------------------------------------------------------------------------
326 // wxCanvasControl
327 //----------------------------------------------------------------------------
328
329 class wxCanvasControl: public wxCanvasObject
330 {
331 public:
332 wxCanvasControl( wxWindow *control );
333 ~wxCanvasControl();
334
335 virtual void Recreate();
336
337 virtual void Move( int x, int y );
338
339 private:
340 wxWindow *m_control;
341 };
342
343 //----------------------------------------------------------------------------
344 // wxCanvasText
345 //----------------------------------------------------------------------------
346
347 class wxCanvasText: public wxCanvasObject
348 {
349 public:
350 wxCanvasText( const wxString &text, double x, double y, const wxString &foneFile, int size );
351 ~wxCanvasText();
352
353 void Recreate();
354
355 virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
356 virtual void WriteSVG( wxTextOutputStream &stream );
357
358 void SetRGB( unsigned char red, unsigned char green, unsigned char blue );
359 void SetFlag( int flag );
360 int GetFlag() { return m_flag; }
361
362 private:
363 wxString m_text;
364 double m_x;
365 double m_y;
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;
372 wxString m_fontFileName;
373 int m_size;
374 };
375
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();
389
390 virtual void SetArea( int width, int height );
391 virtual void SetColour( unsigned char red, unsigned char green, unsigned char blue );
392 virtual void Update( int x, int y, int width, int height, bool blit = TRUE );
393 virtual void UpdateNow();
394
395 virtual void Freeze();
396 virtual void Thaw();
397
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 );
402
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 );
408
409 // ... and call this to tell all objets to recreate then
410 virtual void Recreate();
411
412 #if IMAGE_CANVAS
413 inline wxImage *GetBuffer() { return &m_buffer; }
414 #else
415 inline wxBitmap *GetBuffer() { return &m_buffer; }
416 inline wxMemoryDC *GetDC() { return m_renderDC; }
417 #endif
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
423 bool NeedUpdate() { return m_needUpdate; }
424 bool IsFrozen() { return m_frozen; }
425
426 void BlitBuffer( wxDC &dc );
427
428 void SetCaptureMouse( wxCanvasObject *obj );
429
430 virtual void ScrollWindow( int dx, int dy,
431 const wxRect* rect = (wxRect *) NULL );
432
433 private:
434 #if IMAGE_CANVAS
435 wxImage m_buffer;
436 #else
437 wxBitmap m_buffer;
438 wxMemoryDC *m_renderDC;
439 #endif
440 int m_bufferX;
441 int m_bufferY;
442 bool m_needUpdate;
443 wxList m_updateRects;
444 wxCanvasObjectGroup* m_root;
445
446 unsigned char m_green,m_red,m_blue;
447 bool m_frozen;
448 wxCanvasObject *m_lastMouse;
449 wxCanvasObject *m_captureMouse;
450
451 int m_oldDeviceX,m_oldDeviceY;
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