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