]> git.saurik.com Git - wxWidgets.git/blame - contrib/include/wx/canvas/canvas.h
bump date on 'easter egg' dialog.
[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{
57public:
dc16900b 58
09cc749c 59 wxCanvasObject();
1e1af41e 60
09cc749c
RR
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
b5789150 96 void SetDragMode(wxDRAG_MODE mode) { m_dragmode=mode; };
09cc749c
RR
97
98 //return the dragmode
b5789150 99 wxDRAG_MODE GetDragMode() { return m_dragmode; };
09cc749c
RR
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
6a2c1874 117 virtual void WriteSVG( wxTextOutputStream &stream );
dc16900b 118
09cc749c
RR
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; }
dc16900b 128
09cc749c 129 //is this a control type of canvas object
6a2c1874 130 bool IsControl() { return m_isControl; }
09cc749c 131 //is this a vector type of canvas object
6a2c1874 132 bool IsVector() { return m_isVector; }
09cc749c 133 //is this an Image type of canvas object
6a2c1874 134 bool IsImage() { return m_isImage; }
6a2c1874 135
09cc749c
RR
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
dc16900b 149 void CaptureMouse();
09cc749c 150 //release the mouse capture for this object
dc16900b 151 void ReleaseMouse();
09cc749c 152 //is the mouse captured for this object
dc16900b
KH
153 bool IsCapturedMouse();
154
09cc749c
RR
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
6a2c1874 188protected:
fcbb6b37 189
09cc749c
RR
190 //administator for rendering and accessing the canvas's
191 wxCanvasAdmin* m_admin;
dc16900b 192
09cc749c
RR
193 //active event handler, default the object itself
194 wxEvtHandler* m_eventHandler;
6a2c1874 195
09cc749c
RR
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;
b5789150 201 wxDRAG_MODE m_dragmode:3;
fcbb6b37 202
09cc749c
RR
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.
215class wxCanvasObjectGroup: public wxCanvasObject
fcbb6b37
KH
216{
217public:
09cc749c 218 wxCanvasObjectGroup(double x, double y);
21840a6c 219 virtual ~wxCanvasObjectGroup();
fcbb6b37 220
09cc749c 221 void SetAdmin(wxCanvasAdmin* admin);
fcbb6b37 222
09cc749c 223 //prepend a wxCanvasObject to this group
fcbb6b37 224 virtual void Prepend( wxCanvasObject* obj );
09cc749c 225 //append a wxCanvasObject to this group
fcbb6b37 226 virtual void Append( wxCanvasObject* obj );
09cc749c 227 //insert a wxCanvasObject to this group
fcbb6b37 228 virtual void Insert( size_t before, wxCanvasObject* obj );
09cc749c 229 //remove the given object from the group
fcbb6b37
KH
230 virtual void Remove( wxCanvasObject* obj );
231
09cc749c
RR
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 );
fcbb6b37 238
09cc749c
RR
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();};
fcbb6b37 242
09cc749c
RR
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);
fcbb6b37
KH
267
268protected:
fcbb6b37 269
09cc749c
RR
270 //to position the object
271 wxTransformMatrix lworld;
fcbb6b37
KH
272
273 wxList m_objects;
274
275 friend class wxCanvas;
276};
277
09cc749c
RR
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.
283class wxCanvasObjectRef: public wxCanvasObject
fcbb6b37
KH
284{
285public:
09cc749c 286 wxCanvasObjectRef(double x, double y,wxCanvasObject* obj);
fcbb6b37 287
09cc749c
RR
288 //set rotation for the reference
289 void SetRotation(double rotation);
fcbb6b37 290
09cc749c
RR
291 //set scale in x and y ( > zero)
292 void SetScale( double scalex, double scaley );
fcbb6b37 293
09cc749c 294 void SetAdmin(wxCanvasAdmin* admin);
fcbb6b37 295
09cc749c
RR
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();};
fcbb6b37 299
09cc749c
RR
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 );
fcbb6b37 304
09cc749c
RR
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);
fcbb6b37 321
09cc749c 322protected:
fcbb6b37 323
09cc749c
RR
324 //to position the object
325 wxTransformMatrix lworld;
fcbb6b37 326
09cc749c
RR
327 //reference to another wxCanvasObject
328 wxCanvasObject* m_obj;
329};
5143c96b 330
09cc749c
RR
331//:defenition
332// wxCanvasRect
333class wxCanvasRect: public wxCanvasObject
5143c96b
KH
334{
335public:
09cc749c
RR
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(); };
5143c96b 339
09cc749c
RR
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();};
5143c96b 343
09cc749c
RR
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 );
5143c96b
KH
348 virtual void WriteSVG( wxTextOutputStream &stream );
349
350private:
5143c96b 351 wxPen m_pen;
09cc749c 352 wxBrush m_brush;
5143c96b 353
09cc749c
RR
354 double m_x;
355 double m_y;
356 double m_width;
357 double m_height;
358 double m_radius;
5143c96b
KH
359};
360
361//----------------------------------------------------------------------------
09cc749c 362// wxCanvasCircle
5143c96b 363//----------------------------------------------------------------------------
09cc749c 364class wxCanvasCircle: public wxCanvasObject
5143c96b
KH
365{
366public:
09cc749c
RR
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(); };
5143c96b 374
09cc749c 375 void TransLate( double x, double y );
5143c96b 376
09cc749c
RR
377 void CalcBoundingBox();
378
379 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
5143c96b
KH
380 virtual void WriteSVG( wxTextOutputStream &stream );
381
09cc749c 382 wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
5143c96b 383
09cc749c 384private:
5143c96b 385 wxPen m_pen;
09cc749c
RR
386 wxBrush m_brush;
387
388 double m_x;
389 double m_y;
390 double m_radius;
391};
5143c96b 392
09cc749c
RR
393//:defenition
394// wxCanvasEllipse
395class wxCanvasEllipse: public wxCanvasObject
396{
397public:
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(); };
5143c96b 401
09cc749c
RR
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();};
5143c96b 405
09cc749c 406 void TransLate( double x, double y );
5143c96b 407
09cc749c 408 void CalcBoundingBox();
5143c96b 409
09cc749c
RR
410 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
411 virtual void WriteSVG( wxTextOutputStream &stream );
5143c96b 412
09cc749c 413 wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
21544859 414
09cc749c
RR
415private:
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
427class wxCanvasEllipticArc: public wxCanvasObject
21544859
RR
428{
429public:
09cc749c
RR
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();};
dc16900b 437
09cc749c
RR
438 void TransLate( double x, double y );
439 void CalcBoundingBox();
dc16900b 440
09cc749c 441 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
21544859 442 virtual void WriteSVG( wxTextOutputStream &stream );
dc16900b 443
09cc749c
RR
444 wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
445
21544859 446private:
27d1065d
RR
447 wxPen m_pen;
448 wxBrush m_brush;
449
4dbd4ee6
RR
450 double m_x;
451 double m_y;
452 double m_width;
dc16900b 453 double m_height;
09cc749c
RR
454 double m_start;
455 double m_end;
21544859
RR
456};
457
09cc749c 458//:defenition
239c1f50 459// wxCanvasLine
239c1f50
RR
460class wxCanvasLine: public wxCanvasObject
461{
462public:
27d1065d 463 wxCanvasLine( double x1, double y1, double x2, double y2 );
09cc749c
RR
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();};
dc16900b 470
09cc749c 471 void TransLate( double x, double y );
dc16900b 472
09cc749c
RR
473 void CalcBoundingBox();
474
475 virtual void Render(wxTransformMatrix* cworld, int clip_x, int clip_y, int clip_width, int clip_height );
239c1f50 476 virtual void WriteSVG( wxTextOutputStream &stream );
09cc749c
RR
477
478 wxCanvasObject* IsHitWorld( double x, double y, double margin = 0 );
479
239c1f50 480private:
27d1065d
RR
481 wxPen m_pen;
482
4dbd4ee6
RR
483 double m_x1;
484 double m_y1;
485 double m_x2;
486 double m_y2;
239c1f50
RR
487};
488
09cc749c 489//:defenition
6a2c1874 490// wxCanvasImage
6a2c1874
RR
491class wxCanvasImage: public wxCanvasObject
492{
493public:
4dbd4ee6 494 wxCanvasImage( const wxImage &image, double x, double y, double w, double h );
09cc749c
RR
495
496 double GetPosX() { return m_x; }
497 double GetPosY() { return m_y; }
880d870e 498 void SetPosXY( double x, double y);
09cc749c
RR
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 );
6a2c1874 505 virtual void WriteSVG( wxTextOutputStream &stream );
09cc749c 506
6a2c1874 507private:
4dbd4ee6
RR
508 double m_x;
509 double m_y;
510 double m_width;
511 double m_height;
09cc749c 512
6a2c1874 513 wxImage m_image;
09cc749c 514 int m_orgw,m_orgh;
880d870e
RR
515
516 // cache
517 wxBitmap m_cBitmap;
518 wxImage m_cImage;
519 int m_cW;
520 int m_cH;
521 double m_cR;
6a2c1874
RR
522};
523
3b111dbe
RR
524//----------------------------------------------------------------------------
525// wxCanvasControl
526//----------------------------------------------------------------------------
527
528class wxCanvasControl: public wxCanvasObject
529{
530public:
531 wxCanvasControl( wxWindow *control );
532 ~wxCanvasControl();
09cc749c
RR
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
3b111dbe
RR
543private:
544 wxWindow *m_control;
545};
546
09cc749c 547//:defenition
d1f9b206 548// wxCanvasText
d1f9b206
RR
549class wxCanvasText: public wxCanvasObject
550{
551public:
4dbd4ee6 552 wxCanvasText( const wxString &text, double x, double y, const wxString &foneFile, int size );
d1f9b206 553 ~wxCanvasText();
dc16900b 554
09cc749c
RR
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(); };
dc16900b 558
09cc749c
RR
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 );
d1f9b206 564 virtual void WriteSVG( wxTextOutputStream &stream );
09cc749c 565
d1f9b206
RR
566 void SetRGB( unsigned char red, unsigned char green, unsigned char blue );
567 void SetFlag( int flag );
239c1f50 568 int GetFlag() { return m_flag; }
dc16900b 569
d1f9b206
RR
570private:
571 wxString m_text;
4dbd4ee6
RR
572 double m_x;
573 double m_y;
d1f9b206
RR
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;
cb281cfc
RR
580 wxString m_fontFileName;
581 int m_size;
d1f9b206
RR
582};
583
09cc749c
RR
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.
8636c073 596class wxCanvas: public wxScrolledWindow
6a2c1874
RR
597{
598public:
599 // constructors and destructors
09cc749c 600 wxCanvas( wxCanvasAdmin* admin ,wxWindow *parent, wxWindowID id = -1,
6a2c1874
RR
601 const wxPoint& pos = wxDefaultPosition,
602 const wxSize& size = wxDefaultSize,
603 long style = wxScrolledWindowStyle );
604 virtual ~wxCanvas();
dc16900b 605
09cc749c
RR
606 //background colour for the canvas
607 virtual void SetColour( const wxColour& background );
608
609 //update the area given in device coordinates
41328253 610 virtual void Update( int x, int y, int width, int height, bool blit = TRUE );
09cc749c
RR
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.
6a2c1874 615 virtual void UpdateNow();
dc16900b 616
09cc749c 617 //prevent canvas activety
239c1f50 618 virtual void Freeze();
09cc749c 619 //allow canvas activety
239c1f50 620 virtual void Thaw();
dc16900b 621
09cc749c 622 //get the buffer that is used for rendering in general
33ebcd80 623 inline wxBitmap *GetBuffer() { return &m_buffer; }
09cc749c
RR
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; }
09cc749c 628
41328253
RR
629 inline int GetBufferWidth() { return m_buffer.GetWidth(); }
630 inline int GetBufferHeight() { return m_buffer.GetHeight(); }
09cc749c
RR
631
632 //updating is needed for the canvas if the buffer did change
6a2c1874 633 bool NeedUpdate() { return m_needUpdate; }
1e1af41e 634 bool IsFrozen() { return m_frozen; }
dc16900b 635
09cc749c 636 //blit damaged areas in the buffer to the screen
3b111dbe 637 void BlitBuffer( wxDC &dc );
dc16900b 638
09cc749c 639 //redirect events to this canvas object
dc16900b 640 void SetCaptureMouse( wxCanvasObject *obj );
09cc749c
RR
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;}
dc16900b 649
8636c073
RR
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
673protected:
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
692private:
693 int m_bufferX,m_bufferY;
694
695protected:
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
704private:
705 DECLARE_CLASS(wxCanvas)
706 DECLARE_EVENT_TABLE()
707};
708
709
710
711class wxVectorCanvas: public wxCanvas
712{
713public:
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
09cc749c 720 //scroll the window in device coordinates
41328253
RR
721 virtual void ScrollWindow( int dx, int dy,
722 const wxRect* rect = (wxRect *) NULL );
dc16900b 723
09cc749c 724 //set if the Yaxis goes up or down
8636c073 725 void SetYaxis(bool up) { m_yaxis=up; }
09cc749c
RR
726
727 //get currently used Yaxis setting
8636c073 728 virtual bool GetYaxis() { return m_yaxis; }
09cc749c
RR
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
8636c073
RR
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;
09cc749c
RR
767
768protected:
8636c073 769 // up or down
09cc749c
RR
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
6a2c1874 790private:
8636c073 791 void OnScroll(wxScrollWinEvent& event);
6a2c1874 792 void OnChar( wxKeyEvent &event );
6a2c1874 793 void OnSize( wxSizeEvent &event );
6a2c1874
RR
794
795private:
8636c073 796 DECLARE_CLASS(wxVectorCanvas)
6a2c1874
RR
797 DECLARE_EVENT_TABLE()
798};
799
800
8636c073 801
09cc749c
RR
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.
808class wxCanvasAdmin
809{
810public:
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
852private:
853 wxList m_canvaslist;
854 wxCanvas* m_active;
855};
856
6a2c1874
RR
857#endif
858 // WXCANVAS
859