kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #00095
XFig-style grid (proof of concept patch)
This patch demonstrates an XFig-style grid: instead of putting
a dot at each grid point, a dotted line is drawn only at
every fourth point. This makes it easier to estimate larger
distances in the grid.
If zooming in makes the grid sparse (more than 20 pixels between
grid points), this patch reverts to the old behaviour, so that
one can still see the grid structure.
Unfortunately, this patch isn't entirely correct:
- it doesn't properly redraw the grid when scrolling
- if the grid switches to "dense mode", the grid lines are no
longer aligned with the origin. Frankly, I don't really
understand how the coordinate system works.
- similarly, I found the rounding in div_next by trial and
error, and it may be wrong. I would have expected that the
integer equivalent of floor() would be sufficient.
Anyway, I hope this at least illustrates the concept.
- Werner
--- kicad-dev/share/drawpanel.cpp.orig 2006-04-08 17:38:13.000000000 -0300
+++ kicad-dev/share/drawpanel.cpp 2006-04-09 00:21:57.000000000 -0300
@@ -457,6 +457,7 @@ void WinEDA_DrawPanel::DrawBackGround(wx
int Color = BLUE;
BASE_SCREEN * screen = GetScreen();
int ii,jj ,xg , yg , color;
+int maskx = 3,masky = 3,zerox,zeroy;
wxSize pas_grille_affichee;
bool drawgrid = FALSE;
int zoom = GetZoom();
@@ -472,11 +473,13 @@ double pasx, pasy;
pas_grille_affichee = screen->GetGrid();
ii = pas_grille_affichee.x / zoom;
- if (ii < 5 ) { pas_grille_affichee.x *= 2 ; ii *= 2; }
+ if (ii < 5 ) { pas_grille_affichee.x *= 2 ; ii *= 2; maskx = 1; }
if( ii < 5 ) drawgrid = FALSE; // grille trop petite
+ if (ii > 20) maskx = 0;
ii = pas_grille_affichee.y / zoom;
- if (ii < 5 ) { pas_grille_affichee.y *= 2 ; ii *= 2; }
+ if (ii < 5 ) { pas_grille_affichee.y *= 2 ; ii *= 2; masky = 1; }
if( ii < 5 ) drawgrid = FALSE; // grille trop petite
+ if (ii > 20) masky = 0;
GetViewStart(&org.x, &org.y);
GetScrollPixelsPerUnit(&ii, &jj);
@@ -495,6 +498,14 @@ double pasx, pasy;
pasx /= 25.4; pasy /= 25.4;
}
+#define div_next(a,b) ((a) >= 0 ? ((a)+(b)/2)/(b) : ((a)-(b)/2)/(b))
+ zerox = div_next(-org.x,
+ screen->m_UserGridIsON ? (int) pasx : pas_grille_affichee.x);
+ zeroy = div_next(-org.y,
+ screen->m_UserGridIsON ? (int) pasy : pas_grille_affichee.y);
+ zerox &= maskx;
+ zeroy &= masky;
+
if( drawgrid)
{
m_Parent->PutOnGrid(&org) ;
@@ -509,7 +520,10 @@ double pasx, pasy;
{
yg = screen->m_UserGridIsON ? (int)( (jj * pasy) + 0.5)
: jj * pas_grille_affichee.y;
- GRPutPixel(&m_ClipBox, DC, xpos, org.y + yg, color);
+ if ((ii & maskx) == zerox ||
+ (jj & masky) == zeroy)
+ GRPutPixel(&m_ClipBox, DC, xpos,
+ org.y + yg, color);
if ( yg > size.y ) break;
}
if ( xg > size.x ) break;
--
_________________________________________________________________________
/ Werner Almesberger, Buenos Aires, Argentina werner@... /
/_http://www.almesberger.net/____________________________________________/