3 Creates the swf file simple_viewer.swf.
4 I'm not much of an designer. Suggestions and improvements concerning
5 this file or simple_viewer.swf are highly welcome. -mk
7 Part of the swftools package.
9 Copyright (c) 2000, 2001 Matthias Kramm <kramm@quiss.org>
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
32 int button_sizex = 20; //button size in pixels
33 int button_sizey = 20;
35 RGBA button_colors[6]=
36 {{0,0x00,0x00,0x80}, //Idle left
37 {0,0x00,0x00,0x80}, // " right
38 {0,0x20,0x20,0xc0}, //MouseOver left
39 {0,0x20,0x20,0xc0}, // " right
40 {0,0x10,0x10,0xff}, //Down left
41 {0,0x10,0x10,0xff}};// " right
43 int useDefineButton2 = 0; // set this to 1 to use DefineButton2 Tags
44 // instead of DefineButton1
46 //#define USE_WATERMARK 1 // set this flag to print-protect your swfs
48 #define ID_WATERMARK 64
50 int main (int argc,char ** argv)
57 S32 width=1024,height = 768;
63 memset(&swf,0x00,sizeof(SWF)); // set global movie parameters
65 swf.fileVersion = 4; // make flash 4 compatible swf
66 swf.frameRate = 0x1900; // about 0x19 frames per second
68 swf.movieSize.xmax = 20*width; // flash units: 1 pixel = 20 units
69 swf.movieSize.ymax = 20*height;
71 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
86 /* the "viewport" object will be replaced by swfcombine
87 with the object to browse. It is placed at the
88 upper left corner (0,0), by setting m.tx and m.ty
89 to 0. Therefore, the buttons are "in" the viewport,
91 tag = swf_InsertTag(tag,ST_DEFINESPRITE);
92 swf_SetU16(tag, 23); //id
93 swf_SetU16(tag, 0); //frames
94 tag = swf_InsertTag(tag,ST_END);
95 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
98 swf_ObjectPlace(tag, 23, 1,&m,0,"viewport");
102 // Insert Alpha watermark to avoid printing
104 tag = swf_InsertTag(tag,ST_DEFINESHAPE3);
106 rgb.r = rgb.g = rgb.b = 0xff;
108 fs1 = swf_ShapeAddSolidFillStyle(s,&rgb);
109 swf_SetU16(tag,ID_WATERMARK);
113 swf_SetRect(tag,&r); // cover whole viewport
114 swf_SetShapeHeader(tag,s);
115 swf_ShapeSetAll(tag,s,0,0,0,fs1,0);
116 swf_ShapeSetLine(tag,s,20*width,0);
117 swf_ShapeSetLine(tag,s,0,20*height);
118 swf_ShapeSetLine(tag,s,-20*width,0);
119 swf_ShapeSetLine(tag,s,0,-20*height);
120 swf_ShapeSetEnd(tag);
123 #endif // USE_WATERMARK
125 for(count=0;count<6;count++)
127 tag = swf_InsertTag(tag,ST_DEFINESHAPE);
128 swf_ShapeNew(&s); // create new shape instance
129 rgb.r = rgb.b = rgb.g = 0x00;
130 ls1 = swf_ShapeAddLineStyle(s,40,&rgb);
131 rgb = button_colors[count];
132 fs1 = swf_ShapeAddSolidFillStyle(s,&rgb);
133 swf_SetU16(tag,32+count); // now set character ID
138 swf_SetRect(tag,&r); // set shape bounds
139 swf_SetShapeHeader(tag,s); // write all styles to tag
142 swf_ShapeSetAll(tag,s,0,0,ls1,fs1,0); // move to (0,0), select linestyle ls1 and no fillstyle
143 /* SetLine coordinates are relative.
144 It's important that the start and end points match, otherwise
145 the Macromedia Flash player will crash. */
146 swf_ShapeSetLine(tag,s,20*button_sizex,20*button_sizey);
147 swf_ShapeSetLine(tag,s,-20*button_sizex,20*button_sizey);
148 swf_ShapeSetLine(tag,s,0,-40*button_sizey);
150 swf_ShapeSetAll(tag,s,20*button_sizex,0,ls1,fs1,0);
151 swf_ShapeSetLine(tag,s,-20*button_sizex,20*button_sizey);
152 swf_ShapeSetLine(tag,s,20*button_sizex,20*button_sizey);
153 swf_ShapeSetLine(tag,s,0,-40*button_sizey);
155 swf_ShapeSetEnd(tag); // finish drawing
156 swf_ShapeFree(s); // clean shape structure (which isn't needed anymore after writing the tag)
159 a1 = action_SetTarget(0, "viewport");
160 a1 = action_PreviousFrame(a1);
161 a1 = action_SetTarget(a1, "");
164 a2 = action_SetTarget(0, "viewport");
165 a2 = action_NextFrame(a2);
166 a2 = action_SetTarget(a2,"");
169 a3 = action_SetTarget(0,"viewport");
170 a3 = action_Stop(a3);
171 a3 = action_SetTarget(a3,"");
173 a3 = action_PushString(a3,"/:subtitle");
174 a3 = action_PushString(a3,""); //reset variable
175 a3 = action_SetVariable(a3);
181 if(!useDefineButton2)
183 tag = swf_InsertTag(tag,ST_DEFINEBUTTON);
184 swf_SetU16(tag,30+t); //id
185 swf_ButtonSetRecord(tag,BS_UP|BS_HIT,32+t,1,NULL,NULL);
186 swf_ButtonSetRecord(tag,BS_OVER,34+t,1,NULL,NULL);
187 swf_ButtonSetRecord(tag,BS_DOWN,36+t,1,NULL,NULL);
188 swf_SetU8(tag,0); // end of button records
191 swf_ActionSet(tag,a2);
193 swf_ActionSet(tag,a1);
197 tag = swf_InsertTag(tag,ST_DEFINEBUTTON2);
198 swf_SetU16(tag,30+t); //id
199 swf_ButtonSetFlags(tag, 0); //menu=no
200 swf_ButtonSetRecord(tag,BS_UP|BS_HIT,32+t,1,NULL,NULL);
201 swf_ButtonSetRecord(tag,BS_OVER,34+t,1,NULL,NULL);
202 swf_ButtonSetRecord(tag,BS_DOWN,36+t,1,NULL,NULL);
203 swf_SetU8(tag,0); // end of button records
205 swf_ButtonSetCondition(tag, BC_OVERDOWN_OVERUP);
207 swf_ActionSet(tag,a2);
209 swf_ActionSet(tag,a1);
211 swf_ButtonPostProcess(tag, 1); // don't forget!
215 tag = swf_InsertTag(tag,ST_DOACTION);
216 swf_ActionSet(tag,a3);
220 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
221 swf_ObjectPlace(tag, 30, 3,&m,0,0);
222 m.tx = button_sizex*30;
223 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
224 swf_ObjectPlace(tag, 31, 4,&m,0,0);
230 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
231 swf_ObjectPlace(tag, ID_WATERMARK, 2, &m, 0,0);
233 #endif // USE_WATERMARK
240 tag = swf_InsertTag(tag,ST_DEFINEFONT2); {
241 U8 data[] = {0x90, 0x00, 0x0f, 0x54, 0x69, 0x6d, 0x65, 0x73,
242 0x20, 0x4e, 0x65, 0x77, 0x20, 0x52, 0x6f, 0x6d,
243 0x61, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
244 0x00, 0x00, 0x00, 0x00};
245 swf_SetU16(tag, 0x76); //id
246 swf_SetBlock(tag, data, sizeof(data));
248 tag = swf_InsertTag(tag,ST_DEFINEEDITTEXT); {
249 EditTextLayout layout;
251 layout.leftmargin = 0;
252 layout.rightmargin = 0;
256 swf_SetU16(tag, 0x77);//id
257 r.xmin = button_sizex*60;
258 r.xmax = r.xmin+ 826*20;
260 r.ymax = button_sizey*80;
261 rgb.r = rgb.g = rgb.b = 0;
263 swf_SetEditText(tag, ET_MULTILINE|ET_READONLY, r, 0, &rgb, 0, 0x76, button_sizey*40, &layout, "/:subtitle");
266 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
267 swf_ObjectPlace(tag, 0x77, 5,&m,0,0);
270 tag = swf_InsertTag(tag,ST_SHOWFRAME);
271 tag = swf_InsertTag(tag,ST_END);
274 f = open("simple_viewer.swf",O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
275 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
278 swf_FreeTags(&swf); // cleanup