]>
git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/canvas/canvas.h
3c12ffa07960f7b8c82a8e42692cec0e3259dc38
1 /////////////////////////////////////////////////////////////////////////////
3 // Author: Robert Roebling
5 // Copyright: 2000 (c) Robert Roebling
6 // Licence: wxWindows Licence
7 /////////////////////////////////////////////////////////////////////////////
10 #define __WXCANVAS_H__
13 #pragma interface "canvas.cpp"
21 #include "wx/txtstrm.h"
22 #include "wx/geometry.h"
25 //----------------------------------------------------------------------------
27 //----------------------------------------------------------------------------
29 #define IMAGE_CANVAS 0
33 //----------------------------------------------------------------------------
35 //----------------------------------------------------------------------------
37 class wxCanvasObject
: public wxEvtHandler
42 // Area occupied by object. Used for clipping, intersection,
43 // mouse enter etc. Screen coordinates
44 void SetArea( int x
, int y
, int width
, int height
);
45 void SetArea( wxRect rect
);
47 // These are for screen output only therefore use
48 // int as coordinates.
49 virtual bool IsHit( int x
, int y
, int margin
= 0 );
50 virtual void Render(int xabs
, int yabs
, int clip_x
, int clip_y
, int clip_width
, int clip_height
);
53 virtual void Move( int x
, int y
);
55 // Once we have world coordinates in doubles, this will get
56 // called for every object if the world coordinate system
58 virtual void Recreate();
61 virtual void WriteSVG( wxTextOutputStream
&stream
);
63 wxCanvas
*GetOwner() { return m_owner
; }
64 virtual void SetOwner( wxCanvas
*owner
) { m_owner
= owner
; }
66 bool IsControl() { return m_isControl
; }
67 bool IsVector() { return m_isVector
; }
68 bool IsImage() { return m_isImage
; }
69 inline int GetX() { return m_area
.x
; }
70 inline int GetY() { return m_area
.y
; }
71 inline int GetWidth() { return m_area
.width
; }
72 inline int GetHeight() { return m_area
.height
; }
76 bool IsCapturedMouse();
84 //relative boundingbox in parent in pixels
87 friend class wxCanvas
;
90 //----------------------------------------------------------------------------
91 // wxCanvasObjectGroup
92 //----------------------------------------------------------------------------
94 class wxCanvasObjectGroup
97 wxCanvasObjectGroup();
98 virtual ~wxCanvasObjectGroup();
100 void SetOwner(wxCanvas
* canvas
);
101 wxCanvas
*GetOwner() { return m_owner
; }
103 virtual void Prepend( wxCanvasObject
* obj
);
104 virtual void Append( wxCanvasObject
* obj
);
105 virtual void Insert( size_t before
, wxCanvasObject
* obj
);
106 virtual void Remove( wxCanvasObject
* obj
);
108 virtual void Recreate();
109 void DeleteContents( bool );
110 virtual void Render(int xabs
, int yabs
,int x
, int y
, int width
, int height
);
111 virtual void WriteSVG( wxTextOutputStream
&stream
);
112 virtual bool IsHit( int x
, int y
, int margin
);
113 virtual wxCanvasObject
* IsHitObject( int x
, int y
, int margin
);
115 void ExtendArea(double x
, double y
);
117 inline int GetXMin() { return m_minx
; }
118 inline int GetYMin() { return m_miny
; }
119 inline int GetXMax() { return m_maxx
; }
120 inline int GetYMax() { return m_maxy
; }
134 friend class wxCanvas
;
137 //----------------------------------------------------------------------------
138 // wxCanvasObjectGroupRef
139 //----------------------------------------------------------------------------
141 class wxCanvasObjectGroupRef
: public wxCanvasObject
144 wxCanvasObjectGroupRef(double x
, double y
,wxCanvasObjectGroup
* group
);
146 void SetOwner(wxCanvas
* canvas
);
148 virtual void Recreate();
149 virtual void Render(int xabs
, int yabs
,int x
, int y
, int width
, int height
);
150 virtual void WriteSVG( wxTextOutputStream
&stream
);
151 virtual bool IsHit( int x
, int y
, int margin
);
152 void Move( int x
, int y
);
154 inline int GetPosX() { return m_x
; }
155 inline int GetPosY() { return m_y
; }
157 void ExtendArea(double x
, double y
);
158 virtual wxCanvasObject
* IsHitObject( int x
, int y
, int margin
);
161 //position of the group
165 //reference to the group
166 wxCanvasObjectGroup
* m_group
;
177 //----------------------------------------------------------------------------
179 //----------------------------------------------------------------------------
181 class wxCanvasPolygon
: public wxCanvasObject
184 wxCanvasPolygon(int n
, wxPoint2DDouble points
[]);
186 SetBrush(wxBrush
& brush
){m_brush
= brush
;};
187 SetPen(wxPen
& pen
){m_pen
= pen
;};
189 virtual void Recreate();
191 virtual void Render(int xabs
, int yabs
, int clip_x
, int clip_y
, int clip_width
, int clip_height
);
192 virtual void WriteSVG( wxTextOutputStream
&stream
);
195 void ExtendArea(double x
, double y
);
201 wxPoint2DDouble
* m_points
;
212 //----------------------------------------------------------------------------
214 //----------------------------------------------------------------------------
216 class wxCanvasPolyline
: public wxCanvasObject
219 wxCanvasPolyline(int n
, wxPoint2DDouble points
[]);
221 SetPen(wxPen
& pen
){m_pen
= pen
;};
223 virtual void Recreate();
225 virtual void Render(int xabs
, int yabs
, int clip_x
, int clip_y
, int clip_width
, int clip_height
);
226 virtual void WriteSVG( wxTextOutputStream
&stream
);
229 void ExtendArea(double x
, double y
);
234 wxPoint2DDouble
* m_points
;
247 //----------------------------------------------------------------------------
249 //----------------------------------------------------------------------------
251 class wxCanvasRect
: public wxCanvasObject
254 wxCanvasRect( double x
, double y
, double w
, double h
,
255 unsigned char red
, unsigned char green
, unsigned char blue
);
257 virtual void Recreate();
259 virtual void Render(int xabs
, int yabs
, int clip_x
, int clip_y
, int clip_width
, int clip_height
);
260 virtual void WriteSVG( wxTextOutputStream
&stream
);
269 unsigned char m_green
;
270 unsigned char m_blue
;
273 //----------------------------------------------------------------------------
275 //----------------------------------------------------------------------------
277 class wxCanvasLine
: public wxCanvasObject
280 wxCanvasLine( double x1
, double y1
, double x2
, double y2
,
281 unsigned char red
, unsigned char green
, unsigned char blue
);
283 virtual void Recreate();
285 virtual void Render(int xabs
, int yabs
, int clip_x
, int clip_y
, int clip_width
, int clip_height
);
286 virtual void WriteSVG( wxTextOutputStream
&stream
);
295 unsigned char m_green
;
296 unsigned char m_blue
;
299 //----------------------------------------------------------------------------
301 //----------------------------------------------------------------------------
303 class wxCanvasImage
: public wxCanvasObject
306 wxCanvasImage( const wxImage
&image
, double x
, double y
, double w
, double h
);
308 virtual void Recreate();
310 virtual void Render(int xabs
, int yabs
, int clip_x
, int clip_y
, int clip_width
, int clip_height
);
311 virtual void WriteSVG( wxTextOutputStream
&stream
);
327 //----------------------------------------------------------------------------
329 //----------------------------------------------------------------------------
331 class wxCanvasControl
: public wxCanvasObject
334 wxCanvasControl( wxWindow
*control
);
337 virtual void Recreate();
339 virtual void Move( int x
, int y
);
345 //----------------------------------------------------------------------------
347 //----------------------------------------------------------------------------
349 class wxCanvasText
: public wxCanvasObject
352 wxCanvasText( const wxString
&text
, double x
, double y
, const wxString
&foneFile
, int size
);
357 virtual void Render(int xabs
, int yabs
, int clip_x
, int clip_y
, int clip_width
, int clip_height
);
358 virtual void WriteSVG( wxTextOutputStream
&stream
);
360 void SetRGB( unsigned char red
, unsigned char green
, unsigned char blue
);
361 void SetFlag( int flag
);
362 int GetFlag() { return m_flag
; }
368 unsigned char *m_alpha
;
374 wxString m_fontFileName
;
378 //----------------------------------------------------------------------------
380 //----------------------------------------------------------------------------
382 class wxCanvas
: public wxScrolledWindow
385 // constructors and destructors
386 wxCanvas( wxWindow
*parent
, wxWindowID id
= -1,
387 const wxPoint
& pos
= wxDefaultPosition
,
388 const wxSize
& size
= wxDefaultSize
,
389 long style
= wxScrolledWindowStyle
);
392 virtual void SetArea( int width
, int height
);
393 virtual void SetColour( unsigned char red
, unsigned char green
, unsigned char blue
);
394 virtual void Update( int x
, int y
, int width
, int height
, bool blit
= TRUE
);
395 virtual void UpdateNow();
397 virtual void Freeze();
400 virtual void Prepend( wxCanvasObject
* obj
);
401 virtual void Append( wxCanvasObject
* obj
);
402 virtual void Insert( size_t before
, wxCanvasObject
* obj
);
403 virtual void Remove( wxCanvasObject
* obj
);
405 // override these to change your coordiate system ...
406 virtual int GetDeviceX( double x
);
407 virtual int GetDeviceY( double y
);
408 virtual int GetDeviceWidth( double width
);
409 virtual int GetDeviceHeight( double height
);
411 // ... and call this to tell all objets to recreate then
412 virtual void Recreate();
415 inline wxImage
*GetBuffer() { return &m_buffer
; }
417 inline wxBitmap
*GetBuffer() { return &m_buffer
; }
418 inline wxMemoryDC
*GetDC() { return m_renderDC
; }
420 inline int GetBufferX() { return m_bufferX
; }
421 inline int GetBufferY() { return m_bufferY
; }
422 inline int GetBufferWidth() { return m_buffer
.GetWidth(); }
423 inline int GetBufferHeight() { return m_buffer
.GetHeight(); }
425 bool NeedUpdate() { return m_needUpdate
; }
426 bool IsFrozen() { return m_frozen
; }
428 void BlitBuffer( wxDC
&dc
);
430 void SetCaptureMouse( wxCanvasObject
*obj
);
432 virtual void ScrollWindow( int dx
, int dy
,
433 const wxRect
* rect
= (wxRect
*) NULL
);
440 wxMemoryDC
*m_renderDC
;
445 wxList m_updateRects
;
446 wxCanvasObjectGroup
* m_root
;
448 unsigned char m_green
,m_red
,m_blue
;
450 wxCanvasObject
*m_lastMouse
;
451 wxCanvasObject
*m_captureMouse
;
453 friend class wxCanvasObject
;
456 void OnChar( wxKeyEvent
&event
);
457 void OnPaint( wxPaintEvent
&event
);
458 void OnMouse( wxMouseEvent
&event
);
459 void OnSize( wxSizeEvent
&event
);
460 void OnIdle( wxIdleEvent
&event
);
461 void OnSetFocus( wxFocusEvent
&event
);
462 void OnKillFocus( wxFocusEvent
&event
);
463 void OnEraseBackground( wxEraseEvent
&event
);
466 DECLARE_CLASS(wxCanvas
)
467 DECLARE_EVENT_TABLE()