2 // linux/gcc: cc texbox.c ../rfxswf.c -funsigned-char -o texbox -lm -ljpeg; cp texbox /home/www/cgi-bin/texbox
11 #define BANNER_TEXT "reflex"
14 #define ID_BANNER 2001
15 #define ID_HIGHLIGHT 2002
16 #define ID_BUTTON 2003
17 #define ID_BITMAP 2004
19 #define ID_SHAPE2 2006
22 int sX[] = { a,-a, a,-a, a,-a, a,-a};
23 int sY[] = { a, a,-a,-a, a, a,-a,-a};
24 int sZ[] = { a, a, a, a,-a,-a,-a,-a};
33 int square_visible[6] = {0,0,0,0,0,0};
34 int square_depth[6][2] = {{2,3},{4,5},{6,7},{8,9},{10,11},{12,13}};
35 int square_light[6] = {0,0,64,64,-64,-64};
37 int sin_[512],cos_[512];
43 { d = ((double)i)/128*3.14159;
44 sin_[i] = (int)(sin(d)*(1<<PRECISION));
45 cos_[i] = (int)(cos(d)*(1<<PRECISION));
49 LPTAG MapSquare(LPTAG t,int dx0,int dy0,int p1,int p2,int p3,int p4,int dx,int dy,int square)
54 { GetCXForm(NULL,&cx,1);
55 cx.r1 = cx.b1 = cx.g1 = square_light[square];
58 if (((dX[p2]-dX[p1])*(dY[p3]-dY[p1])-(dX[p3]-dX[p1])*(dY[p2]-dY[p1]))<0)
59 { if (square_visible[square])
60 { t = InsertTag(t,ST_REMOVEOBJECT2); SetU16(t,square_depth[square][0]);
61 t = InsertTag(t,ST_REMOVEOBJECT2); SetU16(t,square_depth[square][1]);
63 square_visible[square] = 0;
67 t = InsertTag(t,ST_PLACEOBJECT2);
69 MatrixMapTriangle(&m,dx0,dy0,dX[p1]+dx,dY[p1]+dy,
73 if (!square_visible[square])
74 ObjectPlace(t,ID_SHAPE,square_depth[square][0],&m,SHADE?&cx:NULL,NULL);
76 ObjectMove(t,square_depth[square][0],&m,SHADE?&cx:NULL);
78 t = InsertTag(t,ST_PLACEOBJECT2);
80 MatrixMapTriangle(&m,dx0,dy0,dX[p3]+dx,dY[p3]+dy,
84 if (!square_visible[square])
85 ObjectPlace(t,ID_SHAPE2,square_depth[square][1],&m,SHADE?&cx:NULL,NULL);
87 ObjectMove(t,square_depth[square][1],&m,SHADE?&cx:NULL);
89 square_visible[square] = 1;
94 void mapBox(int xw,int yw,int zw)
96 int x1,y1,z1,x2,y2,z2,x3,y3,z3;
108 y1 = ( y*cos_[xw]- z*sin_[xw])>>PRECISION;
109 z1 = ( y*sin_[xw]+ z*cos_[xw])>>PRECISION;
112 x2 = (x1*cos_[yw]+z1*sin_[yw])>>PRECISION;
115 x3 = (x2*cos_[zw]-y2*sin_[zw])>>PRECISION;
116 y3 = (x2*sin_[zw]+y2*cos_[zw])>>PRECISION;
117 z3 = (z1*cos_[yw]-x1*sin_[yw])>>PRECISION;
119 dX[i] = x3*4000/(z3+950);
120 dY[i] = y3*4000/(z3+950);
125 void mapLights(int xw,int yw,int zw)
127 int x1,y1,z1,x2,y2,z2,x3,y3,z3;
129 int y[] = {0,0,0,0,256,-256};
130 int x[] = {0,0,256,-256,0,0};
131 int z[] = {256,-256,0,0,0,0};
133 int lz = 256; // lightvector
134 int lx = 200, ly = 200;
137 { y1 = (y[i]*cos_[xw]-z[i]*sin_[xw])>>PRECISION;
138 z1 = (y[i]*sin_[xw]+z[i]*cos_[xw])>>PRECISION;
141 x2 = (x1*cos_[yw]+z1*sin_[yw])>>PRECISION;
143 z2 = (z1*cos_[yw]-x1*sin_[yw])>>PRECISION;
145 x3 = (x2*cos_[zw]-y2*sin_[zw])>>PRECISION;
146 y3 = (x2*sin_[zw]+y2*cos_[zw])>>PRECISION;
149 square_light[i] = -128-((x3*lx + y3*ly + z3*lz)>>9);
154 int main (int argc,char ** argv)
160 S32 width = 800,height = 800;
162 int fs,ls; // line & fillstyle
170 f = open("Arial.efont",O_RDONLY);
172 { if (FAILED(FontImport(f,&font)))
173 { fprintf(stderr,"Font import failed\n");
179 { fprintf(stderr,"Font not found\n");
184 FontSetID(font,ID_FONT);
186 FontUse(&use,BANNER_TEXT);
187 FontReduce(font,&use);
191 memset(&swf,0x00,sizeof(SWF));
194 swf.FrameRate = 0x4000;
195 swf.MovieSize.xmax = 4*width;
196 swf.MovieSize.ymax = 4*height;
198 swf.FirstTag = InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
206 t = InsertTag(t,ST_DEFINEFONT);
208 FontSetDefine(t,font);
210 t = InsertTag(t,ST_DEFINEFONTINFO);
214 t = InsertTag(t,ST_DEFINETEXT);
216 SetU16(t,ID_BANNER); // ID
226 TextCountBits(font,BANNER_TEXT,80,&gbits,&abits);
235 TextSetInfoRecord(t,font,height/4,&rgb,0,200);
236 TextSetCharRecord(t,font,BANNER_TEXT,80,gbits,abits);
240 t = InsertTag(t,ST_DEFINETEXT);
242 SetU16(t,ID_HIGHLIGHT); // ID
244 r.xmin = 0; r.ymin = 0; r.xmax = 800; r.ymax = 400;
248 TextCountBits(font,BANNER_TEXT,80,&gbits,&abits);
257 TextSetInfoRecord(t,font,height/4,&rgb,0,200);
258 TextSetCharRecord(t,font,BANNER_TEXT,80,gbits,abits);
262 t = InsertTag(t,ST_DEFINEBUTTON);
269 SetU16(t,ID_BUTTON); // ID
270 ButtonSetRecord(t,BS_UP,ID_BANNER,1,&m,NULL);
271 ButtonSetRecord(t,BS_DOWN|BS_HIT|BS_OVER,ID_HIGHLIGHT,1,&m,NULL);
272 SetU8(t,0); // End of Button Records
273 SetU8(t,0); // End of Action Records
276 t = InsertTag(t,ST_PLACEOBJECT2);
278 ObjectPlace(t,ID_BUTTON,1,NULL,NULL,NULL);
280 t = InsertTag(t,ST_DEFINEBITSJPEG2);
283 SetJPEGBits(t,"eye.jpg",QUALITY);
285 t = InsertTag(t,ST_DEFINESHAPE);
288 rgb.b = rgb.g = rgb.r = 0x00;
289 ls = ShapeAddLineStyle(s,10,&rgb);
294 m.sx = m.sy = width<<8;
296 fs = ShapeAddBitmapFillStyle(s,&m,ID_BITMAP,0);
298 SetU16(t,ID_SHAPE); // ID
300 r.xmin = 0; r.ymin = 0;
301 r.xmax = 2*width; r.ymax = 2*height;
305 ShapeSetAll(t,s,width,0,0,fs,0);
306 ShapeSetLine(t,s,-width,height);
307 ShapeSetStyle(t,s,ls,fs,0);
308 ShapeSetLine(t,s,0,-height);
309 ShapeSetLine(t,s,width,0);
314 t = InsertTag(t,ST_DEFINESHAPE);
317 rgb.b = rgb.g = rgb.r = 0x00;
318 ls = ShapeAddLineStyle(s,10,&rgb);
323 m.sx = m.sy = -(width<<8);
325 fs = ShapeAddBitmapFillStyle(s,&m,ID_BITMAP,0);
327 SetU16(t,ID_SHAPE2); // ID
329 r.xmin = 0; r.ymin = 0;
330 r.xmax = 2*width; r.ymax = 2*height;
334 ShapeSetAll(t,s,width,0,0,fs,0);
335 ShapeSetLine(t,s,-width,height);
336 ShapeSetStyle(t,s,ls,fs,0);
337 ShapeSetLine(t,s,0,-height);
338 ShapeSetLine(t,s,width,0);
343 for (frame=0;frame<256;frame++)
344 { int dc = 3; // whitespace correction
346 mapBox(frame<<1,frame<<1,frame);
347 if (SHADE) mapLights(frame<<1,frame<<1,frame);
349 t = MapSquare(t,width-dc,height-dc,0,2,3,1,2*width,2*height,0);
350 t = MapSquare(t,width-dc,height-dc,4,5,7,6,2*width,2*height,1);
351 t = MapSquare(t,width-dc,height-dc,0,4,6,2,2*width,2*height,2);
352 t = MapSquare(t,width-dc,height-dc,1,3,7,5,2*width,2*height,3);
353 t = MapSquare(t,width-dc,height-dc,0,1,5,4,2*width,2*height,4);
354 t = MapSquare(t,width-dc,height-dc,2,6,7,3,2*width,2*height,5);
356 t = InsertTag(t,ST_SHOWFRAME);
360 t = InsertTag(t,ST_END);