]> git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/canvas/canvas.h
f0a08a707a9a00bc6ad564b0d765355b4dc60260
[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);
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
511 // cache
512 wxBitmap m_cBitmap;
513 wxImage m_cImage;
514 int m_cW;
515 int m_cH;
516 double m_cR;
517 };
518
519 //----------------------------------------------------------------------------
520 // wxCanvasControl
521 //----------------------------------------------------------------------------
522
523 class wxCanvasControl: public wxCanvasObject
524 {
525 public:
526 wxCanvasControl( wxWindow *control );
527 ~wxCanvasControl();
528
529 double GetPosX();
530 double GetPosY();
531 void SetPosXY( double x, double y);
532
533 void TransLate( double x, double y );
534 void MoveRelative( double x, double y );
535
536 void CalcBoundingBox();
537
538 private:
539 wxWindow *m_control;
540 };
541
542 //:defenition
543 // wxCanvasText
544 class wxCanvasText: public wxCanvasObject
545 {
546 public:
547 wxCanvasText( const wxString &text, double x, double y, const wxString &foneFile, int size );
548 ~wxCanvasText();
549
550 double GetPosX() { return m_x; }
551 double GetPosY() { return m_y; }
552 void SetPosXY( double x, double y) {m_x=x; m_y=y;CalcBoundingBox(); };
553
554 void TransLate( double x, double y );
555
556 void CalcBoundingBox();
557
558 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
559 virtual void WriteSVG( wxTextOutputStream &stream );
560
561 void SetRGB( unsigned char red, unsigned char green, unsigned char blue );
562 void SetFlag( int flag );
563 int GetFlag() { return m_flag; }
564
565 private:
566 wxString m_text;
567 double m_x;
568 double m_y;
569 unsigned char *m_alpha;
570 void *m_faceData;
571 int m_flag;
572 int m_red;
573 int m_green;
574 int m_blue;
575 wxString m_fontFileName;
576 int m_size;
577 };
578
579 //:defenition
580 // wxCanvas is used to display a wxCanvasGroupObject, which contains wxCanvasObject derived
581 // drawable objects. The group to draw is called the root.
582 // All objects are defined in world coordinates, relative to its parent (e.g. nested groups)
583 // There are methods to convert from world to device coordinates and visa versa.
584 // Rendering a draw is normally started on the root, it to a buffer, afterwords
585 // an update of the damaged parts will blitted from the buffer to the screen.
586 // This is done in Idle time, but can also be forced.
587 // World coordinates can be with the Y axis going up are down.
588 // The area of the drawing in world coordinates that is visible on the canvas
589 // can be set. Parts of this area can be zoomed into resulting in scroll bars
590 // to be displayed.
591 class wxCanvas: public wxScrolledWindow
592 {
593 public:
594 // constructors and destructors
595 wxCanvas( wxCanvasAdmin* admin ,wxWindow *parent, wxWindowID id = -1,
596 const wxPoint& pos = wxDefaultPosition,
597 const wxSize& size = wxDefaultSize,
598 long style = wxScrolledWindowStyle );
599 virtual ~wxCanvas();
600
601 //background colour for the canvas
602 virtual void SetColour( const wxColour& background );
603
604 //update the area given in device coordinates
605 virtual void Update( int x, int y, int width, int height, bool blit = TRUE );
606
607 //blit all updated areas now to the screen, else it will happen in idle time.
608 //Use this to support dragging for instance, becuase in such cases idle time
609 //will take to long.
610 virtual void UpdateNow();
611
612 //prevent canvas activety
613 virtual void Freeze();
614 //allow canvas activety
615 virtual void Thaw();
616
617 //get the buffer that is used for rendering in general
618 inline wxBitmap *GetBuffer() { return &m_buffer; }
619 //get the DC that is used for rendering
620 inline wxDC *GetDC() { return m_renderDC; }
621 //set the DC that is used for rendering
622 inline void SetDC(wxDC* dc) { m_renderDC=dc; }
623
624 inline int GetBufferWidth() { return m_buffer.GetWidth(); }
625 inline int GetBufferHeight() { return m_buffer.GetHeight(); }
626
627 //updating is needed for the canvas if the buffer did change
628 bool NeedUpdate() { return m_needUpdate; }
629 bool IsFrozen() { return m_frozen; }
630
631 //blit damaged areas in the buffer to the screen
632 void BlitBuffer( wxDC &dc );
633
634 //redirect events to this canvas object
635 void SetCaptureMouse( wxCanvasObject *obj );
636 //are events redirected, if so return the object else NULL
637 inline wxCanvasObject* GetCaptured() { return m_captureMouse;}
638
639 //set the root group where the objects for this canvas are stored
640 void SetRoot(wxCanvasObjectGroup* aroot){m_root=aroot;}
641
642 //get root group that is displayed on the canvas
643 wxCanvasObjectGroup* GetRoot(){return m_root;}
644
645 //scroll the window in device coordinates
646 virtual void ScrollWindow( int dx, int dy,
647 const wxRect* rect = (wxRect *) NULL );
648
649 //get y axis orientation
650 virtual bool GetYaxis() { return FALSE; }
651
652 //get the visible part in world coordinates
653 virtual double GetMinX() const;
654 virtual double GetMinY() const;
655 virtual double GetMaxX() const;
656 virtual double GetMaxY() const;
657
658 //convert from window to virtual coordinates
659 virtual double DeviceToLogicalX(int x) const;
660 virtual double DeviceToLogicalY(int y) const;
661 virtual double DeviceToLogicalXRel(int x) const;
662 virtual double DeviceToLogicalYRel(int y) const;
663 virtual int LogicalToDeviceX(double x) const;
664 virtual int LogicalToDeviceY(double y) const;
665 virtual int LogicalToDeviceXRel(double x) const;
666 virtual int LogicalToDeviceYRel(double y) const;
667
668 protected:
669 wxBitmap m_buffer;
670
671 //always available and m_buffer selected
672 wxDC* m_renderDC;
673
674 bool m_needUpdate;
675 wxList m_updateRects;
676 wxCanvasObjectGroup* m_root;
677
678 wxColour m_background;
679 bool m_frozen;
680 wxCanvasObject *m_lastMouse;
681 wxCanvasObject *m_captureMouse;
682
683 int m_oldDeviceX,m_oldDeviceY;
684
685 wxCanvasAdmin* m_admin;
686
687 private:
688 int m_bufferX,m_bufferY;
689
690 protected:
691 void OnMouse( wxMouseEvent &event );
692 void OnPaint( wxPaintEvent &event );
693 void OnSize( wxSizeEvent &event );
694 void OnIdle( wxIdleEvent &event );
695 void OnSetFocus( wxFocusEvent &event );
696 void OnKillFocus( wxFocusEvent &event );
697 void OnEraseBackground( wxEraseEvent &event );
698
699 private:
700 DECLARE_CLASS(wxCanvas)
701 DECLARE_EVENT_TABLE()
702 };
703
704
705
706 class wxVectorCanvas: public wxCanvas
707 {
708 public:
709 // constructors and destructors
710 wxVectorCanvas( wxCanvasAdmin* admin ,wxWindow *parent, wxWindowID id = -1,
711 const wxPoint& pos = wxDefaultPosition,
712 const wxSize& size = wxDefaultSize,
713 long style = wxScrolledWindowStyle );
714
715 //scroll the window in device coordinates
716 virtual void ScrollWindow( int dx, int dy,
717 const wxRect* rect = (wxRect *) NULL );
718
719 //set if the Yaxis goes up or down
720 void SetYaxis(bool up) { m_yaxis=up; }
721
722 //get currently used Yaxis setting
723 virtual bool GetYaxis() { return m_yaxis; }
724
725 //to set the total area in world coordinates that can be scrolled.
726 // when totaly zoomed out (SetMappingScroll same size as given here),
727 // this will be the area displayed.
728 // To display all of a drawing, set this here to the boundingbox of the root group
729 // of the canvas.
730 void SetScroll(double vx1,double vy1,double vx2,double vy2);
731
732 //given the virtual size to be displayed, the mappingmatrix will be calculated
733 //in such a manner that it fits (same ratio in width and height) to the window size.
734 //The window size is used to intitialize the mapping.
735 //The virtual size is just an indication, it will be ajusted to fit in the client window ratio.
736 //When border is set an extra margin is added so that the drawing will fit nicely.
737 // To display all of a drawing, set this here to the boundingbox of the root group
738 // of the canvas.
739 void SetMappingScroll(double vx1,double vy1,double vx2,double vy2,bool border);
740
741 //matrix for calculating the virtual coordinate given a screen coordinate
742 wxTransformMatrix GetInverseMappingMatrix();
743
744 //matrix for calculating the screen coordinate given a virtual coordinate
745 wxTransformMatrix GetMappingMatrix();
746
747 //get minimum X of the visible part in world coordinates
748 virtual double GetMinX() const;
749 virtual double GetMinY() const;
750 virtual double GetMaxX() const;
751 virtual double GetMaxY() const;
752
753 //convert from window to virtual coordinates and back
754 virtual double DeviceToLogicalX(int x) const;
755 virtual double DeviceToLogicalY(int y) const;
756 virtual double DeviceToLogicalXRel(int x) const;
757 virtual double DeviceToLogicalYRel(int y) const;
758 virtual int LogicalToDeviceX(double x) const;
759 virtual int LogicalToDeviceY(double y) const;
760 virtual int LogicalToDeviceXRel(double x) const;
761 virtual int LogicalToDeviceYRel(double y) const;
762
763 protected:
764 // up or down
765 bool m_yaxis;
766
767 // holds the matrix for mapping from virtual to screen coordinates
768 wxTransformMatrix m_mapping_matrix;
769
770 // holds the inverse of the mapping matrix
771 wxTransformMatrix m_inverse_mapping;
772
773 //virtual coordinates of total drawing
774 double m_virtm_minX, m_virtm_minY, m_virtm_maxX, m_virtm_maxY;
775
776 // virtual coordinates box
777 double m_virt_minX, m_virt_minY, m_virt_maxX, m_virt_maxY;
778
779 // bounding box
780 double m_minX, m_minY, m_maxX, m_maxY;
781
782 //are scroll bars active?
783 bool m_scrolled;
784
785 private:
786 void OnScroll(wxScrollWinEvent& event);
787 void OnChar( wxKeyEvent &event );
788 void OnSize( wxSizeEvent &event );
789
790 private:
791 DECLARE_CLASS(wxVectorCanvas)
792 DECLARE_EVENT_TABLE()
793 };
794
795
796
797 //:defenition
798 //Contains a list of wxCanvas Objects that will be maintained through this class.
799 //Each wxCanvasObject can be displayed on several wxCanvas Objects at the same time.
800 //The active wxCanvas is used to render and convert coordinates from world to device.
801 //So it is important to set the active wxCanvas based on the wxCanvas that has the focus
802 //or is scrolled etc. This is normally done within wxCanvas when appropriate.
803 class wxCanvasAdmin
804 {
805 public:
806 // constructors and destructors
807 wxCanvasAdmin();
808 virtual ~wxCanvasAdmin();
809
810 //convert from window to virtual coordinates
811 double DeviceToLogicalX(int x) const;
812 //convert from window to virtual coordinates
813 double DeviceToLogicalY(int y) const;
814 //convert from window to virtual coordinates relatif
815 double DeviceToLogicalXRel(int x) const;
816 //convert from window to virtual coordinates relatif
817 double DeviceToLogicalYRel(int y) const;
818 //convert from virtual to window coordinates
819 int LogicalToDeviceX(double x) const;
820 //convert from virtual to window coordinates
821 int LogicalToDeviceY(double y) const;
822 //convert from virtual to window coordinates relatif
823 int LogicalToDeviceXRel(double x) const;
824 //convert from virtual to window coordinates relatif
825 int LogicalToDeviceYRel(double y) const;
826
827 //update in the buffer off all canvases, the area given in world coordinates
828 virtual void Update(wxCanvasObject* obj, double x, double y, double width, double height);
829
830 //blit all updated areas now to the screen, else it will happen in idle time.
831 //Use this to support dragging for instance, becuase in such cases idle time
832 //will take to long.
833 virtual void UpdateNow();
834
835 //append another canvas
836 virtual void Append( wxCanvas* canvas );
837
838 //remove a canvas
839 virtual void Remove( wxCanvas* canvas );
840
841 //set the given canvas as active (for rendering, coordinate conversion etc.)
842 void SetActive(wxCanvas* activate);
843
844 //get active canvas
845 inline wxCanvas* GetActive() {return m_active;};
846
847 private:
848 wxList m_canvaslist;
849 wxCanvas* m_active;
850 };
851
852 #endif
853 // WXCANVAS
854