]>
git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/canvas/canvas.h
eb435e6cd9f520cc706bda633160e67e81bd4db3
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"
23 //----------------------------------------------------------------------------
25 //----------------------------------------------------------------------------
27 #define IMAGE_CANVAS 0
31 //----------------------------------------------------------------------------
33 //----------------------------------------------------------------------------
35 class wxCanvasObject
: public wxEvtHandler
40 // Area occupied by object. Used for clipping, intersection,
41 // mouse enter etc. Screen coordinates
42 void SetArea( int x
, int y
, int width
, int height
);
43 void SetArea( wxRect rect
);
45 // These are for screen output only therefore use
46 // int as coordinates.
47 virtual bool IsHit( int x
, int y
, int margin
= 0 );
48 virtual void Render(int xabs
, int yabs
, int clip_x
, int clip_y
, int clip_width
, int clip_height
);
51 virtual void Move( int x
, int y
);
53 // Once we have world coordinates in doubles, this will get
54 // called for every object if the world coordinate system
56 virtual void Recreate();
59 virtual void WriteSVG( wxTextOutputStream
&stream
);
61 wxCanvas
*GetOwner() { return m_owner
; }
62 virtual void SetOwner( wxCanvas
*owner
) { m_owner
= owner
; }
64 bool IsControl() { return m_isControl
; }
65 bool IsVector() { return m_isVector
; }
66 bool IsImage() { return m_isImage
; }
67 inline int GetX() { return m_area
.x
; }
68 inline int GetY() { return m_area
.y
; }
69 inline int GetWidth() { return m_area
.width
; }
70 inline int GetHeight() { return m_area
.height
; }
74 bool IsCapturedMouse();
82 //relative boundingbox in parent in pixels
85 friend class wxCanvas
;
88 //----------------------------------------------------------------------------
89 // wxCanvasObjectGroup
90 //----------------------------------------------------------------------------
92 class wxCanvasObjectGroup
95 wxCanvasObjectGroup();
96 virtual ~wxCanvasObjectGroup();
98 void SetOwner(wxCanvas
* canvas
);
99 wxCanvas
*GetOwner() { return m_owner
; }
101 virtual void Prepend( wxCanvasObject
* obj
);
102 virtual void Append( wxCanvasObject
* obj
);
103 virtual void Insert( size_t before
, wxCanvasObject
* obj
);
104 virtual void Remove( wxCanvasObject
* obj
);
106 virtual void Recreate();
107 void DeleteContents( bool );
108 virtual void Render(int xabs
, int yabs
,int x
, int y
, int width
, int height
);
109 virtual void WriteSVG( wxTextOutputStream
&stream
);
110 virtual bool IsHit( int x
, int y
, int margin
);
111 virtual wxCanvasObject
* IsHitObject( int x
, int y
, int margin
);
113 void ExtendArea(int x
, int y
);
115 inline int GetXMin() { return m_minx
; }
116 inline int GetYMin() { return m_miny
; }
117 inline int GetXMax() { return m_maxx
; }
118 inline int GetYMax() { return m_maxy
; }
132 friend class wxCanvas
;
135 //----------------------------------------------------------------------------
136 // wxCanvasObjectGroupRef
137 //----------------------------------------------------------------------------
139 class wxCanvasObjectGroupRef
: public wxCanvasObject
142 wxCanvasObjectGroupRef(double x
, double y
,wxCanvasObjectGroup
* group
);
144 void SetOwner(wxCanvas
* canvas
);
146 virtual void Recreate();
147 virtual void Render(int xabs
, int yabs
,int x
, int y
, int width
, int height
);
148 virtual void WriteSVG( wxTextOutputStream
&stream
);
149 virtual bool IsHit( int x
, int y
, int margin
);
150 void Move( int x
, int y
);
152 inline int GetPosX() { return m_x
; }
153 inline int GetPosY() { return m_y
; }
155 void ExtendArea(int x
, int y
);
156 virtual wxCanvasObject
* IsHitObject( int x
, int y
, int margin
);
159 //position of the group
163 //reference to the group
164 wxCanvasObjectGroup
* m_group
;
175 //----------------------------------------------------------------------------
177 //----------------------------------------------------------------------------
179 class wxCanvasRect
: public wxCanvasObject
182 wxCanvasRect( double x
, double y
, double w
, double h
,
183 unsigned char red
, unsigned char green
, unsigned char blue
);
185 virtual void Recreate();
187 virtual void Render(int xabs
, int yabs
, int clip_x
, int clip_y
, int clip_width
, int clip_height
);
188 virtual void WriteSVG( wxTextOutputStream
&stream
);
197 unsigned char m_green
;
198 unsigned char m_blue
;
201 //----------------------------------------------------------------------------
203 //----------------------------------------------------------------------------
205 class wxCanvasLine
: public wxCanvasObject
208 wxCanvasLine( double x1
, double y1
, double x2
, double y2
,
209 unsigned char red
, unsigned char green
, unsigned char blue
);
211 virtual void Recreate();
213 virtual void Render(int xabs
, int yabs
, int clip_x
, int clip_y
, int clip_width
, int clip_height
);
214 virtual void WriteSVG( wxTextOutputStream
&stream
);
223 unsigned char m_green
;
224 unsigned char m_blue
;
227 //----------------------------------------------------------------------------
229 //----------------------------------------------------------------------------
231 class wxCanvasImage
: public wxCanvasObject
234 wxCanvasImage( const wxImage
&image
, double x
, double y
, double w
, double h
);
236 virtual void Recreate();
238 virtual void Render(int xabs
, int yabs
, int clip_x
, int clip_y
, int clip_width
, int clip_height
);
239 virtual void WriteSVG( wxTextOutputStream
&stream
);
255 //----------------------------------------------------------------------------
257 //----------------------------------------------------------------------------
259 class wxCanvasControl
: public wxCanvasObject
262 wxCanvasControl( wxWindow
*control
);
265 virtual void Recreate();
267 virtual void Move( int x
, int y
);
273 //----------------------------------------------------------------------------
275 //----------------------------------------------------------------------------
277 class wxCanvasText
: public wxCanvasObject
280 wxCanvasText( const wxString
&text
, double x
, double y
, const wxString
&foneFile
, int size
);
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
);
288 void SetRGB( unsigned char red
, unsigned char green
, unsigned char blue
);
289 void SetFlag( int flag
);
290 int GetFlag() { return m_flag
; }
296 unsigned char *m_alpha
;
302 wxString m_fontFileName
;
306 //----------------------------------------------------------------------------
308 //----------------------------------------------------------------------------
310 class wxCanvas
: public wxScrolledWindow
313 // constructors and destructors
314 wxCanvas( wxWindow
*parent
, wxWindowID id
= -1,
315 const wxPoint
& pos
= wxDefaultPosition
,
316 const wxSize
& size
= wxDefaultSize
,
317 long style
= wxScrolledWindowStyle
);
320 virtual void SetArea( int width
, int height
);
321 virtual void SetColour( unsigned char red
, unsigned char green
, unsigned char blue
);
322 virtual void Update( int x
, int y
, int width
, int height
, bool blit
= TRUE
);
323 virtual void UpdateNow();
325 virtual void Freeze();
328 virtual void Prepend( wxCanvasObject
* obj
);
329 virtual void Append( wxCanvasObject
* obj
);
330 virtual void Insert( size_t before
, wxCanvasObject
* obj
);
331 virtual void Remove( wxCanvasObject
* obj
);
333 // override these to change your coordiate system ...
334 virtual int GetDeviceX( double x
);
335 virtual int GetDeviceY( double y
);
336 virtual int GetDeviceWidth( double width
);
337 virtual int GetDeviceHeight( double height
);
339 // ... and call this to tell all objets to recreate then
340 virtual void Recreate();
343 inline wxImage
*GetBuffer() { return &m_buffer
; }
345 inline wxBitmap
*GetBuffer() { return &m_buffer
; }
346 inline wxMemoryDC
*GetDC() { return m_renderDC
; }
348 inline int GetBufferX() { return m_bufferX
; }
349 inline int GetBufferY() { return m_bufferY
; }
350 inline int GetBufferWidth() { return m_buffer
.GetWidth(); }
351 inline int GetBufferHeight() { return m_buffer
.GetHeight(); }
353 bool NeedUpdate() { return m_needUpdate
; }
354 bool IsFrozen() { return m_frozen
; }
356 void BlitBuffer( wxDC
&dc
);
358 void SetCaptureMouse( wxCanvasObject
*obj
);
360 virtual void ScrollWindow( int dx
, int dy
,
361 const wxRect
* rect
= (wxRect
*) NULL
);
368 wxMemoryDC
*m_renderDC
;
373 wxList m_updateRects
;
374 wxCanvasObjectGroup
* m_root
;
376 unsigned char m_green
,m_red
,m_blue
;
378 wxCanvasObject
*m_lastMouse
;
379 wxCanvasObject
*m_captureMouse
;
381 friend class wxCanvasObject
;
384 void OnChar( wxKeyEvent
&event
);
385 void OnPaint( wxPaintEvent
&event
);
386 void OnMouse( wxMouseEvent
&event
);
387 void OnSize( wxSizeEvent
&event
);
388 void OnIdle( wxIdleEvent
&event
);
389 void OnSetFocus( wxFocusEvent
&event
);
390 void OnKillFocus( wxFocusEvent
&event
);
391 void OnEraseBackground( wxEraseEvent
&event
);
394 DECLARE_CLASS(wxCanvas
)
395 DECLARE_EVENT_TABLE()