home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / fermiVogle.tar.Z / fermiVogle.tar / devel / drivers / hpgt.c < prev    next >
C/C++ Source or Header  |  1996-02-07  |  6KB  |  388 lines

  1.  
  2. /*
  3.  *    Driver for HP Graphics Terminals
  4. #define BSD 1
  5.  */
  6. #include <stdio.h>
  7. #ifdef BSD
  8. #include <sgtty.h>
  9. #else
  10. #include <sys/termio.h>
  11. #endif
  12. #include "vogle.h"
  13.  
  14. #define    HPGT_X_SIZE        640
  15. #define    HPGT_Y_SIZE        400
  16.  
  17. #include <signal.h>
  18.  
  19. static int    click, tlstx, tlsty;
  20. static FILE    *fp;
  21. extern FILE    *_voutfile();
  22.  
  23. static int noop(void);
  24. static int HPGT_init(void);
  25. static void HPGT_exit(void);
  26. static void HPGT_draw(int x, int y);
  27. static int HPGT_getkey(void);
  28. static int HPGT_locator(int *x, int *y);
  29. static void HPGT_clear(void);
  30. static void HPGT_color(int i);
  31. static int HPGT_font(char *font);
  32. static void HPGT_char(char c);
  33. static void HPGT_string(char *s);
  34. static void HPGT_fill(int n, int x[], int y[]);
  35. static void HPGT_sync(void);
  36.  
  37. /*
  38.  * noop
  39.  *
  40.  *      do nothing but return -1
  41.  */
  42. static int
  43. noop(void)
  44. {
  45.     return(-1);
  46. }
  47.  
  48. /*
  49.  * HPGT_init
  50.  *
  51.  *    set up the graphics mode.
  52.  */
  53. static int
  54. HPGT_init(void)
  55. {
  56.     /*
  57.      * Find out if we are mono or colour.
  58.      * and what our resolution currently is.
  59.      */
  60.     char    buf[128];
  61.     int    i, b1, b2, b3, llx, lly, urx, ury; 
  62.  
  63.     click = 0;
  64.     fp = _voutfile();
  65.  
  66. /*
  67.     fprintf(fp, "\033*s5^");
  68.     fgets(buf, 128, stdin);
  69.     sscanf(buf, "%d,%d,%d,%d\n", &llx, &lly, &urx, &ury);
  70.     vdevice.depth = 1;
  71.     fprintf(fp, "\033*s6^");
  72.     fgets(buf, 128, stdin);
  73.     sscanf(buf, "%d,%d,%d", &b1, &b2, &b3);
  74.  
  75.     if (b3 == 0)
  76.         vdevice.depth = 1;
  77.     else
  78.         vdevice.depth = 4;
  79.     */
  80.  
  81.     vdevice.depth = 4;
  82.  
  83.     fprintf(fp, "\033*dC");
  84.     fprintf(fp, "\033*dF");
  85.     /*
  86.      * Solid area fills
  87.      */
  88.     fprintf(fp, "\033*m1g");
  89.     /*
  90.      * Clear graphics memory
  91.      */
  92.     fprintf(fp, "\033*dA");
  93.  
  94.     vdevice.sizeSx = urx - llx;
  95.     vdevice.sizeSy = ury - lly;
  96.     vdevice.sizeSx = HPGT_X_SIZE;
  97.     vdevice.sizeSy = HPGT_Y_SIZE;
  98.     vdevice.sizeX = vdevice.sizeY = vdevice.sizeSy;
  99.     tlstx = tlsty = -1;
  100.     HPGT_font("5x7");
  101.     fflush(fp);
  102.  
  103.         return(1);
  104. }
  105.  
  106.  
  107. /*
  108.  * HPGT_exit
  109.  *
  110.  *    cleans up before going back to normal mode
  111.  */
  112. static void
  113. HPGT_exit(void)
  114. {
  115.     /* 
  116.      * Graphics display off
  117.      * Alpha display on.
  118.      */
  119.     fprintf(fp, "\033*dD\033*dE");
  120. }
  121.  
  122. /*
  123.  * HPGT_draw
  124.  *
  125.  *    draw from the current graphics position to the new one (x, y)
  126.  */
  127. static void
  128. HPGT_draw(int x, int y)
  129. {
  130.     fprintf(fp, "\033*pa%d,%d", vdevice.cpVx, vdevice.cpVy);
  131.     fprintf(fp, " %d,%dZ", x, y);
  132.     tlstx = x;
  133.     tlsty = y;
  134. }
  135.  
  136. /*
  137.  * HPGT_getkey
  138.  *
  139.  *    return the next key typed.
  140.  */
  141. static int
  142. HPGT_getkey(void)
  143. {
  144. #ifdef BSD
  145.     struct sgttyb    oldtty, newtty;
  146.     char        c;
  147.  
  148.     fflush(fp);
  149.     ioctl(0, TIOCGETP, &oldtty);
  150.  
  151.     newtty = oldtty;
  152.     newtty.sg_flags = RAW;
  153.  
  154.     ioctl(0, TIOCSETP, &newtty);
  155.  
  156.     read(0, &c, 1);
  157.  
  158.     ioctl(0, TIOCSETP, &oldtty);
  159. #else
  160.     struct termio   oldtty, newtty;
  161.     char            c;
  162.       
  163.     fflush(fp);
  164.     ioctl(0, TCGETA, &oldtty);
  165.  
  166.     newtty = oldtty;
  167.     newtty.c_iflag = BRKINT | IXON | ISTRIP;
  168.     newtty.c_lflag = 0;
  169.     newtty.c_cc[VEOF] = 1;
  170.  
  171.     ioctl(0, TCSETA, &newtty);
  172.  
  173.     read(0, &c, 1);
  174.  
  175.     ioctl(0, TCSETA, &oldtty);
  176. #endif
  177.     return(c);
  178. }
  179.  
  180. /*
  181.  * HPGT_locator
  182.  *
  183.  *    get the position of the crosshairs. This gets a bit sticky since
  184.  * we have no mouse, and the crosshairs do not beahve like a mouse - even a rat!
  185.  * In this case the keys 1 to 9 are used, with each one returning a power of
  186.  * two.
  187.  */
  188. static int
  189. HPGT_locator(int *x, int *y)
  190. {
  191.     int        c, i;
  192.     char        buf[50];
  193.  
  194.     if (click) {            /* for compatability with other devs */
  195.         click = 0;
  196.         return(0);
  197.     }
  198.  
  199.     click = 1;
  200.     c = -1;
  201.  
  202.     if (fp == stdout) {
  203.         fprintf(fp, "\033*s4^");
  204.         fgets(buf, 50, stdin);
  205.         sscanf(buf, "%d,%d,%d", x, y, &c);
  206.     }
  207.     return(1 << (c - '1'));
  208. }
  209.  
  210. /*
  211.  * HPGT_clear
  212.  *
  213.  *    clear the screen.
  214.  *
  215.  */
  216. static void
  217. HPGT_clear(void)
  218. {
  219.     /*
  220.      * A rectangular fill absoloute
  221.     if (vdevice.depth == 4)
  222.         fprintf(fp, "\033*m0,0,%d,%de", vdevice.sizeSx, vdevice.sizeSy);
  223.     else
  224.      */
  225.         /*
  226.          * Clear graphics memory
  227.          */
  228.         fprintf(fp, "\033*dA");
  229.  
  230.     tlstx = tlsty = -1;
  231.  
  232. }
  233.  
  234. static void
  235. HPGT_color(int i)
  236. {
  237.     /* Select 1 of the standard colours from the system pallete */
  238.     if (vdevice.depth == 1)
  239.         return;
  240.  
  241.     i %= 8;
  242.     fprintf(fp, "\033*m%dx", i);
  243.     /*... and the graphics text */
  244.     fprintf(fp, "\033*n%dx", i);
  245.     fprintf(fp, "\033*e%dx", i);
  246.     fflush(fp);
  247. }
  248. /*
  249.  * HPGT_font
  250.  *
  251.  *    set for large or small mode.
  252.  */
  253. static int
  254. HPGT_font(char *font)
  255. {
  256.     int    size;
  257.     vdevice.hwidth = 5.0;
  258.     vdevice.hheight = 7.0;
  259.     size = 2;
  260.  
  261.     if (strcmp(font, "5x7") == 0)
  262.         size = 1;
  263.     else if ((strcmp(font, "10x14") == 0) || (strcmp(font, "small") == 0))
  264.         size = 2;
  265.     else if ((strcmp(font, "15x21") == 0) || (strcmp(font, "large") == 0))
  266.         size = 3;
  267.     else if (strcmp(font, "20x28") == 0)
  268.         size = 4;
  269.     else if (strcmp(font, "25x35") == 0)
  270.         size = 5;
  271.     else if (strcmp(font, "30x42") == 0)
  272.         size = 6;
  273.     else if (strcmp(font, "35x49") == 0)
  274.         size = 7;
  275.     else if (strcmp(font, "40x56") == 0)
  276.         size = 8;
  277.  
  278.     vdevice.hwidth *= size;
  279.     vdevice.hheight *= size;
  280.     fprintf(fp, "\033*m%dm", size);
  281.     tlstx = tlsty = -1;
  282.     fflush(fp);
  283.  
  284.     return(1);
  285. }
  286.  
  287. /*
  288.  * HPGT_char
  289.  *
  290.  *    outputs one char
  291.  */
  292. static void
  293. HPGT_char(char c)
  294. {
  295.     /*
  296.      * Output a label.
  297.      */
  298.     if (tlstx != vdevice.cpVx || tlsty != vdevice.cpVy)
  299.         fprintf(fp, "\033*pa%d,%dZ", vdevice.cpVx, vdevice.cpVy);
  300.  
  301.     fprintf(fp, "\033*l%c\015", c);
  302.     tlstx = vdevice.cpVx += (int)vdevice.hwidth;
  303.     fflush(fp);
  304. }
  305.  
  306. /*
  307.  * HPGT_string
  308.  *
  309.  *    outputs a string
  310.  */
  311. static void
  312. HPGT_string(char *s)
  313. {
  314.     if (tlstx != vdevice.cpVx || tlsty != vdevice.cpVy)
  315.         fprintf(fp, "\033*pa%d,%dZ", vdevice.cpVx, vdevice.cpVy);
  316.  
  317.     fprintf(fp, "\033*l%s\015", s);
  318.     fflush(fp);
  319.     tlstx = vdevice.cpVx += strlen(s) * (int)vdevice.hwidth;
  320. }
  321.  
  322. /*
  323.  * HPGT_fill
  324.  *
  325.  *      "fill" a polygon
  326.  */
  327. static void
  328. HPGT_fill(int n, int x[], int y[])
  329. {
  330.     int     i;
  331.  
  332.     fprintf(fp, "\033*pas");
  333.     for (i = 0; i < n; i++)
  334.         fprintf(fp, "%d,%d ", x[i], y[i]);
  335.  
  336.     fprintf(fp, "T");
  337.     fflush(fp);
  338. }
  339.  
  340. /*
  341.  * Flush/sync the graphics
  342.  */
  343. static void
  344. HPGT_sync(void)
  345. {
  346.     fflush(fp);
  347. }
  348.  
  349. /*
  350.  * the device entry
  351.  */
  352. static DevEntry    hpgtdev = {
  353.     "hpgt",
  354.     "large",
  355.     "small",
  356.     noop,
  357.     HPGT_char,
  358.     noop,         /* HPGT_checkkey, */
  359.     HPGT_clear,
  360.     HPGT_color,
  361.     HPGT_draw,
  362.     HPGT_exit,
  363.     HPGT_fill,
  364.     HPGT_font,
  365.     noop,
  366.     HPGT_getkey,
  367.     HPGT_init,
  368.     HPGT_locator,
  369.     noop,
  370.     noop,
  371.     HPGT_string,
  372.     noop,
  373.     HPGT_sync
  374. };
  375.  
  376. /*
  377.  * _HPGT_devcpy
  378.  *
  379.  *      copy the tektronix device into vdevice.dev.
  380.  */
  381. void
  382. _HPGT_devcpy(void)
  383. {
  384.         vdevice.dev = hpgtdev;
  385. }
  386.  
  387.  
  388.