initial revision.
[swftools.git] / swfs / keyboard_viewer.c
1 /* keyboard_viewer.c
2
3    Creates the swf file keyboard_viewer.swf. 
4    This can be used to navigate through frames using the keyboard (space,
5    cursor left, cursor right)
6    Notice that the movie has to clicked with the mouse once to get
7    navigation activated in most browsers.
8    
9    Part of the swftools package.
10
11    Copyright (c) 2000, 2001 Matthias Kramm <kramm@quiss.org>
12  
13    This file is distributed under the GPL, see file COPYING for details 
14 */
15
16 #include <stdio.h>
17 #include <fcntl.h>
18 #include <math.h>
19 #include "rfxswf.h"
20
21 TAG* tag;
22
23 #define SUBTITLES 1
24
25 int main (int argc,char ** argv)
26 { SWF swf;
27   RGBA rgb;
28   SRECT r;
29   LPSHAPE s;
30   MATRIX m;
31   ActionTAG*a1,*a2,*a3,*a4,*a5;
32   S32 width=1024,height = 768;
33   
34   int f,i,ls1,fs1;
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   tag = swf.firstTag;
46   rgb.r = 0xff;
47   rgb.g = 0xff;
48   rgb.b = 0xff;
49   swf_SetRGB(tag,&rgb);
50  
51   // initialize matrix
52   m.sx = 65536; //scale
53   m.sy = 65536;
54   m.r0 = 0; //rotate
55   m.r1 = 0;
56   m.tx = 0; //move
57   m.ty = 0;
58
59   /* the "viewport" object will be replaced by swfcombine
60      with the object to browse. It is placed at the
61      upper left corner (0,0), by setting m.tx and m.ty
62      to 0. Therefore, the buttons are "in" the viewport,
63      not above it*/
64   tag = swf_InsertTag(tag,ST_DEFINESPRITE);
65   swf_SetU16(tag, 23); //id
66   swf_SetU16(tag, 0); //frames
67   tag = swf_InsertTag(tag,ST_END);
68   tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
69   m.tx = 0; //move
70   m.ty = 0;
71   swf_ObjectPlace(tag, 23, 1,&m,0,"viewport");
72
73     a1 = action_SetTarget(0, "viewport");
74     a1 = action_PreviousFrame(a1);
75     a1 = action_SetTarget(a1, "");
76     a1 = action_End(a1);
77
78     a2 = action_SetTarget(0, "viewport");
79     a2 = action_NextFrame(a2);
80     a2 = action_SetTarget(a2,"");
81     a2 = action_End(a2);
82
83     a3 = action_Stop(0);
84     a3 = action_SetTarget(a3,"viewport");
85     a3 = action_Stop(a3);
86     a3 = action_SetTarget(a3,"");
87 #ifdef SUBTITLES
88     a3 = action_PushString(a3,"/:subtitle");
89     a3 = action_PushString(a3,""); //reset variable
90     a3 = action_SetVariable(a3);
91 #endif
92     a3 = action_End(a3);
93
94     a4 = action_GetUrl(0, "lichtfarbe.html", "_this");
95     a4 = action_End(a4);
96     
97     a5 = action_GetUrl(0, "phybas.html","_this"); // load html in this window
98     a5 = action_End(a5);
99
100   tag = swf_InsertTag(tag,ST_DEFINESHAPE);
101     swf_ShapeNew(&s);               // create new shape instance
102     rgb.r = rgb.b = rgb.g = 0x00;           
103     ls1 = swf_ShapeAddLineStyle(s,40,&rgb);
104     fs1 = swf_ShapeAddSolidFillStyle(s,&rgb);
105     swf_SetU16(tag,77);
106     r.xmin = 0;
107     r.ymin = 0;
108     r.xmax = 20*width;
109     r.ymax = 20*height;
110     swf_SetRect(tag,&r);              // set shape bounds
111     swf_SetShapeHeader(tag,s);        // write all styles to tag
112         
113     swf_ShapeSetAll(tag,s,0,0,ls1,fs1,0); // move to (0,0), select linestyle ls1 and no fillstyle
114     /* SetLine coordinates are relative.
115        It's important that the start and end points match, otherwise
116        the Macromedia Flash player will crash. */
117     swf_ShapeSetLine(tag,s,20*width,0*height);
118     swf_ShapeSetLine(tag,s,0*width,20*height);
119     swf_ShapeSetLine(tag,s,-20*width,0*height);
120     swf_ShapeSetLine(tag,s,0*width,-20*height);
121
122     swf_ShapeSetEnd(tag);   // finish drawing
123     swf_ShapeFree(s);   // clean shape structure (which isn't needed anymore after writing the tag)
124
125   tag = swf_InsertTag(tag,ST_DEFINEBUTTON2);
126   swf_SetU16(tag,30); //id
127   swf_ButtonSetFlags(tag, 0); //menu=no
128   swf_ButtonSetRecord(tag,BS_HIT,77,1,NULL,NULL);
129   swf_SetU8(tag,0); // end of button records
130   
131   swf_ButtonSetCondition(tag, BC_CURSORLEFT);
132     swf_ActionSet(tag,a1);
133   swf_ButtonSetCondition(tag, BC_CURSORRIGHT);
134     swf_ActionSet(tag,a2);
135   swf_ButtonSetCondition(tag, BC_SPACE);
136     swf_ActionSet(tag,a2);
137   swf_ButtonSetCondition(tag, BC_ESCAPE);
138     swf_ActionSet(tag,a4);
139   swf_ButtonSetCondition(tag, BC_ENTER);
140     swf_ActionSet(tag,a5);
141    
142   swf_ButtonPostProcess(tag, 5); // don't forget!
143   
144
145   tag = swf_InsertTag(tag,ST_DOACTION);
146   swf_ActionSet(tag,a3);
147
148   m.tx = 0; //move
149   m.ty = 0;
150   tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
151   swf_ObjectPlace(tag, 30, 2,&m,0,0);
152   
153   swf_ActionFree(a1);
154   swf_ActionFree(a2);
155   swf_ActionFree(a3);
156   swf_ActionFree(a4);
157   swf_ActionFree(a5);
158   
159
160
161 #ifdef SUBTITLES
162   tag = swf_InsertTag(tag,ST_DEFINEFONT2); {
163       U8 data[] = {0x90, 0x00, 0x0f, 0x54, 0x69, 0x6d, 0x65, 0x73, 
164                    0x20, 0x4e, 0x65, 0x77, 0x20, 0x52, 0x6f, 0x6d, 
165                    0x61, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
166                    0x00, 0x00, 0x00, 0x00};
167       swf_SetU16(tag, 0x76); //id
168       swf_SetBlock(tag, data, sizeof(data));
169   }
170   tag = swf_InsertTag(tag,ST_DEFINEEDITTEXT); {
171       EditTextLayout layout;
172       layout.align = 0;
173       layout.leftmargin = 0;
174       layout.rightmargin = 0;
175       layout.indent = 0;
176       layout.leading = 0;
177
178       swf_SetU16(tag, 0x77);//id
179       r.xmin = 20*60;
180       r.xmax = r.xmin+ 826*20;
181       r.ymin = 0;
182       r.ymax = 20*80;
183       rgb.r = rgb.g = rgb.b = 0;
184       rgb.a = 255;
185       swf_SetEditText(tag, ET_MULTILINE|ET_READONLY, r, 0, &rgb, 0, 0x76, 20*40, &layout, "/:subtitle");
186       m.tx = m.ty = 0;
187   }
188   tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
189   swf_ObjectPlace(tag, 0x77, 4,&m,0,0);
190 #endif
191
192   tag = swf_InsertTag(tag,ST_SHOWFRAME);
193   tag = swf_InsertTag(tag,ST_END);
194   
195   f = open("keyboard_viewer.swf",O_WRONLY|O_CREAT|O_TRUNC, 0644);
196   if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
197   close(f);
198
199   swf_FreeTags(&swf);                       // cleanup
200   return 0;
201 }
202
203