From ef865aab68c5d2f8a763f81be5dd6d2061950fa5 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 24 Jun 2013 14:33:02 +0200 Subject: [PATCH] Grid settings apply to GAL based rendering. --- common/drawframe.cpp | 62 ++++++++++++++++------- common/drawpanel_gal.cpp | 5 -- common/gal/graphics_abstraction_layer.cpp | 6 +++ common/gal/opengl/opengl_gal.cpp | 2 + include/gal/graphics_abstraction_layer.h | 14 ++++- 5 files changed, 66 insertions(+), 23 deletions(-) diff --git a/common/drawframe.cpp b/common/drawframe.cpp index 6fec87f2a3..58df3c1766 100644 --- a/common/drawframe.cpp +++ b/common/drawframe.cpp @@ -236,7 +236,15 @@ void EDA_DRAW_FRAME::SkipNextLeftButtonReleaseEvent() void EDA_DRAW_FRAME::OnToggleGridState( wxCommandEvent& aEvent ) { SetGridVisibility( !IsGridVisible() ); - m_canvas->Refresh(); +#ifdef KICAD_GAL + if( m_galCanvasActive ) + { + m_galCanvas->GetGAL()->SetGridVisibility( IsGridVisible() ); + m_galCanvas->Refresh(); + } + else +#endif /* KICAD_GAL */ + m_canvas->Refresh(); } @@ -388,6 +396,14 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event ) m_LastGridSizeId = id - ID_POPUP_GRID_LEVEL_1000; screen->SetGrid( id ); screen->SetCrossHairPosition( screen->RefPos( true ) ); +#ifdef KICAD_GAL + if( m_galCanvasActive ) + { + KiGfx::GAL* gal = m_galCanvas->GetGAL(); + gal->SetGridSize( VECTOR2D( screen->GetGrid().m_Size ) ); + } +#endif /* KICAD_GAL */ + Refresh(); } @@ -945,32 +961,44 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) KiGfx::VIEW* view = m_galCanvas->GetView(); KiGfx::GAL* gal = m_galCanvas->GetGAL(); - if( aEnable && m_galCanvasActive ) - { - // When we switch between GAL based canvases, all we need is a refresh - m_galCanvas->Refresh(); - } - - if( !( aEnable ^ m_galCanvasActive ) ) - return; - double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); // Display the same view after canvas switching if( aEnable ) { - double zoom = 1 / ( zoomFactor * m_canvas->GetZoom() ); - view->SetScale( zoom ); + BASE_SCREEN* screen = GetScreen(); - view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) ); + // Switch to GAL rendering + if( !m_galCanvasActive ) + { + // Change view settings only if GAL was not active previously + double zoom = 1.0 / ( zoomFactor * m_canvas->GetZoom() ); + view->SetScale( zoom ); + view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) ); + } + + // Set up grid settings + gal->SetGridVisibility( IsGridVisible() ); + // Default grid color - dark cyan does not look good + //gal->SetGridColor( KiGfx::COLOR4D( GetGridColor() ) ); + gal->SetGridColor( KiGfx::COLOR4D( 0.1, 0.1, 0.1, 1.0 ) ); + gal->SetGridSize( VECTOR2D( screen->GetGridSize() ) ); + gal->SetGridOrigin( VECTOR2D( screen->GetGridOrigin() ) ); + gal->SetGridOriginMarkerSize( 15 ); + gal->SetGridDrawThreshold( 10 ); } else { - double zoom = 1 / ( zoomFactor * view->GetScale() ); - m_canvas->SetZoom( zoom ); + // Switch to standard rendering + if( m_galCanvasActive ) + { + // Change view settings only if GAL was active previously + double zoom = 1.0 / ( zoomFactor * view->GetScale() ); + m_canvas->SetZoom( zoom ); - VECTOR2D center = view->GetCenter(); - RedrawScreen( wxPoint( center.x, center.y ), false ); + VECTOR2D center = view->GetCenter(); + RedrawScreen( wxPoint( center.x, center.y ), false ); + } } m_canvas->SetEvtHandlerEnabled( !aEnable ); diff --git a/common/drawpanel_gal.cpp b/common/drawpanel_gal.cpp index 822d368739..2896be651f 100644 --- a/common/drawpanel_gal.cpp +++ b/common/drawpanel_gal.cpp @@ -140,11 +140,6 @@ void EDA_DRAW_PANEL_GAL::Refresh( bool eraseBackground, const wxRect* rect ) m_gal->BeginDrawing(); m_gal->SetBackgroundColor( KiGfx::COLOR4D( 0, 0, 0, 1.0 ) ); m_gal->ClearScreen(); - m_gal->SetGridOrigin( VECTOR2D( 0, 0 ) ); - m_gal->SetGridOriginMarkerSize( 15 ); - m_gal->SetGridSize( VECTOR2D( METRIC_UNIT_LENGTH / 10000.0, METRIC_UNIT_LENGTH / 10000.0 ) ); - m_gal->SetGridDrawThreshold( 10 ); - m_gal->SetLayerDepth( 0 ); m_gal->DrawGrid(); m_view->Redraw(); diff --git a/common/gal/graphics_abstraction_layer.cpp b/common/gal/graphics_abstraction_layer.cpp index a996fcbafb..51c5bd5786 100644 --- a/common/gal/graphics_abstraction_layer.cpp +++ b/common/gal/graphics_abstraction_layer.cpp @@ -44,6 +44,7 @@ GAL::GAL() SetZoomFactor( 1.0 ); SetFillColor( COLOR4D( 0.0, 0.0, 0.0, 0.0 ) ); SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) ); + SetGridVisibility( true ); SetGridColor( COLOR4D( 1, 1, 1, 0.1 ) ); SetCoarseGrid( 5 ); SetLineWidth( 1.0 ); @@ -58,6 +59,9 @@ GAL::~GAL() void GAL::DrawGrid() { + if( !gridVisibility ) + return; + // The grid consists of lines // For the drawing the start points, end points and increments have to be calculated in world coordinates VECTOR2D screenStartPoint( 0, 0 ); @@ -98,6 +102,7 @@ void GAL::DrawGrid() double origSize = (double) gridOriginMarkerSize / worldScale; + // Draw the origin marker SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) ); SetIsFill( false ); DrawLine( gridOrigin + VECTOR2D( -origSize, -origSize ), gridOrigin + VECTOR2D( origSize, origSize ) ); @@ -109,6 +114,7 @@ void GAL::DrawGrid() if( std::max( gridScreenSizeDense, gridScreenSizeCoarse ) < gridDrawThreshold ) return; + SetLayerDepth( 0.0 ); // Now draw the grid, every coarse grid line gets the double width for( int j = gridStartY; j < gridEndY; j += 1 ) { diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 63068170c9..097c141077 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -1909,10 +1909,12 @@ void OPENGL_GAL::DrawGridLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEnd if( aStartPoint.x == aEndPoint.x ) { + // Vertical grid line perpendicularVector = VECTOR2D( 0.5 * lineWidth, 0 ); } else { + // Horizontal grid line perpendicularVector = VECTOR2D( 0, 0.5 * lineWidth ); } diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index 747525dd88..e7524a65e1 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -524,6 +524,16 @@ public: // Grid methods // ------------- + /** + * @brief Sets the visibility setting of the grid. + * + * @param aVisibility is the new visibility setting of the grid. + */ + inline void SetGridVisibility( bool aVisibility ) + { + gridVisibility = aVisibility; + } + /** * @brief Set the origin point for the grid. * @@ -698,13 +708,15 @@ protected: double layerDepth; ///< The actual layer depth VECTOR2D depthRange; ///< Range of the depth + // Grid settings + bool gridVisibility; ///< Should the grid be shown VECTOR2D gridSize; ///< The grid size VECTOR2D gridOrigin; ///< The grid origin COLOR4D gridColor; ///< Color of the grid int gridTick; ///< Every tick line gets the double width double gridLineWidth; ///< Line width of the grid int gridDrawThreshold; ///< Minimum screen size of the grid (pixels) - ///< below which the grid is not drawn + ///< below which the grid is not drawn int gridOriginMarkerSize; ///< Grid origin indicator size (pixels) bool isCursorEnabled; ///< Is the cursor enabled?