diff --git a/common/gal/cairo/cairo_gal.cpp b/common/gal/cairo/cairo_gal.cpp index 724e863d8d..52093d4aa0 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(); @@ -819,7 +820,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 ee72e43b3c..803adf3d8a 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 aaModeConfigVals = @@ -57,7 +58,10 @@ static const UTIL::CFG_MAP gridStyleConfigVals = GAL_DISPLAY_OPTIONS::GAL_DISPLAY_OPTIONS() : gl_antialiasing_mode( OPENGL_ANTIALIASING_MODE::NONE ), - m_gridStyle( GRID_STYLE::DOTS ) + m_gridStyle( GRID_STYLE::DOTS ), + m_gridLineWidth( 0.5 ), + m_gridMinSpacing( 10 ), + m_axesEnabled( false ) {} @@ -79,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(); } @@ -96,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 f9182f79c8..3d83d05597 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 8a6ddf054c..3e56a8cf57 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,23 @@ 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 de8f389a56..733cb2b918 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 4b5d46f229..a9e9fed7e9 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -799,6 +799,16 @@ public: gridColor = aGridColor; } + /** + * @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. * @@ -975,6 +985,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)