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