]> git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/canvas/canvas.h
Dialogs can now show a question mark for context-sensitive help.
[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 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 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 wxRect m_area;
78
79 friend class wxCanvas;
80 };
81
82 //----------------------------------------------------------------------------
83 // wxCanvasRect
84 //----------------------------------------------------------------------------
85
86 class wxCanvasRect: public wxCanvasObject
87 {
88 public:
89 wxCanvasRect( double x, double y, double w, double h,
90 unsigned char red, unsigned char green, unsigned char blue );
91
92 virtual void Recreate();
93
94 virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height );
95 virtual void WriteSVG( wxTextOutputStream &stream );
96
97 private:
98 double m_x;
99 double m_y;
100 double m_width;
101 double m_height;
102
103 unsigned char m_red;
104 unsigned char m_green;
105 unsigned char m_blue;
106 };
107
108 //----------------------------------------------------------------------------
109 // wxCanvasLine
110 //----------------------------------------------------------------------------
111
112 class wxCanvasLine: public wxCanvasObject
113 {
114 public:
115 wxCanvasLine( double x1, double y1, double x2, double y2,
116 unsigned char red, unsigned char green, unsigned char blue );
117
118 virtual void Recreate();
119
120 virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height );
121 virtual void WriteSVG( wxTextOutputStream &stream );
122
123 private:
124 double m_x1;
125 double m_y1;
126 double m_x2;
127 double m_y2;
128
129 unsigned char m_red;
130 unsigned char m_green;
131 unsigned char m_blue;
132 };
133
134 //----------------------------------------------------------------------------
135 // wxCanvasImage
136 //----------------------------------------------------------------------------
137
138 class wxCanvasImage: public wxCanvasObject
139 {
140 public:
141 wxCanvasImage( const wxImage &image, double x, double y, double w, double h );
142
143 virtual void Recreate();
144
145 virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height );
146 virtual void WriteSVG( wxTextOutputStream &stream );
147
148 private:
149 double m_x;
150 double m_y;
151 double m_width;
152 double m_height;
153
154 wxImage m_image;
155 wxImage m_tmp;
156 };
157
158 //----------------------------------------------------------------------------
159 // wxCanvasControl
160 //----------------------------------------------------------------------------
161
162 class wxCanvasControl: public wxCanvasObject
163 {
164 public:
165 wxCanvasControl( wxWindow *control );
166 ~wxCanvasControl();
167
168 virtual void Recreate();
169
170 virtual void Move( int x, int y );
171
172 private:
173 wxWindow *m_control;
174 };
175
176 //----------------------------------------------------------------------------
177 // wxCanvasText
178 //----------------------------------------------------------------------------
179
180 class wxCanvasText: public wxCanvasObject
181 {
182 public:
183 wxCanvasText( const wxString &text, double x, double y, const wxString &foneFile, int size );
184 ~wxCanvasText();
185
186 void Recreate();
187
188 virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height );
189 virtual void WriteSVG( wxTextOutputStream &stream );
190
191 void SetRGB( unsigned char red, unsigned char green, unsigned char blue );
192 void SetFlag( int flag );
193 int GetFlag() { return m_flag; }
194
195 private:
196 wxString m_text;
197 double m_x;
198 double m_y;
199 unsigned char *m_alpha;
200 void *m_faceData;
201 int m_flag;
202 int m_red;
203 int m_green;
204 int m_blue;
205 wxString m_fontFileName;
206 int m_size;
207 };
208
209 //----------------------------------------------------------------------------
210 // wxCanvas
211 //----------------------------------------------------------------------------
212
213 class wxCanvas: public wxScrolledWindow
214 {
215 public:
216 // constructors and destructors
217 wxCanvas( wxWindow *parent, wxWindowID id = -1,
218 const wxPoint& pos = wxDefaultPosition,
219 const wxSize& size = wxDefaultSize,
220 long style = wxScrolledWindowStyle );
221 virtual ~wxCanvas();
222
223 virtual void SetArea( int width, int height );
224 virtual void SetColour( unsigned char red, unsigned char green, unsigned char blue );
225 virtual void Update( int x, int y, int width, int height, bool blit = TRUE );
226 virtual void UpdateNow();
227
228 virtual void Freeze();
229 virtual void Thaw();
230
231 virtual void Prepend( wxCanvasObject* obj );
232 virtual void Append( wxCanvasObject* obj );
233 virtual void Insert( size_t before, wxCanvasObject* obj );
234 virtual void Remove( wxCanvasObject* obj );
235
236 // override these to change your coordiate system ...
237 virtual int GetDeviceX( double x );
238 virtual int GetDeviceY( double y );
239 virtual int GetDeviceWidth( double width );
240 virtual int GetDeviceHeight( double height );
241
242 // ... and call this to tell all objets to recreate then
243 virtual void Recreate();
244
245 inline wxImage *GetBuffer() { return &m_buffer; }
246 inline int GetBufferX() { return m_bufferX; }
247 inline int GetBufferY() { return m_bufferY; }
248 inline int GetBufferWidth() { return m_buffer.GetWidth(); }
249 inline int GetBufferHeight() { return m_buffer.GetHeight(); }
250
251 bool NeedUpdate() { return m_needUpdate; }
252 bool IsFrozen() { return m_frozen; }
253
254 void BlitBuffer( wxDC &dc );
255
256 void SetCaptureMouse( wxCanvasObject *obj );
257
258 virtual void ScrollWindow( int dx, int dy,
259 const wxRect* rect = (wxRect *) NULL );
260
261 private:
262 wxImage m_buffer;
263 int m_bufferX;
264 int m_bufferY;
265 bool m_needUpdate;
266 wxList m_updateRects;
267 wxList m_objects;
268 unsigned char m_green,m_red,m_blue;
269 bool m_frozen;
270 bool m_requestNewBuffer;
271 wxCanvasObject *m_lastMouse;
272 wxCanvasObject *m_captureMouse;
273
274 friend class wxCanvasObject;
275
276 private:
277 void OnChar( wxKeyEvent &event );
278 void OnPaint( wxPaintEvent &event );
279 void OnMouse( wxMouseEvent &event );
280 void OnSize( wxSizeEvent &event );
281 void OnIdle( wxIdleEvent &event );
282 void OnSetFocus( wxFocusEvent &event );
283 void OnKillFocus( wxFocusEvent &event );
284
285 private:
286 DECLARE_CLASS(wxCanvas)
287 DECLARE_EVENT_TABLE()
288 };
289
290
291 #endif
292 // WXCANVAS
293