99ad495934ff3f03c8fbbb9859333900cdd8a1a2
[swftools.git] / lib / example / buttontest.c
1 /* shape1.c
2
3    Example implementation for creating a button with rfxswf
4    
5    Part of the swftools package.
6
7    Copyright (c) 2000, 2001 Matthias Kramm <kramm@quiss.org>
8                             Rainer Böhme <rfxswf@reflex-studio.de>
9  
10    This file is distributed under the GPL, see file COPYING for details 
11 */
12
13 #include <stdio.h>
14 #include <fcntl.h>
15 #include <math.h>
16 #include "../rfxswf.h"
17
18 TAG* t;
19
20 int useDefineButton2 = 0; // set this to 1 to use DefineButton2 Tags
21                           // instead of DefineButton1
22                
23 int main (int argc,char ** argv)
24 { SWF swf;
25   RGBA rgb;
26   SRECT r;
27   LPSHAPE s;
28   ActionTAG*a1,*a2,*a3, *actiontoset;
29   S32 width=300,height = 300;
30   
31   int f,i,ls1,fs1;
32   int count;
33
34   memset(&swf,0x00,sizeof(SWF));        // set global movie parameters
35
36   swf.fileVersion    = 4;               // make flash 4 compatible swf
37   swf.frameRate      = 0x1900;          // about 0x19 frames per second
38   
39   swf.movieSize.xmax = 20*width;        // flash units: 1 pixel = 20 units
40   swf.movieSize.ymax = 20*height;
41
42   swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
43   t = swf.firstTag;
44   rgb.r = 0xff;
45   rgb.g = 0xff;
46   rgb.b = 0xff;
47   swf_SetRGB(t,&rgb);
48
49   for(count=0;count<4;count++)
50   {
51       t = swf_InsertTag(t,ST_DEFINESHAPE);
52       swf_ShapeNew(&s);               // create new shape instance
53       rgb.r = rgb.b = rgb.g = 0x00;           
54       ls1 = swf_ShapeAddLineStyle(s,40,&rgb);
55       rgb.r = count*0x40; rgb.b = 0xff;
56       fs1 = swf_ShapeAddSolidFillStyle(s,&rgb);
57       swf_SetU16(t,33+count);                // now set character ID
58       r.xmin = 0;
59       r.ymin = 0;
60       r.xmax = 20*width;
61       r.ymax = 20*height;
62       swf_SetRect(t,&r);              // set shape bounds
63       swf_SetShapeHeader(t,s);        // write all styles to tag
64       swf_ShapeSetAll(t,s,0,0,ls1,fs1,0); // move to (0,0), select linestyle ls1 and no fillstyle
65       swf_ShapeSetCircle(t,s,width*10,height*10,width*10,height*10);
66       swf_ShapeSetEnd(t);                 // finish drawing
67       swf_ShapeFree(s);                   // clean shape structure (which isn't needed anymore after writing the tag)
68   }
69
70   a1 = swf_ActionStart(t);
71     action_SetTarget("movie");
72     action_NextFrame();
73     action_SetTarget("");
74     action_End();
75   swf_ActionEnd();
76  
77   a2 = swf_ActionStart(t);
78     //action_GetUrl("test.swf","_level0"); // load a swf
79     //action_GetUrl("index.html","_this"); // load html in new window
80     action_GetUrl("http://www.quiss.org/swftools/index.html","_parent"); // load html in this window
81     action_End();
82   swf_ActionEnd();
83
84   a3 = swf_ActionStart(t);
85     action_GotoFrame(33);
86     action_End();
87   swf_ActionEnd();
88
89   actiontoset = a2;  
90
91   if(!useDefineButton2)
92   {
93       t = swf_InsertTag(t,ST_DEFINEBUTTON);
94       swf_SetU16(t,31); //id
95       swf_ButtonSetFlags(t, 0); //menu=no
96       swf_ButtonSetRecord(t,0x01,33,1,0,0);
97       swf_ButtonSetRecord(t,0x02,34,1,0,0);
98       swf_ButtonSetRecord(t,0x04,35,1,0,0);
99       swf_ButtonSetRecord(t,0x08,36,1,0,0);
100       swf_SetU8(t,0);
101       swf_SetActions(t,actiontoset);
102       swf_SetU8(t,0);
103   }
104   else
105   {
106       t = swf_InsertTag(t,ST_DEFINEBUTTON2);
107       swf_SetU16(t,31); //id
108       swf_ButtonSetFlags(t, 0); //menu=no
109       swf_ButtonSetRecord(t,0x01,33,1,0,0);
110       swf_ButtonSetRecord(t,0x02,34,1,0,0);
111       swf_ButtonSetRecord(t,0x04,35,1,0,0);
112       swf_ButtonSetRecord(t,0x08,36,1,0,0);
113       swf_SetU8(t,0);
114
115       swf_ButtonSetCondition(t, 4);
116        swf_SetActions(t,actiontoset);
117        swf_SetU8(t,0);
118
119       swf_ButtonSetCondition(t, 0);
120        swf_SetU8(t,0);
121
122       swf_SetU8(t,0);
123
124       swf_ButtonPostProcess(t, 2);
125   }
126
127   t = swf_InsertTag(t,ST_PLACEOBJECT2);
128   swf_ObjectPlace(t, 31, 2,0,0,0);
129
130   t = swf_InsertTag(t,ST_SHOWFRAME);
131   t = swf_InsertTag(t,ST_END);
132
133   f = open("button.swf",O_WRONLY|O_CREAT, 0644);
134   if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
135   close(f);
136
137   swf_FreeTags(&swf);                       // cleanup
138   return 0;
139 }
140
141