ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/sundev.c
Revision: 1.10
Committed: Tue Jan 30 11:37:44 1990 UTC (35 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.9: +4 -2 lines
Log Message:
fixed bug where drivers would send commands inappropriately

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1988 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * sundev.c - standalone driver for Sunwindows.
9     *
10     * 10/3/88
11     */
12    
13     #include <stdio.h>
14     #include <fcntl.h>
15     #include <suntool/sunview.h>
16     #include <suntool/canvas.h>
17     #include <suntool/tty.h>
18    
19     #include "color.h"
20    
21     #include "driver.h"
22    
23     short icon_image[] = {
24     #include "suntools.icon"
25     };
26     DEFINE_ICON_FROM_IMAGE(sun_icon, icon_image);
27    
28     #ifndef TTYPROG
29     #define TTYPROG "sun.com" /* tty program */
30     #endif
31    
32 greg 1.4 #define GAMMA 2.2 /* exponent for color correction */
33 greg 1.1
34     #define COMLH 3 /* number of command lines */
35    
36     #define FIRSTCOLOR 2 /* first usable entry */
37 greg 1.5 #define NCOLORS 251 /* number of usable colors */
38 greg 1.1
39 greg 1.8 int sun_close(), sun_clear(), sun_paintr(), sun_getcur(),
40 greg 1.1 sun_comout(), sun_comin();
41    
42 greg 1.8 static struct driver sun_driver = {
43     sun_close, sun_clear, sun_paintr,
44     sun_getcur, sun_comout, sun_comin,
45 greg 1.9 1.0, 1100, 800
46 greg 1.1 };
47    
48 greg 1.8 static FILE *ttyin;
49 greg 1.1
50 greg 1.8 static Frame frame = 0;
51     static Tty tty = 0;
52     static Canvas canvas = 0;
53 greg 1.1
54 greg 1.8 static int xres = 0, yres = 0;
55 greg 1.1
56 greg 1.8 extern char *progname;
57 greg 1.1
58    
59 greg 1.8 struct driver *
60     dinit(name, id) /* initialize SunView (independent) */
61     char *name, *id;
62 greg 1.1 {
63     extern Notify_value my_notice_destroy();
64 greg 1.8 char *ttyargv[4], arg1[16], arg2[16];
65 greg 1.1 int pd[2];
66     int com;
67    
68     frame = window_create(0, FRAME,
69 greg 1.8 FRAME_LABEL, id==NULL ? name : id,
70 greg 1.1 FRAME_ICON, &sun_icon,
71     WIN_X, 0, WIN_Y, 0,
72     0);
73 greg 1.8 if (frame == 0) {
74     stderr_v("cannot create frame\n");
75     return(NULL);
76     }
77     if (pipe(pd) == -1) {
78     stderr_v("cannot create pipe\n");
79     return(NULL);
80     }
81 greg 1.1 sprintf(arg1, "%d", getppid());
82     sprintf(arg2, "%d", pd[1]);
83     ttyargv[0] = TTYPROG;
84     ttyargv[1] = arg1;
85     ttyargv[2] = arg2;
86     ttyargv[3] = NULL;
87     #ifdef BSD
88     fcntl(pd[0], F_SETFD, 1);
89     #endif
90     tty = window_create(frame, TTY,
91     TTY_ARGV, ttyargv,
92     WIN_ROWS, COMLH,
93 greg 1.8 TTY_QUIT_ON_CHILD_DEATH, TRUE,
94 greg 1.1 0);
95 greg 1.8 if (tty == 0) {
96     stderr_v("cannot create tty subwindow\n");
97     return(NULL);
98     }
99 greg 1.1 close(pd[1]);
100 greg 1.8 if ((ttyin = fdopen(pd[0], "r")) == NULL) {
101     stderr_v("cannot open tty\n");
102     return(NULL);
103     }
104 greg 1.1 canvas = window_create(frame, CANVAS,
105     CANVAS_RETAINED, FALSE,
106     WIN_INPUT_DESIGNEE, window_get(tty,WIN_DEVICE_NUMBER),
107     WIN_CONSUME_PICK_EVENTS, WIN_NO_EVENTS,
108     MS_LEFT, MS_MIDDLE, MS_RIGHT, 0,
109     0);
110 greg 1.8 if (canvas == 0) {
111     stderr_v("cannot create canvas\n");
112     return(NULL);
113     }
114     if (getmap() < 0) {
115     stderr_v("not a color screen\n");
116     return(NULL);
117     }
118 greg 1.6 make_gmap(GAMMA);
119 greg 1.1 window_set(canvas, CANVAS_RETAINED, TRUE, 0);
120    
121 greg 1.8 sun_driver.inpready = 0;
122     return(&sun_driver);
123 greg 1.1 }
124    
125    
126 greg 1.8 sun_close() /* all done */
127 greg 1.1 {
128 greg 1.8 if (frame != 0) {
129     window_set(frame, FRAME_NO_CONFIRM, TRUE, 0);
130     window_destroy(frame);
131 greg 1.1 }
132 greg 1.8 frame = 0;
133 greg 1.1 }
134    
135    
136 greg 1.8 sun_clear(nwidth, nheight) /* clear our canvas */
137     int nwidth, nheight;
138 greg 1.1 {
139     register Pixwin *pw;
140    
141     pw = canvas_pixwin(canvas);
142     if (nwidth != xres || nheight != yres) {
143     window_set(frame, WIN_SHOW, FALSE, 0);
144     window_set(canvas, CANVAS_AUTO_SHRINK, TRUE,
145     CANVAS_AUTO_EXPAND, TRUE, 0);
146     window_set(canvas, WIN_WIDTH, nwidth, WIN_HEIGHT, nheight, 0);
147     window_set(canvas, CANVAS_AUTO_SHRINK, FALSE,
148     CANVAS_AUTO_EXPAND, FALSE, 0);
149     window_fit(frame);
150     window_set(frame, WIN_SHOW, TRUE, 0);
151     notify_do_dispatch();
152     xres = nwidth;
153     yres = nheight;
154     }
155     pw_writebackground(pw, 0, 0, xres, xres, PIX_SRC);
156 greg 1.6 new_ctab(NCOLORS);
157 greg 1.1 }
158    
159    
160 greg 1.8 sun_paintr(col, xmin, ymin, xmax, ymax) /* fill a rectangle */
161     COLOR col;
162     int xmin, ymin, xmax, ymax;
163 greg 1.1 {
164 greg 1.6 extern int newcolr();
165 greg 1.1 int pval;
166     register Pixwin *pw;
167    
168 greg 1.6 pval = get_pixel(col, newcolr) + FIRSTCOLOR;
169 greg 1.1 pw = canvas_pixwin(canvas);
170     pw_rop(pw, xmin, yres-ymax, xmax-xmin, ymax-ymin,
171     PIX_SRC|PIX_COLOR(pval), NULL, 0, 0);
172     }
173    
174    
175 greg 1.10 sun_comin(buf, prompt) /* input a string from the command line */
176     char *buf, *prompt;
177 greg 1.1 {
178 greg 1.10 if (prompt != NULL)
179     sun_comout(prompt);
180 greg 1.1 /* echo characters */
181     do {
182     mygets(buf, ttyin);
183 greg 1.8 sun_comout(buf);
184 greg 1.1 } while (buf[0]);
185     /* get result */
186     mygets(buf, ttyin);
187     }
188    
189    
190 greg 1.8 int
191     sun_getcur(xpp, ypp) /* get cursor position */
192     int *xpp, *ypp;
193 greg 1.1 {
194 greg 1.3 Event ev;
195 greg 1.1 int c;
196    
197     notify_no_dispatch(); /* allow read to block */
198     window_set(canvas, WIN_CONSUME_KBD_EVENT, WIN_ASCII_EVENTS, 0);
199 greg 1.3 again:
200     if (window_read_event(canvas, &ev) == -1) {
201     notify_perror();
202 greg 1.8 stderr_v("window event read error\n");
203     quit(1);
204 greg 1.3 }
205     c = event_id(&ev);
206     switch (c) {
207     case MS_LEFT:
208     c = MB1;
209 greg 1.1 break;
210 greg 1.3 case MS_MIDDLE:
211     c = MB2;
212     break;
213     case MS_RIGHT:
214     c = MB3;
215     break;
216     default:
217     if (c < ASCII_FIRST || c > ASCII_LAST)
218     goto again;
219     break;
220 greg 1.1 }
221 greg 1.8 *xpp = event_x(&ev);
222     *ypp = yres-1 - event_y(&ev);
223 greg 1.3
224 greg 1.1 window_set(canvas, WIN_IGNORE_KBD_EVENT, WIN_ASCII_EVENTS, 0);
225     notify_do_dispatch();
226 greg 1.8 return(c);
227 greg 1.1 }
228    
229    
230 greg 1.8 sun_comout(s) /* put string out to tty subwindow */
231 greg 1.1 register char *s;
232     {
233     char buf[256];
234     register char *cp;
235    
236     for (cp = buf; *s; s++) {
237     if (*s == '\n')
238     *cp++ = '\r';
239     *cp++ = *s;
240     }
241 greg 1.8 /* must be a single call */
242 greg 1.1 ttysw_output(tty, buf, cp-buf);
243     }
244    
245    
246 greg 1.4 getmap() /* allocate color map segments */
247 greg 1.1 {
248 greg 1.4 char cmsname[20];
249 greg 1.5 unsigned char red[256], green[256], blue[256];
250 greg 1.1 register Pixwin *pw;
251 greg 1.5 register int i;
252    
253     for (i = 0; i < 256; i++)
254     red[i] = green[i] = blue[i] = 128;
255     red[0] = green[0] = blue[0] = 255;
256     red[1] = green[1] = blue[1] = 0;
257     red[255] = green[255] = blue[255] = 0;
258     red[254] = green[254] = blue[254] = 255;
259     red[253] = green[253] = blue[253] = 0;
260 greg 1.4 /* name shared segment */
261     sprintf(cmsname, "rv%d", getpid());
262     /* set canvas */
263 greg 1.1 pw = canvas_pixwin(canvas);
264 greg 1.4 if (pw->pw_pixrect->pr_depth < 8)
265     return(-1);
266     pw_setcmsname(pw, cmsname);
267 greg 1.5 pw_putcolormap(pw, 0, 256, red, green, blue);
268 greg 1.4 /* set tty subwindow */
269 greg 1.1 pw = (Pixwin *)window_get(tty, WIN_PIXWIN);
270 greg 1.4 pw_setcmsname(pw, cmsname);
271 greg 1.5 pw_putcolormap(pw, 0, 256, red, green, blue);
272 greg 1.4 /* set frame */
273     pw = (Pixwin *)window_get(frame, WIN_PIXWIN);
274     pw_setcmsname(pw, cmsname);
275 greg 1.5 pw_putcolormap(pw, 0, 256, red, green, blue);
276 greg 1.1
277 greg 1.4 return(0);
278 greg 1.1 }
279    
280    
281 greg 1.5 newcolr(ndx, r, g, b) /* enter a color into hardware table */
282     int ndx;
283     unsigned char r, g, b;
284 greg 1.1 {
285     register Pixwin *pw;
286 greg 1.5
287 greg 1.1 pw = canvas_pixwin(canvas);
288 greg 1.5 pw_putcolormap(pw, ndx+FIRSTCOLOR, 1,
289     &r, &g, &b);
290 greg 1.1 pw = (Pixwin *)window_get(tty, WIN_PIXWIN);
291 greg 1.5 pw_putcolormap(pw, ndx+FIRSTCOLOR, 1,
292     &r, &g, &b);
293 greg 1.1 }