// Define the repainting behaviour void MyCanvas::OnDraw(wxDC& dc) { dc.SetFont(*wxSWISS_FONT); dc.SetPen(*wxGREEN_PEN); dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); dc.SetBrush(*wxCYAN_BRUSH); dc.SetPen(*wxRED_PEN); dc.DrawRectangle(100, 100, 100, 50); dc.DrawRoundedRectangle(150, 150, 100, 50, 20); dc.DrawEllipse(250, 250, 100, 50); #if wxUSE_SPLINES dc.DrawSpline(50, 200, 50, 100, 200, 10); #endif // wxUSE_SPLINES dc.DrawLine(50, 230, 200, 230); dc.DrawText(wxT("This is a test string"), 50, 230); wxPoint points[3]; points[0].x = 200; points[0].y = 300; points[1].x = 100; points[1].y = 400; points[2].x = 300; points[2].y = 400; dc.DrawPolygon(3, points); }
void Group::DrawConnections(wxDC& dc) const { for (List<InputPort *>::Iterator input = m_inputs.Iterate(); !input; input++) { dc.SetPen(*wxBLACK_PEN); for (List<Shape *>::Iterator i = (*input)->SourceIterator(); !i; i++) { wxPoint points[4]; points[2] = points[3] = (*input)->GetConnPoint(); points[0] = points[1] = (*i)->GetConnPoint(); points[1].x += 20; points[2].x -= 20; dc.DrawSpline(4, points); dc.SetPen(*wxRED_PEN); } } }
void MyApp::Draw(wxDC&dc) { // This routine just draws a bunch of random stuff on the screen so that we // can check that different types of object are being drawn consistently // between the screen image, the print preview image (at various zoom // levels), and the printed page. dc.SetBackground(*wxWHITE_BRUSH); // dc.Clear(); dc.SetFont(m_testFont); // dc.SetBackgroundMode(wxTRANSPARENT); dc.SetPen(*wxBLACK_PEN); dc.SetBrush(*wxLIGHT_GREY_BRUSH); dc.DrawRectangle(0, 0, 230, 350); dc.DrawLine(0, 0, 229, 349); dc.DrawLine(229, 0, 0, 349); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetBrush(*wxCYAN_BRUSH); dc.SetPen(*wxRED_PEN); dc.DrawRoundedRectangle(0, 20, 200, 80, 20); dc.DrawText( wxT("Rectangle 200 by 80"), 40, 40); dc.SetPen( wxPen(*wxBLACK, 0, wxPENSTYLE_DOT_DASH) ); dc.DrawEllipse(50, 140, 100, 50); dc.SetPen(*wxRED_PEN); dc.DrawText( wxT("Test message: this is in 10 point text"), 10, 180); #if wxUSE_UNICODE const char *test = "Hebrew שלום -- Japanese (日本語)"; wxString tmp = wxConvUTF8.cMB2WC( test ); dc.DrawText( tmp, 10, 200 ); #endif wxPoint points[5]; points[0].x = 0; points[0].y = 0; points[1].x = 20; points[1].y = 0; points[2].x = 20; points[2].y = 20; points[3].x = 10; points[3].y = 20; points[4].x = 10; points[4].y = -20; dc.DrawPolygon( 5, points, 20, 250, wxODDEVEN_RULE ); dc.DrawPolygon( 5, points, 50, 250, wxWINDING_RULE ); dc.DrawEllipticArc( 80, 250, 60, 30, 0.0, 270.0 ); points[0].x = 150; points[0].y = 250; points[1].x = 180; points[1].y = 250; points[2].x = 180; points[2].y = 220; points[3].x = 200; points[3].y = 220; dc.DrawSpline( 4, points ); dc.DrawArc( 20,10, 10,10, 25,40 ); wxString str; int i = 0; str.Printf( wxT("---- Text at angle %d ----"), i ); dc.DrawRotatedText( str, 100, 300, i ); i = m_angle; str.Printf( wxT("---- Text at angle %d ----"), i ); dc.DrawRotatedText( str, 100, 300, i ); wxIcon my_icon = wxICON(sample); dc.DrawIcon( my_icon, 100, 100); if (m_bitmap.IsOk()) dc.DrawBitmap( m_bitmap, 10, 10 ); #if wxUSE_GRAPHICS_CONTEXT wxGraphicsContext *gc = NULL; wxPrinterDC *printer_dc = wxDynamicCast( &dc, wxPrinterDC ); if (printer_dc) gc = wxGraphicsContext::Create( *printer_dc ); wxWindowDC *window_dc = wxDynamicCast( &dc, wxWindowDC ); if (window_dc) gc = wxGraphicsContext::Create( *window_dc ); #ifdef __WXMSW__ wxEnhMetaFileDC *emf_dc = wxDynamicCast( &dc, wxEnhMetaFileDC ); if (emf_dc) gc = wxGraphicsContext::Create( *emf_dc ); #endif if (gc) { // make a path that contains a circle and some lines, centered at 100,100 gc->SetPen( *wxRED_PEN ); wxGraphicsPath path = gc->CreatePath(); path.AddCircle( 50.0, 50.0, 50.0 ); path.MoveToPoint(0.0, 50.0); path.AddLineToPoint(100.0, 50.0); path.MoveToPoint(50.0, 0.0); path.AddLineToPoint(50.0, 100.0 ); path.CloseSubpath(); path.AddRectangle(25.0, 25.0, 50.0, 50.0); gc->StrokePath(path); // draw some text wxString text("Text by wxGraphicsContext"); gc->SetFont( m_testFont, *wxBLACK ); gc->DrawText(text, 25.0, 60.0); // draw rectangle around the text double w, h, d, el; gc->GetTextExtent(text, &w, &h, &d, &el); gc->SetPen( *wxBLACK_PEN ); gc->DrawRectangle(25.0, 60.0, w, h); delete gc; } #endif }
// Define the repainting behaviour void MyCanvas::OnDraw(wxDC& dc) { // vars to use ... #if wxUSE_STATUSBAR wxString s; #endif // wxUSE_STATUSBAR wxPen wP; wxBrush wB; wxPoint points[6]; wxColour wC; wxFont wF; dc.SetFont(*wxSWISS_FONT); dc.SetPen(*wxGREEN_PEN); switch (m_index) { default: case 0: // draw lines to make a cross dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); // draw point colored line and spline wP = *wxCYAN_PEN; wP.SetWidth(3); dc.SetPen(wP); dc.DrawPoint (25,15); dc.DrawLine(50, 30, 200, 30); dc.DrawSpline(50, 200, 50, 100, 200, 10); #if wxUSE_STATUSBAR s = wxT("Green Cross, Cyan Line and spline"); #endif // wxUSE_STATUSBAR break; case 1: // draw standard shapes dc.SetBrush(*wxCYAN_BRUSH); dc.SetPen(*wxRED_PEN); dc.DrawRectangle(10, 10, 100, 70); wB = wxBrush (wxT("DARK ORCHID"), wxBRUSHSTYLE_TRANSPARENT); dc.SetBrush (wB); dc.DrawRoundedRectangle(50, 50, 100, 70, 20); dc.SetBrush (wxBrush(wxT("GOLDENROD")) ); dc.DrawEllipse(100, 100, 100, 50); points[0].x = 100; points[0].y = 200; points[1].x = 70; points[1].y = 260; points[2].x = 160; points[2].y = 230; points[3].x = 40; points[3].y = 230; points[4].x = 130; points[4].y = 260; points[5].x = 100; points[5].y = 200; dc.DrawPolygon(5, points); dc.DrawLines (6, points, 160); #if wxUSE_STATUSBAR s = wxT("Blue rectangle, red edge, clear rounded rectangle, gold ellipse, gold and clear stars"); #endif // wxUSE_STATUSBAR break; case 2: // draw text in Arial or similar font dc.DrawLine(50,25,50,35); dc.DrawLine(45,30,55,30); dc.DrawText(wxT("This is a Swiss-style string"), 50, 30); wC = dc.GetTextForeground(); dc.SetTextForeground (wxT("FIREBRICK")); // no effect in msw ?? 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); wF = wxFont ( 18, wxROMAN, wxITALIC, wxBOLD, false, wxT("Times New Roman")); dc.SetFont(wF); dc.SetTextForeground (wC); dc.DrawText(wxT("This is a Times-style string"), 50, 60); #if wxUSE_STATUSBAR s = wxT("Swiss, Times text; red text, rotated and colored orange"); #endif // wxUSE_STATUSBAR break; case 3 : // four arcs start and end points, center dc.SetBrush(*wxGREEN_BRUSH); dc.DrawArc ( 200,300, 370,230, 300,300 ); dc.SetBrush(*wxBLUE_BRUSH); dc.DrawArc ( 270-50, 270-86, 270-86, 270-50, 270,270 ); dc.SetDeviceOrigin(-10,-10); dc.DrawArc ( 270-50, 270-86, 270-86, 270-50, 270,270 ); dc.SetDeviceOrigin(0,0); wP.SetColour (wxT("CADET BLUE")); dc.SetPen(wP); dc.DrawArc ( 75,125, 110, 40, 75, 75 ); wP.SetColour (wxT("SALMON")); dc.SetPen(wP); dc.SetBrush(*wxRED_BRUSH); //top left corner, width and height, start and end angle // 315 same center and x-radius as last pie-arc, half Y radius dc.DrawEllipticArc(25,50,100,50,180.0,45.0); wP = *wxCYAN_PEN; wP.SetWidth(3); dc.SetPen(wP); //wxTRANSPARENT)); 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); dc.DrawEllipticArc(300,100,200,100,90.0,345.0); #if wxUSE_STATUSBAR s = wxT("This is an arc test page"); #endif // wxUSE_STATUSBAR break; case 4: dc.DrawCheckMark ( 30,30,25,25); dc.SetBrush (wxBrush (wxT("SALMON"),wxBRUSHSTYLE_TRANSPARENT)); dc.DrawCheckMark ( 80,50,75,75); dc.DrawRectangle ( 80,50,75,75); #if wxUSE_STATUSBAR s = wxT("Two check marks"); #endif // wxUSE_STATUSBAR break; case 5: wF = wxFont ( 18, wxROMAN, wxITALIC, wxBOLD, false, wxT("Times New Roman")); dc.SetFont(wF); dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); dc.DrawText(wxT("This is an 18pt string"), 50, 60); // rescale and draw in blue wP = *wxCYAN_PEN; dc.SetPen(wP); dc.SetUserScale (2.0,0.5); dc.SetDeviceOrigin(200,0); dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); dc.DrawText(wxT("This is an 18pt string 2 x 0.5 UserScaled"), 50, 60); dc.SetUserScale (2.0,2.0); dc.SetDeviceOrigin(200,200); dc.DrawText(wxT("This is an 18pt string 2 x 2 UserScaled"), 50, 60); wP = *wxRED_PEN; dc.SetPen(wP); dc.SetUserScale (1.0,1.0); dc.SetDeviceOrigin(0,10); dc.SetMapMode (wxMM_METRIC); //svg ignores this dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); dc.DrawText(wxT("This is an 18pt string in MapMode"), 50, 60); #if wxUSE_STATUSBAR s = wxT("Scaling test page"); #endif // wxUSE_STATUSBAR break; case 6: 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); #endif // wxUSE_STATUSBAR }
//void simple_vector_layer::Draw(wxDC &dc, wxCoord x, wxCoord y, bool transparent, double zoomFactor, double translationX, double translationY, double resolution) const void simple_vector_layer::draw(wxDC &dc, wxCoord x, wxCoord y, bool transparent) const { wxPen pen; wxBrush brush; // 2D pen.SetWidth(m_polygon_border_width); pen.SetColour(m_polygon_border_color); pen.SetStyle(m_polygon_border_style); brush.SetColour(m_polygon_inner_color); brush.SetStyle(m_polygon_inner_style); dc.SetPen(pen); dc.SetBrush(brush); for (unsigned int i = 0; i < m_circles.size(); i++) { wxPoint p = transform().from_local_int(m_circles[i]); wxCoord r = static_cast<wxCoord>(m_circles[i].radius / transform().zoom_factor()); dc.DrawCircle(p, r); } // Ellipses alignees for (unsigned int i=0;i<m_ellipses.size();++i) { wxPoint p = transform().from_local_int(m_ellipses[i]); wxSize s( static_cast<wxCoord>(2*m_ellipses[i].a/transform().zoom_factor()), static_cast<wxCoord>(2*m_ellipses[i].b/transform().zoom_factor()) ); dc.DrawEllipse(p,s); //dc.DrawEllipticArc(p,s,0.,90.); //dc.DrawEllipticArcRot(p,s,0.,90.); } // Ellipses non alignees for (unsigned int i=0;i<m_rotatedellipses.size();++i) { std::vector<wxPoint> points; points.reserve( m_rotatedellipses[i].controlPoints.size() ); for (unsigned int j=0;j<m_rotatedellipses[i].controlPoints.size();++j) points.push_back(transform().from_local_int(m_rotatedellipses[i].controlPoints[j])); dc.DrawSpline(static_cast<int>(points.size()),&points.front()); } for (unsigned int i=0;i<m_polygons.size();++i) { std::vector<wxPoint> points; points.reserve( m_polygons[i].size() ); for (unsigned int j=0;j<m_polygons[i].size();++j) points.push_back(transform().from_local_int(m_polygons[i][j])); dc.DrawPolygon( static_cast<int>(points.size()) , &(points.front()) ); } // 1D pen.SetColour(m_line_color); pen.SetWidth(m_line_width); pen.SetStyle(m_line_style); dc.SetPen(pen); for (unsigned int i = 0; i < m_arcs.size(); i++) { const arc_type &local_tab = m_arcs[i]; for (unsigned int j = 0; j < local_tab.arc_points.size() - 1; ++j) { wxPoint p = transform().from_local_int(local_tab.arc_points[j ]); wxPoint q = transform().from_local_int(local_tab.arc_points[j+1]); dc.DrawLine(p,q); } } // Splines for (unsigned int i=0;i<m_splines.size();++i) { const spline_type& spline = m_splines[i]; std::vector<wxPoint> points; unsigned int n = static_cast<int>(spline.size()); for (unsigned int j=0;j<n;++j) { wxPoint p = transform().from_local_int(spline[j]); points.push_back(p); } dc.DrawSpline(n,&points.front()); } // 0D pen.SetColour(m_point_color); pen.SetWidth(m_point_width); dc.SetPen(pen); for (unsigned int i = 0; i < m_points.size(); i++) { wxPoint p = transform().from_local_int(m_points[i]); //dc.DrawLine(p); dc.DrawPoint(p); } // Text if(text_visibility()) { pen.SetColour(m_text_color); dc.SetPen(pen); for (unsigned int i = 0; i < m_texts.size(); i++) { wxPoint p = transform().from_local_int(m_texts[i].first); //dc.DrawLine(p); dc.DrawText(wxString(m_texts[i].second.c_str(),*wxConvCurrent),p); } } }
void MyFrame::Draw(wxDC& dc) { // This routine just draws a bunch of random stuff on the screen so that we // can check that different types of object are being drawn consistently // between the screen image, the print preview image (at various zoom // levels), and the printed page. dc.SetBackground(*wxWHITE_BRUSH); dc.Clear(); dc.SetFont(wxGetApp().m_testFont); dc.SetBackgroundMode(wxTRANSPARENT); dc.SetPen(*wxBLACK_PEN); dc.SetBrush(*wxLIGHT_GREY_BRUSH); // dc.SetBackground(*wxWHITE_BRUSH); dc.DrawRectangle(0, 0, 230, 350); dc.DrawLine(0, 0, 229, 349); dc.DrawLine(229, 0, 0, 349); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetBrush(*wxCYAN_BRUSH); dc.SetPen(*wxRED_PEN); dc.DrawRoundedRectangle(0, 20, 200, 80, 20); dc.DrawText( wxT("Rectangle 200 by 80"), 40, 40); dc.SetPen( wxPen(*wxBLACK,0,wxDOT_DASH) ); dc.DrawEllipse(50, 140, 100, 50); dc.SetPen(*wxRED_PEN); dc.DrawText( wxT("Test message: this is in 10 point text"), 10, 180); #if wxUSE_UNICODE //char *test = "Hebrew שלום -- Japanese (日本語)"; //wxString tmp = wxConvUTF8.cMB2WC( test ); //dc.DrawText( tmp, 10, 200 ); #endif wxPoint points[5]; points[0].x = 0; points[0].y = 0; points[1].x = 20; points[1].y = 0; points[2].x = 20; points[2].y = 20; points[3].x = 10; points[3].y = 20; points[4].x = 10; points[4].y = -20; dc.DrawPolygon( 5, points, 20, 250, wxODDEVEN_RULE ); dc.DrawPolygon( 5, points, 50, 250, wxWINDING_RULE ); dc.DrawEllipticArc( 80, 250, 60, 30, 0.0, 270.0 ); points[0].x = 150; points[0].y = 250; points[1].x = 180; points[1].y = 250; points[2].x = 180; points[2].y = 220; points[3].x = 200; points[3].y = 220; dc.DrawSpline( 4, points ); dc.DrawArc( 20,10, 10,10, 25,40 ); wxString str; int i = 0; str.Printf( wxT("---- Text at angle %d ----"), i ); dc.DrawRotatedText( str, 100, 300, i ); i = m_angle; str.Printf( wxT("---- Text at angle %d ----"), i ); dc.DrawRotatedText( str, 100, 300, i ); wxIcon my_icon = wxICON(mondrian) ; dc.DrawIcon( my_icon, 100, 100); if (m_bitmap.Ok()) { dc.DrawBitmap(m_bitmap, 10, 25); } if (m_imgUp.Ok()) { dc.DrawBitmap(m_imgUp, 300, 200); dc.DrawBitmap(m_imgUp, 300, 250, true); } }
void RawDataVisualizeFrame::DrawIndividualRawDensityPlot(wxDC& dc){ //PrepareDC(dc); //SetUpDC(dc); int w,h; dc.GetSize(&w, &h); /* labeledplotAxes myAxes(wxPoint(80,80), wxPoint(w-30*5,h-30*5), wxRealPoint(0.0,1000.0), wxRealPoint(50.0,4000.0), true); */ int min_x = min((int)(pltarea_min_x*(double)w),(int)(160*(double)(dc.GetPPI().x)/(double)72)); int min_y = min((int)(pltarea_min_y*(double)h),(int)(165*(double)(dc.GetPPI().x)/(double)72)); int max_x = max((int)((pltarea_max_x-pltarea_min_x)*(double)w),(int)(w - 100*(double)(dc.GetPPI().x)/(double)72 - min_x)); int max_y = max((int)((pltarea_max_y-pltarea_min_y)*(double)h),(int)(h-160*(double)(dc.GetPPI().x)/(double)72 - min_y)); labeledplotAxes myAxes(dc, wxPoint(min_x,min_y), wxPoint(max_x,max_y), wxRealPoint(3.0,0.0), wxRealPoint(15.5,1.0), true); dc.Clear(); myAxes.setBackgroundColor(*wxWHITE_BRUSH); myAxes.setupDCforPlot(dc); // myAxes.addGrid(2, 0.2); wxArrayDouble xtickpoints; wxArrayDouble ytickpoints; int i,j; wxArrayString x_tick_labels; wxArrayString y_tick_labels; for (i=3; i <= 15; i++){ xtickpoints.Add((double)i); x_tick_labels.Add(wxString::Format(_T("%d"), i)); } for (i =0; i <= 10; i++){ ytickpoints.Add((double)i/10.0); y_tick_labels.Add(wxString::Format(_T("%.2f"), i/10.0)); } myAxes.setTickLocationX(xtickpoints); myAxes.setTickLocationY(ytickpoints); myAxes.setTickLabelsX(x_tick_labels); myAxes.setTickLabelsY(y_tick_labels); wxString x_label = wxT("log2 PM"); wxString y_label = wxT("Density"); myAxes.setAxisLabelX(x_label); myAxes.setAxisLabelY(y_label); myAxes.setTitle(MyRawData->GetArrayNames()[whichdensity]); wxPoint xsq[512]; j = whichdensity; for (i =0; i < 512; i++){ xsq[i] = myAxes.FindPoint(wxRealPoint((*DensityPlotStatistics_x)[j*512 + i], (*DensityPlotStatistics_y)[j*512 + i])); } dc.DrawSpline(WXSIZEOF(xsq),xsq); dc.DestroyClippingRegion(); myAxes.Draw(dc); }
// Define the repainting behaviour void MyCanvas::OnDraw(wxDC& dc) { // vars to use ... #if wxUSE_STATUSBAR wxString s ; #endif // wxUSE_STATUSBAR wxPen wP ; wxBrush wB ; wxPoint points[6]; wxColour wC; wxFont wF ; dc.SetFont(*wxSWISS_FONT); dc.SetPen(*wxGREEN_PEN); switch (m_index) { default: case 0: // draw lines to make a cross dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); // draw point colored line and spline wP = *wxCYAN_PEN ; wP.SetWidth(3); dc.SetPen(wP); dc.DrawPoint (25,15) ; dc.DrawLine(50, 30, 200, 30); dc.DrawSpline(50, 200, 50, 100, 200, 10); #if wxUSE_STATUSBAR s = wxT("Green Cross, Cyan Line and spline"); #endif // wxUSE_STATUSBAR break ; case 1: // draw standard shapes dc.SetBrush(*wxCYAN_BRUSH); dc.SetPen(*wxRED_PEN); dc.DrawRectangle(10, 10, 100, 70); wB = wxBrush (_T("DARK ORCHID"), wxTRANSPARENT); dc.SetBrush (wB); dc.DrawRoundedRectangle(50, 50, 100, 70, 20); dc.SetBrush (wxBrush(_T("GOLDENROD"), wxSOLID) ); dc.DrawEllipse(100, 100, 100, 50); points[0].x = 100; points[0].y = 200; points[1].x = 70; points[1].y = 260; points[2].x = 160; points[2].y = 230; points[3].x = 40; points[3].y = 230; points[4].x = 130; points[4].y = 260; points[5].x = 100; points[5].y = 200; dc.DrawPolygon(5, points); dc.DrawLines (6, points, 160); #if wxUSE_STATUSBAR s = wxT("Blue rectangle, red edge, clear rounded rectangle, gold ellipse, gold and clear stars"); #endif // wxUSE_STATUSBAR break ; case 2: // draw text in Arial or similar font dc.DrawLine(50,25,50,35); dc.DrawLine(45,30,55,30); dc.DrawText(wxT("This is a Swiss-style string"), 50, 30); wC = dc.GetTextForeground() ; dc.SetTextForeground (_T("FIREBRICK")); // no effect in msw ?? dc.SetTextBackground (_T("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); wF = wxFont ( 18, wxROMAN, wxITALIC, wxBOLD, false, wxT("Times New Roman")); dc.SetFont(wF); dc.SetTextForeground (wC) ; dc.DrawText(wxT("This is a Times-style string"), 50, 60); #if wxUSE_STATUSBAR s = wxT("Swiss, Times text; red text, rotated and colored orange"); #endif // wxUSE_STATUSBAR break ; case 3 : // four arcs start and end points, center dc.SetBrush(*wxGREEN_BRUSH); dc.DrawArc ( 200,300, 370,230, 300,300 ); dc.SetBrush(*wxBLUE_BRUSH); dc.DrawArc ( 270-50, 270-86, 270-86, 270-50, 270,270 ); dc.SetDeviceOrigin(-10,-10); dc.DrawArc ( 270-50, 270-86, 270-86, 270-50, 270,270 ); dc.SetDeviceOrigin(0,0); wP.SetColour (_T("CADET BLUE")); dc.SetPen(wP); dc.DrawArc ( 75,125, 110, 40, 75, 75 ); wP.SetColour (_T("SALMON")); dc.SetPen(wP); dc.SetBrush(*wxRED_BRUSH); //top left corner, width and height, start and end angle // 315 same center and x-radius as last pie-arc, half Y radius dc.DrawEllipticArc(25,50,100,50,180.0,45.0) ; wP = *wxCYAN_PEN ; wP.SetWidth(3); dc.SetPen(wP); //wxTRANSPARENT)); dc.SetBrush (wxBrush (_T("SALMON"),wxSOLID)) ; dc.DrawEllipticArc(300, 0,200,100, 0.0,145.0) ; //same end point dc.DrawEllipticArc(300, 50,200,100,90.0,145.0) ; dc.DrawEllipticArc(300,100,200,100,90.0,345.0) ; #if wxUSE_STATUSBAR s = wxT("This is an arc test page"); #endif // wxUSE_STATUSBAR break ; case 4: dc.DrawCheckMark ( 30,30,25,25); dc.SetBrush (wxBrush (_T("SALMON"),wxTRANSPARENT)); dc.DrawCheckMark ( 80,50,75,75); dc.DrawRectangle ( 80,50,75,75); #if wxUSE_STATUSBAR s = wxT("Two check marks"); #endif // wxUSE_STATUSBAR break ; case 5: wF = wxFont ( 18, wxROMAN, wxITALIC, wxBOLD, false, wxT("Times New Roman")); dc.SetFont(wF); dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); dc.DrawText(wxT("This is an 18pt string"), 50, 60); // rescale and draw in blue wP = *wxCYAN_PEN ; dc.SetPen(wP); dc.SetUserScale (2.0,0.5); dc.SetDeviceOrigin(200,0); dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); dc.DrawText(wxT("This is an 18pt string 2 x 0.5 UserScaled"), 50, 60); dc.SetUserScale (2.0,2.0); dc.SetDeviceOrigin(200,200); dc.DrawText(wxT("This is an 18pt string 2 x 2 UserScaled"), 50, 60); wP = *wxRED_PEN ; dc.SetPen(wP); dc.SetUserScale (1.0,1.0); dc.SetDeviceOrigin(0,10); dc.SetMapMode (wxMM_METRIC) ; //svg ignores this dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); dc.DrawText(wxT("This is an 18pt string in MapMode"), 50, 60); #if wxUSE_STATUSBAR s = wxT("Scaling test page"); #endif // wxUSE_STATUSBAR break ; case 6: dc.DrawIcon( wxIcon(mondrian_xpm), 10, 10 ); dc.DrawBitmap ( wxBitmap(svgbitmap_xpm), 50,15); #if wxUSE_STATUSBAR s = wxT("Icon and Bitmap "); #endif // wxUSE_STATUSBAR break ; } #if wxUSE_STATUSBAR m_child->SetStatusText(s); #endif // wxUSE_STATUSBAR }
void GLCanvas::drawUserInterface(wxDC &dc) const { wxSize size = GetSize(); wxPoint pos(0, 0); pos.x = size.x - _buttonSize; wxSize buttonSize(_buttonSize, _buttonSize); wxPen whitePen(wxColour(255, 255, 255)); whitePen.SetWidth(1); wxPen blackPen(wxColour(0, 0, 0)); blackPen.SetWidth(1); wxPen greenPen(wxColour(0, 255, 0)); wxBrush brush; dc.SetPen(blackPen); brush.SetColour(wxColour(0, 0, 0)); dc.SetBrush(brush); // draw black background behind all buttons dc.DrawRectangle(pos.x - 1, pos.y, _buttonSize + 1, _numButtons * _buttonSize + 1); // draw grit if (_style & DRAW_GRID) { dc.SetPen(greenPen); } else { dc.SetPen(whitePen); } dc.DrawRectangle(pos.x + 1, pos.y + 1, _buttonSize - 2, _buttonSize - 2); dc.DrawLine(pos.x + _buttonSizeHalf, pos.y + 1, pos.x + _buttonSizeHalf, pos.y + _buttonSize - 1); dc.DrawLine(pos.x + 1, pos.y + _buttonSizeHalf, size.x - 1, pos.y + _buttonSizeHalf); pos.y += _buttonSize; // draw a cube for showing AABB if (_style & DRAW_AABB) { dc.SetPen(greenPen); } else { dc.SetPen(whitePen); } dc.DrawRectangle(pos.x + _buttonSizeHalf - 3, pos.y + 3, _buttonSizeHalf, _buttonSizeHalf); dc.DrawRectangle(pos.x + 2, pos.y + _buttonSizeHalf - 2, _buttonSizeHalf, _buttonSizeHalf); dc.DrawLine(pos.x + 2, pos.y + _buttonSizeHalf - 2, pos.x + _buttonSizeHalf - 3, pos.y + 3); dc.DrawLine(pos.x + 2 + _buttonSizeHalf, pos.y + _buttonSizeHalf - 2, pos.x + _buttonSize - 3, pos.y + 3); dc.DrawLine(pos.x + 2 + _buttonSizeHalf, pos.y + _buttonSize - 3, pos.x + _buttonSize - 3, pos.y + _buttonSizeHalf + 2); pos.y += _buttonSize; // draw coordinate system if (_style & DRAW_LOCAL_COORDINATE_SYSTEM) { dc.SetPen(greenPen); } else { dc.SetPen(whitePen); } dc.DrawLine(pos.x + 2, pos.y + 3, pos.x + 2, pos.y + _buttonSize - 2); dc.DrawLine(pos.x + 2, pos.y + _buttonSize - 2, size.x - 3, pos.y + _buttonSize - 2); dc.DrawLine(pos.x + 2, pos.y + _buttonSize - 2, pos.x + _buttonSize - 6, pos.y + _buttonSizeHalf + 2); pos.y += _buttonSize; // draw joint constraints if (_style & DRAW_JOINT_CONSTRAINTS) { dc.SetPen(greenPen); } else { dc.SetPen(whitePen); } //dc.DrawCircle(pos.x + _buttonSizeHalf, pos.y + _buttonSizeHalf, _buttonSizeHalf - 3); //dc.DrawArc(pos.x + 4, pos.y + 5, pos.x + 4, pos.y + _buttonSize - 5, pos.x + _buttonSizeHalf + 2, pos.y + _buttonSizeHalf); //dc.DrawCircle(pos.x + 6, pos.y + _buttonSizeHalf, 3); dc.DrawEllipse(pos.x + 4, pos.y + 3, _buttonSizeHalf - 5, _buttonSizeHalf + 4); dc.DrawLine(pos.x + 8, pos.y + 3, pos.x + _buttonSizeHalf + 5, pos.y + _buttonSizeHalf); dc.DrawLine(pos.x + 8, pos.y + _buttonSizeHalf + 7, pos.x + _buttonSizeHalf + 5, pos.y + _buttonSizeHalf); pos.y += _buttonSize; // draw rotation axis if (_style & DRAW_ROTATION_AXIS) { dc.SetPen(greenPen); } else { dc.SetPen(whitePen); } dc.DrawArc(pos.x + _buttonSizeHalf + 2, pos.y + _buttonSize - 2, pos.x + _buttonSizeHalf, pos.y + _buttonSizeHalf + 1, pos.x + 2, pos.y + _buttonSize - 2); //dc.DrawEllipse(pos.x + 6, pos.y + 5, _buttonSize - 12, _buttonSize - 10); //dc.DrawCircle(pos.x + _buttonSizeHalf + 2, pos.y + _buttonSizeHalf - 2, 3); dc.DrawLine(pos.x + 2, pos.y + _buttonSize - 2, pos.x + _buttonSize - 2, pos.y + 2); dc.DrawLine(pos.x + 2, pos.y + _buttonSize - 2, pos.x + _buttonSize - 2, pos.y + _buttonSize - 2); pos.y += _buttonSize; // draw label if (_style & DRAW_LABEL) { dc.SetPen(greenPen); } else { dc.SetPen(whitePen); } dc.DrawRoundedRectangle(pos.x + 4, pos.y + 3, _buttonSize - 5, _buttonSizeHalf, 3.0); dc.DrawSpline(pos.x + 4, pos.y + _buttonSizeHalf - 3, pos.x + 1, pos.y + _buttonSizeHalf + 4, pos.x + _buttonSizeHalf + 4, pos.y + _buttonSizeHalf + 6); pos.y += _buttonSize; // draw locate skeleton button dc.SetPen(whitePen); dc.DrawLine(pos.x + _buttonSizeHalf, pos.y + 2, pos.x + _buttonSizeHalf, pos.y + _buttonSize - 1); dc.DrawLine(pos.x + 2, pos.y + _buttonSizeHalf, size.x - 1, pos.y + _buttonSizeHalf); dc.DrawCircle(pos.x + _buttonSizeHalf, pos.y + _buttonSizeHalf, _buttonSizeHalf - 4); brush.SetColour(wxColour(255, 255, 255)); dc.SetBrush(brush); dc.DrawCircle(pos.x + _buttonSizeHalf, pos.y + _buttonSizeHalf, _buttonSizeHalf - 8); pos.y += _buttonSize; // draw settings button dc.DrawCircle(pos.x + _buttonSizeHalf, pos.y + _buttonSizeHalf, _buttonSizeHalf - 3); dc.SetPen(blackPen); brush.SetColour(wxColour(0, 0, 0)); dc.SetBrush(brush); dc.DrawCircle(pos.x + _buttonSizeHalf + 6, pos.y + _buttonSizeHalf, 2); dc.DrawCircle(pos.x + _buttonSizeHalf - 6, pos.y + _buttonSizeHalf, 2); dc.DrawCircle(pos.x + _buttonSizeHalf, pos.y + _buttonSizeHalf + 6, 2); dc.DrawCircle(pos.x + _buttonSizeHalf, pos.y + _buttonSizeHalf - 6, 2); dc.SetPen(whitePen); dc.DrawCircle(pos.x + _buttonSizeHalf, pos.y + _buttonSizeHalf, _buttonSizeHalf - 7); }