]> git.saurik.com Git - wxWidgets.git/blame - contrib/include/wx/canvas/canvas.h
make wxArtProvider pure virtual (I was not so on
[wxWidgets.git] / contrib / include / wx / canvas / canvas.h
CommitLineData
6a2c1874
RR
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"
5143c96b 22#include "wx/geometry.h"
09cc749c
RR
23#include "wx/matrix.h"
24#include "bbox.h"
5143c96b 25
dc16900b 26
33ebcd80
RR
27//----------------------------------------------------------------------------
28// decls
29//----------------------------------------------------------------------------
30
33ebcd80 31class wxCanvas;
09cc749c 32class wxCanvasAdmin;
6a2c1874
RR
33
34//----------------------------------------------------------------------------
35// wxCanvasObject
36//----------------------------------------------------------------------------
b5789150
RR
37enum wxDRAG_MODE
38{
39 wxDRAG_RECTANGLE,
40 wxDRAG_ONTOP,
41 wxDRAG_REDRAW
42};
09cc749c
RR
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
6a2c1874
RR
55class wxCanvasObject: public wxEvtHandler
56{
a977709b 57 DECLARE_CLASS(wxCanvasObject)
6a2c1874 58public:
dc16900b 59
09cc749c 60 wxCanvasObject();
1e1af41e 61
09cc749c
RR
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
b5789150 97 void SetDragMode(wxDRAG_MODE mode) { m_dragmode=mode; };
09cc749c
RR
98
99 //return the dragmode
b5789150 100 wxDRAG_MODE GetDragMode() { return m_dragmode; };
09cc749c
RR
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
6a2c1874 118 virtual void WriteSVG( wxTextOutputStream &stream );
dc16900b 119
09cc749c
RR
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; }
dc16900b 129
09cc749c 130 //is this a control type of canvas object
6a2c1874 131 bool IsControl() { return m_isControl; }
09cc749c 132 //is this a vector type of canvas object
6a2c1874 133 bool IsVector() { return m_isVector; }
09cc749c 134 //is this an Image type of canvas object
6a2c1874 135 bool IsImage() { return m_isImage; }
6a2c1874 136
09cc749c
RR
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
dc16900b 150 void CaptureMouse();
09cc749c 151 //release the mouse capture for this object
dc16900b 152 void ReleaseMouse();
09cc749c 153 //is the mouse captured for this object
dc16900b
KH
154 bool IsCapturedMouse();
155
09cc749c
RR
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
6a2c1874 189protected:
fcbb6b37 190
09cc749c
RR
191 //administator for rendering and accessing the canvas's
192 wxCanvasAdmin* m_admin;
dc16900b 193
09cc749c
RR
194 //active event handler, default the object itself
195 wxEvtHandler* m_eventHandler;
6a2c1874 196
09cc749c
RR
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;
b5789150 202 wxDRAG_MODE m_dragmode:3;
fcbb6b37 203
09cc749c
RR
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.
216class wxCanvasObjectGroup: public wxCanvasObject
fcbb6b37 217{
a977709b 218 DECLARE_CLASS(wxCanvasObjectGroup)
fcbb6b37 219public:
09cc749c 220 wxCanvasObjectGroup(double x, double y);
21840a6c 221 virtual ~wxCanvasObjectGroup();
fcbb6b37 222
09cc749c 223 void SetAdmin(wxCanvasAdmin* admin);
fcbb6b37 224
09cc749c 225 //prepend a wxCanvasObject to this group
fcbb6b37 226 virtual void Prepend( wxCanvasObject* obj );
09cc749c 227 //append a wxCanvasObject to this group
fcbb6b37 228 virtual void Append( wxCanvasObject* obj );
09cc749c 229 //insert a wxCanvasObject to this group
fcbb6b37 230 virtual void Insert( size_t before, wxCanvasObject* obj );
09cc749c 231 //remove the given object from the group
fcbb6b37
KH
232 virtual void Remove( wxCanvasObject* obj );
233
09cc749c
RR
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 );
fcbb6b37 240
09cc749c
RR
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();};
fcbb6b37 244
09cc749c
RR
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);
fcbb6b37
KH
269
270protected:
fcbb6b37 271
09cc749c
RR
272 //to position the object
273 wxTransformMatrix lworld;
fcbb6b37
KH
274
275 wxList m_objects;
276
277 friend class wxCanvas;
278};
279
09cc749c
RR
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.
285class wxCanvasObjectRef: public wxCanvasObject
fcbb6b37 286{
a977709b 287 DECLARE_CLASS(wxCanvasObjectRef)
fcbb6b37 288public:
09cc749c 289 wxCanvasObjectRef(double x, double y,wxCanvasObject* obj);
fcbb6b37 290
09cc749c
RR
291 //set rotation for the reference
292 void SetRotation(double rotation);
fcbb6b37 293
09cc749c
RR
294 //set scale in x and y ( > zero)
295 void SetScale( double scalex, double scaley );
fcbb6b37 296
09cc749c 297 void SetAdmin(wxCanvasAdmin* admin);
fcbb6b37 298
09cc749c
RR
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();};
fcbb6b37 302
09cc749c
RR
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 );
fcbb6b37 307
09cc749c
RR
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);
fcbb6b37 324
09cc749c 325protected:
fcbb6b37 326
09cc749c
RR
327 //to position the object
328 wxTransformMatrix lworld;
fcbb6b37 329
09cc749c
RR
330 //reference to another wxCanvasObject
331 wxCanvasObject* m_obj;
332};
5143c96b 333
09cc749c
RR
334//:defenition
335// wxCanvasRect
336class wxCanvasRect: public wxCanvasObject
5143c96b 337{
a977709b 338 DECLARE_CLASS(wxCanvasRect)
5143c96b 339public:
09cc749c
RR
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(); };
5143c96b 343
09cc749c
RR
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();};
5143c96b 347
09cc749c
RR
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 );
5143c96b
KH
352 virtual void WriteSVG( wxTextOutputStream &stream );
353
354private:
5143c96b 355 wxPen m_pen;
09cc749c 356 wxBrush m_brush;
5143c96b 357
09cc749c
RR
358 double m_x;
359 double m_y;
360 double m_width;
361 double m_height;
362 double m_radius;
5143c96b
KH
363};
364
365//----------------------------------------------------------------------------
09cc749c 366// wxCanvasCircle
5143c96b 367//----------------------------------------------------------------------------
09cc749c 368class wxCanvasCircle: public wxCanvasObject
5143c96b
KH
369{
370public:
09cc749c
RR
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(); };
5143c96b 378
09cc749c 379 void TransLate( double x, double y );
5143c96b 380
09cc749c
RR
381 void CalcBoundingBox();
382
383 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
5143c96b
KH
384 virtual void WriteSVG( wxTextOutputStream &stream );
385
09cc749c 386 wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
5143c96b 387
09cc749c 388private:
5143c96b 389 wxPen m_pen;
09cc749c
RR
390 wxBrush m_brush;
391
392 double m_x;
393 double m_y;
394 double m_radius;
395};
5143c96b 396
09cc749c
RR
397//:defenition
398// wxCanvasEllipse
399class wxCanvasEllipse: public wxCanvasObject
400{
401public:
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(); };
5143c96b 405
09cc749c
RR
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();};
5143c96b 409
09cc749c 410 void TransLate( double x, double y );
5143c96b 411
09cc749c 412 void CalcBoundingBox();
5143c96b 413
09cc749c
RR
414 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
415 virtual void WriteSVG( wxTextOutputStream &stream );
5143c96b 416
09cc749c 417 wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
21544859 418
09cc749c
RR
419private:
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
431class wxCanvasEllipticArc: public wxCanvasObject
21544859
RR
432{
433public:
09cc749c
RR
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();};
dc16900b 441
09cc749c
RR
442 void TransLate( double x, double y );
443 void CalcBoundingBox();
dc16900b 444
09cc749c 445 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
21544859 446 virtual void WriteSVG( wxTextOutputStream &stream );
dc16900b 447
09cc749c
RR
448 wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
449
21544859 450private:
27d1065d
RR
451 wxPen m_pen;
452 wxBrush m_brush;
453
4dbd4ee6
RR
454 double m_x;
455 double m_y;
456 double m_width;
dc16900b 457 double m_height;
09cc749c
RR
458 double m_start;
459 double m_end;
21544859
RR
460};
461
09cc749c 462//:defenition
239c1f50 463// wxCanvasLine
239c1f50
RR
464class wxCanvasLine: public wxCanvasObject
465{
466public:
27d1065d 467 wxCanvasLine( double x1, double y1, double x2, double y2 );
09cc749c
RR
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();};
dc16900b 474
09cc749c 475 void TransLate( double x, double y );
dc16900b 476
09cc749c
RR
477 void CalcBoundingBox();
478
479 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
239c1f50 480 virtual void WriteSVG( wxTextOutputStream &stream );
09cc749c
RR
481
482 wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
483
239c1f50 484private:
27d1065d
RR
485 wxPen m_pen;
486
4dbd4ee6
RR
487 double m_x1;
488 double m_y1;
489 double m_x2;
490 double m_y2;
239c1f50
RR
491};
492
09cc749c 493//:defenition
6a2c1874 494// wxCanvasImage
6a2c1874
RR
495class wxCanvasImage: public wxCanvasObject
496{
497public:
4dbd4ee6 498 wxCanvasImage( const wxImage &image, double x, double y, double w, double h );
09cc749c
RR
499
500 double GetPosX() { return m_x; }
501 double GetPosY() { return m_y; }
880d870e 502 void SetPosXY( double x, double y);
09cc749c
RR
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 );
6a2c1874 509 virtual void WriteSVG( wxTextOutputStream &stream );
09cc749c 510
6a2c1874 511private:
4dbd4ee6
RR
512 double m_x;
513 double m_y;
514 double m_width;
515 double m_height;
09cc749c 516
6a2c1874 517 wxImage m_image;
09cc749c 518 int m_orgw,m_orgh;
880d870e
RR
519
520 // cache
521 wxBitmap m_cBitmap;
522 wxImage m_cImage;
523 int m_cW;
524 int m_cH;
525 double m_cR;
6a2c1874
RR
526};
527
3b111dbe
RR
528//----------------------------------------------------------------------------
529// wxCanvasControl
530//----------------------------------------------------------------------------
531
532class wxCanvasControl: public wxCanvasObject
533{
534public:
535 wxCanvasControl( wxWindow *control );
536 ~wxCanvasControl();
09cc749c
RR
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
3b111dbe
RR
547private:
548 wxWindow *m_control;
549};
550
09cc749c 551//:defenition
d1f9b206 552// wxCanvasText
d1f9b206
RR
553class wxCanvasText: public wxCanvasObject
554{
555public:
4dbd4ee6 556 wxCanvasText( const wxString &text, double x, double y, const wxString &foneFile, int size );
d1f9b206 557 ~wxCanvasText();
dc16900b 558
09cc749c
RR
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(); };
dc16900b 562
09cc749c
RR
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 );
d1f9b206 568 virtual void WriteSVG( wxTextOutputStream &stream );
09cc749c 569
d1f9b206
RR
570 void SetRGB( unsigned char red, unsigned char green, unsigned char blue );
571 void SetFlag( int flag );
239c1f50 572 int GetFlag() { return m_flag; }
dc16900b 573
d1f9b206
RR
574private:
575 wxString m_text;
4dbd4ee6
RR
576 double m_x;
577 double m_y;
d1f9b206
RR
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;
cb281cfc
RR
584 wxString m_fontFileName;
585 int m_size;
d1f9b206
RR
586};
587
09cc749c
RR
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.
8636c073 600class wxCanvas: public wxScrolledWindow
6a2c1874
RR
601{
602public:
603 // constructors and destructors
09cc749c 604 wxCanvas( wxCanvasAdmin* admin ,wxWindow *parent, wxWindowID id = -1,
6a2c1874
RR
605 const wxPoint& pos = wxDefaultPosition,
606 const wxSize& size = wxDefaultSize,
607 long style = wxScrolledWindowStyle );
608 virtual ~wxCanvas();
dc16900b 609
09cc749c
RR
610 //background colour for the canvas
611 virtual void SetColour( const wxColour& background );
612
613 //update the area given in device coordinates
41328253 614 virtual void Update( int x, int y, int width, int height, bool blit = TRUE );
09cc749c
RR
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.
6a2c1874 619 virtual void UpdateNow();
dc16900b 620
09cc749c 621 //prevent canvas activety
239c1f50 622 virtual void Freeze();
09cc749c 623 //allow canvas activety
239c1f50 624 virtual void Thaw();
dc16900b 625
09cc749c 626 //get the buffer that is used for rendering in general
33ebcd80 627 inline wxBitmap *GetBuffer() { return &m_buffer; }
09cc749c
RR
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; }
09cc749c 632
41328253
RR
633 inline int GetBufferWidth() { return m_buffer.GetWidth(); }
634 inline int GetBufferHeight() { return m_buffer.GetHeight(); }
09cc749c
RR
635
636 //updating is needed for the canvas if the buffer did change
6a2c1874 637 bool NeedUpdate() { return m_needUpdate; }
1e1af41e 638 bool IsFrozen() { return m_frozen; }
dc16900b 639
09cc749c 640 //blit damaged areas in the buffer to the screen
3b111dbe 641 void BlitBuffer( wxDC &dc );
dc16900b 642
09cc749c 643 //redirect events to this canvas object
dc16900b 644 void SetCaptureMouse( wxCanvasObject *obj );
09cc749c
RR
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;}
dc16900b 653
8636c073
RR
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
677protected:
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
696private:
697 int m_bufferX,m_bufferY;
698
699protected:
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
708private:
709 DECLARE_CLASS(wxCanvas)
710 DECLARE_EVENT_TABLE()
711};
712
713
714
715class wxVectorCanvas: public wxCanvas
716{
717public:
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
09cc749c 724 //scroll the window in device coordinates
41328253
RR
725 virtual void ScrollWindow( int dx, int dy,
726 const wxRect* rect = (wxRect *) NULL );
dc16900b 727
09cc749c 728 //set if the Yaxis goes up or down
8636c073 729 void SetYaxis(bool up) { m_yaxis=up; }
09cc749c
RR
730
731 //get currently used Yaxis setting
8636c073 732 virtual bool GetYaxis() { return m_yaxis; }
09cc749c
RR
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
8636c073
RR
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;
09cc749c
RR
771
772protected:
8636c073 773 // up or down
09cc749c
RR
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
6a2c1874 794private:
8636c073 795 void OnScroll(wxScrollWinEvent& event);
6a2c1874 796 void OnChar( wxKeyEvent &event );
6a2c1874 797 void OnSize( wxSizeEvent &event );
6a2c1874
RR
798
799private:
8636c073 800 DECLARE_CLASS(wxVectorCanvas)
6a2c1874
RR
801 DECLARE_EVENT_TABLE()
802};
803
804
8636c073 805
09cc749c
RR
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.
812class wxCanvasAdmin
813{
814public:
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
856private:
857 wxList m_canvaslist;
858 wxCanvas* m_active;
859};
860
6a2c1874
RR
861#endif
862 // WXCANVAS
863