Annotation of OpenXM_contrib2/asir2000/lib/glib, Revision 1.21
1.21 ! takayama 1: /* $OpenXM: OpenXM_contrib2/asir2000/lib/glib,v 1.20 2008/08/07 06:00:34 takayama Exp $ */
1.1 takayama 2:
1.9 takayama 3: /* BUG: this library has not yet been adapted to the new automatic launcher
4: of ox_plot. 2002, Aug, 4. Do not load glib more than twice.
5: */
1.1 takayama 6:
1.17 takayama 7: extern Cfep_loaded$
1.21 ! takayama 8: extern Cfep_use_opengl$
1.17 takayama 9:
1.12 takayama 10: #define DO_NOT_START_SERVER_EXPLICITLY
11:
1.1 takayama 12: /* #define CLIP 1 */
13: /* #define DEBUG 1 */
14: #define LIST 4
15:
1.5 takayama 16: def glib_floor(N) {
1.1 takayama 17: return(pari(floor,N));
18: }
19:
1.5 takayama 20: /*
1.1 takayama 21: def join(A,B) {
22: if (type(B) == 0) return(A);
23: return(append(A,B));
24: }
25: def eigenvalues(M) {
26: return(pari(eigen,M));
27: }
28: def roots(F) {
29: return(pari(roots,F));
30: }
1.5 takayama 31: */
1.1 takayama 32:
33: /* ---------------------------------------------- */
1.8 takayama 34: def glib_ox_get_errors(P) {
1.1 takayama 35: ox_push_cmd(P,276);
36: return(ox_pop_cmo(P));
37: }
38:
39: def reset_plot() {
40: extern Glib_process;
1.21 ! takayama 41: if ((!Cfep_loaded) || (!Cfep_use_opengl)) {
1.17 takayama 42: print(" Sending signal to ox_plot",0);
43: ox_reset(Glib_process);
44: print(" Done.");
45: }
1.1 takayama 46: }
1.5 takayama 47: Glib_ps = 0$
48: Glib_h = []$
1.1 takayama 49: Glib_canvas_x = 400$
50: Glib_canvas_y = 400$
51: Glib_xmin=0$ Glib_xmax=Glib_canvas_x$
52: Glib_ymin=0$ Glib_ymax=Glib_canvas_y$
1.11 takayama 53: Glib_math_coordinate=0$
1.12 takayama 54:
1.1 takayama 55:
56: Glib_canvas = -1$
57: Glib_xmag = 1$ Glib_ymag=1$ Glib_xoffset=0$ Glib_yoffset=0$
58: Glib_safe_mode = 2 $
59: Glib_counter = 100$
60:
1.16 takayama 61: extern Glib_ps_sx$
62: extern Glib_ps_sy$
63: Glib_ps_sx=2$ /* mag=1/2 for PS picture. cf. glib_ps_form, glib_tops */
64: Glib_ps_sy=2$ /* mag=1/2 for PS picture */
65:
1.1 takayama 66: def open_Canvas(P,S) {
1.12 takayama 67: extern Glib_process;
1.17 takayama 68: /* print("open_Canvas: ",0);print(S); */
1.21 ! takayama 69: if ((!Cfep_loaded) || (!Cfep_use_opengl)) {
1.17 takayama 70: if (P < 0) P=open_canvas(S); /* BUG, get process No. */
71: else open_canvas(P,S);
72: Glib_process = P;
1.1 takayama 73: R = ox_pop_cmo(P);
1.17 takayama 74: /*
75: if (glib_ox_get_errors(P) == []) {
76: R = ox_pop_cmo(P);
77: }else{
78: debug;
79: }
80: */
1.21 ! takayama 81: }else {
1.17 takayama 82: R=cfep.open_canvas(S);
1.1 takayama 83: }
84: return(R);
85: }
86:
1.8 takayama 87: /*&usage begin: glib_open()
88: It starts the ox_plot server and opens a canvas.
89: The canvas size is set to {Glib_canvas_x} X {Glib_canvas_y}
90: (the default value is 400).
91: This function is automatically called when the user calls glib
92: functions.
93: end: */
94:
1.1 takayama 95: def glib_open() {
96: extern Glib_canvas_x, Glib_canvas_y,
1.12 takayama 97: Glib_process, Glib_canvas,
98: Glib_server_started, Glib_process$
1.21 ! takayama 99: if ((!Cfep_loaded) || (!Cfep_use_opengl)) return glib_openx11();
1.17 takayama 100: else {
101: Glib_canvas = open_Canvas(-1,[Glib_canvas_x,Glib_canvas_y])$
102: Glib_server_started = 1$
103: return(Glib_canvas);
104: }
105: }
106: def glib_openx11() {
107: extern Glib_canvas_x, Glib_canvas_y,
108: Glib_process, Glib_canvas,
109: Glib_server_started, Glib_process$
1.12 takayama 110: #ifndef DO_NOT_START_SERVER_EXPLICITLY
1.17 takayama 111: if (type(Glib_server_started) == 0) {
1.12 takayama 112: Glib_process = ox_launch_nox(0,"ox_plot")$
113: register_handler(reset_plot);
114: Glib_server_started = 1$
115: }$
1.1 takayama 116: Glib_canvas = open_Canvas(Glib_process,[Glib_canvas_x,Glib_canvas_y])$
1.12 takayama 117: #else
118: Glib_canvas = open_Canvas(-1,[Glib_canvas_x,Glib_canvas_y])$
119: register_handler(reset_plot);
120: Glib_server_started = 1$
121: #endif
1.1 takayama 122: glib_check_strict();
123: return(Glib_canvas);
124: }
125:
126: def glib_check() {
127: extern Glib_process, Glib_canvas, Glib_safe_mode,
128: Glib_canvas_x, Glib_canvas_y, Glib_counter;
129: if (Glib_safe_mode == 0) {
130: return(0);
131: }
132: if (Glib_safe_mode == 2) {
133: if (Glib_counter > 0) {
134: Glib_counter--;
135: return(0);
136: }else{
137: Glib_counter=100;
138: }
139: }
140: glib_check_strict();
141: }
142: def glib_check_strict() {
143: extern Glib_process, Glib_canvas, Glib_safe_mode,
144: Glib_canvas_x, Glib_canvas_y, Glib_counter;
145: if (Glib_canvas < 0) {
146: glib_open();
147: }
1.21 ! takayama 148: if (Cfep_loaded && Cfep_use_opengl) return ;
1.8 takayama 149: E = glib_ox_get_errors(Glib_process);
1.1 takayama 150: if (E != []) {
151: ox_pops(Glib_process,200);
152: print(E);
153: print("Warning: ",0);
154: print("Drawing canvas seems to be closed.");
155: print("Opening a new canvas.");
156: Glib_canvas = open_Canvas(Glib_process,[Glib_canvas_x,Glib_canvas_y])$
157: error("Drawing aborted");
158: }
159: }
160:
1.19 takayama 161: /*&usage begin: glib_clear()
162: Clear the screen.
163: end: */
1.1 takayama 164: def glib_clear() {
165: extern Glib_process, Glib_canvas;
166: if (Glib_canvas < 0) glib_open();
1.21 ! takayama 167: if ((!Cfep_loaded) || (!Cfep_use_opengl)) clear_canvas(Glib_process,Glib_canvas);
1.19 takayama 168: else cfep.glib_clear();
1.1 takayama 169: }
170:
1.5 takayama 171: /*&usage begin: glib_window(Xmin,Ymin,Xmax,Ymax)
172: It generates a window with the left top corner [{Xmin},{Ymin}] and
173: the right bottom corner [{Xmax},{Ymax}].
1.11 takayama 174: If the global variable {Glib_math_coordinate} is set to 1, mathematical
175: coordinate system will be employed, i.e., the left top
176: corner will have the coordinate [{Xmin},{Ymax}].
1.5 takayama 177: example: glib_window(-1,-1,10,10);
178: end: */
1.1 takayama 179: def glib_window(Xmin,Ymin,Xmax,Ymax) {
180: extern Glib_xmin, Glib_xmax, Glib_ymin, Glib_ymax,
181: Glib_canvas_x, Glib_canvas_y, Glib_process, Glib_canvas,
182: Glib_xoffset, Glib_yoffset, Glib_xmag, Glib_ymag;
183: if (Xmax <= Xmin) error("glib window: Invalid size");
184: if (Ymax <= Ymin) error("glib window: Invalid size");
1.2 takayama 185: glib_check_arg(Xmin,Ymin); glib_check_arg(Xmax,Ymax);
1.1 takayama 186: Glib_xmin = Xmin; Glib_xmax = Xmax;
187: Glib_ymin = Ymin; Glib_ymax = Ymax;
188: Glib_xoffset = -Xmin;
189: Glib_yoffset = -Ymin;
190: Glib_xmag = Glib_canvas_x/(Xmax-Xmin);
191: Glib_ymag = Glib_canvas_y/(Ymax-Ymin);
192: if (Glib_canvas < 0) glib_open();
193: }
194:
1.2 takayama 195: def glib_check_arg(X,Y) {
196: if (type(X) <= 1 && type(Y) <= 1) return 1;
197: else {
198: print("Error in glib: arguments ",0);
199: print([X,Y],0);
200: print(" are not numbers.");
201: error("Invalid argument for glib_window, glib_putpixel, glib_line.");
202: }
203: }
204:
1.6 takayama 205: /*&usage begin: glib_putpixel(X,Y|color)
1.5 takayama 206: It puts a pixel at [{X},{Y}] with {color}
207: example: glib_putpixel(1,2 | color=0xffff00);
208: end: */
1.1 takayama 209: def glib_putpixel(X,Y) {
210: extern Glib_process, Glib_canvas,
1.11 takayama 211: Glib_xoffset, Glib_yoffset, Glib_xmag, Glib_ymag, Glib_ps,
212: Glib_math_coordinate, Glib_canvas_y;
1.1 takayama 213: if (Glib_canvas < 0) glib_open();
214: glib_check();
1.2 takayama 215: glib_check_arg(X,Y);
1.3 noro 216: C = getopt(color);
1.11 takayama 217: if (Glib_math_coordinate) {
218: Pos = [glib_floor(Glib_xmag*(X+Glib_xoffset)),
219: Glib_canvas_y-glib_floor(Glib_ymag*(Y+Glib_yoffset))];
220: Pos2= [glib_floor(Glib_xmag*(X+Glib_xoffset)),
221: glib_floor(Glib_ymag*(Y+Glib_yoffset))];
222: }else{
223: Pos = [glib_floor(Glib_xmag*(X+Glib_xoffset)),
224: glib_floor(Glib_ymag*(Y+Glib_yoffset))];
225: Pos2= [glib_floor(Glib_xmag*(X+Glib_xoffset)),
226: Glib_canvas_y-glib_floor(Glib_ymag*(Y+Glib_yoffset))];
227: }
1.5 takayama 228: if ( type(C) != -1 ) {
1.21 ! takayama 229: if ((!Cfep_loaded) || (!Cfep_use_opengl)) draw_obj(Glib_process,Glib_canvas,Pos,C);
1.17 takayama 230: else cfep.draw_obj2(Glib_process,Glib_canvas,Pos,C);
1.11 takayama 231: if (Glib_ps) glib_history(["putpixel",Pos2,C]);
1.5 takayama 232: }else{
1.21 ! takayama 233: if ((!Cfep_loaded) || (!Cfep_use_opengl)) draw_obj(Glib_process,Glib_canvas,Pos);
1.17 takayama 234: else cfep.draw_obj(Glib_process,Glib_canvas,Pos);
1.11 takayama 235: if (Glib_ps) glib_history(["putpixel",Pos2,0]);
1.5 takayama 236: }
1.1 takayama 237: }
238:
1.20 takayama 239: /*&usage begin: glib_line(X0,Y0,X1,Y1|color,shape)
240: It draws the line [{X0},{Y0}]-- [{X1},{Y1}] with {color} and {shape}
1.5 takayama 241: example: glib_line(0,0,5,3/2 | color=0xff00ff);
1.20 takayama 242: glib_line(0,0,10,0 | shape=arrow);
1.5 takayama 243: end: */
1.1 takayama 244: def glib_line(X0,Y0,X1,Y1) {
245: extern Glib_xmag, Glib_ymag, Glib_xoffset, Glib_yoffset;
1.3 noro 246: C = getopt(color);
1.2 takayama 247: glib_check_arg(X0,Y0);
248: glib_check_arg(X1,Y1);
1.5 takayama 249: glib_clip_line(glib_floor(Glib_xmag*(X0+Glib_xoffset)),
250: glib_floor(Glib_ymag*(Y0+Glib_yoffset)),
251: glib_floor(Glib_xmag*(X1+Glib_xoffset)),
252: glib_floor(Glib_ymag*(Y1+Glib_yoffset)),C);
1.20 takayama 253: Shape = getopt(shape);
254: if (type(Shape) != 2) return;
255: Px = X0+(7/8)*(X1-X0);
256: Py = Y0+(7/8)*(Y1-Y0);
257: Qx = (Y0-Y1)/8;
258: Qy = (X1-X0)/8;
259: if (type(C)>0) glib_line(X1,Y1,Px+Qx,Py+Qy | color=C);
260: else glib_line(X1,Y1,Px+Qx,Py+Qy);
261: if (type(C)>0) glib_line(X1,Y1,Px-Qx,Py-Qy | color=C);
262: else glib_line(X1,Y1,Px-Qx,Py-Qy);
1.1 takayama 263: }
264:
1.3 noro 265: def glib_clip_line(X0,Y0,X1,Y1,Color) {
1.1 takayama 266: /* X0, Y0, X1, Y1 should be integers.
267: Coordinates are already translated. */
1.5 takayama 268: extern Glib_process, Glib_canvas, Glib_canvas_x, Glib_canvas_y,
1.11 takayama 269: Glib_ps, Glib_math_coordinate;
1.1 takayama 270: if (Glib_canvas < 0) glib_open();
271:
1.5 takayama 272: if (Glib_ps) {
1.1 takayama 273: #ifdef DEBUG
274: print(["clip_line",[X0,Y0,X1,Y1]]);
275: #endif
276: /* clip by x = 0 */
277: S = glib_clip0_x(X0,Y0,X1,Y1,0);
278: #ifdef DEBUG
279: print(["clip0_x",S]);
280: #endif
281: if (type(S) == 0) return;
282: X0 = S[0]; Y0 = S[1]; X1 = S[2]; Y1 = S[3];
283:
284: S = glib_clip1_x(X0,Y0,X1,Y1,Glib_canvas_x-1);
285: #ifdef DEBUG
286: print(["clip1_x",S]);
287: #endif
288: if (type(S) == 0) return;
289: X0 = S[0]; Y0 = S[1]; X1 = S[2]; Y1 = S[3];
290:
291: S = glib_clip0_y(X0,Y0,X1,Y1,0);
292: #ifdef DEBUG
293: print(["clip0_y",S]);
294: #endif
295: if (type(S) == 0) return;
296: X0 = S[0]; Y0 = S[1]; X1 = S[2]; Y1 = S[3];
297:
298: S = glib_clip1_y(X0,Y0,X1,Y1,Glib_canvas_y-1);
299: #ifdef DEBUG
300: print(["clip1_y",S]);
301: #endif
302: if (type(S) == 0) return;
303: X0 = S[0]; Y0 = S[1]; X1 = S[2]; Y1 = S[3];
304:
305: #ifdef DEBUG
306: print([X0,Y0,X1,Y1]);
307: #endif
1.5 takayama 308: }
309:
1.1 takayama 310: glib_check();
1.11 takayama 311: if (Glib_math_coordinate) {
312: Pos = [glib_floor(X0),Glib_canvas_y-glib_floor(Y0),
313: glib_floor(X1),Glib_canvas_y-glib_floor(Y1)];
314: Pos2= [glib_floor(X0),glib_floor(Y0),glib_floor(X1),glib_floor(Y1)];
315: }else{
316: Pos = [glib_floor(X0),glib_floor(Y0),glib_floor(X1),glib_floor(Y1)];
317: Pos2 = [glib_floor(X0),Glib_canvas_y-glib_floor(Y0),
318: glib_floor(X1),Glib_canvas_y-glib_floor(Y1)];
319: }
1.5 takayama 320: if ( type(Color) != -1 ) {
1.21 ! takayama 321: if ((!Cfep_loaded) || (!Cfep_use_opengl)) draw_obj(Glib_process,Glib_canvas,Pos,Color);
1.17 takayama 322: else cfep.draw_obj2(Glib_process,Glib_canvas,Pos,Color);
1.11 takayama 323: if (Glib_ps) glib_history(["line",Pos2,Color]);
1.5 takayama 324: }else{
1.21 ! takayama 325: if ((!Cfep_loaded) || (!Cfep_use_opengl)) draw_obj(Glib_process,Glib_canvas,Pos);
1.17 takayama 326: else cfep.draw_obj(Glib_process,Glib_canvas,Pos);
1.11 takayama 327: if (Glib_ps) glib_history(["line",Pos2,0]);
1.5 takayama 328: }
1.1 takayama 329: }
330:
331: def glib_clip0_x(X0,Y0,X1,Y1,Clip) {
332: if (X0 < Clip && X1 < Clip) return(0);
333: if (X0 < Clip && X1 > Clip) {
334: return([Clip, Y0+(Clip-X0)*(Y1-Y0)/(X1-X0),X1,Y1]);
335: }
336: if (X1 > Clip && X1 < Clip) {
337: return([X0,Y0,Clip, Y1+(Clip-X1)*(Y0-Y1)/(X0-X1)]);
338: }
339: return([X0,Y0,X1,Y1]);
340: }
341: def glib_clip0_y(X0,Y0,X1,Y1,Clip) {
342: if (Y0 < Clip && Y1 < Clip) return(0);
343: if (Y0 < Clip && Y1 > Clip) {
344: return([X0+(Clip-Y0)*(X1-X0)/(Y1-Y0),Clip,X1,Y1]);
345: }
346: if (Y1 > Clip && Y1 < Clip) {
347: return([X0,Y0,X1+(Clip-Y1)*(X0-X1)/(Y0-Y1),Clip]);
348: }
349: return([X0,Y0,X1,Y1]);
350: }
351: def glib_clip1_x(X0,Y0,X1,Y1,Clip) {
352: if (X0 > Clip && X1 > Clip) return(0);
353: if (X0 > Clip && X1 < Clip) {
354: return([Clip, Y0+(Clip-X0)*(Y1-Y0)/(X1-X0),X1,Y1]);
355: }
356: if (X1 < Clip && X1 > Clip) {
357: return([X0,Y0,Clip, Y1+(Clip-X1)*(Y0-Y1)/(X0-X1)]);
358: }
359: return([X0,Y0,X1,Y1]);
360: }
361: def glib_clip1_y(X0,Y0,X1,Y1,Clip) {
362: if (Y0 > Clip && Y1 > Clip) return(0);
363: if (Y0 > Clip && Y1 < Clip) {
364: return([X0+(Clip-Y0)*(X1-X0)/(Y1-Y0),Clip,X1,Y1]);
365: }
366: if (Y0 < Clip && Y1 > Clip) {
367: return([X0,Y0,X1+(Clip-Y1)*(X0-X1)/(Y0-Y1),Clip]);
368: }
369: return([X0,Y0,X1,Y1]);
1.4 takayama 370: }
371:
1.6 takayama 372: /*&usage begin: glib_print(X,Y,Text|color)
1.4 takayama 373: It put a string {Text} at [{X},{Y}] on the glib canvas.
374: example: glib_print(100,100,"Hello Worlds" | color=0xff0000);
375: end: */
376: def glib_print(X,Y,Text) {
377: extern Glib_process, Glib_canvas,
1.11 takayama 378: Glib_xoffset, Glib_yoffset, Glib_xmag, Glib_ymag, Glib_ps,
379: Glib_math_coordinate, Glib_canvas_y;
1.4 takayama 380: if (Glib_canvas < 0) glib_open();
381: glib_check();
382: glib_check_arg(X,Y);
383: if (type(Text) != 7) error("glib_print(X,Y,Text): Text must be a string.");
384: C = getopt(color);
1.11 takayama 385: if (Glib_math_coordinate) {
386: Pos = [glib_floor(Glib_xmag*(X+Glib_xoffset)),
387: Glib_canvas_y-glib_floor(Glib_ymag*(Y+Glib_yoffset))];
388: Pos2= [glib_floor(Glib_xmag*(X+Glib_xoffset)),
389: glib_floor(Glib_ymag*(Y+Glib_yoffset))];
390: }else{
391: Pos = [glib_floor(Glib_xmag*(X+Glib_xoffset)),
392: glib_floor(Glib_ymag*(Y+Glib_yoffset))];
393: Pos2= [glib_floor(Glib_xmag*(X+Glib_xoffset)),
394: Glib_canvas_y-glib_floor(Glib_ymag*(Y+Glib_yoffset))];
395: }
1.5 takayama 396: if ( type(C) != -1 ) {
1.21 ! takayama 397: if ((!Cfep_loaded) || (!Cfep_use_opengl)) draw_string(Glib_process,Glib_canvas,Pos,Text,C);
1.17 takayama 398: else cfep.draw_string2(Glib_process,Glib_canvas,Pos,Text,C);
1.11 takayama 399: if (Glib_ps) glib_history(["print",Pos2,Text,C]);
1.5 takayama 400: }else{
1.21 ! takayama 401: if ((!Cfep_loaded) || (!Cfep_use_opengl)) draw_string(Glib_process,Glib_canvas,Pos,Text);
1.17 takayama 402: else cfep.draw_string(Glib_process,Glib_canvas,Pos,Text);
1.11 takayama 403: if (Glib_ps) glib_history(["print",Pos2,Text,0]);
1.5 takayama 404: }
405: }
406:
407: def glib_history(L) {
1.11 takayama 408: extern Glib_h, Glib_canvas_x, Glib_canvas_y,
409: Glib_math_coodinate;
1.5 takayama 410: if (L[0] == "putpixel" || L[0] == "print") {
411: if (L[1][0] <= Glib_canvas_x && L[1][0] >= 0) {
412: if (L[1][1] <= Glib_canvas_x && L[1][1] >= 0)
413: Glib_h = cons(L,Glib_h);
414: }
415: }else {
416: Glib_h = cons(L,Glib_h);
417: }
418: return 0;
419: }
420:
1.16 takayama 421: #define xxx(x) idiv(x,Glib_ps_sx)
422: #define yyy(y) idiv(y,Glib_ps_sy)
423:
1.6 takayama 424: /*&usage begin: glib_tops()
1.5 takayama 425: If Glib_ps is set to 1,
426: it returns a postscript program to draw the picture on the canvas.
1.8 takayama 427: ref: print_output
1.5 takayama 428: end: */
429: def glib_tops() {
430: extern Glib_h;
431: return glib_ps(Glib_h);
432: }
433: def glib_ps(L) {
1.16 takayama 434: extern Glib_ps_sx;
435: extern Glib_ps_sy;
1.13 takayama 436: PS = string_to_tb("");
1.5 takayama 437: Prev_color = 0;
438: /* Prolog */
1.13 takayama 439: write_to_tb("%%!PS-Adobe-1.0\n",PS);
440: write_to_tb("%%BoundingBox: 0 0 " +
1.16 takayama 441: rtostr(xxx(Glib_canvas_x)) + " " + rtostr(yyy(Glib_canvas_y)) + "\n",PS);
1.13 takayama 442: write_to_tb("%%Creator: This is generated by ifplot\n",PS);
443: write_to_tb("%%Title: ifplot\n",PS);
444: write_to_tb("%%EndComments: \n",PS);
445: write_to_tb("0.1 setlinewidth \n",PS);
446: write_to_tb("2 setlinecap \n",PS);
447: write_to_tb("2 setlinejoin \n",PS);
448: write_to_tb("/ifplot_putpixel { \n",PS);
449: write_to_tb(" /yyy 2 1 roll def /xxx 2 1 roll def \n",PS);
450: write_to_tb(" gsave newpath xxx yyy .5 0 360 arc \n",PS);
451: write_to_tb(" fill grestore \n",PS);
452: write_to_tb("} def \n",PS);
1.5 takayama 453:
454: L = reverse(L);
455: N = length(L);
456: for (I=0; I<N; I++) {
457: C = L[I];
458: if (C[length(C)-1] != Prev_color) {
459: Prev_color = C[length(C)-1];
1.13 takayama 460: write_to_tb(rtostr(deval(ishift(Prev_color,16)/256)) + " " +
1.5 takayama 461: rtostr(deval(iand(ishift(Prev_color,8),0xff)/256)) + " " +
1.13 takayama 462: rtostr(deval(iand(Prev_color,0xff)/256)) + " setrgbcolor \n",PS);
1.5 takayama 463: }
464: if (C[0] == "putpixel") {
1.16 takayama 465: write_to_tb(rtostr(xxx(C[1][0])) + " " + rtostr(yyy(C[1][1])) + " ifplot_putpixel \n",PS);
1.5 takayama 466: }
467: if (C[0] == "line") {
1.13 takayama 468: write_to_tb(" newpath ",PS);
1.16 takayama 469: write_to_tb(rtostr(xxx(C[1][0])) + " " + rtostr(yyy(C[1][1])) + " moveto " +
470: rtostr(xxx(C[1][2])) + " " + rtostr(yyy(C[1][3])) + " lineto stroke \n",PS);
1.5 takayama 471: }
472: if (C[0] == "print") {
1.13 takayama 473: write_to_tb("/Times-Roman findfont 10 scalefont setfont \n",PS);
1.16 takayama 474: write_to_tb(rtostr(xxx(C[1][0])) + " " + rtostr(yyy(C[1][1])) + " moveto ",PS);
1.13 takayama 475: write_to_tb("(" + C[2] + ") show \n",PS);
1.5 takayama 476: }
477: }
478:
479: /* Epilog */
1.13 takayama 480: write_to_tb("0 0 0 setrgbcolor \n",PS);
481: write_to_tb("showpage \n",PS);
1.5 takayama 482:
1.13 takayama 483: return tb_to_string(PS);
1.14 takayama 484: }
485:
486: /*&usage begin: glib_ps_form(S)
487: It returns the PS code generated by executing {S}
488: (experimental).
489: example: glib_ps_form(quote( glib_line(0,0,100,100) ));
1.15 takayama 490: example: glib_ps_form(quote([glib_line(0,0,100,100),glib_line(100,0,0,100)]));
1.14 takayama 491: ref: glib_tops
492: end: */
1.15 takayama 493: /* Todo. Change the canvas size. */
1.14 takayama 494: def glib_ps_form(F) {
495: extern Glib_h;
496: extern Glib_ps;
497: H = Glib_h; /* push Glib_h */
498: P = Glib_ps; /* push Glib_ps */
499:
500: Glib_ps=1; Glib_h = [];
1.16 takayama 501: if (type(F) != 17) {
502: return "Error: argument should be quote(...).";
503: }
1.14 takayama 504: eval_quote(F);
505: /* bug. eval_str causes seg fault for ccurve.rr main(8) */
506: R = glib_tops();
507: Glib_h = H; /* pop Glib_h */
508: Glib_ps = P; /* pop Glib_ps */
509: return R;
1.1 takayama 510: }
1.10 takayama 511:
512: /*&usage begin: glib_plot(F)
513: It plots an object {F} on the glib canvas.
514: example: glib_plot([[0,1],[0.1,0.9],[0.2,0.7],[0.3,0.5],[0.4,0.8]]);
515: example: glib_plot(tan(x));
516: end: */
517: /* bug, xmin, xmax, color should be optional variables. */
518: def glib_plot(F) {
519: Opt = getopt();
520: taka_glib_plot(F,Opt);
521: }
522:
1.18 takayama 523: /*&usage begin: glib_flush();
524: Flush the output.
525: (Cfep only. It also set initGL to 1.).
526: end: */
1.17 takayama 527: def glib_flush() {
528: extern Glib_canvas;
1.18 takayama 529: if (Glib_canvas < 0) glib_open();
1.21 ! takayama 530: if (Cfep_loaded && Cfep_use_opengl) cfep.draw_flush(Glib_canvas);
1.17 takayama 531: }
1.18 takayama 532: /*&usage begin: glib_set_pixel_size(P)
533: Set the size of putpixel to P. 1.0 is the default.
534: (cfep only).
535: end: */
536: def glib_set_pixel_size(X) {
537: extern Glib_canvas;
538: if (Glib_canvas < 0) glib_open();
1.21 ! takayama 539: if ((!Cfep_loaded) || (!Cfep_use_opengl)) /*Not implemented.*/ ;
1.18 takayama 540: else cfep.glib_set_pixel_size(X);
541: }
1.19 takayama 542:
1.18 takayama 543: /*&usage begin: glib_remove_last()
544: Remove the last object. glib_flush() should also be called to remove
545: the last object.
546: (cfep only).
547: end: */
548: def glib_remove_last() {
549: extern Glib_canvas;
550: if (Glib_canvas < 0) glib_open();
1.21 ! takayama 551: if ((!Cfep_loaded) || (!Cfep_use_opengl)) /*Not implemented.*/ ;
1.18 takayama 552: else cfep.glib_remove_last();
553: }
554:
1.21 ! takayama 555: if (Cfep_loaded && (!Cfep_use_opengl)) {
! 556: printf("OpenGL is no longer supported on cfep.asir. Use X11 instead.\n")$
! 557: }else{;}$
! 558:
1.1 takayama 559: end$
560:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>