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