Annotation of OpenXM/src/asir-contrib/packages/src/cfep-init.rr, Revision 1.5
1.1 takayama 1:
2: load("oxrfc103.rr");
3:
4: module cfep;
5: localf initStatic$
6: localf setup$
7: localf test0$
8: localf test2$
9: localf t_encode$
10: localf t_encode1$
11: localf t_encode_str$
12: localf glib_send$
1.4 takayama 13: localf glib_send2$
1.1 takayama 14: localf glib_init_send$
15:
16: localf open_canvas$
17: localf open_canvas2$
18: localf draw_obj$
19: localf draw_obj2$
20: localf draw_string$
21: localf draw_string2$
22: localf draw_flush$
1.2 takayama 23: localf getGlib_canvas$
1.1 takayama 24: localf x11toGLx$
25: localf x11toGLy$
1.3 takayama 26: localf glib_clear$
27: localf glib_remove_last$
28: localf glib_set_pixel_size$
29:
1.1 takayama 30:
31: static Glib_canvas;
32: static Glib_canvas_x;
33: static Glib_canvas_y;
34: def initStatic() {
1.4 takayama 35: ctrl("double_output",1);
1.1 takayama 36: Glib_canvas = 0; /* gid */
37: Glib_canvas_x = 400;
38: Glib_canvas_y = 400;
39: }
40: initStatic()$
41: def setup() {
42: ctrl("debug_window",0);
43: }
44:
1.2 takayama 45: def getGlib_canvas() {
46: return Glib_canvas;
47: }
1.1 takayama 48: /* Example */
49: def test0() {
50: /* gid; commands */
51: glib_init_send("0; [glColor4f, 1.0,0.0,0.0,0.3]");
52: glib_init_send("0; [glRectf, -0.1,-0.1,0.1,0.1]");
53: glib_init_send("0; [glib_flush]");
54: glib_send("0; [glib_line,0.0,0.0,0.5,0.5,(int)255]");
55: glib_send("0; [glib_flush]");
56: }
57: def test2() {
58: glib_init_send("0;[glib3_ray_init]");
59: glib_init_send("0;[glib_flush]");
60: glib_send("0;[glib3_ray]");
61: glib_send("0;[glib_flush]");
62: }
63:
64: def open_canvas(S) {
65: Glib_canvas++;
66: if (S[0] != 0) Glib_canvas_x = S[0];
67: else error("The fisrst argument of cfep.open_canvas is 0.");
68: if (S[1] != 0) Glib_canvas_y = S[1];
69: else error("The first argument of cfep.open_canvas is 0.");
70: return Glib_canvas;
71: }
72: def open_canvas2(P,S) {
73: return open_canvas(S);
74: }
75:
76: def draw_obj(P,Canvas,S) {
77: draw_obj2(P,Canvas,S,0);
78: }
79:
80:
1.3 takayama 81: def x11toGLx(X) { X=deval(X); return (-1.0+2*X/Glib_canvas_x); }
82: def x11toGLy(Y) { Y=deval(Y); return (1.0-2*Y/Glib_canvas_y); }
1.1 takayama 83: def draw_obj2(P,Canvas,S,Color) {
84: if (length(S) == 4) { /* line */
85: X = rtostr(x11toGLx(S[0])); Y = rtostr(x11toGLy(S[1]));
86: X2 = rtostr(x11toGLx(S[2])); Y2 = rtostr(x11toGLy(S[3]));
87: CC="(int)"+rtostr(Color);
88: glib_send(rtostr(Canvas)+"; [glib_line,"+X+","+Y+","+X2+","+Y2+","+CC+"]");
89: }else if (length(S) == 2) { /* point */
90: X = rtostr(x11toGLx(S[0])); Y = rtostr(x11toGLy(S[1]));
91: CC="(int)"+rtostr(Color);
92: glib_send(rtostr(Canvas)+"; [glib_putpixel,"+X+","+Y+","+CC+"]");
93: }
94: } /* cfep.draw_obj2(0,0,[100,100],0xff0000); cfep.draw_flush(); */
95:
96: def draw_string(P,C,Pos,Text) {
97: draw_string2(P,C,Pos,Text,0);
98: }
99: def draw_string2(P,C,Pos,Test,Color) {
100: print("cfep.draw_string2() has not been implemented.");
101: }
102: def draw_flush(Canvas) {
103: glib_send(rtostr(Canvas)+"; [glib_flush]");
104: }
105:
106: def t_encode1(X) {
107: return [
108: ior(0xf8,iand(0x3,ishift(X,6))),
109: ior(0xf0,iand(0x7,ishift(X,3))),
110: ior(0xf0,iand(0x7,X))];
111: }
112: def t_encode_str(S) {
113: Ans = [ ];
114: Codes = strtoascii(S);
115: N = length(Codes);
116: for (I=0; I<N; I++) {
117: T = t_encode1(Codes[I]);
118: Ans = cons(T[0],Ans);
119: Ans = cons(T[1],Ans);
120: Ans = cons(T[2],Ans);
121: }
122: return reverse(Ans);
123: }
124: def t_encode(S) {
125: return asciitostr(t_encode_str(S));
126: }
1.5 ! takayama 127: def glib_send(S) {
1.1 takayama 128: S=S+"\n";
129: N=length(strtoascii(S))+1;
130: C=t_encode("{1<"+rtostr(N)+" "+S+" >}");
131: ctrl("hex",1);
132: output(); ctrl("hex",0);
1.5 ! takayama 133: print(C,0); output(); /* channel 1 is for OpenGL redraw. */
1.1 takayama 134: }
135: def glib_init_send(S) {
136: S=S+"\n";
137: N=length(strtoascii(S))+1;
138: C=t_encode("{2<"+rtostr(N)+" "+S+" >}");
139: ctrl("hex",1);
140: output(); ctrl("hex",0);
1.5 ! takayama 141: print(C,0); output(); /* channel 2 is for OpenGL init. */
1.1 takayama 142: }
1.4 takayama 143: def glib_send2(Channel,S) {
144: S=S+"\n";
145: if (Channel==1) Channel="1"; /* regular */
146: else Channel="2"; /* init */
147: N=length(strtoascii(S))+1;
148: C=t_encode("{"+Channel+"<"+rtostr(N)+" "+S+" >}");
149: ctrl("hex",1);
150: output(); ctrl("hex",0);
1.5 ! takayama 151: print(C,0); output(); /* channel 2 is for OpenGL init. */
1.4 takayama 152: }
1.1 takayama 153:
1.3 takayama 154: /* glib_line(0,0,100,100); glib_flush();
155: cfep.glib_clear();
156: */
157: def glib_clear() {
158: Glib_canvas = cfep.getGlib_canvas();
159: glib_send(rtostr(Glib_canvas)+";meta_removeAllInit");
160: glib_send(rtostr(Glib_canvas)+";meta_removeAll");
161: glib_init_send(rtostr(Glib_canvas)+"; [glClearColor,1.0,1.0,1.0,1.0]");
162: /* GL_COLOR_BUFFER_BIT 0x4000, = 16384 */
163: glib_init_send(rtostr(Glib_canvas)+"; [glClear,(int)16384]");
164: glib_flush();
165: }
166:
167: def glib_remove_last() {
168: Glib_canvas = cfep.getGlib_canvas();
169: glib_send(rtostr(Glib_canvas)+";meta_removeLast");
170: }
171:
172: def glib_set_pixel_size(P) {
173: Glib_canvas = cfep.getGlib_canvas();
174: P = deval(P);
175: glib_send(rtostr(Glib_canvas)+"; [glPointSize,"+rtostr(P)+"]");
176: }
177:
1.1 takayama 178: endmodule;
179:
180: Cfep_loaded = 1$
181:
182: cfep.setup()$
183: /*
184: cfep.draw_obj2(0,0,[0,0,400,400],0x0000ff);
185: cfep.draw_obj(0,0,[0,0,200,100]);
186: cfep.draw_flush(0);
187: */
188:
189: /* Initialization file for cfep.
190: This file is loaded after ASIRRC and ./.asirrc is executed from ox_texmacs.
191: cf. ox_texmacs --asirInitFile filename, MyEnvironment.m of cfep.
192:
193: module_definedp("cfep");
194: #define x11toGLx(x) (-1.0+2*x/Glib_canvas_x)
195: #define x11toGLy(y) (1.0-2*y/Glib_canvas_y)
196: */
1.3 takayama 197:
198: /* Should be moved to the buildin function. */
199: def radian(D) {
200: return (D/180)*@pi;
201: }
202:
1.5 ! takayama 203: /* $OpenXM: OpenXM/src/asir-contrib/packages/src/cfep-init.rr,v 1.4 2006/03/10 11:48:02 takayama Exp $ */
1.1 takayama 204:
205:
206: end$
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>