home *** CD-ROM | disk | FTP | other *** search
- /*
- * lemtick.c - perform ticking
- *
- * copyright (c) by Alan W. Paeth, 1987. All rights reserved.
- */
-
- #include "lem.h"
- #include "lemfont.h"
-
- tickalign(x, y)
- int *x, *y;
- {
- if (tickflag && (ticksize < 6))
- {
- tx = 1<<ticksize;
- ty = 1<<ticksize;
- *x = ((*x-txoff+tx/2) / tx) * tx + txoff;
- *y = ((*y-tyoff+ty/2) / ty) * ty + tyoff;
- }
- if (tickflag && (ticksize >= 6))
- {
- int xl, yi, yl, d1, d2, d3, d4;
- tx = 1<<(ticksize-3);
- ty = (tx*14+7)/16;
- yi = ((*y-tyoff)/ty);
- yl = yi*ty + tyoff;
- xl = (((*x-txoff+((yi&0x1)?tx/2:0))/tx)*tx-((yi&0x1)?tx/2:0))+txoff;
-
- d1 = dist(*x,*y,xl ,yl);
- d2 = dist(*x,*y,xl+tx/2 ,yl+ty);
- d3 = dist(*x,*y,xl+tx ,yl);
- d4 = dist(*x,*y,xl+3*tx/2,yl+ty);
- if ((d1<=d2) && (d1<=d3) && (d1<=d4)) { *x = xl; *y = yl; }
- if ((d2<=d1) && (d2<=d3) && (d2<=d4)) { *x = xl+tx/2; *y = yl+ty; }
- if ((d3<=d1) && (d3<=d2) && (d3<=d4)) { *x = xl+tx; *y = yl; }
- if ((d4<=d1) && (d4<=d2) && (d4<=d3)) { *x = xl+3*tx/2; *y = yl+ty; }
- }
- }
-
- tickset()
- {
- char ch;
- int tmpx, tmpy;
- tickflag = !tickflag;
- if (tickflag)
- {
- msgpost("ticksize[1-5/6-9]: ");
- ch = getstroke();
- msgclear();
- if ((ch < '0') || (ch > '9'))
- {
- tickflag = 0;
- return;
- }
- ticksize = ch - '0';
- tmpx = markon ? markx : 0;
- tmpy = markon ? marky : 0;
- txoff = 0;
- tyoff = 0;
- tickalign(&tmpx, &tmpy); /* sets tx and ty as well */
- txoff = (markon ? markx : 0) - tmpx;
- tyoff = (markon ? marky : 0) - tmpy;
- while (tyoff > 0) tyoff -= ty;
- while (tyoff < 0) tyoff += ty;
- while (txoff > 0) txoff -= tx;
- while (txoff < 0) txoff += tx;
- }
- tickdraw();
- if (!tickflag)
- {
- txoff = 0;
- tyoff = 0;
- }
- }
-
- tickdraw()
- {
- int x, y, xstep, ystep;
- xstep = tx;
- ystep = ty;
- while (xstep<MINTICK) xstep *= 2;
- while (ystep<MINTICK) ystep *= 2;
- if (ticksize < 6)
- {
- for(y = tyoff ; y<screenh; y+=ystep)
- for (x = txoff; x<screenw; x+=xstep)
- {
- drawvec(x, y, x + tickdot, y, tickflag ? TICKONCOL:TICKOFFCOL,
- 1,EMPHNONE); /* tickdot sets 0/1 width dot */
- }
- }
- else
- {
- int ylim, iy;
- ylim = screenh/ty;
- y = tyoff;
- for(iy=0; iy<ylim; iy++)
- {
- y += ty;
- for (x = txoff + ((iy&0x1) ? 0 : (tx/2)); x<screenw; x+=tx)
- if ((x>0) && (y>0))
- drawvec(x, y, x + tickdot, y,
- tickflag ? TICKONCOL:TICKOFFCOL,1,EMPHNONE);
- }
- }
- }
-