1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id$"; |
3 |
#endif |
4 |
/* |
5 |
* qt.c - driver for qt |
6 |
*/ |
7 |
#include "math.h" |
8 |
#include "copyright.h" |
9 |
#include "standard.h" |
10 |
#include "platform.h" |
11 |
#include "color.h" |
12 |
#include "driver.h" |
13 |
#include "rpaint.h" |
14 |
#include "color.h" |
15 |
|
16 |
static char lastPrompt[1024]; |
17 |
static const char* currentCommand =0; |
18 |
static int abort_render = 0; |
19 |
static int progress = 0; |
20 |
static int last_total_progress = 0; |
21 |
#define GAMMA 2.2 /* default exponent correction */ |
22 |
|
23 |
static dr_closef_t qt_close; |
24 |
static dr_clearf_t qt_clear; |
25 |
static dr_paintrf_t qt_paintr; |
26 |
static dr_getcurf_t qt_getcur; |
27 |
static dr_comoutf_t qt_comout; |
28 |
static dr_cominf_t qt_comin; |
29 |
static dr_flushf_t qt_flush; |
30 |
|
31 |
static struct driver qt_driver = { |
32 |
qt_close, qt_clear, qt_paintr, qt_getcur, |
33 |
qt_comout, qt_comin, qt_flush, 1.0 |
34 |
}; |
35 |
|
36 |
/* functions from qt_rvu_main.cxx */ |
37 |
extern qt_rvu_init(char*, char*, int*, int* ); |
38 |
extern qt_resize(int, int); |
39 |
extern qt_rvu_paint(int r,int g,int b,int xmin, |
40 |
int ymin,int xmax,int ymax); |
41 |
extern void qt_flush_display(); |
42 |
extern int qt_rvu_run(); |
43 |
extern void qt_window_comout(const char*); |
44 |
extern void qt_set_progress(int); |
45 |
extern int qt_open_text_dialog(char* , const char*); |
46 |
|
47 |
extern struct driver * |
48 |
qt_init( /* initialize driver */ |
49 |
char *name, |
50 |
char *id |
51 |
) |
52 |
{ |
53 |
lastPrompt[0] = 0; |
54 |
make_gmap(GAMMA); |
55 |
qt_rvu_init(name, id, &qt_driver.xsiz, &qt_driver.ysiz); |
56 |
return(&qt_driver); |
57 |
} |
58 |
|
59 |
|
60 |
static void |
61 |
qt_close(void) /* close our display */ |
62 |
{ |
63 |
fprintf(stderr, "Qt close\n"); |
64 |
} |
65 |
|
66 |
static void |
67 |
qt_clear( /* clear our display */ |
68 |
int xres, |
69 |
int yres |
70 |
) |
71 |
{ |
72 |
qt_resize(xres, yres); |
73 |
} |
74 |
|
75 |
|
76 |
static void |
77 |
qt_paintr( /* fill a rectangle */ |
78 |
COLOR col, |
79 |
int xmin, |
80 |
int ymin, |
81 |
int xmax, |
82 |
int ymax |
83 |
) |
84 |
{ |
85 |
uby8 rgb[3]; |
86 |
map_color(rgb, col); |
87 |
qt_rvu_paint(rgb[RED], rgb[GRN], rgb[BLU], |
88 |
xmin, ymin, xmax, ymax); |
89 |
} |
90 |
|
91 |
#define SCALE 1.2 |
92 |
|
93 |
static void |
94 |
qt_flush(void) /* flush output */ |
95 |
{ |
96 |
int p; |
97 |
if(last_total_progress) |
98 |
{ |
99 |
progress++; |
100 |
p = pdepth*10 + |
101 |
(int)floor(10 * |
102 |
atan( SCALE * progress / last_total_progress) * 2.0/3.141593); |
103 |
qt_set_progress(p); |
104 |
} |
105 |
qt_flush_display(); |
106 |
} |
107 |
|
108 |
|
109 |
static int comincalls = 0; |
110 |
static void |
111 |
qt_comin( /* read in command line qt gui */ |
112 |
char *inp, |
113 |
char *prompt |
114 |
) |
115 |
{ |
116 |
if (prompt && strlen(prompt)) |
117 |
{ |
118 |
qt_comout(prompt); |
119 |
} |
120 |
if(comincalls < 2) |
121 |
{ |
122 |
comincalls++; |
123 |
} |
124 |
/* if prompt is not set, then use the lastPrompt which |
125 |
comes from the last call to comout */ |
126 |
if(!prompt) |
127 |
{ |
128 |
prompt = lastPrompt; |
129 |
} |
130 |
/* first time call to qt_comin start qt event loop */ |
131 |
if(comincalls == 1) |
132 |
{ |
133 |
qt_rvu_run(); |
134 |
/* when qt is done we are done so exit */ |
135 |
exit(0); |
136 |
} |
137 |
/* This code will be called from inside the running |
138 |
qt_rvu_run loop in two cases: |
139 |
1. when a user enters a new command to the text widget. In |
140 |
this case the currentCommand is not null. |
141 |
2. when a command calls comin directly, that is the else |
142 |
case. */ |
143 |
if(currentCommand) |
144 |
{ |
145 |
/* A user has entered a new command */ |
146 |
qt_comout((char*)currentCommand); |
147 |
/* copy the user command into inp, set |
148 |
currentCommand to null so as not to use it again, |
149 |
and then return */ |
150 |
strcpy(inp, currentCommand); |
151 |
currentCommand = 0; |
152 |
return; |
153 |
} |
154 |
else |
155 |
{ |
156 |
/* in this case comin has been called from inside a |
157 |
command call like view. |
158 |
OK tricky bit here. If the prompt is empty, it |
159 |
is just trying to get the user to hit enter so that |
160 |
the most recent comout does not scrool away. Since the |
161 |
qt interface has a scroll bar we don't have to do that, |
162 |
and do not want to prompt the user. Also, if the prompt |
163 |
is set to "done: ", then we don't want to prompt the user. |
164 |
In other cases we assume that we are inside a command |
165 |
that is asking for more input and we use a dialog box |
166 |
to get it. */ |
167 |
if(strlen(prompt) > 0 && strcmp(prompt, "done: ") != 0) |
168 |
{ |
169 |
/* if the user entered new text, then echo that |
170 |
to the output window. */ |
171 |
if(qt_open_text_dialog(inp, prompt)) |
172 |
{ |
173 |
qt_window_comout(inp); |
174 |
} |
175 |
lastPrompt[0] = 0; |
176 |
} |
177 |
} |
178 |
} |
179 |
|
180 |
static void |
181 |
qt_comout( /* write out string to stdout */ |
182 |
char *outp |
183 |
) |
184 |
{ |
185 |
if (!outp) |
186 |
{ |
187 |
return; |
188 |
} |
189 |
if (strlen(outp) > 0) |
190 |
{ |
191 |
if(outp[strlen(outp)-2] == ':') |
192 |
{ |
193 |
strcpy(lastPrompt, outp); |
194 |
} |
195 |
qt_window_comout(outp); |
196 |
} |
197 |
} |
198 |
|
199 |
extern void qt_rvu_get_position(int *x, int *y); |
200 |
|
201 |
static int |
202 |
qt_getcur( /* get cursor position */ |
203 |
int *xp, |
204 |
int *yp |
205 |
) |
206 |
{ |
207 |
qt_rvu_get_position(xp, yp); |
208 |
return 0; |
209 |
} |
210 |
|
211 |
void qt_set_abort(int value) |
212 |
{ |
213 |
dev->inpready = value; |
214 |
} |
215 |
|
216 |
|
217 |
/* process one command from the GUI */ |
218 |
void qt_process_command(const char* com) |
219 |
{ |
220 |
char buf[512]; |
221 |
buf[0] = 0; |
222 |
/* set the currentCommand to the command */ |
223 |
currentCommand = com; |
224 |
/* Call command with no prompt, this will in |
225 |
turn call qt_comin which will use the currentCommand |
226 |
pointer as the command to process */ |
227 |
command(""); |
228 |
/* after processing a command try to do a render */ |
229 |
for ( ; ; ) |
230 |
{ |
231 |
if (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth) |
232 |
{ |
233 |
qt_set_progress(100); |
234 |
qt_comout("done"); |
235 |
return; |
236 |
} |
237 |
errno = 0; |
238 |
if (hresolu <= psample<<pdepth && vresolu <= psample<<pdepth) |
239 |
{ |
240 |
sprintf(buf, "%d sampling...\n", 1<<pdepth); |
241 |
qt_comout(buf); |
242 |
last_total_progress = progress ? progress:1; |
243 |
progress = 0; |
244 |
rsample(); |
245 |
} |
246 |
else |
247 |
{ |
248 |
sprintf(buf, "%d refining...\n", 1<<pdepth); |
249 |
qt_comout(buf); |
250 |
last_total_progress = progress ? progress:1; |
251 |
progress = 0; |
252 |
refine(&ptrunk, pdepth+1); |
253 |
} |
254 |
if (dev->inpready) |
255 |
{ |
256 |
qt_comout("abort"); |
257 |
dev->inpready = 0; |
258 |
pdepth = 10; |
259 |
return; |
260 |
} |
261 |
/* finished this depth */ |
262 |
pdepth++; |
263 |
} |
264 |
} |
265 |
|