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