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 and 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 SUNTOOLSWIN
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 #include <mfdisplay.h>
84 
85 /*
86  * init_screen: boolean;  return true if window operations legal
87  */
88 
89 int
mf_sun_initscreen(void)90 mf_sun_initscreen(void)
91 {
92 	frame = window_create(NULL,FRAME,
93 			      FRAME_LABEL, "METAFONT",
94 			      FRAME_SHOW_LABEL, TRUE,
95     WIN_ERROR_MSG, "! Window access requires METAFONT to run under suntools\n",
96 			      0);
97 	canvas = window_create(frame, CANVAS,
98 			       CANVAS_RESIZE_PROC, resize_proc,
99 			       CANVAS_FAST_MONO, TRUE,
100 			       WIN_ERROR_MSG, "Can't creat canvas",
101 			       0);
102 	pw = canvas_pixwin(canvas);
103 
104 	metafont_sw->mf_pixwin = canvas_pixwin(canvas);
105 
106 	/* interpose a destroy procedure so we can shut down cleanly */
107 	(void) notify_interpose_destroy_func(frame, mf_notice_destroy);
108 
109 	/*
110 	 * Instead of using window_main_loop, just show the frame.
111 	 * Metafont's procedures will be in control, not the notifier.
112 	 */
113 	window_set(frame,WIN_SHOW, TRUE, 0);
114 
115 	rect = (Rect *)window_get(canvas, WIN_RECT);  /* Get current dimensions */
116 	pw_replrop(pw,
117 		   0, 0,
118 		   rect->r_width,
119 		   rect->r_height,
120 		   PIX_SRC,
121 		   &mf_sunview_gray_bkgr, 0, 0);	/* clear subwindow */
122 
123 	return(1); /* Caller expects a TRUE value */
124 }
125 
126 /*
127  * updatescreen; -- just make sure screen is ready to view
128  */
129 
130 void
mf_sun_updatescreen(void)131 mf_sun_updatescreen(void)
132 {
133 	(void)notify_dispatch();
134 /*	if (destroy_ready != 0) return; */
135 	rect = (Rect *)window_get(canvas, WIN_RECT);  /* Get current dimensions */
136 	if (metafont_sw->mf_flags & MF_RESTART) {
137 		metafont_sw->mf_flags &= ~MF_RESTART;
138 		pw_replrop(pw,
139 			   0, 0,
140 			   rect->r_width,
141 			   rect->r_height,
142 			   PIX_SRC,
143 			   &mf_sunview_gray_bkgr, 0, 0);	/* clear subwindow */
144 	}
145 }
146 
147 /*
148  * blankrectangle: reset rectangle bounded by ([left,right],[top,bottom])
149  *			to background color
150  */
151 
152 void
mf_sun_blankrectangle(screencol left,screencol right,screenrow top,screenrow bottom)153 mf_sun_blankrectangle (screencol left,
154                        screencol right,
155                        screenrow top,
156                        screenrow bottom)
157 {
158 	pw_writebackground(pw, left, top,
159 				right-left+1, bottom-top+1, PIX_CLR);
160 }
161 
162 /*
163  * paintrow -- paint "row" starting with color "init_color",  up to next
164  *		transition specified by "transition_vector", switch colors,
165  *		and continue for "vector_size" transitions.
166  */
167 
168 void
mf_sun_paintrow(screenrow row,pixelcolor init_color,transspec transition_vector,screencol vector_size)169 mf_sun_paintrow (screenrow row,
170                  pixelcolor init_color,
171                  transspec transition_vector,
172                  screencol vector_size)
173 {
174 	register	col;
175 	register	color;
176 
177 	(void)notify_dispatch();
178 	color = (init_color == 0)? 0 : 1;
179 
180 	do {
181 		col = *transition_vector++;
182 		pw_vector(pw,
183 			  col, row, (*transition_vector)-1, row,
184 			  PIX_SRC, color);
185 		color = 1 - color;
186 	} while (--vector_size);
187 }
188 
189 static void
repaint_proc()190 repaint_proc( /* Ignore args */ )
191 {
192 	/* if repainting is required, just restart */
193 	metafont_sw->mf_flags |= MF_RESTART;
194 }
195 
196 static void
resize_proc()197 resize_proc( /* Ignore args */ )
198 {
199 	metafont_sw->mf_flags |= MF_RESTART;
200 }
201 
202 static	Notify_value
mf_notice_destroy(frame,status)203 mf_notice_destroy(frame, status)
204 	Frame frame;
205 	Destroy_status status;
206 {
207 	if (status != DESTROY_CHECKING) {
208 	  destroy_ready = TRUE;
209 	  (void)notify_stop();
210 	}
211 	return(notify_next_destroy_func(frame,status));
212 }
213 
214 #else
215 int sunview_dummy;
216 #endif /* SUNTOOLSWIN */
217