Generated from configure.in
[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 program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
22
23 #include <stdio.h>
24 #include <fcntl.h>
25 #include <math.h>
26 #include "../rfxswf.h"
27
28                
29 int main (int argc,char ** argv)
30 { SWF swf;
31   LPTAG t;
32   RGBA rgb;
33   SRECT r;
34   LPSHAPE s;
35   S32 width=300,height = 300;
36   
37   int f,i,ls1,ls2;
38
39   memset(&swf,0x00,sizeof(SWF));        // set global movie parameters
40
41   swf.fileVersion    = 4;               // make flash 4 compatible swf
42   swf.frameRate      = 0x1900;          // about 0x19 frames per second
43   
44   swf.movieSize.xmax = 20*width;        // flash units: 1 pixel = 20 units
45   swf.movieSize.ymax = 20*height;
46
47   swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
48
49                                         // now create a tag list be connecting one after another
50   
51   t = swf.firstTag;
52
53         rgb.r = 0xff;
54         rgb.g = 0xff;
55         rgb.b = 0xff;
56         swf_SetRGB(t,&rgb);
57
58   t = swf_InsertTag(t,ST_DEFINESHAPE);
59
60         swf_ShapeNew(&s);               // create new shape instance
61
62                                         // add two different linestyles
63         rgb.b = rgb.g = 0x00;           
64         ls1 = swf_ShapeAddLineStyle(s,40,&rgb);
65         
66         rgb.r = 0; rgb.b = 0xff;
67         ls2 = swf_ShapeAddLineStyle(s,40,&rgb);
68
69         swf_SetU16(t,1);                // now set character ID
70
71         r.xmin = 0;
72         r.ymin = 0;
73         r.xmax = 20*width;
74         r.ymax = 20*height;
75         
76         swf_SetRect(t,&r);              // set shape bounds
77
78
79         swf_SetShapeHeader(t,s);        // write all styles to tag
80
81         swf_ShapeSetAll(t,s,0,0,ls1,0,0); // move to (0,0), select linestyle ls1 and no fillstyle
82
83                                         
84         swf_ShapeSetLine(t,s,10*width,10*height);    // draw something
85         swf_ShapeSetStyle(t,s,ls2,0,0);            // change to second linestyle 
86         
87         for (i=1;i<10;i++)
88           swf_ShapeSetCircle(t,s,10*width,10*height,i*width,i*height);
89           
90         swf_ShapeSetEnd(t);                 // finish drawing
91
92         swf_ShapeFree(s);                   // clean shape structure (which isn't needed anymore after writing the tag)
93
94   t = swf_InsertTag(t,ST_PLACEOBJECT2);     // append tag to place your shape into the scene
95
96         swf_ObjectPlace(t,1,1,NULL,NULL,NULL); // set character with id 1 (our shape) to depth 1 (upper most layer)
97
98   t = swf_InsertTag(t,ST_SHOWFRAME);        // finish current frame
99
100   t = swf_InsertTag(t,ST_END);              // finish current movie (which has just one frame)
101   
102 //  swf_WriteCGI(&swf);    <- use this to create direct CGI output
103   
104                                             // write movie to file
105
106   f = open("shape1.swf",O_WRONLY|O_CREAT|O_TRUNC, 0644);
107   if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
108   close(f);
109
110   swf_FreeTags(&swf);                       // cleanup
111
112 #ifdef __NT__                               // start flash player to show result on windows systems
113   system("start ..\\shape1.swf");
114 #endif
115   
116   return 0;
117 }
118
119