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