ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/nwsdev.c
Revision: 1.2
Committed: Wed Jul 18 21:54:07 1990 UTC (34 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +6 -7 lines
Log Message:
bug fixes for SGI IRIS

File Contents

# Content
1 #ifndef lint
2 static char SCCSid[] = "$SunId$ LBL";
3 #endif
4
5 /*
6 * NeWS driver, by Isaac Kwo
7 *
8 * July 1990
9 */
10
11 #include <math.h>
12 #include "newsconstants.h"
13 #include "driver.h"
14 #include "nwsdev.h"
15 char inputbuffer[256];
16 int pos;
17 float gamma[257];
18
19 static int nws_close(),nws_clear(),nws_painter(),nws_getclick(),
20 nws_printer(),nws_getinput(),nws_flush(),nws_errout();
21 static struct driver nws_driver =
22 {
23 nws_close,nws_clear,nws_painter,nws_getclick,
24 nws_printer,nws_getinput,nws_flush,1.0
25 };
26
27 static int
28 nws_clear()
29 {
30 cps_clear();
31 }
32
33 static int
34 nws_getclick(xp,yp)
35 int *xp,*yp;
36 {
37 int key;
38 cps_getclick(xp,yp,&key);
39 nws_driver.inpready=0;
40 return(key);
41 }
42
43 struct driver *
44 nws_init(name,id) /* initialize driver */
45 char *name,*id;
46 {
47 int wX,wY,wW,wH,i;
48 gamma[256]=1;
49 for(i=0;i<256;i++)
50 gamma[i]=minfrac+(1-minfrac)*pow(i/256.,1./gammacorrection);
51 ps_open_PostScript();
52 getthebox(&wX,&wY,&wW,&wH);
53 if(wW<100)wW=100;
54 if(wH<100+textareaheight)wH=100+textareaheight;
55 cps_initcanvas
56 (wX,wY,wW,wH,(int)MB1,(int)MB2,(int)MB3);
57 nws_driver.xsiz=wW;
58 nws_driver.ysiz=wH-textareaheight;
59 nws_driver.inpready=0;
60 cmdvec=nws_printer;
61 if(wrnvec!=NULL)wrnvec=nws_errout;
62 return(&nws_driver);
63 }
64
65 static int
66 nws_close() /* close the display */
67 {
68 cmdvec=NULL;
69 if(wrnvec!=NULL)wrnvec=stderr_v;
70 cps_cleanup();
71 ps_flush_PostScript();
72 ps_close_PostScript();
73 }
74
75 static int
76 nws_flush() /* flush output and check for keyboard input */
77 {
78 ps_flush_PostScript();
79 isready(&(nws_driver.inpready));
80 }
81
82 static int
83 nws_errout(msg) /* output an error message */
84 char *msg; /* my comments are so bogus */
85 {
86 stderr_v(msg);
87 nws_printer(msg);
88 }
89
90 static int
91 nws_painter(col,xmin,ymin,xmax,ymax)
92 float col[3];
93 int xmin,ymin,xmax,ymax;
94 {
95 int i;
96 float col2[3];
97 /* NeWS trashes the window if a float value less than 1/256 is sent
98 to it. Therefore, weed out all such values first */
99 for(i=0;i<3;i++)
100 {
101 col2[i]=col[i];
102 if(col2[i]>1)col2[i]=1;
103 col2[i]=gamma[(int)(col2[i]*256)];
104 }
105 box(xmin,ymin+textareaheight,xmax,ymax+textareaheight
106 ,col2[0],col2[1],col2[2]);
107 }
108
109 static int
110 nws_printer(orig) /* printer recognises \n as a linefeed */
111 char *orig;
112 {
113 char *m,*s,string[BUFSIZ]; /* s is for string and m is for message */
114 m=s=string;
115 while((*(s++))=(*(orig++)));
116 s=string;
117 while(*s)
118 if(*s++=='\n')
119 {
120 *(s-1)=0;
121 linefeed(m);
122 m=s;
123 }
124 printout(m);
125 }
126
127 static int
128 mygetc()
129 {
130 int key;
131 getkey(&key);
132 return(key);
133 }
134 static int
135 myputs(str)
136 char *str;
137 {
138 char buf[2]; buf[1]=0;
139 for(;*str;str++)
140 switch(*str)
141 {
142 case '\n': pos=0; linefeed(""); break;
143 case '\b':
144 buf[0]=inputbuffer[--pos];
145 delete(buf);
146 break;
147 default:
148 buf[0]=inputbuffer[pos++]=(*str);
149 printout(buf);
150 break;
151 }
152 return(0);
153 }
154 static int
155 nws_getinput(s,prompt)
156 char s[BUFSIZ];
157 {
158 if(prompt)nws_printer(prompt);
159 startcomin();
160 pos=0;
161 editline(s,mygetc,myputs);
162 endcomin();
163 nws_driver.inpready=0;
164 }