Commit 544726e4 authored by Maciej Suminski's avatar Maciej Suminski

New display style for grid (dotted).

parent d34df18f
......@@ -47,6 +47,7 @@ GAL::GAL() :
// Set grid defaults
SetGridVisibility( true );
SetGridStyle( GRID_STYLE_LINES );
SetGridColor( COLOR4D( 0.4, 0.4, 0.4, 1.0 ) );
SetCoarseGrid( 10 );
SetGridLineWidth( 0.5 );
......@@ -97,7 +98,20 @@ void GAL::DrawGrid()
SetTarget( TARGET_NONCACHED );
// The grid consists of lines
// Draw the origin marker
double origSize = static_cast<double>( gridOriginMarkerSize ) / worldScale;
SetLayerDepth( 0.0 );
SetIsFill( false );
SetIsStroke( true );
SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
SetLineWidth( gridLineWidth / worldScale );
DrawLine( gridOrigin + VECTOR2D( -origSize, -origSize ),
gridOrigin + VECTOR2D( origSize, origSize ) );
DrawLine( gridOrigin + VECTOR2D( -origSize, origSize ),
gridOrigin + VECTOR2D( origSize, -origSize ) );
DrawCircle( gridOrigin, origSize * 0.7 );
// Draw the grid
// For the drawing the start points, end points and increments have
// to be calculated in world coordinates
MATRIX3x3D inverseMatrix = worldScreenMatrix.Inverse();
......@@ -107,23 +121,9 @@ void GAL::DrawGrid()
int gridScreenSizeDense = round( gridSize.x * worldScale );
int gridScreenSizeCoarse = round( gridSize.x * static_cast<double>( gridTick ) * worldScale );
// Compute the line width of the grid
double width = 2.0 * gridLineWidth / worldScale;
double doubleWidth = 2.0 * width;
SetIsFill( false );
SetIsStroke( true );
// Draw the origin marker
SetLayerDepth( 0.0 );
double origSize = static_cast<double>( gridOriginMarkerSize ) / worldScale;
SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
SetLineWidth( width );
DrawLine( gridOrigin + VECTOR2D( -origSize, -origSize ),
gridOrigin + VECTOR2D( origSize, origSize ) );
DrawLine( gridOrigin + VECTOR2D( -origSize, origSize ),
gridOrigin + VECTOR2D( origSize, -origSize ) );
DrawCircle( gridOrigin, origSize * 0.7 );
// Compute the line marker or point radius of the grid
double marker = 2.0 * gridLineWidth / worldScale;
double doubleMarker = 2.0 * marker;
// Check if the grid would not be too dense
if( std::max( gridScreenSizeDense, gridScreenSizeCoarse ) > gridDrawThreshold )
......@@ -144,21 +144,22 @@ void GAL::DrawGrid()
gridEndX += 1;
gridEndY += 1;
// Draw the grid behind all layers
// Draw the grid behind all other layers
SetLayerDepth( depthRange.y * 0.75 );
if( gridStyle == GRID_STYLE_LINES )
{
SetIsFill( false );
SetIsStroke( true );
SetStrokeColor( gridColor );
// Now draw the grid, every coarse grid line gets the double width
for( int j = gridStartY; j < gridEndY; j += 1 )
{
if( j % gridTick == 0 && gridScreenSizeDense > gridDrawThreshold )
{
SetLineWidth( doubleWidth );
}
SetLineWidth( doubleMarker );
else
{
SetLineWidth( width );
}
SetLineWidth( marker );
if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridDrawThreshold )
|| gridScreenSizeDense > gridDrawThreshold )
......@@ -171,13 +172,9 @@ void GAL::DrawGrid()
for( int i = gridStartX; i < gridEndX; i += 1 )
{
if( i % gridTick == 0 && gridScreenSizeDense > gridDrawThreshold )
{
SetLineWidth( doubleWidth );
}
SetLineWidth( doubleMarker );
else
{
SetLineWidth( width );
}
SetLineWidth( marker );
if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridDrawThreshold )
|| gridScreenSizeDense > gridDrawThreshold )
......@@ -187,6 +184,39 @@ void GAL::DrawGrid()
}
}
}
else // Dotted grid
{
bool tickX, tickY;
SetIsFill( true );
SetIsStroke( false );
SetFillColor( gridColor );
for( int j = gridStartY; j < gridEndY; j += 1 )
{
if( j % gridTick == 0 && gridScreenSizeDense > gridDrawThreshold )
tickY = true;
else
tickY = false;
for( int i = gridStartX; i < gridEndX; i += 1 )
{
if( i % gridTick == 0 && gridScreenSizeDense > gridDrawThreshold )
tickX = true;
else
tickX = false;
if( tickX || tickY || gridScreenSizeDense > gridDrawThreshold )
{
double radius = ( tickX && tickY ) ? doubleMarker : marker;
DrawRectangle( VECTOR2D( i * gridSize.x - radius,
j * gridSize.y - radius ),
VECTOR2D( i * gridSize.x + radius,
j * gridSize.y + radius ) );
}
}
}
}
}
}
......
......@@ -44,7 +44,7 @@ namespace KiGfx
/**
* GridStyle: Type definition of the grid style
*/
enum GridStyle
enum GRID_STYLE
{
GRID_STYLE_LINES, ///< Use lines for the grid
GRID_STYLE_DOTS ///< Use dots for the grid
......@@ -668,8 +668,15 @@ public:
/// @brief Draw the grid
void DrawGrid();
// TODO Not yet implemented
// virtual void SetGridStyle(GridStyle gridStyle);
/**
* @brief Change the grid display style.
*
* @param aGridStyle is the new style for grid.
*/
inline virtual void SetGridStyle( GRID_STYLE aGridStyle )
{
gridStyle = aGridStyle;
}
// -------
// Cursor
......@@ -758,6 +765,7 @@ protected:
// Grid settings
bool gridVisibility; ///< Should the grid be shown
GRID_STYLE gridStyle; ///< Grid display style
VECTOR2D gridSize; ///< The grid size
VECTOR2D gridOrigin; ///< The grid origin
COLOR4D gridColor; ///< Color of the grid
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment