]>
git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/canvas/canvas.h
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 double GetXMin() { return m_minx
; }
118 inline double GetYMin() { return m_miny
; }
119 inline double GetXMax() { return m_maxx
; }
120 inline double 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 double GetPosX() { return m_x
; }
155 inline double 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 void SetBrush(wxBrush
& brush
) { m_brush
= brush
; };
187 void 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 void 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 void SetBrush(wxBrush
& brush
) { m_brush
= brush
; };
256 void SetPen(wxPen
& pen
) { m_pen
= pen
; };
258 virtual void Recreate();
260 virtual void Render(int xabs
, int yabs
, int clip_x
, int clip_y
, int clip_width
, int clip_height
);
261 virtual void WriteSVG( wxTextOutputStream
&stream
);
273 //----------------------------------------------------------------------------
275 //----------------------------------------------------------------------------
277 class wxCanvasLine
: public wxCanvasObject
280 wxCanvasLine( double x1
, double y1
, double x2
, double y2
);
281 void SetPen(wxPen
& pen
) { m_pen
= pen
; };
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
);
297 //----------------------------------------------------------------------------
299 //----------------------------------------------------------------------------
301 class wxCanvasImage
: public wxCanvasObject
304 wxCanvasImage( const wxImage
&image
, double x
, double y
, double w
, double h
);
306 virtual void Recreate();
308 virtual void Render(int xabs
, int yabs
, int clip_x
, int clip_y
, int clip_width
, int clip_height
);
309 virtual void WriteSVG( wxTextOutputStream
&stream
);
325 //----------------------------------------------------------------------------
327 //----------------------------------------------------------------------------
329 class wxCanvasControl
: public wxCanvasObject
332 wxCanvasControl( wxWindow
*control
);
335 virtual void Recreate();
337 virtual void Move( int x
, int y
);
343 //----------------------------------------------------------------------------
345 //----------------------------------------------------------------------------
347 class wxCanvasText
: public wxCanvasObject
350 wxCanvasText( const wxString
&text
, double x
, double y
, const wxString
&foneFile
, int size
);
355 virtual void Render(int xabs
, int yabs
, int clip_x
, int clip_y
, int clip_width
, int clip_height
);
356 virtual void WriteSVG( wxTextOutputStream
&stream
);
358 void SetRGB( unsigned char red
, unsigned char green
, unsigned char blue
);
359 void SetFlag( int flag
);
360 int GetFlag() { return m_flag
; }
366 unsigned char *m_alpha
;
372 wxString m_fontFileName
;
376 //----------------------------------------------------------------------------
378 //----------------------------------------------------------------------------
380 class wxCanvas
: public wxScrolledWindow
383 // constructors and destructors
384 wxCanvas( wxWindow
*parent
, wxWindowID id
= -1,
385 const wxPoint
& pos
= wxDefaultPosition
,
386 const wxSize
& size
= wxDefaultSize
,
387 long style
= wxScrolledWindowStyle
);
390 virtual void SetArea( int width
, int height
);
391 virtual void SetColour( unsigned char red
, unsigned char green
, unsigned char blue
);
392 virtual void Update( int x
, int y
, int width
, int height
, bool blit
= TRUE
);
393 virtual void UpdateNow();
395 virtual void Freeze();
398 virtual void Prepend( wxCanvasObject
* obj
);
399 virtual void Append( wxCanvasObject
* obj
);
400 virtual void Insert( size_t before
, wxCanvasObject
* obj
);
401 virtual void Remove( wxCanvasObject
* obj
);
403 // override these to change your coordiate system ...
404 virtual int GetDeviceX( double x
);
405 virtual int GetDeviceY( double y
);
406 virtual int GetDeviceWidth( double width
);
407 virtual int GetDeviceHeight( double height
);
409 // ... and call this to tell all objets to recreate then
410 virtual void Recreate();
413 inline wxImage
*GetBuffer() { return &m_buffer
; }
415 inline wxBitmap
*GetBuffer() { return &m_buffer
; }
416 inline wxMemoryDC
*GetDC() { return m_renderDC
; }
418 inline int GetBufferX() { return m_bufferX
; }
419 inline int GetBufferY() { return m_bufferY
; }
420 inline int GetBufferWidth() { return m_buffer
.GetWidth(); }
421 inline int GetBufferHeight() { return m_buffer
.GetHeight(); }
423 bool NeedUpdate() { return m_needUpdate
; }
424 bool IsFrozen() { return m_frozen
; }
426 void BlitBuffer( wxDC
&dc
);
428 void SetCaptureMouse( wxCanvasObject
*obj
);
430 virtual void ScrollWindow( int dx
, int dy
,
431 const wxRect
* rect
= (wxRect
*) NULL
);
438 wxMemoryDC
*m_renderDC
;
443 wxList m_updateRects
;
444 wxCanvasObjectGroup
* m_root
;
446 unsigned char m_green
,m_red
,m_blue
;
448 wxCanvasObject
*m_lastMouse
;
449 wxCanvasObject
*m_captureMouse
;
451 int m_oldDeviceX
,m_oldDeviceY
;
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()