]>
Commit | Line | Data |
---|---|---|
6a2c1874 RR |
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: | |
4dbd4ee6 RR |
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 ); | |
6a2c1874 | 40 | |
1e1af41e RR |
41 | // These are for screen output only therefore use |
42 | // int as coordinates. | |
239c1f50 | 43 | virtual bool IsHit( int x, int y, int margin = 0 ); |
6a2c1874 | 44 | virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height ); |
1e1af41e | 45 | |
4dbd4ee6 RR |
46 | // use doubles later |
47 | virtual void Move( int x, int y ); | |
48 | ||
1e1af41e RR |
49 | // Once we have world coordinates in doubles, this will get |
50 | // called for every object if the world coordinate system | |
51 | // changes (zooming). | |
4dbd4ee6 | 52 | virtual void Recreate(); |
1e1af41e RR |
53 | |
54 | // Later... | |
6a2c1874 RR |
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 | ||
21544859 RR |
78 | //---------------------------------------------------------------------------- |
79 | // wxCanvasRect | |
80 | //---------------------------------------------------------------------------- | |
81 | ||
82 | class wxCanvasRect: public wxCanvasObject | |
83 | { | |
84 | public: | |
4dbd4ee6 RR |
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(); | |
21544859 RR |
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: | |
4dbd4ee6 RR |
94 | double m_x; |
95 | double m_y; | |
96 | double m_width; | |
97 | double m_height; | |
98 | ||
21544859 RR |
99 | unsigned char m_red; |
100 | unsigned char m_green; | |
101 | unsigned char m_blue; | |
102 | }; | |
103 | ||
239c1f50 RR |
104 | //---------------------------------------------------------------------------- |
105 | // wxCanvasLine | |
106 | //---------------------------------------------------------------------------- | |
107 | ||
108 | class wxCanvasLine: public wxCanvasObject | |
109 | { | |
110 | public: | |
4dbd4ee6 RR |
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(); | |
239c1f50 RR |
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: | |
4dbd4ee6 RR |
120 | double m_x1; |
121 | double m_y1; | |
122 | double m_x2; | |
123 | double m_y2; | |
124 | ||
239c1f50 RR |
125 | unsigned char m_red; |
126 | unsigned char m_green; | |
127 | unsigned char m_blue; | |
128 | }; | |
129 | ||
6a2c1874 RR |
130 | //---------------------------------------------------------------------------- |
131 | // wxCanvasImage | |
132 | //---------------------------------------------------------------------------- | |
133 | ||
134 | class wxCanvasImage: public wxCanvasObject | |
135 | { | |
136 | public: | |
4dbd4ee6 RR |
137 | wxCanvasImage( const wxImage &image, double x, double y, double w, double h ); |
138 | ||
139 | virtual void Recreate(); | |
6a2c1874 RR |
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: | |
4dbd4ee6 RR |
145 | double m_x; |
146 | double m_y; | |
147 | double m_width; | |
148 | double m_height; | |
149 | ||
6a2c1874 | 150 | wxImage m_image; |
4dbd4ee6 | 151 | wxImage m_tmp; |
6a2c1874 RR |
152 | }; |
153 | ||
3b111dbe RR |
154 | //---------------------------------------------------------------------------- |
155 | // wxCanvasControl | |
156 | //---------------------------------------------------------------------------- | |
157 | ||
158 | class wxCanvasControl: public wxCanvasObject | |
159 | { | |
160 | public: | |
161 | wxCanvasControl( wxWindow *control ); | |
162 | ~wxCanvasControl(); | |
163 | ||
4dbd4ee6 RR |
164 | virtual void Recreate(); |
165 | ||
3b111dbe | 166 | virtual void Move( int x, int y ); |
3b111dbe RR |
167 | |
168 | private: | |
169 | wxWindow *m_control; | |
170 | }; | |
171 | ||
d1f9b206 RR |
172 | //---------------------------------------------------------------------------- |
173 | // wxCanvasText | |
174 | //---------------------------------------------------------------------------- | |
175 | ||
176 | class wxCanvasText: public wxCanvasObject | |
177 | { | |
178 | public: | |
4dbd4ee6 | 179 | wxCanvasText( const wxString &text, double x, double y, const wxString &foneFile, int size ); |
d1f9b206 RR |
180 | ~wxCanvasText(); |
181 | ||
4dbd4ee6 RR |
182 | void Recreate(); |
183 | ||
d1f9b206 RR |
184 | virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height ); |
185 | virtual void WriteSVG( wxTextOutputStream &stream ); | |
186 | ||
d1f9b206 RR |
187 | void SetRGB( unsigned char red, unsigned char green, unsigned char blue ); |
188 | void SetFlag( int flag ); | |
239c1f50 | 189 | int GetFlag() { return m_flag; } |
d1f9b206 RR |
190 | |
191 | private: | |
192 | wxString m_text; | |
4dbd4ee6 RR |
193 | double m_x; |
194 | double m_y; | |
d1f9b206 RR |
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; | |
cb281cfc RR |
201 | wxString m_fontFileName; |
202 | int m_size; | |
d1f9b206 RR |
203 | }; |
204 | ||
6a2c1874 RR |
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 ); | |
cb281cfc | 220 | virtual void SetColour( unsigned char red, unsigned char green, unsigned char blue ); |
6a2c1874 RR |
221 | virtual void Update( int x, int y, int width, int height ); |
222 | virtual void UpdateNow(); | |
223 | ||
239c1f50 RR |
224 | virtual void Freeze(); |
225 | virtual void Thaw(); | |
226 | ||
6a2c1874 RR |
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 | ||
4dbd4ee6 RR |
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 | ||
6a2c1874 RR |
244 | wxImage *GetBuffer() { return &m_buffer; } |
245 | bool NeedUpdate() { return m_needUpdate; } | |
1e1af41e | 246 | bool IsFrozen() { return m_frozen; } |
6a2c1874 | 247 | |
3b111dbe RR |
248 | void BlitBuffer( wxDC &dc ); |
249 | ||
6a2c1874 | 250 | private: |
239c1f50 RR |
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; | |
4dbd4ee6 | 258 | wxCanvasObject *m_captureMouse; |
239c1f50 | 259 | |
6a2c1874 RR |
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 |