New display style for grid (dotted).
This commit is contained in:
parent
d34df18f2c
commit
544726e4f3
|
@ -47,6 +47,7 @@ GAL::GAL() :
|
||||||
|
|
||||||
// Set grid defaults
|
// Set grid defaults
|
||||||
SetGridVisibility( true );
|
SetGridVisibility( true );
|
||||||
|
SetGridStyle( GRID_STYLE_LINES );
|
||||||
SetGridColor( COLOR4D( 0.4, 0.4, 0.4, 1.0 ) );
|
SetGridColor( COLOR4D( 0.4, 0.4, 0.4, 1.0 ) );
|
||||||
SetCoarseGrid( 10 );
|
SetCoarseGrid( 10 );
|
||||||
SetGridLineWidth( 0.5 );
|
SetGridLineWidth( 0.5 );
|
||||||
|
@ -97,7 +98,20 @@ void GAL::DrawGrid()
|
||||||
|
|
||||||
SetTarget( TARGET_NONCACHED );
|
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
|
// For the drawing the start points, end points and increments have
|
||||||
// to be calculated in world coordinates
|
// to be calculated in world coordinates
|
||||||
MATRIX3x3D inverseMatrix = worldScreenMatrix.Inverse();
|
MATRIX3x3D inverseMatrix = worldScreenMatrix.Inverse();
|
||||||
|
@ -107,23 +121,9 @@ void GAL::DrawGrid()
|
||||||
int gridScreenSizeDense = round( gridSize.x * worldScale );
|
int gridScreenSizeDense = round( gridSize.x * worldScale );
|
||||||
int gridScreenSizeCoarse = round( gridSize.x * static_cast<double>( gridTick ) * worldScale );
|
int gridScreenSizeCoarse = round( gridSize.x * static_cast<double>( gridTick ) * worldScale );
|
||||||
|
|
||||||
// Compute the line width of the grid
|
// Compute the line marker or point radius of the grid
|
||||||
double width = 2.0 * gridLineWidth / worldScale;
|
double marker = 2.0 * gridLineWidth / worldScale;
|
||||||
double doubleWidth = 2.0 * width;
|
double doubleMarker = 2.0 * marker;
|
||||||
|
|
||||||
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 );
|
|
||||||
|
|
||||||
// Check if the grid would not be too dense
|
// Check if the grid would not be too dense
|
||||||
if( std::max( gridScreenSizeDense, gridScreenSizeCoarse ) > gridDrawThreshold )
|
if( std::max( gridScreenSizeDense, gridScreenSizeCoarse ) > gridDrawThreshold )
|
||||||
|
@ -144,46 +144,76 @@ void GAL::DrawGrid()
|
||||||
gridEndX += 1;
|
gridEndX += 1;
|
||||||
gridEndY += 1;
|
gridEndY += 1;
|
||||||
|
|
||||||
// Draw the grid behind all layers
|
// Draw the grid behind all other layers
|
||||||
SetLayerDepth( depthRange.y * 0.75 );
|
SetLayerDepth( depthRange.y * 0.75 );
|
||||||
SetStrokeColor( gridColor );
|
|
||||||
|
|
||||||
// Now draw the grid, every coarse grid line gets the double width
|
if( gridStyle == GRID_STYLE_LINES )
|
||||||
for( int j = gridStartY; j < gridEndY; j += 1 )
|
|
||||||
{
|
{
|
||||||
if( j % gridTick == 0 && gridScreenSizeDense > gridDrawThreshold )
|
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 )
|
||||||
{
|
{
|
||||||
SetLineWidth( doubleWidth );
|
if( j % gridTick == 0 && gridScreenSizeDense > gridDrawThreshold )
|
||||||
}
|
SetLineWidth( doubleMarker );
|
||||||
else
|
else
|
||||||
{
|
SetLineWidth( marker );
|
||||||
SetLineWidth( width );
|
|
||||||
|
if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridDrawThreshold )
|
||||||
|
|| gridScreenSizeDense > gridDrawThreshold )
|
||||||
|
{
|
||||||
|
drawGridLine( VECTOR2D( gridStartX * gridSize.x, j * gridSize.y ),
|
||||||
|
VECTOR2D( gridEndX * gridSize.x, j * gridSize.y ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridDrawThreshold )
|
for( int i = gridStartX; i < gridEndX; i += 1 )
|
||||||
|| gridScreenSizeDense > gridDrawThreshold )
|
|
||||||
{
|
{
|
||||||
drawGridLine( VECTOR2D( gridStartX * gridSize.x, j * gridSize.y ),
|
if( i % gridTick == 0 && gridScreenSizeDense > gridDrawThreshold )
|
||||||
VECTOR2D( gridEndX * gridSize.x, j * gridSize.y ) );
|
SetLineWidth( doubleMarker );
|
||||||
|
else
|
||||||
|
SetLineWidth( marker );
|
||||||
|
|
||||||
|
if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridDrawThreshold )
|
||||||
|
|| gridScreenSizeDense > gridDrawThreshold )
|
||||||
|
{
|
||||||
|
drawGridLine( VECTOR2D( i * gridSize.x, gridStartY * gridSize.y ),
|
||||||
|
VECTOR2D( i * gridSize.x, gridEndY * gridSize.y ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else // Dotted grid
|
||||||
for( int i = gridStartX; i < gridEndX; i += 1 )
|
|
||||||
{
|
{
|
||||||
if( i % gridTick == 0 && gridScreenSizeDense > gridDrawThreshold )
|
bool tickX, tickY;
|
||||||
{
|
SetIsFill( true );
|
||||||
SetLineWidth( doubleWidth );
|
SetIsStroke( false );
|
||||||
}
|
SetFillColor( gridColor );
|
||||||
else
|
|
||||||
{
|
|
||||||
SetLineWidth( width );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridDrawThreshold )
|
for( int j = gridStartY; j < gridEndY; j += 1 )
|
||||||
|| gridScreenSizeDense > gridDrawThreshold )
|
|
||||||
{
|
{
|
||||||
drawGridLine( VECTOR2D( i * gridSize.x, gridStartY * gridSize.y ),
|
if( j % gridTick == 0 && gridScreenSizeDense > gridDrawThreshold )
|
||||||
VECTOR2D( i * gridSize.x, gridEndY * gridSize.y ) );
|
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
|
* GridStyle: Type definition of the grid style
|
||||||
*/
|
*/
|
||||||
enum GridStyle
|
enum GRID_STYLE
|
||||||
{
|
{
|
||||||
GRID_STYLE_LINES, ///< Use lines for the grid
|
GRID_STYLE_LINES, ///< Use lines for the grid
|
||||||
GRID_STYLE_DOTS ///< Use dots for the grid
|
GRID_STYLE_DOTS ///< Use dots for the grid
|
||||||
|
@ -668,8 +668,15 @@ public:
|
||||||
/// @brief Draw the grid
|
/// @brief Draw the grid
|
||||||
void DrawGrid();
|
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
|
// Cursor
|
||||||
|
@ -758,6 +765,7 @@ protected:
|
||||||
|
|
||||||
// Grid settings
|
// Grid settings
|
||||||
bool gridVisibility; ///< Should the grid be shown
|
bool gridVisibility; ///< Should the grid be shown
|
||||||
|
GRID_STYLE gridStyle; ///< Grid display style
|
||||||
VECTOR2D gridSize; ///< The grid size
|
VECTOR2D gridSize; ///< The grid size
|
||||||
VECTOR2D gridOrigin; ///< The grid origin
|
VECTOR2D gridOrigin; ///< The grid origin
|
||||||
COLOR4D gridColor; ///< Color of the grid
|
COLOR4D gridColor; ///< Color of the grid
|
||||||
|
|
Loading…
Reference in New Issue