+void MyCanvas::DrawWithLogicalOps(wxDC& dc)
+{
+ static const wxCoord w = 60;
+ static const wxCoord h = 60;
+
+ // reuse the text colour here
+ dc.SetPen(wxPen(m_owner->m_colourForeground, 1, wxSOLID));
+ dc.SetBrush(*wxTRANSPARENT_BRUSH);
+
+ size_t n;
+ for ( n = 0; n < WXSIZEOF(rasterOperations); n++ )
+ {
+ wxCoord x = 20 + 150*(n%4),
+ y = 20 + 100*(n/4);
+
+ dc.DrawText(rasterOperations[n].name, x, y - 20);
+ dc.SetLogicalFunction(rasterOperations[n].rop);
+ dc.DrawRectangle(x, y, w, h);
+ dc.DrawLine(x, y, x + w, y + h);
+ dc.DrawLine(x + w, y, x, y + h);
+ }
+
+ // now some filled rectangles
+ dc.SetBrush(wxBrush(m_owner->m_colourForeground, wxSOLID));
+
+ for ( n = 0; n < WXSIZEOF(rasterOperations); n++ )
+ {
+ wxCoord x = 20 + 150*(n%4),
+ y = 500 + 100*(n/4);
+
+ dc.DrawText(rasterOperations[n].name, x, y - 20);
+ dc.SetLogicalFunction(rasterOperations[n].rop);
+ dc.DrawRectangle(x, y, w, h);
+ }
+}
+
+#if wxUSE_GRAPHICS_CONTEXT
+#ifdef __WXGTK20__
+void MyCanvas::DrawAlpha(wxDC& no_dc)
+#else
+void MyCanvas::DrawAlpha(wxDC& dc)
+#endif
+{
+#ifdef __WXGTK__
+ wxGCDC dc( this );
+ PrepareDC( dc );
+#endif
+
+ wxDouble margin = 20 ;
+ wxDouble width = 180 ;
+ wxDouble radius = 30 ;
+
+ dc.SetPen( wxPen( wxColour( 128, 0, 0, 255 ),12, wxSOLID));
+ dc.SetBrush( wxBrush( wxColour( 255, 0, 0, 255),wxSOLID));
+
+ wxRect r(margin,margin+width*0.66,width,width) ;
+
+ dc.DrawRoundedRectangle( r.x, r.y, r.width, r.width, radius ) ;
+
+ dc.SetPen( wxPen( wxColour( 0, 0, 128, 255 ),12, wxSOLID));
+ dc.SetBrush( wxBrush( wxColour( 0, 0, 255, 255),wxSOLID));
+
+ r.Offset( width * 0.8 , - width * 0.66 ) ;
+
+ dc.DrawRoundedRectangle( r.x, r.y, r.width, r.width, radius ) ;
+
+ dc.SetPen( wxPen( wxColour( 128, 128, 0, 255 ),12, wxSOLID));
+ dc.SetBrush( wxBrush( wxColour( 192, 192, 0, 255),wxSOLID));
+
+ r.Offset( width * 0.8 , width *0.5 ) ;
+
+ dc.DrawRoundedRectangle( r.x, r.y, r.width, r.width, radius ) ;
+
+ dc.SetPen( *wxTRANSPARENT_PEN ) ;
+ dc.SetBrush( wxBrush( wxColour(255,255,128,128) ) );
+ dc.DrawRoundedRectangle( 0 , margin + width / 2 , width * 3 , 100 , radius) ;
+
+ dc.SetTextForeground( wxColour(255,255,0,128) );
+ dc.SetFont( wxFont( 40, wxFONTFAMILY_SWISS, wxFONTSTYLE_ITALIC, wxFONTWEIGHT_NORMAL ) );
+ dc.DrawText( wxT("Hello!"), 120, 80 );
+}
+
+#endif
+
+#if wxUSE_GRAPHICS_CONTEXT
+
+const int BASE = 80.0;
+const int BASE2 = BASE/2;
+const int BASE4 = BASE/4;
+
+static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
+
+
+// modeled along Robin Dunn's GraphicsContext.py sample
+
+void MyCanvas::DrawGraphics(wxGraphicsContext* gc)
+{
+ wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
+ gc->SetFont(font,*wxBLACK);
+
+ // make a path that contains a circle and some lines, centered at 0,0
+ wxGraphicsPath path = gc->CreatePath() ;
+ path.AddCircle( 0, 0, BASE2 );
+ path.MoveToPoint(0, -BASE2);
+ path.AddLineToPoint(0, BASE2);
+ path.MoveToPoint(-BASE2, 0);
+ path.AddLineToPoint(BASE2, 0);
+ path.CloseSubpath();
+ path.AddRectangle(-BASE4, -BASE4/2, BASE2, BASE4);
+
+ // Now use that path to demonstrate various capbilites of the grpahics context
+ gc->PushState(); // save current translation/scale/other state
+ gc->Translate(60, 75); // reposition the context origin
+
+ gc->SetPen(wxPen("navy", 1));
+ gc->SetBrush(wxBrush("pink"));
+
+ for( int i = 0 ; i < 3 ; ++i )
+ {
+ wxString label;
+ switch( i )
+ {
+ case 0 :
+ label = "StrokePath";
+ break;
+ case 1 :
+ label = "FillPath";
+ break;
+ case 2 :
+ label = "DrawPath";
+ break;
+ }
+ wxDouble w, h;
+ gc->GetTextExtent(label, &w, &h, NULL, NULL);
+ gc->DrawText(label, -w/2, -BASE2-h-4);
+ switch( i )
+ {
+ case 0 :
+ gc->StrokePath(path);
+ break;
+ case 1 :
+ gc->FillPath(path);
+ break;
+ case 2 :
+ gc->DrawPath(path);
+ break;
+ }
+ gc->Translate(2*BASE, 0);
+ }
+
+ gc->PopState(); // restore saved state
+ gc->PushState(); // save it again
+ gc->Translate(60, 200); // offset to the lower part of the window
+
+ gc->DrawText("Scale", 0, -BASE2);
+ gc->Translate(0, 20);
+
+ gc->SetBrush(wxBrush(wxColour(178, 34, 34, 128)));// 128 == half transparent
+ for( int i = 0 ; i < 8 ; ++i )
+ {
+ gc->Scale(1.08, 1.08); // increase scale by 8%
+ gc->Translate(5,5);
+ gc->DrawPath(path);
+ }
+
+ gc->PopState(); // restore saved state
+ gc->PushState(); // save it again
+ gc->Translate(400, 200);
+
+ gc->DrawText("Rotate", 0, -BASE2);
+
+ // Move the origin over to the next location
+ gc->Translate(0, 75);
+
+ // draw our path again, rotating it about the central point,
+ // and changing colors as we go
+ for ( int angle = 0 ; angle < 360 ; angle += 30 )
+ {
+ gc->PushState(); // save this new current state so we can
+ // pop back to it at the end of the loop
+ wxImage::RGBValue val = wxImage::HSVtoRGB(wxImage::HSVValue(float(angle)/360, 1, 1));
+ gc->SetBrush(wxBrush(wxColour(val.red, val.green, val.blue, 64)));
+ gc->SetPen(wxPen(wxColour(val.red, val.green, val.blue, 128)));
+
+ // use translate to artfully reposition each drawn path
+ gc->Translate(1.5 * BASE2 * cos(DegToRad(angle)),
+ 1.5 * BASE2 * sin(DegToRad(angle)));
+
+ // use Rotate to rotate the path
+ gc->Rotate(DegToRad(angle));
+
+ // now draw it
+ gc->DrawPath(path);
+ gc->PopState();
+ }
+ gc->PopState();
+}
+#endif
+
+void MyCanvas::DrawCircles(wxDC& dc)
+{
+ int x = 100,
+ y = 100,
+ r = 20;
+
+ dc.SetPen( *wxRED_PEN );
+ dc.SetBrush( *wxGREEN_BRUSH );
+
+ dc.DrawText(_T("Some circles"), 0, y);
+ dc.DrawCircle(x, y, r);
+ dc.DrawCircle(x + 2*r, y, r);
+ dc.DrawCircle(x + 4*r, y, r);
+
+ y += 2*r;
+ dc.DrawText(_T("And ellipses"), 0, y);
+ dc.DrawEllipse(x - r, y, 2*r, r);
+ dc.DrawEllipse(x + r, y, 2*r, r);
+ dc.DrawEllipse(x + 3*r, y, 2*r, r);
+
+ y += 2*r;
+ dc.DrawText(_T("And arcs"), 0, y);
+ dc.DrawArc(x - r, y, x + r, y, x, y);
+ dc.DrawArc(x + 4*r, y, x + 2*r, y, x + 3*r, y);
+ dc.DrawArc(x + 5*r, y, x + 5*r, y, x + 6*r, y);
+
+ y += 2*r;
+ dc.DrawEllipticArc(x - r, y, 2*r, r, 0, 90);
+ dc.DrawEllipticArc(x + r, y, 2*r, r, 90, 180);
+ dc.DrawEllipticArc(x + 3*r, y, 2*r, r, 180, 270);
+ dc.DrawEllipticArc(x + 5*r, y, 2*r, r, 270, 360);
+
+ // same as above, just transparent brush
+
+ dc.SetPen( *wxRED_PEN );
+ dc.SetBrush( *wxTRANSPARENT_BRUSH );
+
+ y += 2*r;
+ dc.DrawText(_T("Some circles"), 0, y);
+ dc.DrawCircle(x, y, r);
+ dc.DrawCircle(x + 2*r, y, r);
+ dc.DrawCircle(x + 4*r, y, r);
+
+ y += 2*r;
+ dc.DrawText(_T("And ellipses"), 0, y);
+ dc.DrawEllipse(x - r, y, 2*r, r);
+ dc.DrawEllipse(x + r, y, 2*r, r);
+ dc.DrawEllipse(x + 3*r, y, 2*r, r);
+
+ y += 2*r;
+ dc.DrawText(_T("And arcs"), 0, y);
+ dc.DrawArc(x - r, y, x + r, y, x, y);
+ dc.DrawArc(x + 4*r, y, x + 2*r, y, x + 3*r, y);
+ dc.DrawArc(x + 5*r, y, x + 5*r, y, x + 6*r, y);
+
+ y += 2*r;
+ dc.DrawEllipticArc(x - r, y, 2*r, r, 0, 90);
+ dc.DrawEllipticArc(x + r, y, 2*r, r, 90, 180);
+ dc.DrawEllipticArc(x + 3*r, y, 2*r, r, 180, 270);
+ dc.DrawEllipticArc(x + 5*r, y, 2*r, r, 270, 360);
+
+}
+
+void MyCanvas::DrawSplines(wxDC& dc)
+{
+#if wxUSE_SPLINES
+ dc.DrawText(_T("Some splines"), 10, 5);
+
+ // values are hardcoded rather than randomly generated
+ // so the output can be compared between native
+ // implementations on platforms with different random
+ // generators
+
+ const int R = 300;
+ const wxPoint center( R + 20, R + 20 );
+ const int angles[7] = { 0, 10, 33, 77, 13, 145, 90 };
+ const int radii[5] = { 100 , 59, 85, 33, 90 };
+ const int n = 200;
+ wxPoint pts[n];
+
+ // background spline calculation
+ unsigned int radius_pos = 0;
+ unsigned int angle_pos = 0;
+ int angle = 0;
+ for ( int i = 0; i < n; i++ )
+ {
+ angle += angles[ angle_pos ];
+ int r = R * radii[ radius_pos ] / 100;
+ pts[ i ].x = center.x + (wxCoord)( r * cos( M_PI * angle / 180.0) );
+ pts[ i ].y = center.y + (wxCoord)( r * sin( M_PI * angle / 180.0) );
+
+ angle_pos++;
+ if ( angle_pos >= WXSIZEOF(angles) ) angle_pos = 0;
+
+ radius_pos++;
+ if ( radius_pos >= WXSIZEOF(radii) ) radius_pos = 0;
+ }
+
+ // background spline drawing
+ dc.SetPen(*wxRED_PEN);
+ dc.DrawSpline(WXSIZEOF(pts), pts);
+
+ // less detailed spline calculation
+ wxPoint letters[4][5];
+ // w
+ letters[0][0] = wxPoint( 0,1); // O O
+ letters[0][1] = wxPoint( 1,3); // * *
+ letters[0][2] = wxPoint( 2,2); // * O *
+ letters[0][3] = wxPoint( 3,3); // * * * *
+ letters[0][4] = wxPoint( 4,1); // O O
+ // x1
+ letters[1][0] = wxPoint( 5,1); // O*O
+ letters[1][1] = wxPoint( 6,1); // *
+ letters[1][2] = wxPoint( 7,2); // O
+ letters[1][3] = wxPoint( 8,3); // *
+ letters[1][4] = wxPoint( 9,3); // O*O
+ // x2
+ letters[2][0] = wxPoint( 5,3); // O*O
+ letters[2][1] = wxPoint( 6,3); // *
+ letters[2][2] = wxPoint( 7,2); // O
+ letters[2][3] = wxPoint( 8,1); // *
+ letters[2][4] = wxPoint( 9,1); // O*O
+ // W
+ letters[3][0] = wxPoint(10,0); // O O
+ letters[3][1] = wxPoint(11,3); // * *
+ letters[3][2] = wxPoint(12,1); // * O *
+ letters[3][3] = wxPoint(13,3); // * * * *
+ letters[3][4] = wxPoint(14,0); // O O
+
+ const int dx = 2 * R / letters[3][4].x;
+ const int h[4] = { -R/2, 0, R/4, R/2 };
+
+ for ( int m = 0; m < 4; m++ )
+ {
+ for ( int n = 0; n < 5; n++ )
+ {
+ letters[m][n].x = center.x - R + letters[m][n].x * dx;
+ letters[m][n].y = center.y + h[ letters[m][n].y ];
+ }
+
+ dc.SetPen( wxPen( wxT("blue"), 1, wxDOT) );
+ dc.DrawLines(5, letters[m]);
+ dc.SetPen( wxPen( wxT("black"), 4, wxSOLID) );
+ dc.DrawSpline(5, letters[m]);
+ }
+
+#else
+ dc.DrawText(_T("Splines not supported."), 10, 5);
+#endif
+}
+
+void MyCanvas::DrawGradients(wxDC& dc)
+{
+ static const int TEXT_HEIGHT = 15;
+
+ // LHS: linear
+ wxRect r(10, 10, 50, 50);
+ dc.DrawText(_T("wxRIGHT"), r.x, r.y);
+ r.Offset(0, TEXT_HEIGHT);
+ dc.GradientFillLinear(r, *wxWHITE, *wxBLUE, wxRIGHT);
+
+ r.Offset(0, r.height + 10);
+ dc.DrawText(_T("wxLEFT"), r.x, r.y);
+ r.Offset(0, TEXT_HEIGHT);
+ dc.GradientFillLinear(r, *wxWHITE, *wxBLUE, wxLEFT);
+
+ r.Offset(0, r.height + 10);
+ dc.DrawText(_T("wxDOWN"), r.x, r.y);
+ r.Offset(0, TEXT_HEIGHT);
+ dc.GradientFillLinear(r, *wxWHITE, *wxBLUE, wxDOWN);
+
+ r.Offset(0, r.height + 10);
+ dc.DrawText(_T("wxUP"), r.x, r.y);
+ r.Offset(0, TEXT_HEIGHT);
+ dc.GradientFillLinear(r, *wxWHITE, *wxBLUE, wxUP);
+
+
+ // RHS: concentric
+ r = wxRect(200, 10, 50, 50);
+ dc.DrawText(_T("Blue inside"), r.x, r.y);
+ r.Offset(0, TEXT_HEIGHT);
+ dc.GradientFillConcentric(r, *wxBLUE, *wxWHITE);
+
+ r.Offset(0, r.height + 10);
+ dc.DrawText(_T("White inside"), r.x, r.y);
+ r.Offset(0, TEXT_HEIGHT);
+ dc.GradientFillConcentric(r, *wxWHITE, *wxBLUE);
+
+ r.Offset(0, r.height + 10);
+ dc.DrawText(_T("Blue in top left corner"), r.x, r.y);
+ r.Offset(0, TEXT_HEIGHT);
+ dc.GradientFillConcentric(r, *wxBLUE, *wxWHITE, wxPoint(0, 0));
+
+ r.Offset(0, r.height + 10);
+ dc.DrawText(_T("Blue in bottom right corner"), r.x, r.y);
+ r.Offset(0, TEXT_HEIGHT);
+ dc.GradientFillConcentric(r, *wxBLUE, *wxWHITE, wxPoint(r.width, r.height));
+
+ // check that the area filled by the gradient is exactly the interior of
+ // the rectangle
+ r.x = 350;
+ r.y = 30;
+ dc.DrawText("The interior should be filled but", r.x, r.y);
+ r.y += 15;
+ dc.DrawText(" the red border should remain visible:", r.x, r.y);
+ r.y += 15;
+
+ r.width =
+ r.height = 50;
+ wxRect r2 = r;
+ r2.x += 60;
+ wxRect r3 = r;
+ r3.y += 60;
+ wxRect r4 = r2;
+ r4.y += 60;
+ dc.SetPen(wxPen(wxColour(255, 0, 0)));
+ dc.DrawRectangle(r);
+ r.Deflate(1);
+ dc.GradientFillLinear(r, wxColour(0,255,0), wxColour(0,0,0), wxNORTH);
+ dc.DrawRectangle(r2);
+ r2.Deflate(1);
+ dc.GradientFillLinear(r2, wxColour(0,0,0), wxColour(0,255,0), wxSOUTH);
+ dc.DrawRectangle(r3);
+ r3.Deflate(1);
+ dc.GradientFillLinear(r3, wxColour(0,255,0), wxColour(0,0,0), wxEAST);
+ dc.DrawRectangle(r4);
+ r4.Deflate(1);
+ dc.GradientFillLinear(r4, wxColour(0,0,0), wxColour(0,255,0), wxWEST);
+}
+
+void MyCanvas::DrawRegions(wxDC& dc)
+{
+ dc.DrawText(_T("You should see a red rect partly covered by a cyan one ")
+ _T("on the left"), 10, 5);
+ dc.DrawText(_T("and 5 smileys from which 4 are partially clipped on the right"),
+ 10, 5 + dc.GetCharHeight());
+ dc.DrawText(_T("The second copy should be identical but right part of it ")
+ _T("should be offset by 10 pixels."),
+ 10, 5 + 2*dc.GetCharHeight());
+
+ DrawRegionsHelper(dc, 10, true);
+ DrawRegionsHelper(dc, 350, false);
+}
+
+void MyCanvas::DrawRegionsHelper(wxDC& dc, wxCoord x, bool firstTime)
+{
+ wxCoord y = 100;
+
+ dc.DestroyClippingRegion();
+ dc.SetBrush( *wxWHITE_BRUSH );
+ dc.SetPen( *wxTRANSPARENT_PEN );
+ dc.DrawRectangle( x, y, 310, 310 );
+
+ dc.SetClippingRegion( x + 10, y + 10, 100, 270 );
+
+ dc.SetBrush( *wxRED_BRUSH );
+ dc.DrawRectangle( x, y, 310, 310 );
+
+ dc.SetClippingRegion( x + 10, y + 10, 100, 100 );
+
+ dc.SetBrush( *wxCYAN_BRUSH );
+ dc.DrawRectangle( x, y, 310, 310 );
+
+ dc.DestroyClippingRegion();
+
+ wxRegion region(x + 110, y + 20, 100, 270);
+#if !defined(__WXMOTIF__) && !defined(__WXMAC__)
+ if ( !firstTime )
+ region.Offset(10, 10);
+#endif
+ dc.SetDeviceClippingRegion(region);
+
+ dc.SetBrush( *wxGREY_BRUSH );
+ dc.DrawRectangle( x, y, 310, 310 );
+
+ if (m_smile_bmp.Ok())
+ {
+ dc.DrawBitmap( m_smile_bmp, x + 150, y + 150, true );
+ dc.DrawBitmap( m_smile_bmp, x + 130, y + 10, true );
+ dc.DrawBitmap( m_smile_bmp, x + 130, y + 280, true );
+ dc.DrawBitmap( m_smile_bmp, x + 100, y + 70, true );
+ dc.DrawBitmap( m_smile_bmp, x + 200, y + 70, true );
+ }
+}
+
+#if TEST_CAIRO_EVERYWHERE
+extern wxGraphicsRenderer* gCairoRenderer;
+#endif
+