changed -f to -r option.
[swftools.git] / lib / example / buttontest.c
1 /* buttontest.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 #define ID_BUTTON 31
21
22 int useDefineButton2 = 0; // set this to 1 to use DefineButton2 Tags
23                           // instead of DefineButton1
24                
25 int main (int argc,char ** argv)
26 { SWF swf;
27   RGBA rgb;
28   SRECT r;
29   LPSHAPE s;
30   ActionTAG*a1,*a2,*a3, *actiontoset;
31   S32 width=300,height = 300;
32   
33   int f,i,ls1,fs1;
34   int count;
35
36   memset(&swf,0x00,sizeof(SWF));        // set global movie parameters
37
38   swf.fileVersion    = 4;               // make flash 4 compatible swf
39   swf.frameRate      = 0x1900;          // about 0x19 frames per second
40   
41   swf.movieSize.xmax = 20*width;        // flash units: 1 pixel = 20 units
42   swf.movieSize.ymax = 20*height;
43
44   swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
45   t = swf.firstTag;
46   rgb.r = 0xff;
47   rgb.g = 0xff;
48   rgb.b = 0xff;
49   swf_SetRGB(t,&rgb);
50
51   for(count=1;count<4;count++)
52   {
53       t = swf_InsertTag(t,ST_DEFINESHAPE);
54       swf_ShapeNew(&s);               // create new shape instance
55       rgb.r = rgb.b = rgb.g = 0x00;           
56       ls1 = swf_ShapeAddLineStyle(s,40,&rgb);
57       rgb.r = count*0x40; rgb.b = 0xff;
58       fs1 = swf_ShapeAddSolidFillStyle(s,&rgb);
59       swf_SetU16(t,33+count);                // now set character ID
60       r.xmin = 0;
61       r.ymin = 0;
62       r.xmax = 20*width;
63       r.ymax = 20*height;
64       swf_SetRect(t,&r);              // set shape bounds
65       swf_SetShapeHeader(t,s);        // write all styles to tag
66       swf_ShapeSetAll(t,s,0,0,ls1,fs1,0); // move to (0,0), select linestyle ls1 and no fillstyle
67       swf_ShapeSetCircle(t,s,width*10,height*10,width*10,height*10);
68       swf_ShapeSetEnd(t);                 // finish drawing
69       swf_ShapeFree(s);                   // clean shape structure (which isn't needed anymore after writing the tag)
70   }
71
72   a1 = action_SetTarget(0, "movie");
73   a1 = action_NextFrame(a1);
74   a1 = action_SetTarget(a1, "");
75   a1 = action_End(a1);
76  
77     //a2 = action_GetUrl(a2, "test.swf","_level0"); // load a swf
78     //a2 = action_GetUrl(a2, "index.html","_this"); // load html in new window
79     a2 = action_GetUrl(0, "http://www.quiss.org/swftools/index.html","_parent"); // load html in this window
80     a2 = action_End(a2);
81
82     a3 = action_GotoFrame(0,33);
83     a3 = action_End(a3);
84
85   actiontoset = a2;  
86
87   if(!useDefineButton2)
88   {
89       t = swf_InsertTag(t,ST_DEFINEBUTTON);
90       swf_SetU16(t,31); //id
91       swf_ButtonSetRecord(t,BS_UP|BS_HIT,34,1,NULL,NULL);
92       swf_ButtonSetRecord(t,BS_OVER,35,1,NULL,NULL);
93       swf_ButtonSetRecord(t,BS_DOWN,36,1,NULL,NULL);
94       swf_SetU8(t,0); // end of button records
95       
96       swf_ActionSet(t,actiontoset);
97   }
98   else
99   {
100       t = swf_InsertTag(t,ST_DEFINEBUTTON2);
101       swf_SetU16(t,ID_BUTTON); //id
102       swf_ButtonSetFlags(t, 0); //menu=no
103       swf_ButtonSetRecord(t,BS_UP|BS_HIT,34,1,NULL,NULL);
104       swf_ButtonSetRecord(t,BS_OVER,35,1,NULL,NULL);
105       swf_ButtonSetRecord(t,BS_DOWN,36,1,NULL,NULL);
106       swf_SetU8(t,0); // end of button records
107
108       swf_ButtonSetCondition(t, BC_OVERDOWN_OVERUP);
109        swf_ActionSet(t,actiontoset);
110        
111       swf_ButtonPostProcess(t, 1); // don't forget!
112   }
113
114   swf_ActionFree(a1);
115   swf_ActionFree(a2);
116   swf_ActionFree(a3);
117
118   t = swf_InsertTag(t,ST_PLACEOBJECT2);
119   swf_ObjectPlace(t, ID_BUTTON, 2,0,0,0);
120
121   t = swf_InsertTag(t,ST_SHOWFRAME);
122   t = swf_InsertTag(t,ST_END);
123
124   f = open("buttontest.swf",O_WRONLY|O_CREAT, 0644);
125   if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
126   close(f);
127
128   swf_FreeTags(&swf);                       // cleanup
129   return 0;
130 }
131
132