home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / v_bit / v_bit.c next >
C/C++ Source or Header  |  1989-09-03  |  9KB  |  228 lines

  1. /************************************************************************/
  2. /*  v_bit.c                 Craig W. Daymon                    9/3/89   */
  3. /*                                                                      */
  4. /*  The following program requires GDOS and a GDOS printer driver as    */
  5. /*  device #21 to be present.  It will display a file selector,         */
  6. /*  allowing the user to select an .IMG file for printing.  The image   */
  7. /*  will be scaled to fit in a 8"x10" area, preserving the proper       */
  8. /*  aspect ratio and centered within the 8x10 area.                     */
  9. /*                                                                      */
  10. /*  The main purpose of this program is to show the proper bindings     */
  11. /*  for the GEM function, v_bit_image().                                */
  12. /*                                                                      */
  13. /*  NOTE: This program contains virtually NO error checking.  If you    */
  14. /*        do not have GDOS installed, it will likely crash.             */
  15. /*                                                                      */
  16. /*              * Written with Laser C from Megamax.                    */
  17. /*                                                                      */
  18. /************************************************************************/
  19.  
  20. #include <stdio.h>
  21. #include <strings.h>
  22.  
  23. #include <osbind.h>
  24. #include <gemdefs.h>
  25. #include <obdefs.h>
  26.  
  27. #define TRUE  1
  28. #define FALSE 0
  29.  
  30. int contrl[12];                     /* The GEM bindings                 */
  31. int intin[256];
  32. int ptsin[256];
  33. int intout[256];
  34. int ptsout[256];
  35.  
  36. char file[105];                     /* Image file name and path.        */
  37. char fname[13];                     /* Fielname: 8 + 3(extender)        */
  38.  
  39. int pix_w, pix_h;       /* Printer pixel width and height in microns.   */
  40.  
  41. int prn_handle;                     /* printer handle                   */
  42.  
  43. int xyarray[8];                     /* Coordinates for 8x10 area.       */
  44.  
  45. main()
  46. {
  47.     register int i;
  48.  
  49.     appl_init();
  50.  
  51.     intin[0] = 21;                      /* GDOS Device #21 - printer    */
  52.     for (i=1;i<10; ++i) intin[i] = 1;   /* use raster coordinates       */
  53.     intin[10] = 2;
  54.     v_opnwk(intin,&prn_handle,intout);
  55.     pix_w = intout[3];                  /* Get printer pixel size.      */
  56.     pix_h = intout[4];
  57.  
  58.     xyarray[0] = xyarray[1] = 0;
  59.  
  60.     /****        There are 25400 microns per inch.                  *****/
  61.  
  62.     xyarray[2] = (25400/pix_w) << 3;            /* 8  inches wide.      */
  63.     xyarray[3] = (25400/pix_h) * 10;            /* 10 inches high.      */
  64.  
  65.     while(TRUE)
  66.     {
  67.         get_filename(file,fname,"*.IMG");   /* Get file to print.       */
  68.  
  69.         if(file[0] == '\0') break;
  70.  
  71.         v_bit_image(prn_handle,file,2,1,0,0,1,1,xyarray); 
  72.         v_updwk(prn_handle);
  73.         v_clrwk(prn_handle);
  74.  
  75.     }   
  76.  
  77.     v_clswk(prn_handle);
  78.  
  79.     appl_exit();
  80.  
  81. } /* End of main()  */
  82.  
  83. /*
  84.     get_filename() is used for file selection.
  85.  
  86.     It is passed 2 string pointers:
  87.  
  88.         file_n_path -   Pointer to a character array to hold the useable
  89.                         path and filename.  It will return a NULL string
  90.                         if a CANCEL is returned by fsel_input() or the no
  91.                         file name is selected.
  92.  
  93.         name        -   Default file name to use.
  94.  
  95.         ext         -   Pointer to a string describing the directory
  96.                         search string/wild card.
  97.  
  98.         **  The string pointed to by file_n_path should be about        **
  99.         **  105 characters in length to accommodate up to 7             **
  100.         **  directories and the file name.                              **
  101.  
  102. */
  103.  
  104. get_filename(file_n_path,name,ext)
  105.  
  106.     char    *file_n_path;   /* Pointer to useable path & file string.   */
  107.     char    *name;
  108.     char    *ext;
  109. {
  110.     char path[90];      /* Directory Path - Disk + a max of 7 folders   */
  111.     int drive;  /* drive number returned by Dgetdrv - A=0,B=1,...       */
  112.     int button; /* Button returned by fsel_input (ok or cancel)         */
  113.     char c;     /*Just a dummy                                          */
  114.  
  115.     drive=Dgetdrv();            /* Get the current active drive         */
  116.     path[0]=drive + 'A';    /* Places the drive letter in 1st position  */
  117.     path[1] = ':';
  118.     Dgetpath(&path[2],(drive+1));   /* Now we have the path             */
  119.     strcat(path,"\\");
  120.     strcat(path,ext);               /* Set initial directory search     */
  121.     fsel_input(path,name,&button);
  122.     if(!button || !strlen(name))
  123.     {
  124.         file_n_path[0] = '\0';
  125.     }
  126.     else
  127.     {
  128.         for(button=strlen(path);
  129.             button && (((c = path[button-1]) != '\\') && (c != ':'));
  130.             button--);
  131.  
  132.         path[button] = '\0';
  133.         strcpy(file_n_path,path);
  134.         strcat(file_n_path,name);
  135.     }
  136.  
  137. } /* End of get_filename */
  138.  
  139. /*
  140.  
  141.     v_bit_image()
  142.  
  143. */
  144.  
  145. v_bit_image(handle,filename,num_pts,aspect,xscale,yscale,halign,valign,points)
  146.     int     handle;
  147.     int     aspect;
  148.     char    filename[];
  149.     int     xscale,yscale;
  150.     int     halign,valign;
  151.     int     num_pts;
  152.     int     points[];
  153. {
  154.  
  155.     int     lv;                 /* Loop variable.                       */
  156.  
  157.     contrl[0]   =   5;          /* Opcode.                              */
  158.  
  159.     contrl[1]   =   num_pts;    /* 0    =   Take rectangle from file.   */
  160.                                 /*                                      */
  161.                                 /* 1    =   Use point as upper left     */
  162.                                 /*          corner and calculate lower  */
  163.                                 /*          left from file.             */
  164.                                 /*                                      */
  165.                                 /* 2    =   Use these points to define  */
  166.                                 /*          the rectangle.              */
  167.  
  168.     contrl[2]   =   0;
  169.  
  170.     contrl[3]   =   strlen(filename) + 5;
  171.  
  172.     contrl[4]   =   0;
  173.  
  174.     contrl[5]   =   23;         /* Function ID.                         */
  175.  
  176.     contrl[6]   =   handle;     /* The workstation device handle.       */
  177.  
  178.     intin[0]    =   aspect;     /* Aspect ratio flag:                   */
  179.                                 /*                                      */
  180.                                 /*  0   =   Ignore aspect ratio.        */
  181.                                 /*                                      */
  182.                                 /*  1   =   Preserve pixel aspect ratio.*/
  183.  
  184.     intin[1]    =   xscale;     /* X-axis scaling flag:                 */
  185.                                 /*                                      */
  186.                                 /*  0   =   Integral scaling.           */
  187.                                 /*                                      */
  188.                                 /*  1   =   Fractional scaling.         */
  189.  
  190.     intin[2]    =   yscale;     /* Y-axis scaling flag:                 */
  191.                                 /*                                      */
  192.                                 /*  0   =   Integral scaling.           */
  193.                                 /*                                      */
  194.                                 /*  1   =   Fractional scaling.         */
  195.  
  196.     intin[3]    =   halign;     /* Horizontal Alignment:                */
  197.                                 /*                                      */
  198.                                 /*  0   =   Left Aligned                */
  199.                                 /*                                      */
  200.                                 /*  1   =   Centered                    */
  201.                                 /*                                      */
  202.                                 /*  2   =   Right Aligned               */
  203.  
  204.     intin[4]    =   valign;     /* Vertical Alignment:                  */
  205.                                 /*                                      */
  206.                                 /*  0   =   Left Aligned                */
  207.                                 /*                                      */
  208.                                 /*  1   =   Centered                    */
  209.                                 /*                                      */
  210.                                 /*  2   =   Right Aligned               */
  211.  
  212.  
  213.  
  214.     for(lv = 0;filename[lv];lv++)
  215.     {
  216.         intin[5 + lv] = (int)filename[lv];
  217.     }
  218.  
  219.     ptsin[0]    =   points[0];
  220.     ptsin[1]    =   points[1];
  221.     ptsin[2]    =   points[2];
  222.     ptsin[3]    =   points[3];
  223.  
  224.     vdi();
  225.  
  226. } /* End of v_bit_image()   */
  227.  
  228.