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