gal: Draw grid from edge to edge

Fixes: lp:1677211
* https://bugs.launchpad.net/kicad/+bug/1677211
This commit is contained in:
Maciej Suminski 2017-12-20 09:27:40 +01:00
parent f4f0c09fe4
commit 7741b90c78
2 changed files with 27 additions and 19 deletions

View File

@ -257,10 +257,10 @@ void GAL::DrawGrid()
// Compute grid staring and ending indexes to draw grid points on the // Compute grid staring and ending indexes to draw grid points on the
// visible screen area // visible screen area
// Note: later any point coordinate will be offsetted by gridOrigin // Note: later any point coordinate will be offsetted by gridOrigin
int gridStartX = KiROUND( (worldStartPoint.x-gridOrigin.x) / gridSize.x ); int gridStartX = KiROUND( ( worldStartPoint.x - gridOrigin.x ) / gridSize.x );
int gridEndX = KiROUND( (worldEndPoint.x-gridOrigin.x) / gridSize.x ); int gridEndX = KiROUND( ( worldEndPoint.x - gridOrigin.x ) / gridSize.x );
int gridStartY = KiROUND( (worldStartPoint.y-gridOrigin.y) / gridSize.y ); int gridStartY = KiROUND( ( worldStartPoint.y - gridOrigin.y ) / gridSize.y );
int gridEndY = KiROUND( (worldEndPoint.y-gridOrigin.y) / gridSize.y ); int gridEndY = KiROUND( ( worldEndPoint.y - gridOrigin.y ) / gridSize.y );
// Ensure start coordinate > end coordinate // Ensure start coordinate > end coordinate
if( gridStartX > gridEndX ) if( gridStartX > gridEndX )
@ -269,6 +269,10 @@ void GAL::DrawGrid()
if( gridStartY > gridEndY ) if( gridStartY > gridEndY )
std::swap( gridStartY, gridEndY ); std::swap( gridStartY, gridEndY );
// Ensure the grid fills the screen
--gridStartX; ++gridEndX;
--gridStartY; ++gridEndY;
// Draw the grid behind all other layers // Draw the grid behind all other layers
SetLayerDepth( depthRange.y * 0.75 ); SetLayerDepth( depthRange.y * 0.75 );
@ -281,7 +285,7 @@ void GAL::DrawGrid()
// Now draw the grid, every coarse grid line gets the double width // Now draw the grid, every coarse grid line gets the double width
// Vertical lines // Vertical lines
for( int j = gridStartY-1; j <= gridEndY; j++ ) for( int j = gridStartY; j <= gridEndY; j++ )
{ {
const double y = j * gridSize.y + gridOrigin.y; const double y = j * gridSize.y + gridOrigin.y;
@ -302,7 +306,7 @@ void GAL::DrawGrid()
} }
// Horizontal lines // Horizontal lines
for( int i = gridStartX-1; i <= gridEndX; i++ ) for( int i = gridStartX; i <= gridEndX; i++ )
{ {
const double x = i * gridSize.x + gridOrigin.x; const double x = i * gridSize.x + gridOrigin.x;
@ -332,7 +336,7 @@ void GAL::DrawGrid()
double lineLen = GetLineWidth() * 2; double lineLen = GetLineWidth() * 2;
// Vertical positions: // Vertical positions:
for( int j = gridStartY-1; j <= gridEndY; j++ ) for( int j = gridStartY; j <= gridEndY; j++ )
{ {
if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridThreshold ) if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold ) || gridScreenSizeDense > gridThreshold )
@ -340,7 +344,7 @@ void GAL::DrawGrid()
int posY = j * gridSize.y + gridOrigin.y; int posY = j * gridSize.y + gridOrigin.y;
// Horizontal positions: // Horizontal positions:
for( int i = gridStartX-1; i <= gridEndX; i++ ) for( int i = gridStartX; i <= gridEndX; i++ )
{ {
if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridThreshold ) if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold ) || gridScreenSizeDense > gridThreshold )
@ -364,14 +368,14 @@ void GAL::DrawGrid()
SetIsStroke( false ); SetIsStroke( false );
SetFillColor( gridColor ); SetFillColor( gridColor );
for( int j = gridStartY-1; j <= gridEndY; j++ ) for( int j = gridStartY; j <= gridEndY; j++ )
{ {
if( j % gridTick == 0 && gridScreenSizeDense > gridThreshold ) if( j % gridTick == 0 && gridScreenSizeDense > gridThreshold )
tickY = true; tickY = true;
else else
tickY = false; tickY = false;
for( int i = gridStartX-1; i <= gridEndX; i++ ) for( int i = gridStartX; i <= gridEndX; i++ )
{ {
if( i % gridTick == 0 && gridScreenSizeDense > gridThreshold ) if( i % gridTick == 0 && gridScreenSizeDense > gridThreshold )
tickX = true; tickX = true;

View File

@ -1020,10 +1020,10 @@ void OPENGL_GAL::DrawGrid()
// Compute grid staring and ending indexes to draw grid points on the // Compute grid staring and ending indexes to draw grid points on the
// visible screen area // visible screen area
// Note: later any point coordinate will be offsetted by gridOrigin // Note: later any point coordinate will be offsetted by gridOrigin
int gridStartX = KiROUND( (worldStartPoint.x-gridOrigin.x) / gridSize.x ); int gridStartX = KiROUND( ( worldStartPoint.x - gridOrigin.x ) / gridSize.x );
int gridEndX = KiROUND( (worldEndPoint.x-gridOrigin.x) / gridSize.x ); int gridEndX = KiROUND( ( worldEndPoint.x - gridOrigin.x ) / gridSize.x );
int gridStartY = KiROUND( (worldStartPoint.y-gridOrigin.y) / gridSize.y ); int gridStartY = KiROUND( ( worldStartPoint.y - gridOrigin.y ) / gridSize.y );
int gridEndY = KiROUND( (worldEndPoint.y-gridOrigin.y) / gridSize.y ); int gridEndY = KiROUND( ( worldEndPoint.y - gridOrigin.y ) / gridSize.y );
// Ensure start coordinate > end coordinate // Ensure start coordinate > end coordinate
if( gridStartX > gridEndX ) if( gridStartX > gridEndX )
@ -1032,6 +1032,10 @@ void OPENGL_GAL::DrawGrid()
if( gridStartY > gridEndY ) if( gridStartY > gridEndY )
std::swap( gridStartY, gridEndY ); std::swap( gridStartY, gridEndY );
// Ensure the grid fills the screen
--gridStartX; ++gridEndX;
--gridStartY; ++gridEndY;
glDisable( GL_DEPTH_TEST ); glDisable( GL_DEPTH_TEST );
glDisable( GL_TEXTURE_2D ); glDisable( GL_TEXTURE_2D );
@ -1053,10 +1057,10 @@ void OPENGL_GAL::DrawGrid()
// calculate a line len = 2 minorLineWidth, in internal unit value // calculate a line len = 2 minorLineWidth, in internal unit value
// (in fact the size of cross is lineLen*2) // (in fact the size of cross is lineLen*2)
int lineLen = KiROUND( minorLineWidth / worldScale *2 ); int lineLen = KiROUND( minorLineWidth / worldScale * 2 );
// Vertical positions // Vertical positions
for( int j = gridStartY-1; j <= gridEndY; j++ ) for( int j = gridStartY; j <= gridEndY; j++ )
{ {
if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridThreshold ) if( ( j % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold ) || gridScreenSizeDense > gridThreshold )
@ -1064,7 +1068,7 @@ void OPENGL_GAL::DrawGrid()
int posY = j * gridSize.y + gridOrigin.y; int posY = j * gridSize.y + gridOrigin.y;
// Horizontal positions // Horizontal positions
for( int i = gridStartX-1; i <= gridEndX; i++ ) for( int i = gridStartX; i <= gridEndX; i++ )
{ {
if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridThreshold ) if( ( i % gridTick == 0 && gridScreenSizeCoarse > gridThreshold )
|| gridScreenSizeDense > gridThreshold ) || gridScreenSizeDense > gridThreshold )
@ -1085,7 +1089,7 @@ void OPENGL_GAL::DrawGrid()
else else
{ {
// Vertical lines // Vertical lines
for( int j = gridStartY-1; j <= gridEndY; j++ ) for( int j = gridStartY; j <= gridEndY; j++ )
{ {
const double y = j * gridSize.y + gridOrigin.y; const double y = j * gridSize.y + gridOrigin.y;
@ -1115,7 +1119,7 @@ void OPENGL_GAL::DrawGrid()
} }
// Horizontal lines // Horizontal lines
for( int i = gridStartX-1; i <= gridEndX; i++ ) for( int i = gridStartX; i <= gridEndX; i++ )
{ {
const double x = i * gridSize.x + gridOrigin.x; const double x = i * gridSize.x + gridOrigin.x;