]> git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/canvas/canvas.h
d3a416e60e92efebdff184dd06346e255de4dbe1
[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 class wxCanvas;
24
25 // WDR: class declarations
26
27 //----------------------------------------------------------------------------
28 // wxCanvasObject
29 //----------------------------------------------------------------------------
30
31 class wxCanvasObject: public wxEvtHandler
32 {
33 public:
34 wxCanvasObject();
35
36 // Area occupied by object. Used for clipping, intersection,
37 // mouse enter etc. Screen coordinates
38 void SetArea( int x, int y, int width, int height );
39 void SetArea( wxRect rect );
40
41 // These are for screen output only therefore use
42 // int as coordinates.
43 virtual bool IsHit( int x, int y, int margin = 0 );
44 virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
45
46 // use doubles later
47 virtual void Move( int x, int y );
48
49 // Once we have world coordinates in doubles, this will get
50 // called for every object if the world coordinate system
51 // changes (zooming).
52 virtual void Recreate();
53
54 // Later...
55 virtual void WriteSVG( wxTextOutputStream &stream );
56
57 wxCanvas *GetOwner() { return m_owner; }
58 virtual void SetOwner( wxCanvas *owner ) { m_owner = owner; }
59
60 bool IsControl() { return m_isControl; }
61 bool IsVector() { return m_isVector; }
62 bool IsImage() { return m_isImage; }
63 inline int GetX() { return m_area.x; }
64 inline int GetY() { return m_area.y; }
65 inline int GetWidth() { return m_area.width; }
66 inline int GetHeight() { return m_area.height; }
67
68 void CaptureMouse();
69 void ReleaseMouse();
70 bool IsCapturedMouse();
71
72 protected:
73 wxCanvas *m_owner;
74 bool m_isControl;
75 bool m_isVector;
76 bool m_isImage;
77
78 //relative boundingbox in parent in pixels
79 wxRect m_area;
80
81 friend class wxCanvas;
82 };
83
84 //----------------------------------------------------------------------------
85 // wxCanvasObjectGroup
86 //----------------------------------------------------------------------------
87
88 class wxCanvasObjectGroup
89 {
90 public:
91 wxCanvasObjectGroup();
92 virtual ~wxCanvasObjectGroup();
93
94 void SetOwner(wxCanvas* canvas);
95 wxCanvas *GetOwner() { return m_owner; }
96
97 virtual void Prepend( wxCanvasObject* obj );
98 virtual void Append( wxCanvasObject* obj );
99 virtual void Insert( size_t before, wxCanvasObject* obj );
100 virtual void Remove( wxCanvasObject* obj );
101
102 virtual void Recreate();
103 void DeleteContents( bool );
104 virtual void Render(int xabs, int yabs,int x, int y, int width, int height );
105 virtual void WriteSVG( wxTextOutputStream &stream );
106 virtual bool IsHit( int x, int y, int margin );
107 virtual wxCanvasObject* IsHitObject( int x, int y, int margin );
108
109 void ExtendArea(int x, int y);
110
111 inline int GetXMin() { return m_minx; }
112 inline int GetYMin() { return m_miny; }
113 inline int GetXMax() { return m_maxx; }
114 inline int GetYMax() { return m_maxy; }
115
116 protected:
117 wxCanvas *m_owner;
118
119 //bounding box
120 double m_minx;
121 double m_miny;
122 double m_maxx;
123 double m_maxy;
124 bool m_validbounds;
125
126 wxList m_objects;
127
128 friend class wxCanvas;
129 };
130
131 //----------------------------------------------------------------------------
132 // wxCanvasObjectGroupRef
133 //----------------------------------------------------------------------------
134
135 class wxCanvasObjectGroupRef: public wxCanvasObject
136 {
137 public:
138 wxCanvasObjectGroupRef(double x, double y,wxCanvasObjectGroup* group);
139
140 void SetOwner(wxCanvas* canvas);
141
142 virtual void Recreate();
143 virtual void Render(int xabs, int yabs,int x, int y, int width, int height );
144 virtual void WriteSVG( wxTextOutputStream &stream );
145 virtual bool IsHit( int x, int y, int margin );
146 void Move( int x, int y );
147
148 inline int GetPosX() { return m_x; }
149 inline int GetPosY() { return m_y; }
150
151 void ExtendArea(int x, int y);
152 virtual wxCanvasObject* IsHitObject( int x, int y, int margin );
153
154 protected:
155 //position of the group
156 double m_x;
157 double m_y;
158
159 //reference to the group
160 wxCanvasObjectGroup* m_group;
161
162 //bounding box
163 double m_minx;
164 double m_miny;
165 double m_maxx;
166 double m_maxy;
167 bool m_validbounds;
168
169 };
170
171 //----------------------------------------------------------------------------
172 // wxCanvasRect
173 //----------------------------------------------------------------------------
174
175 class wxCanvasRect: public wxCanvasObject
176 {
177 public:
178 wxCanvasRect( double x, double y, double w, double h,
179 unsigned char red, unsigned char green, unsigned char blue );
180
181 virtual void Recreate();
182
183 virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
184 virtual void WriteSVG( wxTextOutputStream &stream );
185
186 private:
187 double m_x;
188 double m_y;
189 double m_width;
190 double m_height;
191
192 unsigned char m_red;
193 unsigned char m_green;
194 unsigned char m_blue;
195 };
196
197 //----------------------------------------------------------------------------
198 // wxCanvasLine
199 //----------------------------------------------------------------------------
200
201 class wxCanvasLine: public wxCanvasObject
202 {
203 public:
204 wxCanvasLine( double x1, double y1, double x2, double y2,
205 unsigned char red, unsigned char green, unsigned char blue );
206
207 virtual void Recreate();
208
209 virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
210 virtual void WriteSVG( wxTextOutputStream &stream );
211
212 private:
213 double m_x1;
214 double m_y1;
215 double m_x2;
216 double m_y2;
217
218 unsigned char m_red;
219 unsigned char m_green;
220 unsigned char m_blue;
221 };
222
223 //----------------------------------------------------------------------------
224 // wxCanvasImage
225 //----------------------------------------------------------------------------
226
227 class wxCanvasImage: public wxCanvasObject
228 {
229 public:
230 wxCanvasImage( const wxImage &image, double x, double y, double w, double h );
231
232 virtual void Recreate();
233
234 virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
235 virtual void WriteSVG( wxTextOutputStream &stream );
236
237 private:
238 double m_x;
239 double m_y;
240 double m_width;
241 double m_height;
242
243 wxImage m_image;
244 wxImage m_tmp;
245 };
246
247 //----------------------------------------------------------------------------
248 // wxCanvasControl
249 //----------------------------------------------------------------------------
250
251 class wxCanvasControl: public wxCanvasObject
252 {
253 public:
254 wxCanvasControl( wxWindow *control );
255 ~wxCanvasControl();
256
257 virtual void Recreate();
258
259 virtual void Move( int x, int y );
260
261 private:
262 wxWindow *m_control;
263 };
264
265 //----------------------------------------------------------------------------
266 // wxCanvasText
267 //----------------------------------------------------------------------------
268
269 class wxCanvasText: public wxCanvasObject
270 {
271 public:
272 wxCanvasText( const wxString &text, double x, double y, const wxString &foneFile, int size );
273 ~wxCanvasText();
274
275 void Recreate();
276
277 virtual void Render(int xabs, int yabs, int clip_x, int clip_y, int clip_width, int clip_height );
278 virtual void WriteSVG( wxTextOutputStream &stream );
279
280 void SetRGB( unsigned char red, unsigned char green, unsigned char blue );
281 void SetFlag( int flag );
282 int GetFlag() { return m_flag; }
283
284 private:
285 wxString m_text;
286 double m_x;
287 double m_y;
288 unsigned char *m_alpha;
289 void *m_faceData;
290 int m_flag;
291 int m_red;
292 int m_green;
293 int m_blue;
294 wxString m_fontFileName;
295 int m_size;
296 };
297
298 //----------------------------------------------------------------------------
299 // wxCanvas
300 //----------------------------------------------------------------------------
301
302 class wxCanvas: public wxScrolledWindow
303 {
304 public:
305 // constructors and destructors
306 wxCanvas( wxWindow *parent, wxWindowID id = -1,
307 const wxPoint& pos = wxDefaultPosition,
308 const wxSize& size = wxDefaultSize,
309 long style = wxScrolledWindowStyle );
310 virtual ~wxCanvas();
311
312 virtual void SetArea( int width, int height );
313 virtual void SetColour( unsigned char red, unsigned char green, unsigned char blue );
314 virtual void Update( int x, int y, int width, int height, bool blit = TRUE );
315 virtual void UpdateNow();
316
317 virtual void Freeze();
318 virtual void Thaw();
319
320 virtual void Prepend( wxCanvasObject* obj );
321 virtual void Append( wxCanvasObject* obj );
322 virtual void Insert( size_t before, wxCanvasObject* obj );
323 virtual void Remove( wxCanvasObject* obj );
324
325 // override these to change your coordiate system ...
326 virtual int GetDeviceX( double x );
327 virtual int GetDeviceY( double y );
328 virtual int GetDeviceWidth( double width );
329 virtual int GetDeviceHeight( double height );
330
331 // ... and call this to tell all objets to recreate then
332 virtual void Recreate();
333
334 inline wxImage *GetBuffer() { return &m_buffer; }
335 inline int GetBufferX() { return m_bufferX; }
336 inline int GetBufferY() { return m_bufferY; }
337 inline int GetBufferWidth() { return m_buffer.GetWidth(); }
338 inline int GetBufferHeight() { return m_buffer.GetHeight(); }
339
340 bool NeedUpdate() { return m_needUpdate; }
341 bool IsFrozen() { return m_frozen; }
342
343 void BlitBuffer( wxDC &dc );
344
345 void SetCaptureMouse( wxCanvasObject *obj );
346
347 virtual void ScrollWindow( int dx, int dy,
348 const wxRect* rect = (wxRect *) NULL );
349
350 private:
351 wxImage m_buffer;
352 int m_bufferX;
353 int m_bufferY;
354 bool m_needUpdate;
355 wxList m_updateRects;
356 wxCanvasObjectGroup* m_root;
357
358 unsigned char m_green,m_red,m_blue;
359 bool m_frozen;
360 bool m_requestNewBuffer;
361 wxCanvasObject *m_lastMouse;
362 wxCanvasObject *m_captureMouse;
363
364 friend class wxCanvasObject;
365
366 private:
367 void OnChar( wxKeyEvent &event );
368 void OnPaint( wxPaintEvent &event );
369 void OnMouse( wxMouseEvent &event );
370 void OnSize( wxSizeEvent &event );
371 void OnIdle( wxIdleEvent &event );
372 void OnSetFocus( wxFocusEvent &event );
373 void OnKillFocus( wxFocusEvent &event );
374 void OnEraseBackground( wxEraseEvent &event );
375
376 private:
377 DECLARE_CLASS(wxCanvas)
378 DECLARE_EVENT_TABLE()
379 };
380
381
382 #endif
383 // WXCANVAS
384