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-sunview.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-28  |  5.3 KB  |  215 lines

  1. /* Link this to sun.c if you are running on a SunView system */
  2.  
  3. /*
  4.  *  author = "Pierre MacKay (from the original by Paul Richards)"
  5.  *  version = "0.5",
  6.  *  date = "5 May 1991 - June 1992"
  7.  *  filename = "sun_sunview.c",
  8.  *  contact = "Pierre MacKay",
  9.  *  email = "mackay@cs.washington.edu"
  10.  * Graphics window interface to Metafont for Suns running
  11.  *    SunView (Sun Unix release 3.n)
  12.  * This code is essentially a translation from the old
  13.  * sun.c which used <suntool/gfxsw.h>.  The model for the
  14.  * translation is the example in Appendix C (C.2.) of the
  15.  * Sunview 1 Programmer's guide as applied to bouncedemo.c
  16.  * There are nice additional benefits, such as a moveable
  17.  * and scalable graphics window, and the chance to see
  18.  * the controlling window while METAFONT is at work
  19.  *
  20.  * Destroy checking is bogus, and SunView does not clean up the mess
  21.  * if you "quit" from the pulldown menu.  You will be left with
  22.  * an hysterical orphaned process screaming for a window that isn't
  23.  * there.  You will have to go elsewhere ant KILL that process.
  24.  * Otherwise it seems clean.
  25.  * 
  26.  * For the moment this and the XView interface seem to be
  27.  * mutually exclusive, since they use library routines with
  28.  * the same names, which mightily confuses the loader. 
  29.  * It doesn't help much to change the name of MFTERM since
  30.  * XView wants to name its own terminal "sun" just like
  31.  * the SunView terminal
  32.  */
  33.  
  34. #define    EXTERN    extern
  35. #include "../mfd.h"
  36.  
  37. #undef _POSIX_SOURCE
  38. #ifdef    SUNWIN
  39.  
  40. /* <sundev/cg9reg.h> wants to have a field named `reset'.  Since we
  41.    don't need the WEB(2C) reset, no problem.  */
  42. #undef reset
  43.  
  44. #include <stdio.h>
  45. #include <sys/types.h>
  46. #include <suntool/sunview.h>
  47. #include <suntool/canvas.h>
  48.  
  49. static void repaint_proc();
  50. static void resize_proc();
  51.  
  52. static Notify_value mf_notice_destroy();
  53. extern Notify_error notify_dispatch();
  54.  
  55. static int destroy_ready;  /* could be used for tighter control */
  56.  
  57. /*
  58.  * global handle on the graphics subwindow 
  59.  */
  60.  
  61. struct    MFsubwindow {
  62.     int    mf_flags;
  63. #define    MF_RESTART    0x01
  64.     struct    pixwin *mf_pixwin;
  65.     struct    rect mf_rect;
  66.       } sun_mf_subwin; /* Make sure that names storage is allocated. */
  67.  
  68. static struct    MFsubwindow    *metafont_sw = &sun_mf_subwin;    /* window handle */
  69.  
  70. /*
  71.  * Gray background for graphics area
  72.  */
  73.  
  74. static short    mf_graybackground_image[] = {0x5555, 0xaaaa};
  75.     mpr_static(mf_sunview_gray_bkgr, 2, 2, 1, mf_graybackground_image);
  76.  
  77.  
  78. Rect *rect;
  79. Frame frame;
  80. Canvas canvas;
  81. Pixwin *pw;
  82.  
  83. /*
  84.  * init_screen: boolean;  return true if window operations legal
  85.  */
  86.  
  87. int
  88. mf_sun_initscreen()
  89. {
  90.     frame = window_create(NULL,FRAME,
  91.                   FRAME_LABEL, "METAFONT",
  92.                   FRAME_SHOW_LABEL, TRUE,
  93.     WIN_ERROR_MSG, "! Window access requires METAFONT to run under suntools\n",
  94.                   0);
  95.     canvas = window_create(frame, CANVAS,
  96.                    CANVAS_RESIZE_PROC, resize_proc,
  97.                    CANVAS_FAST_MONO, TRUE,
  98.                    WIN_ERROR_MSG, "Can't creat canvas",
  99.                    0);
  100.     pw = canvas_pixwin(canvas);
  101.  
  102.     metafont_sw->mf_pixwin = canvas_pixwin(canvas);
  103.  
  104.     /* interpose a destroy procedure so we can shut down cleanly */
  105.     (void) notify_interpose_destroy_func(frame, mf_notice_destroy);
  106.  
  107.     /* 
  108.      * Instead of using window_main_loop, just show the frame.
  109.      * Metafont's procedures will be in control, not the notifier.
  110.      */
  111.     window_set(frame,WIN_SHOW, TRUE, 0);
  112.  
  113.     rect = (Rect *)window_get(canvas, WIN_RECT);  /* Get current dimensions */
  114.     pw_replrop(pw,
  115.            0, 0,
  116.            rect->r_width,
  117.            rect->r_height,
  118.            PIX_SRC,
  119.            &mf_sunview_gray_bkgr, 0, 0);    /* clear subwindow */
  120.  
  121.     return(1); /* Caller expects a TRUE value */
  122. }
  123.  
  124. /*
  125.  * updatescreen; -- just make sure screen is ready to view
  126.  */
  127.  
  128. void
  129. mf_sun_updatescreen()
  130. {
  131.     (void)notify_dispatch();
  132. /*    if (destroy_ready != 0) return; */
  133.     rect = (Rect *)window_get(canvas, WIN_RECT);  /* Get current dimensions */
  134.     if (metafont_sw->mf_flags & MF_RESTART) {
  135.         metafont_sw->mf_flags &= ~MF_RESTART;
  136.         pw_replrop(pw,
  137.                0, 0,
  138.                rect->r_width,
  139.                rect->r_height,
  140.                PIX_SRC,
  141.                &mf_sunview_gray_bkgr, 0, 0);    /* clear subwindow */
  142.     }
  143. }
  144.  
  145. /*
  146.  * blankrectangle: reset rectangle bounded by ([left,right],[top,bottom])
  147.  *            to background color
  148.  */
  149.  
  150. void
  151. mf_sun_blankrectangle(left, right, top, bottom)
  152.     screencol left, right;
  153.     screenrow top, bottom;
  154. {
  155.     pw_writebackground(pw, left, top,
  156.                 right-left+1, bottom-top+1, PIX_CLR);
  157. }
  158.  
  159. /*
  160.  * paintrow -- paint "row" starting with color "init_color",  up to next
  161.  *        transition specified by "transition_vector", switch colors,
  162.  *        and continue for "vector_size" transitions.
  163.  */
  164.  
  165. void
  166. mf_sun_paintrow(row, init_color, transition_vector, vector_size)
  167.     screenrow    row;
  168.     pixelcolor    init_color;
  169.     transspec    transition_vector;
  170.     screencol    vector_size;
  171. {
  172.     register    col;
  173.     register    color;
  174.  
  175.     (void)notify_dispatch();
  176.     color = (init_color == 0)? 0 : 1;
  177.  
  178.     do {
  179.         col = *transition_vector++;
  180.         pw_vector(pw,
  181.               col, row, (*transition_vector)-1, row,
  182.               PIX_SRC, color);
  183.         color = 1 - color;
  184.     } while (--vector_size);
  185. }
  186.  
  187. static void
  188. repaint_proc( /* Ignore args */ )
  189. {
  190.     /* if repainting is required, just restart */
  191.     metafont_sw->mf_flags |= MF_RESTART;
  192. }
  193.  
  194. static void
  195. resize_proc( /* Ignore args */ )
  196. {
  197.     metafont_sw->mf_flags |= MF_RESTART;
  198. }
  199.  
  200. static    Notify_value
  201. mf_notice_destroy(frame, status)
  202.     Frame frame;
  203.     Destroy_status status;
  204. {
  205.     if (status != DESTROY_CHECKING) {
  206.       destroy_ready = TRUE;
  207.       (void)notify_stop();
  208.     }
  209.     return(notify_next_destroy_func(frame,status));
  210. }
  211.  
  212. #else
  213. int sunview_dummy;
  214. #endif /* SUNWIN */
  215.