void EDA_DRAW_PANEL::DrawGridAxis( wxDC* aDC, GR_DRAWMODE aDrawMode, const wxPoint& aGridOrigin ) { if( !GetParent()->GetShowGridAxis() || ( !aGridOrigin.x && !aGridOrigin.y ) ) return; COLOR4D color = GetParent()->GetGridColor(); GRSetDrawMode( aDC, aDrawMode ); #if DRAW_AXIS_AS_LINES wxSize pageSize = GetParent()->GetPageSizeIU(); // Draw the Y axis GRLine( &m_ClipBox, aDC, aGridOrigin.x, -pageSize.y, aGridOrigin.x, pageSize.y, 0, color ); // Draw the X axis GRLine( &m_ClipBox, aDC, -pageSize.x, aGridOrigin.y, pageSize.x, aGridOrigin.y, 0, color ); #else int radius = aDC->DeviceToLogicalXRel( AXIS_SIZE_IN_PIXELS ); int linewidth = aDC->DeviceToLogicalXRel( 1 ); GRSetColorPen( aDC, GetParent()->GetGridColor(), linewidth ); GRLine( &m_ClipBox, aDC, aGridOrigin.x-radius, aGridOrigin.y-radius, aGridOrigin.x+radius, aGridOrigin.y+radius, 0, color ); // Draw the X shape GRLine( &m_ClipBox, aDC, aGridOrigin.x+radius, aGridOrigin.y-radius, aGridOrigin.x-radius, aGridOrigin.y+radius, 0, color ); GRCircle( &m_ClipBox, aDC, aGridOrigin, radius, linewidth, color ); #endif }
static void WinClipAndDrawLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, EDA_COLOR_T Color, int width = 1 ) { GRLastMoveToX = x2; GRLastMoveToY = y2; if( ClipBox ) { EDA_RECT clipbox(*ClipBox); clipbox.Inflate(width/2); if( clipLine( &clipbox, x1, y1, x2, y2 ) ) return; } GRSetColorPen( DC, Color, width ); DC->DrawLine( x1, y1, x2, y2 ); }
void EDA_DRAW_PANEL::DrawAuxiliaryAxis( wxDC* aDC, GR_DRAWMODE aDrawMode ) { wxPoint origin = GetParent()->GetAuxOrigin(); if( origin == wxPoint( 0, 0 ) ) return; COLOR4D color = COLOR4D( RED ); GRSetDrawMode( aDC, aDrawMode ); #if DRAW_AXIS_AS_LINES wxSize pageSize = GetParent()->GetPageSizeIU(); // Draw the Y axis GRLine( &m_ClipBox, aDC, origin.x, -pageSize.y, origin.x, pageSize.y, 0, color ); // Draw the X axis GRLine( &m_ClipBox, aDC, -pageSize.x, origin.y, pageSize.x, origin.y, 0, color ); #else int radius = aDC->DeviceToLogicalXRel( AXIS_SIZE_IN_PIXELS ); int linewidth = aDC->DeviceToLogicalXRel( 1 ); GRSetColorPen( aDC, color, linewidth ); GRLine( &m_ClipBox, aDC, origin.x, origin.y-radius, origin.x, origin.y+radius, 0, color ); // Draw the + shape GRLine( &m_ClipBox, aDC, origin.x-radius, origin.y, origin.x+radius, origin.y, 0, color ); GRCircle( &m_ClipBox, aDC, origin, radius, linewidth, color ); #endif }
void EDA_DRAW_PANEL::DrawGrid( wxDC* aDC ) { #define MIN_GRID_SIZE 10 // min grid size in pixels to allow drawing BASE_SCREEN* screen = GetScreen(); wxRealPoint gridSize; wxSize screenSize; wxPoint org; wxRealPoint screenGridSize; /* The grid must be visible. this is possible only is grid value * and zoom value are sufficient */ gridSize = screen->GetGridSize(); screen->m_StartVisu = CalcUnscrolledPosition( wxPoint( 0, 0 ) ); screenSize = GetClientSize(); screenGridSize.x = aDC->LogicalToDeviceXRel( KiROUND( gridSize.x ) ); screenGridSize.y = aDC->LogicalToDeviceYRel( KiROUND( gridSize.y ) ); org = m_ClipBox.GetPosition(); if( screenGridSize.x < MIN_GRID_SIZE || screenGridSize.y < MIN_GRID_SIZE ) { screenGridSize.x *= 2.0; screenGridSize.y *= 2.0; gridSize.x *= 2.0; gridSize.y *= 2.0; } if( screenGridSize.x < MIN_GRID_SIZE || screenGridSize.y < MIN_GRID_SIZE ) return; org = GetParent()->GetNearestGridPosition( org, &gridSize ); // Setting the nearest grid position can select grid points outside the clip box. // Incrementing the start point by one grid step should prevent drawing grid points // outside the clip box. if( org.x < m_ClipBox.GetX() ) org.x += KiROUND( gridSize.x ); if( org.y < m_ClipBox.GetY() ) org.y += KiROUND( gridSize.y ); // Use a pixel based draw to display grid. There are a lot of calls, so the cost is // high and grid is slowly drawn on some platforms. Another way using blit transfert was used, // a long time ago, but it did not give very good results. // The better way is highly dependent on the platform and the graphic card. int xpos; double right = ( double ) m_ClipBox.GetRight(); double bottom = ( double ) m_ClipBox.GetBottom(); #if defined( USE_WX_GRAPHICS_CONTEXT ) wxGCDC *gcdc = wxDynamicCast( aDC, wxGCDC ); if( gcdc ) { // Much faster grid drawing on systems using wxGraphicsContext wxGraphicsContext *gc = gcdc->GetGraphicsContext(); // Grid point size const int gsz = 1; const double w = aDC->DeviceToLogicalXRel( gsz ); const double h = aDC->DeviceToLogicalYRel( gsz ); // Use our own pen wxPen pen( GetParent()->GetGridColor().ToColour(), h ); pen.SetCap( wxCAP_BUTT ); gc->SetPen( pen ); // draw grid wxGraphicsPath path = gc->CreatePath(); for( double x = (double) org.x - w/2.0; x <= right - w/2.0; x += gridSize.x ) { for( double y = (double) org.y; y <= bottom; y += gridSize.y ) { path.MoveToPoint( x, y ); path.AddLineToPoint( x+w, y ); } } gc->StrokePath( path ); } else #endif { GRSetColorPen( aDC, GetParent()->GetGridColor() ); for( double x = (double) org.x; x <= right; x += gridSize.x ) { xpos = KiROUND( x ); for( double y = (double) org.y; y <= bottom; y += gridSize.y ) { aDC->DrawPoint( xpos, KiROUND( y ) ); } } } }
void EDA_DRAW_PANEL::DrawGrid( wxDC* aDC ) { #define MIN_GRID_SIZE 10 // min grid size in pixels to allow drawing BASE_SCREEN* screen = GetScreen(); wxRealPoint gridSize; wxSize screenSize; wxPoint org; wxRealPoint screenGridSize; /* The grid must be visible. this is possible only is grid value * and zoom value are sufficient */ gridSize = screen->GetGridSize(); screen->m_StartVisu = CalcUnscrolledPosition( wxPoint( 0, 0 ) ); screenSize = GetClientSize(); screenGridSize.x = aDC->LogicalToDeviceXRel( KiROUND( gridSize.x ) ); screenGridSize.y = aDC->LogicalToDeviceYRel( KiROUND( gridSize.y ) ); org = m_ClipBox.GetPosition(); if( screenGridSize.x < MIN_GRID_SIZE || screenGridSize.y < MIN_GRID_SIZE ) { screenGridSize.x *= 2.0; screenGridSize.y *= 2.0; gridSize.x *= 2.0; gridSize.y *= 2.0; } if( screenGridSize.x < MIN_GRID_SIZE || screenGridSize.y < MIN_GRID_SIZE ) return; org = GetParent()->GetNearestGridPosition( org, &gridSize ); // Setting the nearest grid position can select grid points outside the clip box. // Incrementing the start point by one grid step should prevent drawing grid points // outside the clip box. if( org.x < m_ClipBox.GetX() ) org.x += KiROUND( gridSize.x ); if( org.y < m_ClipBox.GetY() ) org.y += KiROUND( gridSize.y ); #if ( defined( __WXMAC__ ) || 1 ) // Use a pixel based draw to display grid. There are a lot of calls, so the cost is // high and grid is slowly drawn on some platforms. Please note that this should // always be enabled until the bitmap based solution below is fixed. #ifndef __WXMAC__ GRSetColorPen( aDC, GetParent()->GetGridColor() ); #else // On mac (Cocoa), a point isn't a pixel and being of size 1 don't survive to antialiasing GRSetColorPen( aDC, GetParent()->GetGridColor(), aDC->DeviceToLogicalXRel(2) ); #endif int xpos; double right = ( double ) m_ClipBox.GetRight(); double bottom = ( double ) m_ClipBox.GetBottom(); for( double x = (double) org.x; x <= right; x += gridSize.x ) { xpos = KiROUND( x ); for( double y = (double) org.y; y <= bottom; y += gridSize.y ) { aDC->DrawPoint( xpos, KiROUND( y ) ); } } #else /* This is fast only if the Blit function is fast. Not true on all platforms. * * A first grid column is drawn in a temporary bitmap, and after is duplicated using * the Blit function (copy from a screen area to an other screen area). */ wxMemoryDC tmpDC; wxBitmap tmpBM( 1, aDC->LogicalToDeviceYRel( m_ClipBox.GetHeight() ) ); tmpDC.SelectObject( tmpBM ); tmpDC.SetLogicalFunction( wxCOPY ); tmpDC.SetBackground( wxBrush( GetBackgroundColour() ) ); tmpDC.Clear(); tmpDC.SetPen( MakeColour( GetParent()->GetGridColor() ) ); double usx, usy; int lox, loy, dox, doy; aDC->GetUserScale( &usx, &usy ); aDC->GetLogicalOrigin( &lox, &loy ); aDC->GetDeviceOrigin( &dox, &doy ); // Create a dummy DC for coordinate translation because the actual DC scale and origin // must be reset in order to work correctly. wxBitmap tmpBitmap( 1, 1 ); wxMemoryDC scaleDC( tmpBitmap ); scaleDC.SetUserScale( usx, usy ); scaleDC.SetLogicalOrigin( lox, loy ); scaleDC.SetDeviceOrigin( dox, doy ); double bottom = ( double ) m_ClipBox.GetBottom(); // Draw a column of grid points. for( double y = (double) org.y; y <= bottom; y += gridSize.y ) { tmpDC.DrawPoint( 0, scaleDC.LogicalToDeviceY( KiROUND( y ) ) ); } // Reset the device context scale and origin and restore on exit. EDA_BLIT_NORMALIZER blitNorm( aDC ); // Mask of everything but the grid points. tmpDC.SelectObject( wxNullBitmap ); tmpBM.SetMask( new wxMask( tmpBM, GetBackgroundColour() ) ); tmpDC.SelectObject( tmpBM ); double right = m_ClipBox.GetRight(); // Blit the column for each row of the damaged region. for( double x = (double) org.x; x <= right; x += gridSize.x ) { aDC->Blit( scaleDC.LogicalToDeviceX( KiROUND( x ) ), scaleDC.LogicalToDeviceY( m_ClipBox.GetY() ), 1, tmpBM.GetHeight(), &tmpDC, 0, 0, wxCOPY, true ); } #endif }
void WinEDA_DrawPanel::DrawBackGround(wxDC * DC) /***********************************************/ /* Trace les axes X et Y et la grille La grille n'est affichee que si elle peut etre facilement visible La grille passe toujours par le centre de l'ecran */ { int Color = BLUE; BASE_SCREEN * screen = GetScreen(); int ii,jj ,xg , yg , color; wxSize pas_grille_affichee; bool drawgrid = FALSE; int zoom = GetZoom(); wxSize size; wxPoint org; double pasx, pasy; color = screen->m_GridColor; GRSetDrawMode(DC, GR_COPY); /* le pas d'affichage doit etre assez grand pour avoir une grille visible */ drawgrid = m_Parent->m_Draw_Grid; pas_grille_affichee = screen->GetGrid(); ii = pas_grille_affichee.x / zoom; if (ii < 5 ) { pas_grille_affichee.x *= 2 ; ii *= 2; } if( ii < 5 ) drawgrid = FALSE; // grille trop petite ii = pas_grille_affichee.y / zoom; if (ii < 5 ) { pas_grille_affichee.y *= 2 ; ii *= 2; } if( ii < 5 ) drawgrid = FALSE; // grille trop petite GetViewStart(&org.x, &org.y); GetScrollPixelsPerUnit(&ii, &jj); org.x *= ii; org.y *= jj; screen->m_StartVisu = org; org.x *= zoom; org.y *= zoom; org.x += screen->m_DrawOrg.x; org.y += screen->m_DrawOrg.y; size = GetClientSize(); size.x *= zoom; size.y *= zoom; pasx = screen->m_UserGrid.x * m_Parent->m_InternalUnits; pasy = screen->m_UserGrid.y * m_Parent->m_InternalUnits; if ( screen->m_UserGridUnit != INCHES ) { pasx /= 25.4; pasy /= 25.4; } if( drawgrid) { m_Parent->PutOnGrid(&org) ; GRSetColorPen(DC, color ); for ( ii = 0 ; ; ii++ ) { xg = screen->m_UserGridIsON ? (int)( (ii * pasx) + 0.5) :ii * pas_grille_affichee.x; int xpos = org.x + xg; for ( jj = 0 ; ; jj++ ) { yg = screen->m_UserGridIsON ? (int)( (jj * pasy) + 0.5) : jj * pas_grille_affichee.y; GRPutPixel(&m_ClipBox, DC, xpos, org.y + yg, color); if ( yg > size.y ) break; } if ( xg > size.x ) break; } } /* trace des axes principaux */ if ( m_Parent->m_Draw_Axes ) { /* Trace de l'axe vertical */ GRDashedLine(&m_ClipBox, DC, 0, -screen->ReturnPageSize().y, 0, screen->ReturnPageSize().y, Color ); /* Trace de l'axe horizontal */ GRDashedLine(&m_ClipBox, DC, -screen->ReturnPageSize().x, 0, screen->ReturnPageSize().x, 0, Color ); } /* trace des axes auxiliaires */ if ( m_Parent->m_Draw_Auxiliary_Axe) { m_Draw_Auxiliary_Axe(DC, FALSE); } }