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