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