Back to index

tetex-bin  3.0
suntools.c
Go to the documentation of this file.
00001 /* Link this to sun.c if you are running on a SunView system */
00002 
00003 /*
00004  *  author = "Pierre MacKay (from the original by Paul Richards)"
00005  *  version = "0.5",
00006  *  date = "5 May 1991 - June 1992"
00007  *  filename = "sun_sunview.c",
00008  *  contact = "Pierre MacKay",
00009  *  email = "mackay@cs.washington.edu"
00010  * Graphics window interface to Metafont for Suns running
00011  *     SunView (Sun Unix release 3.n)
00012  * This code is essentially a translation from the old
00013  * sun.c which used <suntool/gfxsw.h>.  The model for the
00014  * translation is the example in Appendix C (C.2.) of the
00015  * Sunview 1 Programmer's guide as applied to bouncedemo.c
00016  * There are nice additional benefits, such as a moveable
00017  * and scalable graphics window, and the chance to see
00018  * the controlling window while METAFONT is at work
00019  *
00020  * Destroy checking is bogus, and SunView does not clean up the mess
00021  * if you "quit" from the pulldown menu.  You will be left with
00022  * an hysterical orphaned process screaming for a window that isn't
00023  * there.  You will have to go elsewhere and KILL that process.
00024  * Otherwise it seems clean.
00025  * 
00026  * For the moment this and the XView interface seem to be
00027  * mutually exclusive, since they use library routines with
00028  * the same names, which mightily confuses the loader. 
00029  * It doesn't help much to change the name of MFTERM since
00030  * XView wants to name its own terminal "sun" just like
00031  * the SunView terminal
00032  */
00033 
00034 #define       EXTERN extern
00035 #include "../mfd.h"
00036 
00037 #undef _POSIX_SOURCE
00038 #ifdef SUNTOOLSWIN
00039 
00040 /* <sundev/cg9reg.h> wants to have a field named `reset'.  Since we
00041    don't need the WEB(2C) reset, no problem.  */
00042 #undef reset
00043 
00044 #include <stdio.h>
00045 #include <sys/types.h>
00046 #include <suntool/sunview.h>
00047 #include <suntool/canvas.h>
00048 
00049 static void repaint_proc();
00050 static void resize_proc();
00051 
00052 static Notify_value mf_notice_destroy();
00053 extern Notify_error notify_dispatch();
00054 
00055 static int destroy_ready;  /* could be used for tighter control */
00056 
00057 /*
00058  * global handle on the graphics subwindow 
00059  */
00060 
00061 struct MFsubwindow {
00062        int    mf_flags;
00063 #define       MF_RESTART    0x01
00064        struct pixwin *mf_pixwin;
00065        struct rect mf_rect;
00066       } sun_mf_subwin; /* Make sure that names storage is allocated. */
00067 
00068 static struct MFsubwindow   *metafont_sw = &sun_mf_subwin;     /* window handle */
00069 
00070 /*
00071  * Gray background for graphics area
00072  */
00073 
00074 static short  mf_graybackground_image[] = {0x5555, 0xaaaa};
00075        mpr_static(mf_sunview_gray_bkgr, 2, 2, 1, mf_graybackground_image);
00076 
00077 
00078 Rect *rect;
00079 Frame frame;
00080 Canvas canvas;
00081 Pixwin *pw;
00082 
00083 /*
00084  * init_screen: boolean;  return true if window operations legal
00085  */
00086 
00087 int
00088 mf_sun_initscreen()
00089 {
00090        frame = window_create(NULL,FRAME,
00091                            FRAME_LABEL, "METAFONT",
00092                            FRAME_SHOW_LABEL, TRUE,
00093     WIN_ERROR_MSG, "! Window access requires METAFONT to run under suntools\n",
00094                            0);
00095        canvas = window_create(frame, CANVAS,
00096                             CANVAS_RESIZE_PROC, resize_proc,
00097                             CANVAS_FAST_MONO, TRUE,
00098                             WIN_ERROR_MSG, "Can't creat canvas",
00099                             0);
00100        pw = canvas_pixwin(canvas);
00101 
00102        metafont_sw->mf_pixwin = canvas_pixwin(canvas);
00103 
00104        /* interpose a destroy procedure so we can shut down cleanly */
00105        (void) notify_interpose_destroy_func(frame, mf_notice_destroy);
00106 
00107        /* 
00108         * Instead of using window_main_loop, just show the frame.
00109         * Metafont's procedures will be in control, not the notifier.
00110         */
00111        window_set(frame,WIN_SHOW, TRUE, 0);
00112 
00113        rect = (Rect *)window_get(canvas, WIN_RECT);  /* Get current dimensions */
00114        pw_replrop(pw,
00115                  0, 0,
00116                  rect->r_width,
00117                  rect->r_height,
00118                  PIX_SRC,
00119                  &mf_sunview_gray_bkgr, 0, 0);   /* clear subwindow */
00120 
00121        return(1); /* Caller expects a TRUE value */
00122 }
00123 
00124 /*
00125  * updatescreen; -- just make sure screen is ready to view
00126  */
00127 
00128 void
00129 mf_sun_updatescreen()
00130 {
00131        (void)notify_dispatch();
00132 /*     if (destroy_ready != 0) return; */
00133        rect = (Rect *)window_get(canvas, WIN_RECT);  /* Get current dimensions */
00134        if (metafont_sw->mf_flags & MF_RESTART) {
00135               metafont_sw->mf_flags &= ~MF_RESTART;
00136               pw_replrop(pw,
00137                         0, 0,
00138                         rect->r_width,
00139                         rect->r_height,
00140                         PIX_SRC,
00141                         &mf_sunview_gray_bkgr, 0, 0);   /* clear subwindow */
00142        }
00143 }
00144 
00145 /*
00146  * blankrectangle: reset rectangle bounded by ([left,right],[top,bottom])
00147  *                   to background color
00148  */
00149 
00150 void
00151 mf_sun_blankrectangle P4C(screencol, left,
00152                           screencol, right,
00153                           screenrow, top,
00154                           screenrow, bottom)
00155 {
00156        pw_writebackground(pw, left, top,
00157                             right-left+1, bottom-top+1, PIX_CLR);
00158 }
00159 
00160 /*
00161  * paintrow -- paint "row" starting with color "init_color",  up to next
00162  *            transition specified by "transition_vector", switch colors,
00163  *            and continue for "vector_size" transitions.
00164  */
00165 
00166 void
00167 mf_sun_paintrow P4C(screenrow,     row,
00168                     pixelcolor,    init_color,
00169                     transspec,     transition_vector,
00170                     screencol,     vector_size)
00171 {
00172        register      col;
00173        register      color;
00174 
00175        (void)notify_dispatch();
00176        color = (init_color == 0)? 0 : 1;
00177 
00178        do {
00179               col = *transition_vector++;
00180               pw_vector(pw,
00181                        col, row, (*transition_vector)-1, row,
00182                        PIX_SRC, color);
00183               color = 1 - color;
00184        } while (--vector_size);
00185 }
00186 
00187 static void
00188 repaint_proc( /* Ignore args */ )
00189 {
00190        /* if repainting is required, just restart */
00191        metafont_sw->mf_flags |= MF_RESTART;
00192 }
00193 
00194 static void
00195 resize_proc( /* Ignore args */ )
00196 {
00197        metafont_sw->mf_flags |= MF_RESTART;
00198 }
00199 
00200 static Notify_value
00201 mf_notice_destroy(frame, status)
00202        Frame frame;
00203        Destroy_status status;
00204 {
00205        if (status != DESTROY_CHECKING) {
00206          destroy_ready = TRUE;
00207          (void)notify_stop();
00208        }
00209        return(notify_next_destroy_func(frame,status));
00210 }
00211 
00212 #else
00213 int sunview_dummy;
00214 #endif /* SUNTOOLSWIN */