void SeqPlot::drawSymbol ( char c , wxDC &dc , int x1 , int y1 , int x2 , int y2 ) { dc.SetPen(*wxBLACK_PEN); int w = x2 - x1 ; int h = y2 - y1 ; if ( c == 'T' ) { x2--; w--; y1++; h--; int y3 = y2 - h/4 ; dc.DrawLine ( x1 , y1 , x2 - w/3 , y1 ) ; dc.DrawLine ( x1 , y3 , x2 - w/3 , y3 ) ; dc.DrawArc ( x2 - w/3 , y3 , x2 - w/3 , y1 , x2 - w/3 , (y1+y3)/2 ) ; dc.SetPen(*wxWHITE_PEN); dc.DrawLine ( x2 - w/3 , y3-1 , x2 - w/3 , y1+1 ) ; dc.SetPen(*wxBLACK_PEN); dc.DrawLine ( x1 , y3 , x1 + w*2/3 , y3 - h/2 ) ; dc.DrawLine ( x1 , y3 , x1 + w*2/3 , y3 + h/2 ) ; } else if ( c == 'b' ) { x1 += w/2 - h/6 ; dc.DrawLine ( x1 , y1 , x1 , y2 ) ; dc.DrawArc ( x1 , y1+h/3 , x1 , y1 , x1 , y1+h/6 ) ; dc.DrawArc ( x1 , y1+h*2/3 , x1 , y1+h/3 , x1 , y1+h*3/6 ) ; } else if ( c == 'a' ) { int x3 = x2 - w/3 ; dc.DrawArc ( x3 , y1 + h/3 , x3 , y2 - h/3 , x1 + w/2 , y1 + h/2 ) ; dc.SetPen(*wxWHITE_PEN); dc.DrawLine ( x3 , y1 + h/3 + 1 , x1 + w/2 , y1 + h/2 ) ; dc.DrawLine ( x3 , y2 - h/3 - 1 , x1 + w/2 , y1 + h/2 ) ; dc.SetPen(*wxBLACK_PEN); dc.DrawLine ( x3 , y1 + h/3 , x2 , y2 ) ; dc.DrawLine ( x3 , y2 - h/3 , x2 , y1 ) ; } }
void DrawCC_DrawCommandList(wxDC& dc, const std::vector<CC_DrawCommand>& draw_commands) { for (auto iter = draw_commands.begin(); iter != draw_commands.end(); ++iter) { switch (iter->mType) { case CC_DrawCommand::Line: dc.DrawLine(iter->x1, iter->y1, iter->x2, iter->y2); break; case CC_DrawCommand::Arc: dc.DrawArc(iter->x1, iter->y1, iter->x2, iter->y2, iter->xc, iter->yc); break; case CC_DrawCommand::Ignore: break; } } }
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 }
void ChipPackage::Draw(wxDC& dc, const wxSize& sz, const wxString& chipModel) { // set some GUI objects common to all packages-drawing code dc.SetPen(*wxBLACK_PEN); switch (Type) { case PDIP: case SOIC: case SSOP: { // some drawing constants: // in these package types, pins are organized in two columns: const unsigned int PinPerSide = GetPinCount()/2; if ((GetPinCount()%2) != 0) { wxLogWarning(_("Invalid odd pin count: %d"), GetPinCount()); return; } // choose reasonable package width&height to // - make best use of the available space // - avoid drawing package excessively big const unsigned int BoxW = sz.GetWidth()/3; const unsigned int BoxH = (unsigned int)((double)sz.GetHeight()*0.8); const unsigned int BoxX = (sz.GetWidth()-BoxW)/2; const unsigned int BoxY = (sz.GetHeight()-BoxH)/2; const unsigned int R = BoxW/6; if (int(BoxW/8) == 0) return; // this happens for very small package sizes; // the check avoids an assertion failure from wxFont ctor later // draw the PIC package box dc.DrawRectangle(BoxX, BoxY, BoxW, BoxH); dc.DrawArc(sz.GetWidth()/2-R, BoxY + 1, sz.GetWidth()/2+R, BoxY + 1, sz.GetWidth()/2, BoxY + 1); dc.SetFont(wxFont(wxSize(0, BoxW/8), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD)); const wxSize& nameSz = dc.GetTextExtent(chipModel); dc.DrawRotatedText(chipModel, (sz.GetWidth() + nameSz.GetHeight())/2, (sz.GetHeight() - nameSz.GetWidth())/2, -90); // draw the pins DrawPins(dc, wxPoint(BoxX, BoxY), BoxH, 0, PinPerSide, 0, wxLEFT); DrawPins(dc, wxPoint(BoxX+BoxW, BoxY), BoxH, PinPerSide, GetPinCount(), DRAWPIN_INVERTED_ORDER, wxRIGHT); } break; case MQFP: case TQFP: case PLCC: case QFN: { // some drawing constants: // in these package types, pins are organized in two columns: const unsigned int PinPerSide = GetPinCount()/4; if ((GetPinCount()%4) != 0) { wxLogWarning(_("Invalid pin count: %d"), GetPinCount()); return; } // choose reasonable package width&height to // - make best use of the available space // - avoid drawing package excessively big const unsigned int BoxL = max(sz.GetWidth()/2,80); const unsigned int BoxX = (sz.GetWidth()-BoxL)/2; const unsigned int BoxY = (sz.GetHeight()-BoxL)/2; const unsigned int R = BoxL/10; if (int(BoxL/10) == 0) return; // this happens for very small package sizes; // the check avoids an assertion failure from wxFont ctor later // draw the PIC package box dc.DrawRectangle(BoxX, BoxY, BoxL, BoxL); dc.DrawCircle(BoxX+int(R*1.3), BoxY+int(R*1.3), R/2); // draw the name of the PIC model in the centre of the box dc.SetFont(wxFont(wxSize(0, BoxL/10), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD)); const wxSize& nameSz = dc.GetTextExtent(chipModel); dc.DrawText(chipModel, (sz.GetWidth() - nameSz.GetWidth())/2, (sz.GetHeight() - nameSz.GetHeight())/2); // draw the pins DrawPins(dc, wxPoint(BoxX, BoxY), BoxL, 0, PinPerSide, DRAWPIN_NUMBERS_INSIDE_PINS, wxLEFT); DrawPins(dc, wxPoint(BoxX, BoxY+BoxL), BoxL, PinPerSide, PinPerSide*2, DRAWPIN_NUMBERS_INSIDE_PINS, wxBOTTOM); DrawPins(dc, wxPoint(BoxX+BoxL, BoxY), BoxL, PinPerSide*2, PinPerSide*3, DRAWPIN_INVERTED_ORDER|DRAWPIN_NUMBERS_INSIDE_PINS, wxRIGHT); DrawPins(dc, wxPoint(BoxX, BoxY), BoxL, PinPerSide*3, PinPerSide*4, DRAWPIN_INVERTED_ORDER|DRAWPIN_NUMBERS_INSIDE_PINS, wxTOP); } break; default: break; } }
// 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 PreviewWindow::DrawPath(wxDC& dc) { wxColour cw = cCWColour; wxColour ccw = cCCWColour; for_each(toDraw.begin(), toDraw.end(), [&](PathPartSimple p) { switch(p.type) { case LINE_NORMAL: { dc.SetPen(wxPen(normalColour, lineWidth, wxSOLID)); p.start = TransformPoint(p.start); p.end = TransformPoint(p.end); dc.DrawLine(p.start.x, p.start.y, p.end.x, p.end.y); } break; case LINE_RAPID: { dc.SetPen(wxPen(rapidColour, lineWidth, wxLONG_DASH)); p.start = TransformPoint(p.start); p.end = TransformPoint(p.end); dc.DrawLine(p.start.x, p.start.y, p.end.x, p.end.y); } break; case CIRCLE_CW: { cw.Set(255-cw.Red(), cw.Green(), cw.Blue());//Differes two circles dc.SetPen(wxPen(cw, lineWidth, wxSOLID)); p.start = TransformPoint(p.start); p.end = TransformPoint(p.end); p.center = TransformPoint(p.center); dc.SetBrush(wxBrush(wxColour(), wxTRANSPARENT)); Vector2D distance(p.start, p.end); if(distance.Length() < 2) break; distance = Vector2D(p.center, p.start); if(distance.Length() < 2) break; dc.DrawArc(p.start.x, p.start.y, p.end.x, p.end.y, p.center.x, p.center.y); } break; case CIRCLE_CCW: { ccw.Set(255-ccw.Red(), ccw.Green(), ccw.Blue());//Differes two circles dc.SetPen(wxPen(ccw, lineWidth, wxSOLID)); p.start = TransformPoint(p.start); p.end = TransformPoint(p.end); p.center = TransformPoint(p.center); dc.SetBrush(wxBrush(wxColour(), wxTRANSPARENT)); Vector2D distance(p.start, p.end); if(distance.Length() < 2) break; distance = Vector2D(p.center, p.start); if(distance.Length() < 2) break; dc.DrawArc(p.end.x, p.end.y, p.start.x, p.start.y, p.center.x, p.center.y); } break; } }); for_each(offsetToDraw.begin(), offsetToDraw.end(), [&](PathPartSimple p) { dc.SetPen(wxPen(wxColor(255, 255, 255), lineWidth, wxSOLID)); switch(p.type) { case LINE_NORMAL: { p.start = TransformPoint(p.start); p.end = TransformPoint(p.end); dc.DrawLine(p.start.x, p.start.y, p.end.x, p.end.y); } break; case LINE_RAPID: { dc.SetPen(wxPen(wxColor(255, 255, 255), lineWidth, wxDOT_DASH)); p.start = TransformPoint(p.start); p.end = TransformPoint(p.end); dc.DrawLine(p.start.x, p.start.y, p.end.x, p.end.y); } break; case CIRCLE_CW: case OFFSET_CIRCLE_CW: { static wxColour c = cCWColour; c.Set(255-c.Red(), c.Green(), c.Blue()); p.start = TransformPoint(p.start); p.end = TransformPoint(p.end); p.center = TransformPoint(p.center); dc.SetBrush(wxBrush(wxColour(), wxTRANSPARENT)); Vector2D distance(p.start, p.end); if(distance.Length() < 2) break; distance = Vector2D(p.center, p.start); if(distance.Length() < 2) break; dc.DrawArc(p.start.x, p.start.y, p.end.x, p.end.y, p.center.x, p.center.y); } break; case CIRCLE_CCW: case OFFSET_CIRCLE_CCW: { static wxColour c = cCCWColour; c.Set(255-c.Red(), c.Green(), c.Blue()); p.start = TransformPoint(p.start); p.end = TransformPoint(p.end); p.center = TransformPoint(p.center); dc.SetBrush(wxBrush(wxColour(), wxTRANSPARENT)); Vector2D distance(p.start, p.end); if(distance.Length() < 2) break; distance = Vector2D(p.center, p.start); if(distance.Length() < 2) break; dc.DrawArc(p.end.x, p.end.y, p.start.x, p.start.y, p.center.x, p.center.y); } break; } }); }
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); } }
// 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); }
void wxLineCrossings::DrawCrossings(wxDiagram& WXUNUSED(diagram), wxDC& dc) { dc.SetBrush(*wxTRANSPARENT_BRUSH); long arcWidth = 8; wxNode* node = m_crossings.GetFirst(); while (node) { wxLineCrossing* crossing = (wxLineCrossing*) node->GetData(); // dc.DrawEllipse((long) (crossing->m_intersect.x - (arcWidth/2.0) + 0.5), (long) (crossing->m_intersect.y - (arcWidth/2.0) + 0.5), // arcWidth, arcWidth); // Let's do some geometry to find the points on either end of the arc. /* (x1, y1) |\ | \ | \ | \ | \ | |\ c c1 | a | \ | \ | - x <-- centre of arc a1 | b |\ | | \ c2 | a2 | \ | - \ | b2 \ | \ |_______________\ (x2, y2) b1 */ double a1 = wxMax(crossing->m_pt1.y, crossing->m_pt2.y) - wxMin(crossing->m_pt1.y, crossing->m_pt2.y) ; double b1 = wxMax(crossing->m_pt1.x, crossing->m_pt2.x) - wxMin(crossing->m_pt1.x, crossing->m_pt2.x) ; double c1 = sqrt( (a1*a1) + (b1*b1) ); double c = arcWidth / 2.0; double a = c * a1/c1 ; double b = c * b1/c1 ; // I'm not sure this is right, since we don't know which direction we should be going in - need // to know which way the line slopes and choose the sign appropriately. double arcX1 = crossing->m_intersect.x - b; double arcY1 = crossing->m_intersect.y - a; double arcX2 = crossing->m_intersect.x + b; double arcY2 = crossing->m_intersect.y + a; dc.SetPen(*wxBLACK_PEN); dc.DrawArc( (long) arcX1, (long) arcY1, (long) arcX2, (long) arcY2, (long) crossing->m_intersect.x, (long) crossing->m_intersect.y); dc.SetPen(*wxWHITE_PEN); dc.DrawLine( (long) arcX1, (long) arcY1, (long) arcX2, (long) arcY2 ); node = node->GetNext(); } }
void PreviewWindow::DrawOrigin(wxDC& dc) { Point offset2 = offset; wxSize size = GetSize(); offset2.x *= 1+wheelPosition/120*zoomFactor; offset2.y *= 1+wheelPosition/120*zoomFactor; offset2.x += size.GetWidth()/2; offset2.y += size.GetHeight()/2; dc.SetPen(*wxBLACK_PEN); dc.SetBrush(*wxWHITE_BRUSH); dc.DrawArc(offset2.x, offset2.y+originSize, offset2.x+originSize, offset2.y, offset2.x, offset2.y); dc.DrawArc(offset2.x, offset2.y-originSize, offset2.x-originSize, offset2.y, offset2.x, offset2.y); dc.SetPen(*wxWHITE_PEN); dc.SetBrush(*wxBLACK_BRUSH); dc.DrawArc(offset2.x+originSize, offset2.y, offset2.x, offset2.y-originSize, offset2.x, offset2.y); dc.DrawArc(offset2.x-originSize, offset2.y, offset2.x, offset2.y+originSize, offset2.x, offset2.y); }