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