]> git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/canvas/canvas.h
fc58e89125788e15a4a3b388183dfbe018a0e8f1
[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 #include "wx/matrix.h"
24 #include "bbox.h"
25
26
27 //----------------------------------------------------------------------------
28 // decls
29 //----------------------------------------------------------------------------
30
31 #define IMAGE_CANVAS 0
32
33 class wxCanvas;
34 class wxCanvasAdmin;
35
36 //----------------------------------------------------------------------------
37 // wxCanvasObject
38 //----------------------------------------------------------------------------
39 enum DRAGMODE {DRAG_RECTANGLE,DRAG_ONTOP,DRAG_REDRAW};
40
41 //:defenition
42 // wxCanvasObject is the base class for Canvas Objects.
43 // All Objects for drawing one the canvas are derived from this class.
44 // It supports dragging and moving methods that can be used in derived
45 // classes for defining several ways of dragging.
46 // Also it is possible to plug in events handlers to do this for all derived classes at once.
47 //
48 // wxCanvasObjects have themselves as their event handlers by default,
49 // but their event handlers could be set to another object entirely. This
50 // separation can reduce the amount of derivation required, and allow
51 // alteration of a wxCanvasObject functionality
52 class wxCanvasObject: public wxEvtHandler
53 {
54 public:
55
56 wxCanvasObject();
57
58 //If the position (x,y) is within the object this return a pointer to the object
59 //Normally this function needs to be defined for each derived wxCanvasObject.
60 //The default is a simple bounding box test.
61 virtual wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
62
63 //render this object to the canvas (either on its buffer or directly on the canvas)
64 //this depends on the wxDC that is set for the active canvas.
65 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
66
67 //x position in world coordinates of the object
68 virtual double GetPosX()=0;
69 //y position in world coordinates of the object
70 virtual double GetPosY()=0;
71
72 //set position in world coordinates for the object
73 virtual void SetPosXY( double x, double y)=0;
74
75 //absolute moving the object to position x,y in world coordinates
76 //also does an update of the old and new area
77 virtual void MoveAbsolute( double x, double y );
78
79 //relative moving the object to position x,y in world coordinates
80 //also does an update of the old and new area
81 virtual void MoveRelative( double x, double y );
82
83 //relative translate the object to position x,y in world coordinates
84 //does NOT update the old and new area
85 //this function must be defined for each derived object,
86 //it is used internally for dragging and moving objects.
87 virtual void TransLate( double x, double y )=0;
88
89 //choose one of the three diffrenet drag methods |
90 //DRAG_RECTANGLE = as a rectangle when drag is in progress |
91 //DRAG_ONTOP = only redraw the object when dragging |
92 //DRAG_REDRAW = redraw the damaged areas when dragging
93 void SetDragMode(DRAGMODE mode) { m_dragmode=mode; };
94
95 //return the dragmode
96 DRAGMODE GetDragMode() { return m_dragmode; };
97
98 //called when starting a drag
99 virtual void DragStart();
100 //called when dragging is in progress
101 virtual void DragRelative( double x, double y);
102 //called when dragging is ended
103 virtual void DragEnd();
104
105 //return the object if it is part of the given object or
106 //if the given object is part of a group within this object.
107 //For group objects this means recursively search for it.
108 virtual wxCanvasObject* Contains( wxCanvasObject* obj );
109
110 //calculate the boundingbox in world coordinates
111 virtual void CalcBoundingBox()=0;
112
113 //write the object as SVG (scalable vector grafhics
114 virtual void WriteSVG( wxTextOutputStream &stream );
115
116 //get the administrator for the object,
117 //this will give access to the canvas's where it is displayed upon.
118 //It is used to render the object to the active canvas.
119 //Conversion from world to Device coordinates and visa versa is
120 //done using the Active canvas at that moment.
121 wxCanvasAdmin *GetAdmin() { return m_admin; }
122
123 //set the administrator
124 virtual void SetAdmin( wxCanvasAdmin *admin ) { m_admin = admin; }
125
126 //is this a control type of canvas object
127 bool IsControl() { return m_isControl; }
128 //is this a vector type of canvas object
129 bool IsVector() { return m_isVector; }
130 //is this an Image type of canvas object
131 bool IsImage() { return m_isImage; }
132
133 //get minimum X of the boundingbox in world coordinates
134 inline double GetXMin() { return m_bbox.GetMinX(); }
135 //get minimum Y of the boundingbox in world coordinates
136 inline double GetYMin() { return m_bbox.GetMinY(); }
137 //get maximum X of the boundingbox in world coordinates
138 inline double GetXMax() { return m_bbox.GetMaxX(); }
139 //get maximum Y of the boundingbox in world coordinates
140 inline double GetYMax() { return m_bbox.GetMaxY(); }
141
142 //get boundingbox
143 inline wxBoundingBox GetBbox() { return m_bbox; }
144
145 //redirect all mouse events for the canvas to this object
146 void CaptureMouse();
147 //release the mouse capture for this object
148 void ReleaseMouse();
149 //is the mouse captured for this object
150 bool IsCapturedMouse();
151
152 //set if this object will visible (be rendered or not)
153 inline void SetVisible(bool visible) { m_visible=visible; }
154 //get visibility
155 inline bool GetVisible() {return m_visible; }
156
157 //can the object be dragged
158 inline void SetDraggable(bool drag) { m_dragable=drag; }
159 //get if the object can be dragged
160 inline bool GetDraggable() {return m_dragable; }
161
162 //get absolute area in the device coordinates where the object
163 //its boundingbox in world coordinates is first translated using the matrix.
164 wxRect GetAbsoluteArea(const wxTransformMatrix& cworld);
165
166 //get currently used eventhandler (always the first in the list)
167 wxEvtHandler *GetEventHandler() const { return m_eventHandler; }
168
169 //process an event for the object, starting with the first eventhandler
170 // in the list.
171 bool ProcessCanvasObjectEvent(wxEvent& event);
172
173 // push/pop event handler: allows to chain a custom event handler to
174 // already existing ones
175 void PushEventHandler( wxEvtHandler *handler );
176
177 //remove first eventhandler in the list (one will be always stay in)
178 wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE );
179 //append an eventhandler to the list, this event handler will be called
180 //if the other skipped the event to process.
181 void AppendEventHandler(wxEvtHandler *handler);
182 //remove last event handler in the list (one will always stay in)
183 wxEvtHandler *RemoveLastEventHandler(bool deleteHandler);
184
185 protected:
186
187 //administator for rendering and accessing the canvas's
188 wxCanvasAdmin* m_admin;
189
190 //active event handler, default the object itself
191 wxEvtHandler* m_eventHandler;
192
193 bool m_isControl:1;
194 bool m_isVector:1;
195 bool m_isImage:1;
196 bool m_visible:1;
197 bool m_dragable:1;
198 DRAGMODE m_dragmode:2;
199
200 //boundingbox in world coordinates
201 wxBoundingBox m_bbox;
202
203 //used for dragging
204 wxBitmap m_atnewpos;
205 };
206
207 //:defenition
208 // wxCanvasObjectGroup is a container for wxCanvas derived Objects.
209 // It renders itself by calling the render methods of the wxCanvasObjects it contains.
210 // It can have nested groups also, in the same way as the other wxCanvasObjects it already contains.
211 // The group has a matrix to position/rotate/scale the group.
212 class wxCanvasObjectGroup: public wxCanvasObject
213 {
214 public:
215 wxCanvasObjectGroup(double x, double y);
216 virtual ~wxCanvasObjectGroup();
217
218 void SetAdmin(wxCanvasAdmin* admin);
219
220 //prepend a wxCanvasObject to this group
221 virtual void Prepend( wxCanvasObject* obj );
222 //append a wxCanvasObject to this group
223 virtual void Append( wxCanvasObject* obj );
224 //insert a wxCanvasObject to this group
225 virtual void Insert( size_t before, wxCanvasObject* obj );
226 //remove the given object from the group
227 virtual void Remove( wxCanvasObject* obj );
228
229 //those this group contain the given object.
230 //in case of nested groups also search in there to the lowwest level.
231 virtual wxCanvasObject* Contains( wxCanvasObject* obj );
232
233 //returns index of the given wxCanvasObject in this group
234 virtual int IndexOf( wxCanvasObject* obj );
235
236 double GetPosX() { return lworld.GetValue(2,0); }
237 double GetPosY() { return lworld.GetValue(2,1); }
238 void SetPosXY( double x, double y) {lworld.SetValue(2,0,x);lworld.SetValue(2,1,y);CalcBoundingBox();};
239
240 void TransLate( double x, double y );
241
242 void CalcBoundingBox();
243 //remove all wxCanvasObjects from the group (flag for deletion of the objectsalso)
244 void DeleteContents( bool );
245 virtual void Render(wxTransformMatrix* cworld,int x, int y, int width, int height );
246 virtual void WriteSVG( wxTextOutputStream &stream );
247
248 //recursive call the IsHitWorld on all contained objects, the first
249 //one that is hit will be returned
250 wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
251
252 //recursive calls for contained objects to set eventhandlers,
253 //and also sets its own eventhandler
254 void PushEventHandler( wxEvtHandler *handler );
255 //recursive calls for contained objects to set eventhandlers,
256 //and also sets its own eventhandler
257 wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE );
258 //recursive calls for contained objects to set eventhandlers,
259 //and also sets its own eventhandler
260 void AppendEventHandler(wxEvtHandler *handler);
261 //recursive calls for contained objects to set eventhandlers,
262 //and also sets its own eventhandler
263 wxEvtHandler *RemoveLastEventHandler(bool deleteHandler);
264
265 protected:
266
267 //to position the object
268 wxTransformMatrix lworld;
269
270 wxList m_objects;
271
272 friend class wxCanvas;
273 };
274
275 //:defenition
276 // wxCanvasObjectRef is a reference to any wxCanvasObject derived class.
277 // It does not duplicate the referenced object.
278 // It has a matrix to reposition/rotate/scale the object it references.
279 // The position/matrix of the referenced Object is accumulated with the one here.
280 class wxCanvasObjectRef: public wxCanvasObject
281 {
282 public:
283 wxCanvasObjectRef(double x, double y,wxCanvasObject* obj);
284
285 //set rotation for the reference
286 void SetRotation(double rotation);
287
288 //set scale in x and y ( > zero)
289 void SetScale( double scalex, double scaley );
290
291 void SetAdmin(wxCanvasAdmin* admin);
292
293 double GetPosX() { return lworld.GetValue(2,0); }
294 double GetPosY() { return lworld.GetValue(2,1); }
295 void SetPosXY( double x, double y) {lworld.SetValue(2,0,x);lworld.SetValue(2,1,y);CalcBoundingBox();};
296
297 void TransLate( double x, double y );
298 void CalcBoundingBox();
299 virtual void Render(wxTransformMatrix* cworld,int x, int y, int width, int height );
300 virtual void WriteSVG( wxTextOutputStream &stream );
301
302 //return this object if one of the objects it references is hit
303 wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
304 virtual wxCanvasObject* Contains( wxCanvasObject* obj );
305
306 //recursive calls for contained objects to set eventhandlers,
307 //and also sets its own eventhandler
308 void PushEventHandler( wxEvtHandler *handler );
309 //recursive calls for contained objects to set eventhandlers,
310 //and also sets its own eventhandler
311 wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE );
312 //recursive calls for contained objects to set eventhandlers,
313 //and also sets its own eventhandler
314 void AppendEventHandler(wxEvtHandler *handler);
315 //recursive calls for contained objects to set eventhandlers,
316 //and also sets its own eventhandler
317 wxEvtHandler *RemoveLastEventHandler(bool deleteHandler);
318
319 protected:
320
321 //to position the object
322 wxTransformMatrix lworld;
323
324 //reference to another wxCanvasObject
325 wxCanvasObject* m_obj;
326 };
327
328 //:defenition
329 // wxCanvasRect
330 class wxCanvasRect: public wxCanvasObject
331 {
332 public:
333 wxCanvasRect( double x, double y, double w, double h , double radius=0 );
334 void SetBrush( const wxBrush& brush) { m_brush = brush; };
335 void SetPen( const wxPen& pen) { m_pen = pen; CalcBoundingBox(); };
336
337 double GetPosX() { return m_x; }
338 double GetPosY() { return m_y; }
339 void SetPosXY( double x, double y) {m_x=x; m_y=y; CalcBoundingBox();};
340
341 void TransLate( double x, double y );
342 void CalcBoundingBox();
343
344 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
345 virtual void WriteSVG( wxTextOutputStream &stream );
346
347 private:
348 wxPen m_pen;
349 wxBrush m_brush;
350
351 double m_x;
352 double m_y;
353 double m_width;
354 double m_height;
355 double m_radius;
356 };
357
358 //----------------------------------------------------------------------------
359 // wxCanvasCircle
360 //----------------------------------------------------------------------------
361 class wxCanvasCircle: public wxCanvasObject
362 {
363 public:
364 wxCanvasCircle( double x, double y, double radius );
365 void SetBrush( const wxBrush& brush) { m_brush = brush; };
366 void SetPen( const wxPen& pen) { m_pen = pen; CalcBoundingBox(); };
367
368 double GetPosX() { return m_x; }
369 double GetPosY() { return m_y; }
370 void SetPosXY( double x, double y) {m_x=x; m_y=y;CalcBoundingBox(); };
371
372 void TransLate( double x, double y );
373
374 void CalcBoundingBox();
375
376 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
377 virtual void WriteSVG( wxTextOutputStream &stream );
378
379 wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
380
381 private:
382 wxPen m_pen;
383 wxBrush m_brush;
384
385 double m_x;
386 double m_y;
387 double m_radius;
388 };
389
390 //:defenition
391 // wxCanvasEllipse
392 class wxCanvasEllipse: public wxCanvasObject
393 {
394 public:
395 wxCanvasEllipse( double x, double y, double width, double height );
396 void SetBrush( const wxBrush& brush) { m_brush = brush; };
397 void SetPen( const wxPen& pen) { m_pen = pen; CalcBoundingBox(); };
398
399 double GetPosX() { return m_x; }
400 double GetPosY() { return m_y; }
401 void SetPosXY( double x, double y) {m_x=x; m_y=y; CalcBoundingBox();};
402
403 void TransLate( double x, double y );
404
405 void CalcBoundingBox();
406
407 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
408 virtual void WriteSVG( wxTextOutputStream &stream );
409
410 wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
411
412 private:
413 wxPen m_pen;
414 wxBrush m_brush;
415
416 double m_x;
417 double m_y;
418 double m_width;
419 double m_height;
420 };
421
422 //:defenition
423 // wxCanvasEllipticArc
424 class wxCanvasEllipticArc: public wxCanvasObject
425 {
426 public:
427 wxCanvasEllipticArc( double x, double y, double width, double height, double start, double end );
428 void SetBrush( const wxBrush& brush) { m_brush = brush; };
429 void SetPen( const wxPen& pen) { m_pen = pen; CalcBoundingBox(); };
430
431 double GetPosX() { return m_x; }
432 double GetPosY() { return m_y; }
433 void SetPosXY( double x, double y) {m_x=x; m_y=y; CalcBoundingBox();};
434
435 void TransLate( double x, double y );
436 void CalcBoundingBox();
437
438 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
439 virtual void WriteSVG( wxTextOutputStream &stream );
440
441 wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
442
443 private:
444 wxPen m_pen;
445 wxBrush m_brush;
446
447 double m_x;
448 double m_y;
449 double m_width;
450 double m_height;
451 double m_start;
452 double m_end;
453 };
454
455 //:defenition
456 // wxCanvasLine
457 class wxCanvasLine: public wxCanvasObject
458 {
459 public:
460 wxCanvasLine( double x1, double y1, double x2, double y2 );
461 void SetPen( const wxPen& pen) { m_pen = pen; CalcBoundingBox(); };
462
463
464 double GetPosX() { return m_x1; }
465 double GetPosY() { return m_y1; }
466 void SetPosXY( double x, double y) {m_x1=x; m_y1=y; CalcBoundingBox();};
467
468 void TransLate( double x, double y );
469
470 void CalcBoundingBox();
471
472 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
473 virtual void WriteSVG( wxTextOutputStream &stream );
474
475 wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
476
477 private:
478 wxPen m_pen;
479
480 double m_x1;
481 double m_y1;
482 double m_x2;
483 double m_y2;
484 };
485
486 //:defenition
487 // wxCanvasImage
488 class wxCanvasImage: public wxCanvasObject
489 {
490 public:
491 wxCanvasImage( const wxImage &image, double x, double y, double w, double h );
492
493 double GetPosX() { return m_x; }
494 double GetPosY() { return m_y; }
495 void SetPosXY( double x, double y) {m_x=x; m_y=y;CalcBoundingBox(); };
496
497 void TransLate( double x, double y );
498
499 void CalcBoundingBox();
500
501 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
502 virtual void WriteSVG( wxTextOutputStream &stream );
503
504 private:
505 double m_x;
506 double m_y;
507 double m_width;
508 double m_height;
509
510 wxImage m_image;
511 int m_orgw,m_orgh;
512 wxImage m_tmp;
513 };
514
515 //----------------------------------------------------------------------------
516 // wxCanvasControl
517 //----------------------------------------------------------------------------
518
519 class wxCanvasControl: public wxCanvasObject
520 {
521 public:
522 wxCanvasControl( wxWindow *control );
523 ~wxCanvasControl();
524
525 double GetPosX();
526 double GetPosY();
527 void SetPosXY( double x, double y);
528
529 void TransLate( double x, double y );
530 void MoveRelative( double x, double y );
531
532 void CalcBoundingBox();
533
534 private:
535 wxWindow *m_control;
536 };
537
538 //:defenition
539 // wxCanvasText
540 class wxCanvasText: public wxCanvasObject
541 {
542 public:
543 wxCanvasText( const wxString &text, double x, double y, const wxString &foneFile, int size );
544 ~wxCanvasText();
545
546 double GetPosX() { return m_x; }
547 double GetPosY() { return m_y; }
548 void SetPosXY( double x, double y) {m_x=x; m_y=y;CalcBoundingBox(); };
549
550 void TransLate( double x, double y );
551
552 void CalcBoundingBox();
553
554 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
555 virtual void WriteSVG( wxTextOutputStream &stream );
556
557 void SetRGB( unsigned char red, unsigned char green, unsigned char blue );
558 void SetFlag( int flag );
559 int GetFlag() { return m_flag; }
560
561 private:
562 wxString m_text;
563 double m_x;
564 double m_y;
565 unsigned char *m_alpha;
566 void *m_faceData;
567 int m_flag;
568 int m_red;
569 int m_green;
570 int m_blue;
571 wxString m_fontFileName;
572 int m_size;
573 };
574
575 //:defenition
576 // wxCanvas is used to display a wxCanvasGroupObject, which contains wxCanvasObject derived
577 // drawable objects. The group to draw is called the root.
578 // All objects are defined in world coordinates, relative to its parent (e.g. nested groups)
579 // There are methods to convert from world to device coordinates and visa versa.
580 // Rendering a draw is normally started on the root, it to a buffer, afterwords
581 // an update of the damaged parts will blitted from the buffer to the screen.
582 // This is done in Idle time, but can also be forced.
583 // World coordinates can be with the Y axis going up are down.
584 // The area of the drawing in world coordinates that is visible on the canvas
585 // can be set. Parts of this area can be zoomed into resulting in scroll bars
586 // to be displayed.
587 class wxCanvas: public wxWindow
588 {
589 public:
590 // constructors and destructors
591 wxCanvas( wxCanvasAdmin* admin ,wxWindow *parent, wxWindowID id = -1,
592 const wxPoint& pos = wxDefaultPosition,
593 const wxSize& size = wxDefaultSize,
594 long style = wxScrolledWindowStyle );
595 virtual ~wxCanvas();
596
597 //intercept scroll events
598 virtual void OnScroll(wxScrollWinEvent& event);
599
600 //background colour for the canvas
601 virtual void SetColour( const wxColour& background );
602
603 //update the area given in device coordinates
604 virtual void Update( int x, int y, int width, int height, bool blit = TRUE );
605
606 //blit all updated areas now to the screen, else it will happen in idle time.
607 //Use this to support dragging for instance, becuase in such cases idle time
608 //will take to long.
609 virtual void UpdateNow();
610
611 //prevent canvas activety
612 virtual void Freeze();
613 //allow canvas activety
614 virtual void Thaw();
615
616 #if IMAGE_CANVAS
617 inline wxImage *GetBuffer() { return &m_buffer; }
618 #else
619 //get the buffer that is used for rendering in general
620 inline wxBitmap *GetBuffer() { return &m_buffer; }
621 //get the DC that is used for rendering
622 inline wxDC *GetDC() { return m_renderDC; }
623 //set the DC that is used for rendering
624 inline void SetDC(wxDC* dc) { m_renderDC=dc; }
625 #endif
626
627 inline int GetBufferWidth() { return m_buffer.GetWidth(); }
628 inline int GetBufferHeight() { return m_buffer.GetHeight(); }
629
630 //updating is needed for the canvas if the buffer did change
631 bool NeedUpdate() { return m_needUpdate; }
632 bool IsFrozen() { return m_frozen; }
633
634 //blit damaged areas in the buffer to the screen
635 void BlitBuffer( wxDC &dc );
636
637 //redirect events to this canvas object
638 void SetCaptureMouse( wxCanvasObject *obj );
639 //are events redirected, if so return the object else NULL
640 inline wxCanvasObject* GetCaptured() { return m_captureMouse;}
641
642 //set the root group where the objects for this canvas are stored
643 void SetRoot(wxCanvasObjectGroup* aroot){m_root=aroot;}
644
645 //get root group that is displayed on the canvas
646 wxCanvasObjectGroup* GetRoot(){return m_root;}
647
648 //scroll the window in device coordinates
649 virtual void ScrollWindow( int dx, int dy,
650 const wxRect* rect = (wxRect *) NULL );
651
652 //set if the Yaxis goes up or down
653 void SetYaxis(bool up){m_yaxis=up;}
654
655 //get currently used Yaxis setting
656 bool GetYaxis(){return m_yaxis;}
657
658 //to set the total area in world coordinates that can be scrolled.
659 // when totaly zoomed out (SetMappingScroll same size as given here),
660 // this will be the area displayed.
661 // To display all of a drawing, set this here to the boundingbox of the root group
662 // of the canvas.
663 void SetScroll(double vx1,double vy1,double vx2,double vy2);
664
665 //given the virtual size to be displayed, the mappingmatrix will be calculated
666 //in such a manner that it fits (same ratio in width and height) to the window size.
667 //The window size is used to intitialize the mapping.
668 //The virtual size is just an indication, it will be ajusted to fit in the client window ratio.
669 //When border is set an extra margin is added so that the drawing will fit nicely.
670 // To display all of a drawing, set this here to the boundingbox of the root group
671 // of the canvas.
672 void SetMappingScroll(double vx1,double vy1,double vx2,double vy2,bool border);
673
674 //matrix for calculating the virtual coordinate given a screen coordinate
675 wxTransformMatrix GetInverseMappingMatrix();
676
677 //matrix for calculating the screen coordinate given a virtual coordinate
678 wxTransformMatrix GetMappingMatrix();
679
680 //get minimum X of the visible part in world coordinates
681 inline double GetMinX(){return m_virt_minX;};
682 //get minimum Y of the visible part in world coordinates
683 inline double GetMinY(){return m_virt_minY;};
684 //get maximum X of the visible part in world coordinates
685 inline double GetMaxX(){return m_virt_maxX;};
686 //get maximum Y of the visible part in world coordinates
687 inline double GetMaxY(){return m_virt_maxY;};
688
689
690 //convert from window to virtual coordinates
691 double DeviceToLogicalX(int x) const;
692 //convert from window to virtual coordinates
693 double DeviceToLogicalY(int y) const;
694 //convert from window to virtual coordinates relatif
695 double DeviceToLogicalXRel(int x) const;
696 //convert from window to virtual coordinates relatif
697 double DeviceToLogicalYRel(int y) const;
698 //convert from virtual to window coordinates
699 int LogicalToDeviceX(double x) const;
700 //convert from virtual to window coordinates
701 int LogicalToDeviceY(double y) const;
702 //convert from virtual to window coordinates relatif
703 int LogicalToDeviceXRel(double x) const;
704 //convert from virtual to window coordinates relatif
705 int LogicalToDeviceYRel(double y) const;
706
707 protected:
708
709 bool m_yaxis;
710
711 // holds the matrix for mapping from virtual to screen coordinates
712 wxTransformMatrix m_mapping_matrix;
713
714 // holds the inverse of the mapping matrix
715 wxTransformMatrix m_inverse_mapping;
716
717 //virtual coordinates of total drawing
718 double m_virtm_minX, m_virtm_minY, m_virtm_maxX, m_virtm_maxY;
719
720 // virtual coordinates box
721 double m_virt_minX, m_virt_minY, m_virt_maxX, m_virt_maxY;
722
723 // bounding box
724 double m_minX, m_minY, m_maxX, m_maxY;
725
726 //are scroll bars active?
727 bool m_scrolled;
728
729 private:
730 #if IMAGE_CANVAS
731 wxImage m_buffer;
732 #else
733 wxBitmap m_buffer;
734
735 //always available and m_buffer selected
736 wxDC* m_renderDC;
737 #endif
738 bool m_needUpdate;
739 wxList m_updateRects;
740 wxCanvasObjectGroup* m_root;
741
742 wxColour m_background;
743 bool m_frozen;
744 wxCanvasObject *m_lastMouse;
745 wxCanvasObject *m_captureMouse;
746
747 int m_oldDeviceX,m_oldDeviceY;
748
749 wxCanvasAdmin* m_admin;
750
751 protected:
752
753 void OnMouse( wxMouseEvent &event );
754
755 private:
756 void OnChar( wxKeyEvent &event );
757 void OnPaint( wxPaintEvent &event );
758 void OnSize( wxSizeEvent &event );
759 void OnIdle( wxIdleEvent &event );
760 void OnSetFocus( wxFocusEvent &event );
761 void OnKillFocus( wxFocusEvent &event );
762 void OnEraseBackground( wxEraseEvent &event );
763
764 private:
765 DECLARE_CLASS(wxCanvas)
766 DECLARE_EVENT_TABLE()
767 };
768
769
770 //:defenition
771 //Contains a list of wxCanvas Objects that will be maintained through this class.
772 //Each wxCanvasObject can be displayed on several wxCanvas Objects at the same time.
773 //The active wxCanvas is used to render and convert coordinates from world to device.
774 //So it is important to set the active wxCanvas based on the wxCanvas that has the focus
775 //or is scrolled etc. This is normally done within wxCanvas when appropriate.
776 class wxCanvasAdmin
777 {
778 public:
779 // constructors and destructors
780 wxCanvasAdmin();
781 virtual ~wxCanvasAdmin();
782
783 //convert from window to virtual coordinates
784 double DeviceToLogicalX(int x) const;
785 //convert from window to virtual coordinates
786 double DeviceToLogicalY(int y) const;
787 //convert from window to virtual coordinates relatif
788 double DeviceToLogicalXRel(int x) const;
789 //convert from window to virtual coordinates relatif
790 double DeviceToLogicalYRel(int y) const;
791 //convert from virtual to window coordinates
792 int LogicalToDeviceX(double x) const;
793 //convert from virtual to window coordinates
794 int LogicalToDeviceY(double y) const;
795 //convert from virtual to window coordinates relatif
796 int LogicalToDeviceXRel(double x) const;
797 //convert from virtual to window coordinates relatif
798 int LogicalToDeviceYRel(double y) const;
799
800 //update in the buffer off all canvases, the area given in world coordinates
801 virtual void Update(wxCanvasObject* obj, double x, double y, double width, double height);
802
803 //blit all updated areas now to the screen, else it will happen in idle time.
804 //Use this to support dragging for instance, becuase in such cases idle time
805 //will take to long.
806 virtual void UpdateNow();
807
808 //append another canvas
809 virtual void Append( wxCanvas* canvas );
810
811 //remove a canvas
812 virtual void Remove( wxCanvas* canvas );
813
814 //set the given canvas as active (for rendering, coordinate conversion etc.)
815 void SetActive(wxCanvas* activate);
816
817 //get active canvas
818 inline wxCanvas* GetActive() {return m_active;};
819
820 private:
821 wxList m_canvaslist;
822 wxCanvas* m_active;
823 };
824
825 #endif
826 // WXCANVAS
827