svgtest.cpp 20 KB

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