brought up to date.
[swftools.git] / lib / example / shape1.c
1 /* shape1.c
2
3    Example implementation for drawing a shape with rfxswf
4    
5    Part of the swftools package.
6
7    Copyright (c) 2000, 2001 Rainer Böhme <rfxswf@reflex-studio.de>
8  
9    This file is distributed under the GPL, see file COPYING for details 
10
11 */
12
13 #include <stdio.h>
14 #include <fcntl.h>
15 #include <math.h>
16 #include "../rfxswf.h"
17
18                
19 int main (int argc,char ** argv)
20 { SWF swf;
21   LPTAG t;
22   RGBA rgb;
23   SRECT r;
24   LPSHAPE s;
25   S32 width=300,height = 300;
26   
27   int f,i,ls1,ls2;
28
29   memset(&swf,0x00,sizeof(SWF));        // set global movie parameters
30
31   swf.fileVersion    = 4;               // make flash 4 compatible swf
32   swf.frameRate      = 0x1900;          // about 0x19 frames per second
33   
34   swf.movieSize.xmax = 20*width;        // flash units: 1 pixel = 20 units
35   swf.movieSize.ymax = 20*height;
36
37   swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
38
39                                         // now create a tag list be connecting one after another
40   
41   t = swf.firstTag;
42
43         rgb.r = 0xff;
44         rgb.g = 0xff;
45         rgb.b = 0xff;
46         swf_SetRGB(t,&rgb);
47
48   t = swf_InsertTag(t,ST_DEFINESHAPE);
49
50         swf_ShapeNew(&s);               // create new shape instance
51
52                                         // add two different linestyles
53         rgb.b = rgb.g = 0x00;           
54         ls1 = swf_ShapeAddLineStyle(s,40,&rgb);
55         
56         rgb.r = 0; rgb.b = 0xff;
57         ls2 = swf_ShapeAddLineStyle(s,40,&rgb);
58
59         swf_SetU16(t,1);                // now set character ID
60
61         r.xmin = 0;
62         r.ymin = 0;
63         r.xmax = 20*width;
64         r.ymax = 20*height;
65         
66         swf_SetRect(t,&r);              // set shape bounds
67
68
69         swf_SetShapeHeader(t,s);        // write all styles to tag
70
71         swf_ShapeSetAll(t,s,0,0,ls1,0,0); // move to (0,0), select linestyle ls1 and no fillstyle
72
73                                         
74         swf_ShapeSetLine(t,s,10*width,10*height);    // draw something
75         swf_ShapeSetStyle(t,s,ls2,0,0);            // change to second linestyle 
76         
77         for (i=1;i<10;i++)
78           swf_ShapeSetCircle(t,s,10*width,10*height,i*width,i*height);
79           
80         swf_ShapeSetEnd(t);                 // finish drawing
81
82         swf_ShapeFree(s);                   // clean shape structure (which isn't needed anymore after writing the tag)
83
84   t = swf_InsertTag(t,ST_PLACEOBJECT2);     // append tag to place your shape into the scene
85
86         swf_ObjectPlace(t,1,1,NULL,NULL,NULL); // set character with id 1 (our shape) to depth 1 (upper most layer)
87
88   t = swf_InsertTag(t,ST_SHOWFRAME);        // finish current frame
89
90   t = swf_InsertTag(t,ST_END);              // finish current movie (which has just one frame)
91   
92 //  swf_WriteCGI(&swf);    <- use this to create direct CGI output
93   
94                                             // write movie to file
95
96   f = open("shape1.swf",O_WRONLY|O_CREAT|O_TRUNC, 0644);
97   if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
98   close(f);
99
100   swf_FreeTags(&swf);                       // cleanup
101
102 #ifdef __NT__                               // start flash player to show result on windows systems
103   system("start ..\\shape1.swf");
104 #endif
105   
106   return 0;
107 }
108
109