Add setting to have GAL draw axes on the grid
This commit is contained in:
parent
14cbdcec1f
commit
2513f0b002
|
@ -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 );
|
||||
}
|
||||
|
||||
|
|
|
@ -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 =
|
||||
|
@ -57,7 +58,10 @@ static const UTIL::CFG_MAP<KIGFX::GRID_STYLE> 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 );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue