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