home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / unixtex-6.1b-src.tgz / tar.out / contrib / unixtex / web2c / mf / MFwindow / sun-gfx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-28  |  2.5 KB  |  121 lines

  1. /*
  2.  * Graphics window interface to Metafont for Suns running
  3.  *    SunWindows (Sun Unix release 1.2 or later?)
  4.  */
  5.  
  6. #define    EXTERN    extern
  7. #include "../mfd.h"
  8.  
  9. #ifdef    SUNWIN
  10.  
  11. #include <stdio.h>
  12. #include <signal.h>
  13. #include <suntool/gfx_hs.h>
  14.  
  15. /*
  16.  * global handle on the graphics subwindow (if run inside gfxtool)
  17.  */
  18.  
  19. struct    gfxsubwindow    *mf_gfxwin;    /* window handle */
  20.  
  21. /*
  22.  * Gray background for graphics area
  23.  */
  24.  
  25. short    mf_graybackground_image[] = {0x5555, 0xaaaa};
  26.     mpr_static(mf_graybackground, 2, 2, 1, mf_graybackground_image);
  27.  
  28.  
  29. /*
  30.  * sigwinch(): handle SIGWINCH signal to refresh graphics
  31.  */
  32.  
  33. static
  34. sigwinch() {
  35.     gfxsw_handlesigwinch(mf_gfxwin);
  36. }
  37.  
  38.  
  39. /*
  40.  * init_screen: boolean;  return true if window operations legal
  41.  */
  42.  
  43. mf_sun_initscreen()
  44. {
  45.     if ((mf_gfxwin = gfxsw_init(0, (char **)NULL)) == NULL) {
  46.         fprintf(stderr, "! Window access requires METAFONT to run under gfxtool\n");
  47.         return(0);
  48.     }
  49.     gfxsw_getretained(mf_gfxwin);    /* let sunwindows repair damage */
  50.     pw_replrop(mf_gfxwin->gfx_pixwin,
  51.                 0, 0,
  52.                 mf_gfxwin->gfx_rect.r_width,
  53.                 mf_gfxwin->gfx_rect.r_height,
  54.                 PIX_SRC,
  55.                 &mf_graybackground, 0, 0);    /* clear subwindow */
  56.     (void) signal(SIGWINCH, sigwinch);
  57.     return(1);
  58. }
  59.  
  60. /*
  61.  * updatescreen; -- just make sure screen is ready to view
  62.  */
  63.  
  64. mf_sun_updatescreen()
  65. {
  66.     if (mf_gfxwin->gfx_flags & GFX_DAMAGED)
  67.         gfxsw_handlesigwinch(mf_gfxwin);
  68.     if (mf_gfxwin->gfx_flags & GFX_RESTART) {
  69.         mf_gfxwin->gfx_flags &= ~GFX_RESTART;
  70.         pw_replrop(mf_gfxwin->gfx_pixwin,
  71.                     0, 0,
  72.                     mf_gfxwin->gfx_rect.r_width,
  73.                     mf_gfxwin->gfx_rect.r_height,
  74.                     PIX_SRC,
  75.                     &mf_graybackground, 0, 0);    /* clear subwindow */
  76.     }
  77. }
  78.  
  79. /*
  80.  * blankrectangle: reset rectangle bounded by ([left,right],[top,bottom])
  81.  *            to background color
  82.  */
  83.  
  84. mf_sun_blankrectangle(left, right, top, bottom)
  85.     screencol left, right;
  86.     screenrow top, bottom;
  87. {
  88.     pw_writebackground(mf_gfxwin->gfx_pixwin, left, top,
  89.                 right-left+1, bottom-top+1, PIX_CLR);
  90. }
  91.  
  92. /*
  93.  * paintrow -- paint "row" starting with color "init_color",  up to next
  94.  *        transition specified by "transition_vector", switch colors,
  95.  *        and continue for "vector_size" transitions.
  96.  */
  97.  
  98. mf_sun_paintrow(row, init_color, transition_vector, vector_size)
  99.     screenrow    row;
  100.     pixelcolor    init_color;
  101.     transspec    transition_vector;
  102.     screencol    vector_size;
  103. {
  104.     register    col;
  105.     register    color;
  106.  
  107.     color = (init_color == 0)? 0 : 1;
  108.  
  109.     do {
  110.         col = *transition_vector++;
  111.         pw_vector(mf_gfxwin->gfx_pixwin,
  112.                 col, row, (*transition_vector)-1, row,
  113.                 PIX_SRC, color);
  114.         color = 1 - color;
  115.     } while (--vector_size);
  116. }
  117.  
  118. #else
  119. int sunview_dummy;
  120. #endif /* SUNWIN */
  121.