]> git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/canvas/canvas.h
eb435e6cd9f520cc706bda633160e67e81bd4db3
[wxWidgets.git] / contrib / include / wx / canvas / canvas.h
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"
22
23 //----------------------------------------------------------------------------
24 // decls
25 //----------------------------------------------------------------------------
26
27 #define IMAGE_CANVAS 0
28
29 class wxCanvas;
30
31 //----------------------------------------------------------------------------
32 // wxCanvasObject
33 //----------------------------------------------------------------------------
34
35 class wxCanvasObject: public wxEvtHandler
36 {
37 public:
38 wxCanvasObject();
39
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 );
44
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 );
49
50 // use doubles later
51 virtual void Move( int x, int y );
52
53 // Once we have world coordinates in doubles, this will get
54 // called for every object if the world coordinate system
55 // changes (zooming).
56 virtual void Recreate();
57
58 // Later...
59 virtual void WriteSVG( wxTextOutputStream &stream );
60
61 wxCanvas *GetOwner() { return m_owner; }
62 virtual void SetOwner( wxCanvas *owner ) { m_owner = owner; }
63
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; }
71
72 void CaptureMouse();
73 void ReleaseMouse();
74 bool IsCapturedMouse();
75
76 protected:
77 wxCanvas *m_owner;
78 bool m_isControl;
79 bool m_isVector;
80 bool m_isImage;
81
82 //relative boundingbox in parent in pixels
83 wxRect m_area;
84
85 friend class wxCanvas;
86 };
87
88 //----------------------------------------------------------------------------
89 // wxCanvasObjectGroup
90 //----------------------------------------------------------------------------
91
92 class wxCanvasObjectGroup
93 {
94 public:
95 wxCanvasObjectGroup();
96 virtual ~wxCanvasObjectGroup();
97
98 void SetOwner(wxCanvas* canvas);
99 wxCanvas *GetOwner() { return m_owner; }
100
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 );
105
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 );
112
113 void ExtendArea(int x, int y);
114
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; }
119
120 protected:
121 wxCanvas *m_owner;
122
123 //bounding box
124 double m_minx;
125 double m_miny;
126 double m_maxx;
127 double m_maxy;
128 bool m_validbounds;
129
130 wxList m_objects;
131
132 friend class wxCanvas;
133 };
134
135 //----------------------------------------------------------------------------
136 // wxCanvasObjectGroupRef
137 //----------------------------------------------------------------------------
138
139 class wxCanvasObjectGroupRef: public wxCanvasObject
140 {
141 public:
142 wxCanvasObjectGroupRef(double x, double y,wxCanvasObjectGroup* group);
143
144 void SetOwner(wxCanvas* canvas);
145
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 );
151
152 inline int GetPosX() { return m_x; }
153 inline int GetPosY() { return m_y; }
154
155 void ExtendArea(int x, int y);
156 virtual wxCanvasObject* IsHitObject( int x, int y, int margin );
157
158 protected:
159 //position of the group
160 double m_x;
161 double m_y;
162
163 //reference to the group
164 wxCanvasObjectGroup* m_group;
165
166 //bounding box
167 double m_minx;
168 double m_miny;
169 double m_maxx;
170 double m_maxy;
171 bool m_validbounds;
172
173 };
174
175 //----------------------------------------------------------------------------
176 // wxCanvasRect
177 //----------------------------------------------------------------------------
178
179 class wxCanvasRect: public wxCanvasObject
180 {
181 public:
182 wxCanvasRect( double x, double y, double w, double h,
183 unsigned char red, unsigned char green, unsigned char blue );
184
185 virtual void Recreate();
186
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 );
189
190 private:
191 double m_x;
192 double m_y;
193 double m_width;
194 double m_height;
195
196 unsigned char m_red;
197 unsigned char m_green;
198 unsigned char m_blue;
199 };
200
201 //----------------------------------------------------------------------------
202 // wxCanvasLine
203 //----------------------------------------------------------------------------
204
205 class wxCanvasLine: public wxCanvasObject
206 {
207 public:
208 wxCanvasLine( double x1, double y1, double x2, double y2,
209 unsigned char red, unsigned char green, unsigned char blue );
210
211 virtual void Recreate();
212
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 );
215
216 private:
217 double m_x1;
218 double m_y1;
219 double m_x2;
220 double m_y2;
221
222 unsigned char m_red;
223 unsigned char m_green;
224 unsigned char m_blue;
225 };
226
227 //----------------------------------------------------------------------------
228 // wxCanvasImage
229 //----------------------------------------------------------------------------
230
231 class wxCanvasImage: public wxCanvasObject
232 {
233 public:
234 wxCanvasImage( const wxImage &image, double x, double y, double w, double h );
235
236 virtual void Recreate();
237
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 );
240
241 private:
242 double m_x;
243 double m_y;
244 double m_width;
245 double m_height;
246
247 wxImage m_image;
248 #if IMAGE_CANVAS
249 wxImage m_tmp;
250 #else
251 wxBitmap m_tmp;
252 #endif
253 };
254
255 //----------------------------------------------------------------------------
256 // wxCanvasControl
257 //----------------------------------------------------------------------------
258
259 class wxCanvasControl: public wxCanvasObject
260 {
261 public:
262 wxCanvasControl( wxWindow *control );
263 ~wxCanvasControl();
264
265 virtual void Recreate();
266
267 virtual void Move( int x, int y );
268
269 private:
270 wxWindow *m_control;
271 };
272
273 //----------------------------------------------------------------------------
274 // wxCanvasText
275 //----------------------------------------------------------------------------
276
277 class wxCanvasText: public wxCanvasObject
278 {
279 public:
280 wxCanvasText( const wxString &text, double x, double y, const wxString &foneFile, int size );
281 ~wxCanvasText();
282
283 void Recreate();
284
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 );
287
288 void SetRGB( unsigned char red, unsigned char green, unsigned char blue );
289 void SetFlag( int flag );
290 int GetFlag() { return m_flag; }
291
292 private:
293 wxString m_text;
294 double m_x;
295 double m_y;
296 unsigned char *m_alpha;
297 void *m_faceData;
298 int m_flag;
299 int m_red;
300 int m_green;
301 int m_blue;
302 wxString m_fontFileName;
303 int m_size;
304 };
305
306 //----------------------------------------------------------------------------
307 // wxCanvas
308 //----------------------------------------------------------------------------
309
310 class wxCanvas: public wxScrolledWindow
311 {
312 public:
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 );
318 virtual ~wxCanvas();
319
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();
324
325 virtual void Freeze();
326 virtual void Thaw();
327
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 );
332
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 );
338
339 // ... and call this to tell all objets to recreate then
340 virtual void Recreate();
341
342 #if IMAGE_CANVAS
343 inline wxImage *GetBuffer() { return &m_buffer; }
344 #else
345 inline wxBitmap *GetBuffer() { return &m_buffer; }
346 inline wxMemoryDC *GetDC() { return m_renderDC; }
347 #endif
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(); }
352
353 bool NeedUpdate() { return m_needUpdate; }
354 bool IsFrozen() { return m_frozen; }
355
356 void BlitBuffer( wxDC &dc );
357
358 void SetCaptureMouse( wxCanvasObject *obj );
359
360 virtual void ScrollWindow( int dx, int dy,
361 const wxRect* rect = (wxRect *) NULL );
362
363 private:
364 #if IMAGE_CANVAS
365 wxImage m_buffer;
366 #else
367 wxBitmap m_buffer;
368 wxMemoryDC *m_renderDC;
369 #endif
370 int m_bufferX;
371 int m_bufferY;
372 bool m_needUpdate;
373 wxList m_updateRects;
374 wxCanvasObjectGroup* m_root;
375
376 unsigned char m_green,m_red,m_blue;
377 bool m_frozen;
378 wxCanvasObject *m_lastMouse;
379 wxCanvasObject *m_captureMouse;
380
381 friend class wxCanvasObject;
382
383 private:
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 );
392
393 private:
394 DECLARE_CLASS(wxCanvas)
395 DECLARE_EVENT_TABLE()
396 };
397
398
399 #endif
400 // WXCANVAS
401