Hi all, This patch adds the ability for GAL to draw axes when drawing the grid. Right now this is only going to be used for GerbView.
Best, Jon
From 384c6e7ca96421645f69976f695e52733b424469 Mon Sep 17 00:00:00 2001 From: Jon Evans <j...@craftyjon.com> Date: Tue, 7 Mar 2017 21:33:19 -0500 Subject: [PATCH] Add setting to have GAL draw axes on the grid --- common/gal/cairo/cairo_gal.cpp | 3 ++- common/gal/gal_display_options.cpp | 10 +++++++++- common/gal/graphics_abstraction_layer.cpp | 21 +++++++++++++++++++++ common/gal/opengl/opengl_gal.cpp | 19 +++++++++++++++++++ include/gal/gal_display_options.h | 3 +++ include/gal/graphics_abstraction_layer.h | 12 ++++++++++++ 6 files changed, 66 insertions(+), 2 deletions(-) diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index e499c9b..060c411 100644 --- a/common/gal/cairo/cairo_gal.cpp +++ b/common/gal/cairo/cairo_gal.cpp @@ -87,6 +87,7 @@ CAIRO_GAL::CAIRO_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, // Grid color settings are different in Cairo and OpenGL SetGridColor( COLOR4D( 0.1, 0.1, 0.1, 0.8 ) ); + SetAxesColor( COLOR4D( BLUE ) ); // Allocate memory for pixel storage allocateBitmaps(); @@ -825,7 +826,7 @@ void CAIRO_GAL::drawGridLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndP { cairo_move_to( currentContext, aStartPoint.x, aStartPoint.y ); cairo_line_to( currentContext, aEndPoint.x, aEndPoint.y ); - cairo_set_source_rgba( currentContext, gridColor.r, gridColor.g, gridColor.b, strokeColor.a ); + cairo_set_source_rgba( currentContext, strokeColor.r, strokeColor.g, strokeColor.b, strokeColor.a ); cairo_stroke( currentContext ); } diff --git a/common/gal/gal_display_options.cpp b/common/gal/gal_display_options.cpp index 3df7c3c..803adf3 100644 --- a/common/gal/gal_display_options.cpp +++ b/common/gal/gal_display_options.cpp @@ -35,6 +35,7 @@ static const wxString GalGLAntialiasingKeyword( "OpenGLAntialiasingMode" ); static const wxString GalGridStyleConfig( "GridStyle" ); static const wxString GalGridLineWidthConfig( "GridLineWidth" ); static const wxString GalGridMaxDensityConfig( "GridMaxDensity" ); +static const wxString GalGridAxesEnabledConfig( "GridAxesEnabled" ); static const UTIL::CFG_MAP<KIGFX::OPENGL_ANTIALIASING_MODE> aaModeConfigVals = @@ -59,7 +60,8 @@ GAL_DISPLAY_OPTIONS::GAL_DISPLAY_OPTIONS() : gl_antialiasing_mode( OPENGL_ANTIALIASING_MODE::NONE ), m_gridStyle( GRID_STYLE::DOTS ), m_gridLineWidth( 0.5 ), - m_gridMinSpacing( 10 ) + m_gridMinSpacing( 10 ), + m_axesEnabled( false ) {} @@ -81,6 +83,9 @@ void GAL_DISPLAY_OPTIONS::ReadConfig( wxConfigBase* aCfg, wxString aBaseName ) aCfg->Read( aBaseName + GalGridMaxDensityConfig, &m_gridMinSpacing, 10 ); + aCfg->Read( aBaseName + GalGridAxesEnabledConfig, + &m_axesEnabled, false ); + NotifyChanged(); } @@ -98,6 +103,9 @@ void GAL_DISPLAY_OPTIONS::WriteConfig( wxConfigBase* aCfg, wxString aBaseName ) aCfg->Write( aBaseName + GalGridMaxDensityConfig, m_gridMinSpacing ); + + aCfg->Write( aBaseName + GalGridAxesEnabledConfig, + m_axesEnabled ); } diff --git a/common/gal/graphics_abstraction_layer.cpp b/common/gal/graphics_abstraction_layer.cpp index f9182f7..3d83d05 100644 --- a/common/gal/graphics_abstraction_layer.cpp +++ b/common/gal/graphics_abstraction_layer.cpp @@ -110,6 +110,12 @@ bool GAL::updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions ) refresh = true; } + if( options.m_axesEnabled != axesEnabled ) + { + axesEnabled = options.m_axesEnabled; + refresh = true; + } + // tell the derived class if the base class needs an update or not return refresh; } @@ -335,6 +341,21 @@ void GAL::DrawGrid() } } } + + // Draw axes if desired + if( axesEnabled ) + { + SetIsFill( false ); + SetIsStroke( true ); + SetStrokeColor( axesColor ); + SetLineWidth( marker ); + + drawGridLine( VECTOR2D( worldStartPoint.x, 0 ), + VECTOR2D( worldEndPoint.x, 0 ) ); + + drawGridLine( VECTOR2D( 0, worldStartPoint.y ), + VECTOR2D( 0, worldEndPoint.y ) ); + } } diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 8a6ddf0..b0f2e62 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -129,6 +129,7 @@ OPENGL_GAL::OPENGL_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent, // Grid color settings are different in Cairo and OpenGL SetGridColor( COLOR4D( 0.8, 0.8, 0.8, 0.1 ) ); + SetAxesColor( COLOR4D( BLUE ) ); // Tesselator initialization tesselator = gluNewTess(); @@ -994,6 +995,24 @@ void OPENGL_GAL::DrawGrid() glDisable( GL_STENCIL_TEST ); } + // Draw axes if desired + if( axesEnabled ) + { + glLineWidth( minorLineWidth ); + glColor4d( axesColor.r, axesColor.g, axesColor.b, 1.0 ); + + glBegin( GL_LINES ); + glVertex2d( worldStartPoint.x, 0 ); + glVertex2d( worldEndPoint.x, 0 ); + glEnd(); + + glBegin( GL_LINES ); + glVertex2d( 0, worldStartPoint.y ); + glVertex2d( 0, worldEndPoint.y ); + glEnd(); + + } + glEnable( GL_DEPTH_TEST ); glEnable( GL_TEXTURE_2D ); } diff --git a/include/gal/gal_display_options.h b/include/gal/gal_display_options.h index de8f389..733cb2b 100644 --- a/include/gal/gal_display_options.h +++ b/include/gal/gal_display_options.h @@ -81,6 +81,9 @@ namespace KIGFX ///> Minimum pixel distance between displayed grid lines double m_gridMinSpacing; + + ///> Whether or not to draw the coordinate system axes + bool m_axesEnabled; }; } diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index 197eb08..2a59bb6 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -813,6 +813,16 @@ public: } /** + * @brief Set the axes color. + * + * @param aAxesColor is the color to draw the axes if enabled. + */ + inline void SetAxesColor( const COLOR4D& aAxesColor ) + { + axesColor = aAxesColor; + } + + /** * @brief Draw every tick line wider. * * @param aInterval increase the width of every aInterval line, if 0 do not use this feature. @@ -988,6 +998,8 @@ protected: VECTOR2D gridOrigin; ///< The grid origin VECTOR2D gridOffset; ///< The grid offset to compensate cursor position COLOR4D gridColor; ///< Color of the grid + COLOR4D axesColor; ///< Color of the axes + bool axesEnabled; ///< Should the axes be drawn int gridTick; ///< Every tick line gets the double width double gridLineWidth; ///< Line width of the grid int gridMinSpacing; ///< Minimum screen size of the grid (pixels) -- 2.7.4
_______________________________________________ Mailing list: https://launchpad.net/~kicad-developers Post to : kicad-developers@lists.launchpad.net Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp