]>
Commit | Line | Data |
---|---|---|
cdf3a589 CE |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: svgtest.cpp | |
3 | // Purpose: SVG sample | |
4 | // Author: Chris Elliott | |
5 | // Modified by: | |
526954c5 | 6 | // Licence: wxWindows licence |
cdf3a589 CE |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
9 | // =========================================================================== | |
10 | // declarations | |
11 | // =========================================================================== | |
12 | ||
13 | // --------------------------------------------------------------------------- | |
14 | // headers | |
15 | // --------------------------------------------------------------------------- | |
16 | ||
17 | // For compilers that support precompilation, includes "wx/wx.h". | |
18 | #include "wx/wxprec.h" | |
19 | ||
20 | #ifdef __BORLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | #ifndef WX_PRECOMP | |
25 | #include "wx/wx.h" | |
26 | #include "wx/mdi.h" | |
27 | #endif | |
28 | ||
ae0fbcee | 29 | #include "wx/toolbar.h" |
18cea871 | 30 | #include "wx/dcsvg.h" |
49e3b82c | 31 | #include "wx/vector.h" |
cdf3a589 CE |
32 | |
33 | #include "bitmaps/new.xpm" | |
34 | #include "bitmaps/save.xpm" | |
35 | #include "bitmaps/help.xpm" | |
36 | #include "SVGlogo24.xpm" | |
a5e6cfa8 | 37 | |
e7092398 | 38 | #ifndef wxHAS_IMAGES_IN_RESOURCES |
3cb332c1 VZ |
39 | #include "../sample.xpm" |
40 | #endif | |
41 | ||
66815259 VZ |
42 | #include <math.h> |
43 | ||
cdf3a589 | 44 | class MyChild; |
49e3b82c FM |
45 | class MyCanvas; |
46 | ||
47 | // --------------------------------------------------------------------------- | |
48 | // classes | |
49 | // --------------------------------------------------------------------------- | |
cdf3a589 | 50 | |
cdf3a589 CE |
51 | class MyApp : public wxApp |
52 | { | |
49e3b82c FM |
53 | public: |
54 | bool OnInit(); | |
cdf3a589 CE |
55 | }; |
56 | ||
cdf3a589 CE |
57 | class MyFrame : public wxMDIParentFrame |
58 | { | |
49e3b82c FM |
59 | public: |
60 | MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, | |
cdf3a589 CE |
61 | const wxPoint& pos, const wxSize& size, const long style); |
62 | ||
49e3b82c FM |
63 | void InitToolBar(wxToolBar* toolBar); |
64 | ||
65 | void OnSize(wxSizeEvent& event); | |
66 | void OnAbout(wxCommandEvent& event); | |
67 | void OnNewWindow(wxCommandEvent& event); | |
68 | void OnQuit(wxCommandEvent& event); | |
69 | void FileSavePicture (wxCommandEvent& event); | |
ce00f59b | 70 | |
49e3b82c FM |
71 | unsigned int GetCountOfChildren() const |
72 | { return m_nWinCreated; } | |
73 | ||
74 | private: | |
75 | unsigned int m_nWinCreated; | |
ce00f59b | 76 | |
49e3b82c | 77 | DECLARE_EVENT_TABLE() |
cdf3a589 CE |
78 | }; |
79 | ||
49e3b82c | 80 | class MyChild: public wxMDIChildFrame |
cdf3a589 | 81 | { |
49e3b82c | 82 | public: |
ce00f59b VZ |
83 | MyChild(wxMDIParentFrame *parent, const wxString& title, |
84 | const wxPoint& pos = wxDefaultPosition, | |
85 | const wxSize& size = wxDefaultSize, | |
49e3b82c FM |
86 | const long style = wxDEFAULT_FRAME_STYLE); |
87 | ~MyChild(); | |
88 | ||
89 | void OnActivate(wxActivateEvent& event); | |
90 | void OnQuit(wxCommandEvent& event); | |
91 | bool OnSave(wxString filename); | |
ce00f59b | 92 | |
49e3b82c FM |
93 | MyFrame* GetFrame() |
94 | { return m_frame; } | |
95 | ||
96 | private: | |
97 | MyCanvas *m_canvas; | |
98 | MyFrame *m_frame; | |
99 | ||
100 | DECLARE_EVENT_TABLE() | |
cdf3a589 CE |
101 | }; |
102 | ||
49e3b82c | 103 | class MyCanvas : public wxScrolledWindow |
cdf3a589 | 104 | { |
49e3b82c FM |
105 | public: |
106 | MyCanvas(MyChild *parent, const wxPoint& pos, const wxSize& size); | |
107 | virtual void OnDraw(wxDC& dc); | |
108 | ||
109 | private: | |
110 | int m_index; | |
111 | MyChild* m_child; | |
ce00f59b | 112 | |
49e3b82c | 113 | DECLARE_EVENT_TABLE() |
cdf3a589 CE |
114 | }; |
115 | ||
49e3b82c FM |
116 | // --------------------------------------------------------------------------- |
117 | // constants | |
118 | // --------------------------------------------------------------------------- | |
119 | ||
cdf3a589 CE |
120 | // menu items ids |
121 | enum | |
122 | { | |
123 | MDI_QUIT = 100, | |
124 | MDI_NEW_WINDOW, | |
125 | MDI_SAVE, | |
126 | MDI_REFRESH, | |
127 | MDI_CHILD_QUIT, | |
128 | MDI_ABOUT | |
129 | }; | |
130 | ||
cdf3a589 CE |
131 | // --------------------------------------------------------------------------- |
132 | // event tables | |
133 | // --------------------------------------------------------------------------- | |
134 | ||
135 | BEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame) | |
49e3b82c FM |
136 | EVT_MENU(MDI_ABOUT, MyFrame::OnAbout) |
137 | EVT_MENU(MDI_NEW_WINDOW, MyFrame::OnNewWindow) | |
138 | EVT_MENU(MDI_QUIT, MyFrame::OnQuit) | |
139 | EVT_MENU (MDI_SAVE, MyFrame::FileSavePicture) | |
cdf3a589 | 140 | |
49e3b82c | 141 | EVT_SIZE(MyFrame::OnSize) |
cdf3a589 CE |
142 | END_EVENT_TABLE() |
143 | ||
144 | // =========================================================================== | |
145 | // implementation | |
146 | // =========================================================================== | |
147 | ||
148 | // --------------------------------------------------------------------------- | |
149 | // MyApp | |
150 | // --------------------------------------------------------------------------- | |
151 | ||
49e3b82c FM |
152 | IMPLEMENT_APP(MyApp) |
153 | ||
cdf3a589 CE |
154 | bool MyApp::OnInit() |
155 | { | |
156 | // Create the main frame window | |
157 | ||
49e3b82c FM |
158 | MyFrame* frame = new MyFrame((wxFrame *)NULL, -1, wxT("SVG Demo"), |
159 | wxDefaultPosition, wxSize(500, 400), | |
160 | wxDEFAULT_FRAME_STYLE | wxHSCROLL | wxVSCROLL); | |
cdf3a589 | 161 | |
d96cdd4a | 162 | frame->Show(true); |
cdf3a589 | 163 | |
c54e5eb0 | 164 | return true; |
cdf3a589 CE |
165 | } |
166 | ||
167 | ||
168 | // --------------------------------------------------------------------------- | |
169 | // MyFrame | |
170 | // --------------------------------------------------------------------------- | |
171 | ||
172 | // Define my frame constructor | |
173 | MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, | |
49e3b82c | 174 | const wxPoint& pos, const wxSize& size, const long style) |
cdf3a589 CE |
175 | : wxMDIParentFrame(parent, id, title, pos, size, style) |
176 | { | |
49e3b82c | 177 | m_nWinCreated = 0; |
cdf3a589 | 178 | |
3cb332c1 | 179 | SetIcon(wxICON(sample)); |
cdf3a589 | 180 | |
49e3b82c FM |
181 | // Make a menubar |
182 | wxMenu *file_menu = new wxMenu; | |
cdf3a589 | 183 | |
49e3b82c FM |
184 | file_menu->Append(MDI_NEW_WINDOW, wxT("&New test\tCtrl+N")); |
185 | file_menu->Append(MDI_QUIT, wxT("&Exit\tAlt+X")); | |
cdf3a589 | 186 | |
49e3b82c FM |
187 | wxMenu *help_menu = new wxMenu; |
188 | help_menu->Append(MDI_ABOUT, wxT("&About")); | |
cdf3a589 | 189 | |
49e3b82c | 190 | wxMenuBar *menu_bar = new wxMenuBar; |
cdf3a589 | 191 | |
49e3b82c FM |
192 | menu_bar->Append(file_menu, wxT("&File")); |
193 | menu_bar->Append(help_menu, wxT("&Help")); | |
194 | ||
195 | // Associate the menu bar with the frame | |
196 | SetMenuBar(menu_bar); | |
197 | ||
198 | #if wxUSE_STATUSBAR | |
199 | CreateStatusBar(); | |
200 | #endif // wxUSE_STATUSBAR | |
201 | ||
202 | CreateToolBar(wxNO_BORDER | wxTB_FLAT | wxTB_HORIZONTAL); | |
203 | InitToolBar(GetToolBar()); | |
204 | } | |
cdf3a589 CE |
205 | |
206 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
207 | { | |
208 | Close(); | |
209 | } | |
210 | ||
cdf3a589 CE |
211 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) |
212 | { | |
49e3b82c FM |
213 | (void)wxMessageBox(wxT("wxWidgets SVG sample\n") |
214 | wxT("Author: Chris Elliott (c) 2002-2009\n") | |
ce00f59b | 215 | wxT("Usage: click File|New to show tests"), |
49e3b82c | 216 | wxT("About SVG Test")); |
cdf3a589 CE |
217 | } |
218 | ||
cdf3a589 CE |
219 | void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) ) |
220 | { | |
221 | // Make another frame, containing a canvas | |
49e3b82c | 222 | MyChild *subframe = new MyChild(this, wxT("SVG Frame")); |
cdf3a589 | 223 | |
cdf3a589 | 224 | wxString title; |
49e3b82c | 225 | title.Printf(wxT("SVG Test Window %d"), m_nWinCreated ); |
ce00f59b | 226 | |
cdf3a589 | 227 | // counts number of children previously, even if now closed |
49e3b82c | 228 | m_nWinCreated ++; |
cdf3a589 CE |
229 | |
230 | // Give it a title and icon | |
231 | subframe->SetTitle(title); | |
3cb332c1 | 232 | subframe->SetIcon(wxICON(sample)); |
cdf3a589 CE |
233 | |
234 | // Make a menubar | |
235 | wxMenu *file_menu = new wxMenu; | |
236 | ||
237 | file_menu->Append(MDI_NEW_WINDOW, wxT("&Another test\tCtrl+N")); | |
238 | file_menu->Append(MDI_SAVE, wxT("&Save\tCtrl+S"), wxT("Save in SVG format")); | |
239 | file_menu->Append(MDI_CHILD_QUIT, wxT("&Close child\tCtrl+F4")); | |
240 | file_menu->Append(MDI_QUIT, wxT("&Exit\tAlt+X")); | |
241 | ||
242 | wxMenu *help_menu = new wxMenu; | |
243 | help_menu->Append(MDI_ABOUT, wxT("&About")); | |
244 | ||
245 | wxMenuBar *menu_bar = new wxMenuBar; | |
246 | ||
247 | menu_bar->Append(file_menu, wxT("&File")); | |
248 | menu_bar->Append(help_menu, wxT("&Help")); | |
249 | ||
250 | // Associate the menu bar with the frame | |
251 | subframe->SetMenuBar(menu_bar); | |
252 | ||
c54e5eb0 | 253 | subframe->Show(true); |
cdf3a589 CE |
254 | } |
255 | ||
756d3e7f | 256 | void MyFrame::OnSize(wxSizeEvent& event) |
cdf3a589 CE |
257 | { |
258 | int w, h; | |
259 | GetClientSize(&w, &h); | |
260 | ||
261 | GetClientWindow()->SetSize(0, 0, w, h); | |
756d3e7f | 262 | event.Skip(); |
cdf3a589 CE |
263 | } |
264 | ||
cdf3a589 CE |
265 | void MyFrame::InitToolBar(wxToolBar* toolBar) |
266 | { | |
49e3b82c | 267 | const int maxBitmaps = 3; |
cdf3a589 CE |
268 | wxBitmap* bitmaps[maxBitmaps]; |
269 | ||
270 | bitmaps[0] = new wxBitmap( new_xpm ); | |
271 | bitmaps[1] = new wxBitmap( save_xpm ); | |
272 | bitmaps[2] = new wxBitmap( help_xpm ); | |
273 | ||
bbe28fbb PC |
274 | toolBar->AddTool(MDI_NEW_WINDOW, wxEmptyString, *(bitmaps[0]), wxS("New SVG test window")); |
275 | toolBar->AddTool(MDI_SAVE, wxEmptyString, *bitmaps[1], wxS("Save test in SVG format")); | |
a5e6cfa8 | 276 | toolBar->AddSeparator(); |
bbe28fbb | 277 | toolBar->AddTool(MDI_ABOUT, wxEmptyString, *bitmaps[2], wxS("Help")); |
cdf3a589 CE |
278 | |
279 | toolBar->Realize(); | |
280 | ||
281 | int i; | |
282 | for (i = 0; i < maxBitmaps; i++) | |
283 | delete bitmaps[i]; | |
284 | } | |
285 | ||
cdf3a589 CE |
286 | void MyFrame::FileSavePicture (wxCommandEvent & WXUNUSED(event) ) |
287 | { | |
c54e5eb0 | 288 | #if wxUSE_FILEDLG |
49e3b82c | 289 | MyChild * pChild = (MyChild *)GetActiveChild(); |
a5e6cfa8 | 290 | if (pChild == NULL) |
cdf3a589 | 291 | { |
49e3b82c | 292 | return; |
cdf3a589 CE |
293 | } |
294 | ||
295 | wxFileDialog dialog(this, wxT("Save Picture as"), wxEmptyString, pChild->GetTitle(), | |
296 | wxT("SVG vector picture files (*.svg)|*.svg"), | |
ff3e84ff | 297 | wxFD_SAVE|wxFD_OVERWRITE_PROMPT); |
cdf3a589 CE |
298 | |
299 | if (dialog.ShowModal() == wxID_OK) | |
300 | { | |
49e3b82c | 301 | if (!pChild->OnSave ( dialog.GetPath() )) |
cdf3a589 | 302 | { |
49e3b82c | 303 | return; |
cdf3a589 CE |
304 | } |
305 | } | |
49e3b82c | 306 | return; |
c54e5eb0 | 307 | #endif // wxUSE_FILEDLG |
cdf3a589 CE |
308 | } |
309 | ||
310 | ||
cdf3a589 CE |
311 | // --------------------------------------------------------------------------- |
312 | // MyCanvas | |
313 | // --------------------------------------------------------------------------- | |
314 | ||
49e3b82c FM |
315 | BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) |
316 | END_EVENT_TABLE() | |
317 | ||
cdf3a589 | 318 | // Define a constructor for my canvas |
49e3b82c FM |
319 | MyCanvas::MyCanvas(MyChild *parent, const wxPoint& pos, const wxSize& size) |
320 | : wxScrolledWindow(parent, wxID_ANY, pos, size, wxSUNKEN_BORDER|wxVSCROLL|wxHSCROLL) | |
cdf3a589 | 321 | { |
ea92bb67 | 322 | SetBackgroundColour(*wxWHITE); |
cdf3a589 | 323 | |
49e3b82c | 324 | m_child = parent; |
614e38db | 325 | m_index = m_child->GetFrame()->GetCountOfChildren() % 9; |
49e3b82c | 326 | } |
cdf3a589 CE |
327 | |
328 | // Define the repainting behaviour | |
329 | void MyCanvas::OnDraw(wxDC& dc) | |
330 | { | |
331 | // vars to use ... | |
d96cdd4a | 332 | #if wxUSE_STATUSBAR |
49e3b82c | 333 | wxString s; |
d96cdd4a | 334 | #endif // wxUSE_STATUSBAR |
49e3b82c FM |
335 | wxPen wP; |
336 | wxBrush wB; | |
cdf3a589 CE |
337 | wxPoint points[6]; |
338 | wxColour wC; | |
49e3b82c | 339 | wxFont wF; |
cdf3a589 CE |
340 | |
341 | dc.SetFont(*wxSWISS_FONT); | |
342 | dc.SetPen(*wxGREEN_PEN); | |
343 | ||
cdf3a589 CE |
344 | switch (m_index) |
345 | { | |
346 | default: | |
347 | case 0: | |
348 | // draw lines to make a cross | |
349 | dc.DrawLine(0, 0, 200, 200); | |
350 | dc.DrawLine(200, 0, 0, 200); | |
351 | // draw point colored line and spline | |
49e3b82c | 352 | wP = *wxCYAN_PEN; |
cdf3a589 CE |
353 | wP.SetWidth(3); |
354 | dc.SetPen(wP); | |
355 | ||
49e3b82c | 356 | dc.DrawPoint (25,15); |
cdf3a589 CE |
357 | dc.DrawLine(50, 30, 200, 30); |
358 | dc.DrawSpline(50, 200, 50, 100, 200, 10); | |
d96cdd4a | 359 | #if wxUSE_STATUSBAR |
cdf3a589 | 360 | s = wxT("Green Cross, Cyan Line and spline"); |
d96cdd4a | 361 | #endif // wxUSE_STATUSBAR |
49e3b82c | 362 | break; |
cdf3a589 CE |
363 | |
364 | case 1: | |
365 | // draw standard shapes | |
366 | dc.SetBrush(*wxCYAN_BRUSH); | |
367 | dc.SetPen(*wxRED_PEN); | |
368 | dc.DrawRectangle(10, 10, 100, 70); | |
9a83f860 | 369 | wB = wxBrush (wxT("DARK ORCHID"), wxBRUSHSTYLE_TRANSPARENT); |
cdf3a589 CE |
370 | dc.SetBrush (wB); |
371 | dc.DrawRoundedRectangle(50, 50, 100, 70, 20); | |
9a83f860 | 372 | dc.SetBrush (wxBrush(wxT("GOLDENROD")) ); |
cdf3a589 CE |
373 | dc.DrawEllipse(100, 100, 100, 50); |
374 | ||
375 | points[0].x = 100; points[0].y = 200; | |
376 | points[1].x = 70; points[1].y = 260; | |
377 | points[2].x = 160; points[2].y = 230; | |
378 | points[3].x = 40; points[3].y = 230; | |
379 | points[4].x = 130; points[4].y = 260; | |
380 | points[5].x = 100; points[5].y = 200; | |
381 | ||
382 | dc.DrawPolygon(5, points); | |
383 | dc.DrawLines (6, points, 160); | |
d96cdd4a | 384 | #if wxUSE_STATUSBAR |
cdf3a589 | 385 | s = wxT("Blue rectangle, red edge, clear rounded rectangle, gold ellipse, gold and clear stars"); |
d96cdd4a | 386 | #endif // wxUSE_STATUSBAR |
49e3b82c | 387 | break; |
cdf3a589 CE |
388 | |
389 | case 2: | |
390 | // draw text in Arial or similar font | |
391 | dc.DrawLine(50,25,50,35); | |
392 | dc.DrawLine(45,30,55,30); | |
393 | dc.DrawText(wxT("This is a Swiss-style string"), 50, 30); | |
49e3b82c | 394 | wC = dc.GetTextForeground(); |
9a83f860 | 395 | dc.SetTextForeground (wxT("FIREBRICK")); |
a5e6cfa8 | 396 | |
cdf3a589 | 397 | // no effect in msw ?? |
9a83f860 | 398 | dc.SetTextBackground (wxT("WHEAT")); |
cdf3a589 CE |
399 | dc.DrawText(wxT("This is a Red string"), 50, 200); |
400 | dc.DrawRotatedText(wxT("This is a 45 deg string"), 50, 200, 45); | |
401 | dc.DrawRotatedText(wxT("This is a 90 deg string"), 50, 200, 90); | |
c54e5eb0 | 402 | wF = wxFont ( 18, wxROMAN, wxITALIC, wxBOLD, false, wxT("Times New Roman")); |
cdf3a589 | 403 | dc.SetFont(wF); |
49e3b82c | 404 | dc.SetTextForeground (wC); |
cdf3a589 | 405 | dc.DrawText(wxT("This is a Times-style string"), 50, 60); |
d96cdd4a | 406 | #if wxUSE_STATUSBAR |
cdf3a589 | 407 | s = wxT("Swiss, Times text; red text, rotated and colored orange"); |
d96cdd4a | 408 | #endif // wxUSE_STATUSBAR |
49e3b82c | 409 | break; |
cdf3a589 CE |
410 | |
411 | case 3 : | |
412 | // four arcs start and end points, center | |
413 | dc.SetBrush(*wxGREEN_BRUSH); | |
216db41f | 414 | dc.DrawArc ( 200,300, 370,230, 300,300 ); |
cdf3a589 | 415 | dc.SetBrush(*wxBLUE_BRUSH); |
216db41f | 416 | dc.DrawArc ( 270-50, 270-86, 270-86, 270-50, 270,270 ); |
cdf3a589 | 417 | dc.SetDeviceOrigin(-10,-10); |
216db41f | 418 | dc.DrawArc ( 270-50, 270-86, 270-86, 270-50, 270,270 ); |
cdf3a589 CE |
419 | dc.SetDeviceOrigin(0,0); |
420 | ||
9a83f860 | 421 | wP.SetColour (wxT("CADET BLUE")); |
cdf3a589 | 422 | dc.SetPen(wP); |
216db41f | 423 | dc.DrawArc ( 75,125, 110, 40, 75, 75 ); |
cdf3a589 | 424 | |
9a83f860 | 425 | wP.SetColour (wxT("SALMON")); |
cdf3a589 CE |
426 | dc.SetPen(wP); |
427 | dc.SetBrush(*wxRED_BRUSH); | |
428 | //top left corner, width and height, start and end angle | |
429 | // 315 same center and x-radius as last pie-arc, half Y radius | |
49e3b82c | 430 | dc.DrawEllipticArc(25,50,100,50,180.0,45.0); |
cdf3a589 | 431 | |
49e3b82c | 432 | wP = *wxCYAN_PEN; |
cdf3a589 CE |
433 | wP.SetWidth(3); |
434 | dc.SetPen(wP); | |
435 | //wxTRANSPARENT)); | |
9a83f860 | 436 | dc.SetBrush (wxBrush (wxT("SALMON"))); |
49e3b82c | 437 | dc.DrawEllipticArc(300, 0,200,100, 0.0,145.0); |
cdf3a589 | 438 | //same end point |
49e3b82c FM |
439 | dc.DrawEllipticArc(300, 50,200,100,90.0,145.0); |
440 | dc.DrawEllipticArc(300,100,200,100,90.0,345.0); | |
cdf3a589 | 441 | |
d96cdd4a | 442 | #if wxUSE_STATUSBAR |
cdf3a589 | 443 | s = wxT("This is an arc test page"); |
d96cdd4a | 444 | #endif // wxUSE_STATUSBAR |
49e3b82c | 445 | break; |
cdf3a589 CE |
446 | |
447 | case 4: | |
448 | dc.DrawCheckMark ( 30,30,25,25); | |
9a83f860 | 449 | dc.SetBrush (wxBrush (wxT("SALMON"),wxBRUSHSTYLE_TRANSPARENT)); |
cdf3a589 CE |
450 | dc.DrawCheckMark ( 80,50,75,75); |
451 | dc.DrawRectangle ( 80,50,75,75); | |
d96cdd4a | 452 | #if wxUSE_STATUSBAR |
cdf3a589 | 453 | s = wxT("Two check marks"); |
d96cdd4a | 454 | #endif // wxUSE_STATUSBAR |
49e3b82c | 455 | break; |
cdf3a589 CE |
456 | |
457 | case 5: | |
c54e5eb0 | 458 | wF = wxFont ( 18, wxROMAN, wxITALIC, wxBOLD, false, wxT("Times New Roman")); |
cdf3a589 CE |
459 | dc.SetFont(wF); |
460 | dc.DrawLine(0, 0, 200, 200); | |
461 | dc.DrawLine(200, 0, 0, 200); | |
462 | dc.DrawText(wxT("This is an 18pt string"), 50, 60); | |
463 | ||
464 | // rescale and draw in blue | |
49e3b82c | 465 | wP = *wxCYAN_PEN; |
cdf3a589 CE |
466 | dc.SetPen(wP); |
467 | dc.SetUserScale (2.0,0.5); | |
468 | dc.SetDeviceOrigin(200,0); | |
469 | dc.DrawLine(0, 0, 200, 200); | |
470 | dc.DrawLine(200, 0, 0, 200); | |
471 | dc.DrawText(wxT("This is an 18pt string 2 x 0.5 UserScaled"), 50, 60); | |
472 | dc.SetUserScale (2.0,2.0); | |
473 | dc.SetDeviceOrigin(200,200); | |
474 | dc.DrawText(wxT("This is an 18pt string 2 x 2 UserScaled"), 50, 60); | |
475 | ||
49e3b82c | 476 | wP = *wxRED_PEN; |
cdf3a589 CE |
477 | dc.SetPen(wP); |
478 | dc.SetUserScale (1.0,1.0); | |
479 | dc.SetDeviceOrigin(0,10); | |
49e3b82c | 480 | dc.SetMapMode (wxMM_METRIC); //svg ignores this |
cdf3a589 CE |
481 | dc.DrawLine(0, 0, 200, 200); |
482 | dc.DrawLine(200, 0, 0, 200); | |
a5e6cfa8 | 483 | dc.DrawText(wxT("This is an 18pt string in MapMode"), 50, 60); |
d96cdd4a | 484 | #if wxUSE_STATUSBAR |
cdf3a589 | 485 | s = wxT("Scaling test page"); |
d96cdd4a | 486 | #endif // wxUSE_STATUSBAR |
49e3b82c | 487 | break; |
cdf3a589 CE |
488 | |
489 | case 6: | |
3cb332c1 | 490 | dc.DrawIcon( wxICON(sample), 10, 10 ); |
756d3e7f | 491 | dc.DrawBitmap ( wxBitmap(svgbitmap_xpm), 50,15); |
d96cdd4a | 492 | #if wxUSE_STATUSBAR |
cdf3a589 | 493 | s = wxT("Icon and Bitmap "); |
d96cdd4a | 494 | #endif // wxUSE_STATUSBAR |
49e3b82c | 495 | break; |
cdf3a589 | 496 | |
66815259 | 497 | case 7: |
614e38db VZ |
498 | dc.SetTextForeground(wxT("RED")); |
499 | dc.DrawText(wxT("Red = Clipping Off"), 30, 5); | |
500 | dc.SetTextForeground(wxT("GREEN")); | |
501 | dc.DrawText(wxT("Green = Clipping On"), 30, 25); | |
502 | ||
503 | dc.SetTextForeground(wxT("BLACK")); | |
504 | ||
505 | dc.SetPen(*wxRED_PEN); | |
506 | dc.SetBrush (wxBrush (wxT("SALMON"),wxBRUSHSTYLE_TRANSPARENT)); | |
507 | dc.DrawCheckMark ( 80,50,75,75); | |
508 | dc.DrawRectangle ( 80,50,75,75); | |
509 | ||
510 | dc.SetPen(*wxGREEN_PEN); | |
511 | ||
512 | // Clipped checkmarks | |
513 | dc.DrawRectangle(180,50,75,75); | |
514 | dc.SetClippingRegion(180,50,75,75); // x,y,width,height version | |
515 | dc.DrawCheckMark ( 180,50,75,75); | |
516 | dc.DestroyClippingRegion(); | |
517 | ||
518 | dc.DrawRectangle(wxRect(80,150,75,75)); | |
519 | dc.SetClippingRegion(wxPoint(80,150),wxSize(75,75)); // pt,size version | |
520 | dc.DrawCheckMark ( 80,150,75,75); | |
521 | dc.DestroyClippingRegion(); | |
522 | ||
523 | dc.DrawRectangle(wxRect(180,150,75,75)); | |
524 | dc.SetClippingRegion(wxRect(180,150,75,75)); // rect version | |
525 | dc.DrawCheckMark ( 180,150,75,75); | |
526 | dc.DestroyClippingRegion(); | |
527 | ||
528 | dc.DrawRectangle(wxRect( 80,250,50,65)); | |
529 | dc.DrawRectangle(wxRect(105,260,50,65)); | |
530 | dc.SetClippingRegion(wxRect( 80,250,50,65)); // second call to SetClippingRegion | |
531 | dc.SetClippingRegion(wxRect(105,260,50,65)); // forms intersection with previous | |
532 | dc.DrawCheckMark(80,250,75,75); | |
533 | dc.DestroyClippingRegion(); // only one call to destroy (there's no stack) | |
534 | ||
535 | /* | |
536 | ** Clipping by wxRegion not implemented for SVG. Should be | |
537 | ** possible, but need to access points that define the wxRegion | |
538 | ** from inside DoSetDeviceClippingRegion() and wxRegion does not | |
539 | ** implement anything like getPoints(). | |
540 | points[0].x = 180; points[0].y = 250; | |
541 | points[1].x = 255; points[1].y = 250; | |
542 | points[2].x = 180; points[2].y = 325; | |
543 | points[3].x = 255; points[3].y = 325; | |
544 | points[4].x = 180; points[4].y = 250; | |
545 | ||
546 | dc.DrawLines (5, points); | |
547 | wxRegion reg = wxRegion(5,points); | |
548 | ||
549 | dc.SetClippingRegion(reg); | |
550 | dc.DrawCheckMark ( 180,250,75,75); | |
551 | dc.DestroyClippingRegion(); | |
552 | */ | |
553 | ||
554 | #if wxUSE_STATUSBAR | |
555 | s = wxT("Clipping region"); | |
556 | #endif // wxUSE_STATUSBAR | |
557 | break; | |
558 | ||
559 | case 8: | |
66815259 VZ |
560 | wxString txtStr; |
561 | wxCoord txtX, txtY, txtW, txtH, txtDescent, txtEL; | |
562 | wxCoord txtPad = 0; | |
563 | ||
564 | wP = *wxRED_PEN; | |
565 | dc.SetPen(wP); | |
566 | //dc.SetBackgroundMode(wxBRUSHSTYLE_SOLID); | |
567 | //dc.SetTextBackground(*wxBLUE); | |
568 | ||
569 | // Horizontal text | |
570 | txtStr = wxT("Horizontal string"); | |
571 | dc.GetTextExtent(txtStr, &txtW, &txtH, &txtDescent, &txtEL); | |
572 | txtX = 50; | |
573 | txtY = 300; | |
574 | dc.DrawRectangle(txtX, txtY, txtW + 2*txtPad, txtH + 2*txtPad); | |
575 | dc.DrawText(txtStr, txtX + txtPad, txtY + txtPad); | |
576 | ||
577 | // Vertical text | |
578 | txtStr = wxT("Vertical string"); | |
579 | dc.GetTextExtent(txtStr, &txtW, &txtH, &txtDescent, &txtEL); | |
580 | txtX = 50; | |
581 | txtY = 250; | |
582 | dc.DrawRectangle(txtX, txtY - (txtW + 2*txtPad), txtH + 2*txtPad, txtW + 2*txtPad); | |
583 | dc.DrawRotatedText(txtStr, txtX + txtPad, txtY - txtPad, 90); | |
584 | ||
585 | // 45 degree text | |
586 | txtStr = wxT("45 deg string"); | |
587 | dc.GetTextExtent(txtStr, &txtW, &txtH, &txtDescent, &txtEL); | |
588 | double lenW = (double)(txtW + 2*txtPad) / sqrt(2.0); | |
589 | double lenH = (double)(txtH + 2*txtPad) / sqrt(2.0); | |
590 | double padding = (double)txtPad / sqrt(2.0); | |
591 | txtX = 150; | |
592 | txtY = 200; | |
593 | dc.DrawLine(txtX - padding, txtY, txtX + lenW, txtY - lenW); // top | |
594 | dc.DrawLine(txtX + lenW, txtY - lenW, txtX - padding + lenH + lenW, txtY + (lenH - lenW)); | |
595 | dc.DrawLine(txtX - padding, txtY, txtX - padding + lenH, txtY + lenH); | |
596 | dc.DrawLine(txtX - padding + lenH, txtY + lenH, txtX - padding + lenH + lenW, txtY + (lenH - lenW)); // bottom | |
597 | dc.DrawRotatedText(txtStr, txtX, txtY, 45); | |
598 | #if wxUSE_STATUSBAR | |
599 | s = wxT("Text position test page"); | |
600 | #endif // wxUSE_STATUSBAR | |
601 | break; | |
cdf3a589 | 602 | } |
d96cdd4a | 603 | #if wxUSE_STATUSBAR |
cdf3a589 | 604 | m_child->SetStatusText(s); |
d96cdd4a | 605 | #endif // wxUSE_STATUSBAR |
cdf3a589 CE |
606 | } |
607 | ||
608 | ||
cdf3a589 CE |
609 | // --------------------------------------------------------------------------- |
610 | // MyChild | |
611 | // --------------------------------------------------------------------------- | |
612 | ||
49e3b82c FM |
613 | // Note that MDI_NEW_WINDOW and MDI_ABOUT commands get passed |
614 | // to the parent window for processing, so no need to | |
615 | // duplicate event handlers here. | |
616 | BEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame) | |
617 | EVT_MENU(MDI_CHILD_QUIT, MyChild::OnQuit) | |
618 | END_EVENT_TABLE() | |
619 | ||
cdf3a589 | 620 | MyChild::MyChild(wxMDIParentFrame *parent, const wxString& title, |
49e3b82c FM |
621 | const wxPoint& pos, const wxSize& size, |
622 | const long style) | |
623 | : wxMDIChildFrame(parent, wxID_ANY, title, pos, size, style) | |
cdf3a589 | 624 | { |
49e3b82c | 625 | m_frame = (MyFrame *) parent; |
ce00f59b | 626 | |
d96cdd4a | 627 | #if wxUSE_STATUSBAR |
cdf3a589 | 628 | CreateStatusBar(); |
a5e6cfa8 | 629 | SetStatusText(title); |
d96cdd4a | 630 | #endif // wxUSE_STATUSBAR |
cdf3a589 | 631 | |
49e3b82c | 632 | m_canvas = new MyCanvas(this, wxPoint(0, 0), GetClientSize()); |
ce00f59b | 633 | |
cdf3a589 CE |
634 | // Give it scrollbars |
635 | m_canvas->SetScrollbars(20, 20, 50, 50); | |
cdf3a589 CE |
636 | } |
637 | ||
cdf3a589 CE |
638 | MyChild::~MyChild() |
639 | { | |
cdf3a589 CE |
640 | } |
641 | ||
cdf3a589 CE |
642 | void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event)) |
643 | { | |
c54e5eb0 | 644 | Close(true); |
cdf3a589 CE |
645 | } |
646 | ||
cdf3a589 CE |
647 | bool MyChild::OnSave(wxString filename) |
648 | { | |
49e3b82c | 649 | wxSVGFileDC svgDC (filename, 600, 650); |
cdf3a589 | 650 | m_canvas->OnDraw (svgDC); |
22e43568 | 651 | return svgDC.IsOk(); |
cdf3a589 CE |
652 | } |
653 | ||
cdf3a589 CE |
654 | void MyChild::OnActivate(wxActivateEvent& event) |
655 | { | |
656 | if ( event.GetActive() && m_canvas ) | |
657 | m_canvas->SetFocus(); | |
658 | } | |
659 |