]> git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/canvas/canvas.h
b82b3da636573726b8759343fb47472de8b55080
[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( int x, int y, int width, int height );
35
36 // These are for screen output only therefore use
37 // int as coordinates.
38 virtual void Move( int x, int y );
39 virtual bool IsHit( int x, int y, int margin = 0 );
40 virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height );
41
42 // Once we have world coordinates in doubles, this will get
43 // called for every object if the world coordinate system
44 // changes (zooming).
45 virtual void Rerender();
46
47 // Later...
48 virtual void WriteSVG( wxTextOutputStream &stream );
49
50 wxCanvas *GetOwner() { return m_owner; }
51 void SetOwner( wxCanvas *owner ) { m_owner = owner; }
52
53 bool IsControl() { return m_isControl; }
54 bool IsVector() { return m_isVector; }
55 bool IsImage() { return m_isImage; }
56 inline int GetX() { return m_area.x; }
57 inline int GetY() { return m_area.y; }
58 inline int GetWidth() { return m_area.width; }
59 inline int GetHeight() { return m_area.height; }
60
61 protected:
62 wxCanvas *m_owner;
63 bool m_isControl;
64 bool m_isVector;
65 bool m_isImage;
66 wxRect m_area;
67
68 friend class wxCanvas;
69 };
70
71 //----------------------------------------------------------------------------
72 // wxCanvasRect
73 //----------------------------------------------------------------------------
74
75 class wxCanvasRect: public wxCanvasObject
76 {
77 public:
78 wxCanvasRect( int x, int y, int w, int h, unsigned char red, unsigned char green, unsigned char blue );
79
80 virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height );
81 virtual void WriteSVG( wxTextOutputStream &stream );
82
83 private:
84 unsigned char m_red;
85 unsigned char m_green;
86 unsigned char m_blue;
87 };
88
89 //----------------------------------------------------------------------------
90 // wxCanvasLine
91 //----------------------------------------------------------------------------
92
93 class wxCanvasLine: public wxCanvasObject
94 {
95 public:
96 wxCanvasLine( int x, int y, int w, int h, unsigned char red, unsigned char green, unsigned char blue );
97
98 virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height );
99 virtual void WriteSVG( wxTextOutputStream &stream );
100
101 private:
102 unsigned char m_red;
103 unsigned char m_green;
104 unsigned char m_blue;
105 };
106
107 //----------------------------------------------------------------------------
108 // wxCanvasImage
109 //----------------------------------------------------------------------------
110
111 class wxCanvasImage: public wxCanvasObject
112 {
113 public:
114 wxCanvasImage( const wxImage &image, int x, int y );
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 wxImage m_image;
121 };
122
123 //----------------------------------------------------------------------------
124 // wxCanvasControl
125 //----------------------------------------------------------------------------
126
127 class wxCanvasControl: public wxCanvasObject
128 {
129 public:
130 wxCanvasControl( wxWindow *control );
131 ~wxCanvasControl();
132
133 virtual void Move( int x, int y );
134 void UpdateSize();
135
136 private:
137 wxWindow *m_control;
138 };
139
140 //----------------------------------------------------------------------------
141 // wxCanvasText
142 //----------------------------------------------------------------------------
143
144 class wxCanvasText: public wxCanvasObject
145 {
146 public:
147 wxCanvasText( const wxString &text, int x, int y, const wxString &foneFile, int size );
148 ~wxCanvasText();
149
150 virtual void Render( int clip_x, int clip_y, int clip_width, int clip_height );
151 virtual void WriteSVG( wxTextOutputStream &stream );
152
153 void CreateBuffer();
154 void SetRGB( unsigned char red, unsigned char green, unsigned char blue );
155 void SetFlag( int flag );
156 int GetFlag() { return m_flag; }
157
158 private:
159 wxString m_text;
160 unsigned char *m_alpha;
161 void *m_faceData;
162 int m_flag;
163 int m_red;
164 int m_green;
165 int m_blue;
166 wxString m_fontFileName;
167 int m_size;
168 };
169
170 //----------------------------------------------------------------------------
171 // wxCanvas
172 //----------------------------------------------------------------------------
173
174 class wxCanvas: public wxScrolledWindow
175 {
176 public:
177 // constructors and destructors
178 wxCanvas( wxWindow *parent, wxWindowID id = -1,
179 const wxPoint& pos = wxDefaultPosition,
180 const wxSize& size = wxDefaultSize,
181 long style = wxScrolledWindowStyle );
182 virtual ~wxCanvas();
183
184 virtual void SetArea( int width, int height );
185 virtual void SetColour( unsigned char red, unsigned char green, unsigned char blue );
186 virtual void Update( int x, int y, int width, int height );
187 virtual void UpdateNow();
188
189 virtual void Freeze();
190 virtual void Thaw();
191
192 virtual void Prepend( wxCanvasObject* obj );
193 virtual void Append( wxCanvasObject* obj );
194 virtual void Insert( size_t before, wxCanvasObject* obj );
195 virtual void Remove( wxCanvasObject* obj );
196
197 wxImage *GetBuffer() { return &m_buffer; }
198 bool NeedUpdate() { return m_needUpdate; }
199 bool IsFrozen() { return m_frozen; }
200
201 void BlitBuffer( wxDC &dc );
202
203 private:
204 wxImage m_buffer;
205 bool m_needUpdate;
206 wxList m_updateRects;
207 wxList m_objects;
208 unsigned char m_green,m_red,m_blue;
209 bool m_frozen;
210 wxCanvasObject *m_lastMouse;
211
212 friend class wxCanvasObject;
213
214 private:
215 void OnChar( wxKeyEvent &event );
216 void OnPaint( wxPaintEvent &event );
217 void OnMouse( wxMouseEvent &event );
218 void OnSize( wxSizeEvent &event );
219 void OnIdle( wxIdleEvent &event );
220 void OnSetFocus( wxFocusEvent &event );
221 void OnKillFocus( wxFocusEvent &event );
222
223 private:
224 DECLARE_CLASS(wxCanvas)
225 DECLARE_EVENT_TABLE()
226 };
227
228
229 #endif
230 // WXCANVAS
231