]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/svg/svgtest.cpp
Make it possible to use svn-find-native-eols script without svn checkout.
[wxWidgets.git] / samples / svg / svgtest.cpp
index ccf21cff55498667cac2c12ffa026fed2132d2f6..a70673a59471aac0e2522f6cc7a8b68b11c38aaa 100644 (file)
@@ -4,7 +4,7 @@
 // Author:      Chris Elliott
 // Modified by:
 // RCS-ID:      $Id$
-// Licence:     wxWindows license
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // ===========================================================================
 #include "wx/dcsvg.h"
 #include "wx/vector.h"
 
-#include "mondrian.xpm"
-
 #include "bitmaps/new.xpm"
 #include "bitmaps/save.xpm"
 #include "bitmaps/help.xpm"
 #include "SVGlogo24.xpm"
 
+#ifndef wxHAS_IMAGES_IN_RESOURCES
+    #include "../sample.xpm"
+#endif
+
+#include <math.h>
+
 class MyChild;
 class MyCanvas;
 
@@ -64,29 +68,29 @@ public:
     void OnNewWindow(wxCommandEvent& event);
     void OnQuit(wxCommandEvent& event);
     void FileSavePicture (wxCommandEvent& event);
-    
+
     unsigned int GetCountOfChildren() const
         { return m_nWinCreated; }
 
 private:
     unsigned int m_nWinCreated;
-        
+
     DECLARE_EVENT_TABLE()
 };
 
 class MyChild: public wxMDIChildFrame
 {
 public:
-    MyChild(wxMDIParentFrame *parent, const wxString& title, 
-            const wxPoint& pos = wxDefaultPosition, 
-            const wxSize& size = wxDefaultSize, 
+    MyChild(wxMDIParentFrame *parent, const wxString& title,
+            const wxPoint& pos = wxDefaultPosition,
+            const wxSize& size = wxDefaultSize,
             const long style = wxDEFAULT_FRAME_STYLE);
     ~MyChild();
 
     void OnActivate(wxActivateEvent& event);
     void OnQuit(wxCommandEvent& event);
     bool OnSave(wxString filename);
-    
+
     MyFrame* GetFrame()
         { return m_frame; }
 
@@ -106,7 +110,7 @@ public:
 private:
     int m_index;
     MyChild* m_child;
-    
+
     DECLARE_EVENT_TABLE()
 };
 
@@ -158,8 +162,6 @@ bool MyApp::OnInit()
 
     frame->Show(true);
 
-    SetTopWindow(frame);
-
     return true;
 }
 
@@ -175,7 +177,7 @@ MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title,
 {
     m_nWinCreated = 0;
 
-    SetIcon(wxICON(mondrian));
+    SetIcon(wxICON(sample));
 
     // Make a menubar
     wxMenu *file_menu = new wxMenu;
@@ -211,7 +213,7 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
 {
     (void)wxMessageBox(wxT("wxWidgets SVG sample\n")
         wxT("Author: Chris Elliott (c) 2002-2009\n")
-        wxT("Usage: click File|New to show tests"), 
+        wxT("Usage: click File|New to show tests"),
         wxT("About SVG Test"));
 }
 
@@ -222,13 +224,13 @@ void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) )
 
     wxString title;
     title.Printf(wxT("SVG Test Window %d"), m_nWinCreated );
-    
+
     // counts number of children previously, even if now closed
     m_nWinCreated ++;
 
     // Give it a title and icon
     subframe->SetTitle(title);
-    subframe->SetIcon(wxICON(mondrian));
+    subframe->SetIcon(wxICON(sample));
 
     // Make a menubar
     wxMenu *file_menu = new wxMenu;
@@ -318,10 +320,10 @@ END_EVENT_TABLE()
 MyCanvas::MyCanvas(MyChild *parent, const wxPoint& pos, const wxSize& size)
     : wxScrolledWindow(parent, wxID_ANY, pos, size, wxSUNKEN_BORDER|wxVSCROLL|wxHSCROLL)
 {
-    SetBackgroundColour(wxColour(_T("WHITE")));
+    SetBackgroundColour(*wxWHITE);
 
     m_child = parent;
-    m_index = m_child->GetFrame()->GetCountOfChildren() % 7;
+    m_index = m_child->GetFrame()->GetCountOfChildren() % 9;
 }
 
 // Define the repainting behaviour
@@ -365,10 +367,10 @@ void MyCanvas::OnDraw(wxDC& dc)
             dc.SetBrush(*wxCYAN_BRUSH);
             dc.SetPen(*wxRED_PEN);
             dc.DrawRectangle(10, 10, 100, 70);
-            wB = wxBrush (_T("DARK ORCHID"), wxBRUSHSTYLE_TRANSPARENT);
+            wB = wxBrush (wxT("DARK ORCHID"), wxBRUSHSTYLE_TRANSPARENT);
             dc.SetBrush (wB);
             dc.DrawRoundedRectangle(50, 50, 100, 70, 20);
-            dc.SetBrush (wxBrush(_T("GOLDENROD")) );
+            dc.SetBrush (wxBrush(wxT("GOLDENROD")) );
             dc.DrawEllipse(100, 100, 100, 50);
 
             points[0].x = 100; points[0].y = 200;
@@ -391,10 +393,10 @@ void MyCanvas::OnDraw(wxDC& dc)
             dc.DrawLine(45,30,55,30);
             dc.DrawText(wxT("This is a Swiss-style string"), 50, 30);
             wC = dc.GetTextForeground();
-            dc.SetTextForeground (_T("FIREBRICK"));
+            dc.SetTextForeground (wxT("FIREBRICK"));
 
             // no effect in msw ??
-            dc.SetTextBackground (_T("WHEAT"));
+            dc.SetTextBackground (wxT("WHEAT"));
             dc.DrawText(wxT("This is a Red string"), 50, 200);
             dc.DrawRotatedText(wxT("This is a 45 deg string"), 50, 200, 45);
             dc.DrawRotatedText(wxT("This is a 90 deg string"), 50, 200, 90);
@@ -417,11 +419,11 @@ void MyCanvas::OnDraw(wxDC& dc)
             dc.DrawArc ( 270-50, 270-86, 270-86, 270-50, 270,270 );
             dc.SetDeviceOrigin(0,0);
 
-            wP.SetColour (_T("CADET BLUE"));
+            wP.SetColour (wxT("CADET BLUE"));
             dc.SetPen(wP);
             dc.DrawArc ( 75,125, 110, 40, 75, 75 );
 
-            wP.SetColour (_T("SALMON"));
+            wP.SetColour (wxT("SALMON"));
             dc.SetPen(wP);
             dc.SetBrush(*wxRED_BRUSH);
             //top left corner, width and height, start and end angle
@@ -432,7 +434,7 @@ void MyCanvas::OnDraw(wxDC& dc)
             wP.SetWidth(3);
             dc.SetPen(wP);
                                  //wxTRANSPARENT));
-            dc.SetBrush (wxBrush (_T("SALMON")));
+            dc.SetBrush (wxBrush (wxT("SALMON")));
             dc.DrawEllipticArc(300,  0,200,100, 0.0,145.0);
                                  //same end point
             dc.DrawEllipticArc(300, 50,200,100,90.0,145.0);
@@ -445,7 +447,7 @@ void MyCanvas::OnDraw(wxDC& dc)
 
         case 4:
             dc.DrawCheckMark ( 30,30,25,25);
-            dc.SetBrush (wxBrush (_T("SALMON"),wxBRUSHSTYLE_TRANSPARENT));
+            dc.SetBrush (wxBrush (wxT("SALMON"),wxBRUSHSTYLE_TRANSPARENT));
             dc.DrawCheckMark ( 80,50,75,75);
             dc.DrawRectangle ( 80,50,75,75);
 #if wxUSE_STATUSBAR
@@ -486,13 +488,118 @@ void MyCanvas::OnDraw(wxDC& dc)
             break;
 
         case 6:
-            dc.DrawIcon( wxIcon(mondrian_xpm), 10, 10 );
+            dc.DrawIcon( wxICON(sample), 10, 10 );
             dc.DrawBitmap ( wxBitmap(svgbitmap_xpm), 50,15);
 #if wxUSE_STATUSBAR
             s = wxT("Icon and Bitmap ");
 #endif // wxUSE_STATUSBAR
             break;
 
+        case 7:
+            dc.SetTextForeground(wxT("RED"));
+            dc.DrawText(wxT("Red = Clipping Off"), 30, 5);
+            dc.SetTextForeground(wxT("GREEN"));
+            dc.DrawText(wxT("Green = Clipping On"), 30, 25);
+
+            dc.SetTextForeground(wxT("BLACK"));
+
+            dc.SetPen(*wxRED_PEN);
+            dc.SetBrush (wxBrush (wxT("SALMON"),wxBRUSHSTYLE_TRANSPARENT));
+            dc.DrawCheckMark ( 80,50,75,75);
+            dc.DrawRectangle ( 80,50,75,75);
+
+            dc.SetPen(*wxGREEN_PEN);
+
+            // Clipped checkmarks
+            dc.DrawRectangle(180,50,75,75);
+            dc.SetClippingRegion(180,50,75,75);                   // x,y,width,height version
+            dc.DrawCheckMark ( 180,50,75,75);
+            dc.DestroyClippingRegion();
+
+            dc.DrawRectangle(wxRect(80,150,75,75));
+            dc.SetClippingRegion(wxPoint(80,150),wxSize(75,75));  // pt,size version
+            dc.DrawCheckMark ( 80,150,75,75);
+            dc.DestroyClippingRegion();
+
+            dc.DrawRectangle(wxRect(180,150,75,75));
+            dc.SetClippingRegion(wxRect(180,150,75,75));          // rect version
+            dc.DrawCheckMark ( 180,150,75,75);
+            dc.DestroyClippingRegion();
+
+            dc.DrawRectangle(wxRect( 80,250,50,65));
+            dc.DrawRectangle(wxRect(105,260,50,65));
+            dc.SetClippingRegion(wxRect( 80,250,50,65));  // second call to SetClippingRegion
+            dc.SetClippingRegion(wxRect(105,260,50,65));  // forms intersection with previous
+            dc.DrawCheckMark(80,250,75,75);
+            dc.DestroyClippingRegion();                   // only one call to destroy (there's no stack)
+
+            /*
+            ** Clipping by wxRegion not implemented for SVG.   Should be
+            ** possible, but need to access points that define the wxRegion
+            ** from inside DoSetDeviceClippingRegion() and wxRegion does not
+            ** implement anything like getPoints().
+            points[0].x = 180; points[0].y = 250;
+            points[1].x = 255; points[1].y = 250;
+            points[2].x = 180; points[2].y = 325;
+            points[3].x = 255; points[3].y = 325;
+            points[4].x = 180; points[4].y = 250;
+
+            dc.DrawLines (5, points);
+            wxRegion reg = wxRegion(5,points);
+
+            dc.SetClippingRegion(reg);
+            dc.DrawCheckMark ( 180,250,75,75);
+            dc.DestroyClippingRegion();
+            */
+
+#if wxUSE_STATUSBAR
+            s = wxT("Clipping region");
+#endif // wxUSE_STATUSBAR
+            break;
+
+        case 8:
+            wxString txtStr;
+            wxCoord txtX, txtY, txtW, txtH, txtDescent, txtEL;
+            wxCoord txtPad = 0;
+
+            wP = *wxRED_PEN;
+            dc.SetPen(wP);
+            //dc.SetBackgroundMode(wxBRUSHSTYLE_SOLID);
+            //dc.SetTextBackground(*wxBLUE);
+
+            // Horizontal text
+            txtStr = wxT("Horizontal string");
+            dc.GetTextExtent(txtStr, &txtW, &txtH, &txtDescent, &txtEL);
+            txtX = 50;
+            txtY = 300;
+            dc.DrawRectangle(txtX, txtY, txtW + 2*txtPad, txtH + 2*txtPad);
+            dc.DrawText(txtStr, txtX + txtPad, txtY + txtPad);
+
+            // Vertical text
+            txtStr = wxT("Vertical string");
+            dc.GetTextExtent(txtStr, &txtW, &txtH, &txtDescent, &txtEL);
+            txtX = 50;
+            txtY = 250;
+            dc.DrawRectangle(txtX, txtY - (txtW + 2*txtPad), txtH + 2*txtPad, txtW + 2*txtPad);
+            dc.DrawRotatedText(txtStr, txtX + txtPad, txtY - txtPad, 90);
+
+            // 45 degree text
+            txtStr = wxT("45 deg string");
+            dc.GetTextExtent(txtStr, &txtW, &txtH, &txtDescent, &txtEL);
+            double lenW = (double)(txtW + 2*txtPad) / sqrt(2.0);
+            double lenH = (double)(txtH + 2*txtPad) / sqrt(2.0);
+            double padding = (double)txtPad / sqrt(2.0);
+            txtX = 150;
+            txtY = 200;
+            dc.DrawLine(txtX - padding, txtY, txtX + lenW, txtY - lenW); // top
+            dc.DrawLine(txtX + lenW, txtY - lenW, txtX - padding + lenH + lenW, txtY + (lenH - lenW));
+            dc.DrawLine(txtX - padding, txtY, txtX - padding + lenH, txtY + lenH);
+            dc.DrawLine(txtX - padding + lenH, txtY + lenH, txtX - padding + lenH + lenW, txtY + (lenH - lenW)); // bottom
+            dc.DrawRotatedText(txtStr, txtX, txtY, 45);
+#if wxUSE_STATUSBAR
+            s = wxT("Text position test page");
+#endif // wxUSE_STATUSBAR
+            break;
     }
 #if wxUSE_STATUSBAR
     m_child->SetStatusText(s);
@@ -517,14 +624,14 @@ MyChild::MyChild(wxMDIParentFrame *parent, const wxString& title,
     : wxMDIChildFrame(parent, wxID_ANY, title, pos, size, style)
 {
     m_frame = (MyFrame *) parent;
-    
+
 #if wxUSE_STATUSBAR
     CreateStatusBar();
     SetStatusText(title);
 #endif // wxUSE_STATUSBAR
 
     m_canvas = new MyCanvas(this, wxPoint(0, 0), GetClientSize());
-    
+
     // Give it scrollbars
     m_canvas->SetScrollbars(20, 20, 50, 50);
 }