home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 266_01 / pixlib.c < prev    next >
C/C++ Source or Header  |  1990-04-27  |  2KB  |  101 lines

  1. /*
  2.    PIXLIB is a file of compiler-independent routines for use in
  3.    device drivers for pixel oriented devices.
  4.                                                   File: PIXLIB.C
  5. */
  6. #include "plox.h"
  7. #include "pixlib.h"
  8.  
  9. static int  LineType = -1, Hatch, Spacing;
  10.  
  11. int Bit (N)
  12. /*  ===    Returns 2 to the N power (i.e., Nth bit on)  */
  13. int N;
  14. {
  15.   int M;
  16.   for (M=1; N>0; --N)
  17.     M = M << 1;
  18.   return M;
  19. }
  20.  
  21. int Dotter ()
  22. /*  ======        Provides dot patterns for lines */
  23. {
  24.   #define CYCLE 6
  25.   static int LastType=-1, Place=0;
  26.   if (LineType != LastType) {
  27.      Place = 0;
  28.      LastType = LineType;
  29.   }
  30.   else Place = (++Place) % CYCLE;
  31.   
  32.   return ((LineType & Bit (Place))? 1: 0);
  33. }
  34.  
  35. int GetWord (From)
  36. /*  =======      reads a binary integer */
  37. FILE *From;
  38. {
  39.   int hold;
  40.   fread(&hold,sizeof(int),1,From);
  41.   return (hold);
  42. }
  43. /* */
  44. void HatchHow (Row, Hit, Gap)
  45. /*   ======== */
  46. int Row;          /* Provides dot-on params for given row for  */
  47. int *Hit, *Gap;   /*  the hatching pattern currently in effect */
  48. #define BIGNUM 32767
  49. {
  50.   switch (Hatch) {
  51.                        /* horizontal */
  52.   case 1: *Hit = 0;
  53.           if (!((Row+1)%Spacing)) *Gap = 1;
  54.           else                    *Gap = BIGNUM;
  55.           break;
  56.                        /* vertical */
  57.   case 2: *Hit = 0;
  58.           *Gap = Spacing;
  59.           break;
  60.                          /* left diagonal */
  61.   case 3: *Gap = Spacing;
  62.           *Hit = Row % *Gap;
  63.           break;
  64.                          /* right diagonal */
  65.   case 4: *Gap = Spacing;
  66.           *Hit = (*Gap-1) - (Row%*Gap);
  67.           break;
  68.                          /* square */
  69.   case 5: *Hit = 0;
  70.           if (!((Row+1)%Spacing)) *Gap = 1;
  71.           else                    *Gap = Spacing;
  72.           break;
  73.                          /* blank */
  74.   default: *Hit = 1;
  75.            *Gap = BIGNUM;
  76.            break;
  77.   }
  78. }
  79.  
  80. int InBounds (int X,int Y)
  81. /*  ======== */
  82. { return (X>=0 && X<=XMAX && Y>=0 && Y<=YMAX); }
  83.  
  84. void SetHatch (int Pattern, int Density)
  85. /*   ========        Sets the hatching pattern */
  86. {
  87.   Hatch = Pattern;
  88.   Spacing = Density;
  89. }
  90.  
  91. void SetLine (int Ltype)
  92. /*   =======              Sets the LineType */
  93. {
  94.   LineType = Ltype;
  95. }
  96. int Sign (int X)
  97. /*  ====          Returns 1 with sign of X  */
  98. {
  99.   if (X < 0) return -1; else return 1;
  100. }
  101.