update copyright date
[gnash.git] / testsuite / misc-ming.all / loading / moviecliploader_test.c
blob4cc78c048bfc1d72dca172749b083f5f21073060
1 /***********************************************************************
3 * Copyright (C) 2005, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 ***********************************************************************
23 * Test case for the MovieClipLoader actionscript class
25 ***********************************************************************/
28 * run as ./movieclip_loader <mediadir>
30 * srcdir is where lynch.jpg, green.jp and offspring.jpg are located
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <ming.h>
38 #define OUTPUT_VERSION 7
39 #define OUTPUT_FILENAME "moviecliploader_test.swf"
41 void add_clip(SWFMovie mo, char* file, char* name, char* url, int x, int y);
43 void
44 add_clip(SWFMovie mo, char* file, char* name,
45 char* url, int x, int y)
47 FILE *fd;
48 SWFJpegBitmap bm;
49 SWFShape sh;
50 SWFMovieClip mc;
51 SWFDisplayItem it;
52 SWFAction ac;
53 char action[1024];
55 printf("Adding %s\n", file);
57 fd = fopen(file, "r");
58 if ( ! fd ) {
59 perror(file);
60 exit(1);
62 bm = newSWFJpegBitmap(fd);
63 sh = newSWFShapeFromBitmap((SWFBitmap)bm, SWFFILL_CLIPPED_BITMAP);
64 mc = newSWFMovieClip();
65 SWFMovieClip_add(mc, (SWFBlock)sh);
66 SWFMovieClip_nextFrame(mc); /* showFrame */
67 it = SWFMovie_add(mo, (SWFBlock)mc);
68 SWFDisplayItem_setName(it, name);
69 SWFDisplayItem_moveTo(it, x, y);
71 /* "Click" handler */
72 sprintf(action, " \
73 %s.onPress = function () { \
74 _root.CoverArtLoader.loadClip('%s', coverart); \
75 }; \
76 ", name, url);
78 ac = compileSWFActionCode(action);
80 SWFMovie_add(mo, (SWFBlock)ac);
83 int
84 main(int argc, char** argv)
86 SWFMovie mo;
87 char file_lynch[256];
88 char file_green[256];
89 char file_offspring[256];
90 char url_lynch[256];
91 char url_green[256];
92 char url_offspring[256];
93 const char *srcdir=".";
94 SWFShape sh_coverart;
95 SWFMovieClip mc_coverart;
96 SWFFillStyle fstyle;
97 SWFDisplayItem it;
98 SWFAction ac;
100 /*********************************************
102 * Initialization
104 *********************************************/
106 if ( argc>1 ) srcdir=argv[1];
107 else
109 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
110 return 1;
113 sprintf(file_lynch, "%s/lynch.jpg", srcdir);
114 sprintf(file_green, "%s/green.jpg", srcdir);
115 sprintf(file_offspring, "%s/offspring.jpg", srcdir);
118 * Test urls with and w/out 'file://' prefix.
119 * Test both jpeg and swf loading.
121 sprintf(url_lynch, "file://%s/lynch.swf", srcdir);
122 sprintf(url_green, "file://%s/green.jpg", srcdir);
123 sprintf(url_offspring, "%s/offspring.swf", srcdir);
126 puts("Setting things up");
128 Ming_init();
129 Ming_useSWFVersion (OUTPUT_VERSION);
130 Ming_setScale(1.0); /* so we talk twips */
132 mo = newSWFMovie();
133 SWFMovie_setDimension (mo, 11000, 8000);
134 SWFMovie_setRate (mo, 12.0);
135 SWFMovie_setBackground (mo, 255, 255, 255);
137 /*****************************************************
139 * MovieClipLoader class
141 *****************************************************/
143 puts("Compiling MovieClipLoader actionscript");
145 /* Action for first frame */
146 ac = compileSWFActionCode
147 (" \
148 stop(); \
149 CoverArtLoader = new MovieClipLoader(); \
151 SWFMovie_add(mo, (SWFBlock)ac);
153 /* Add the LYNCH clip */
154 add_clip(mo, file_lynch, "lynch", url_lynch, 200, 4419);
156 /* Add the GREEN clip */
157 add_clip(mo, file_green, "green", url_green, 3800, 4419);
159 /* Add the OFFSPRING clip */
160 add_clip(mo, file_offspring, "offspring", url_offspring, 7400, 4419);
162 /*****************************************************
164 * Add the coverart clip
166 *****************************************************/
168 puts("Adding coverart");
170 sh_coverart = newSWFShape();
171 fstyle = SWFShape_addSolidFillStyle(sh_coverart, 0,0,0,255);
172 SWFShape_setRightFillStyle(sh_coverart, fstyle);
173 SWFShape_movePenTo(sh_coverart, 3400, 3400);
174 SWFShape_drawLine(sh_coverart, -3400, 0);
175 SWFShape_drawLine(sh_coverart, 0, -3400);
176 SWFShape_drawLine(sh_coverart, 3400, 0);
177 SWFShape_drawLine(sh_coverart, 0, 3400);
179 mc_coverart = newSWFMovieClip();
180 SWFMovieClip_add(mc_coverart, (SWFBlock)sh_coverart);
181 SWFMovieClip_nextFrame(mc_coverart); /* showFrame */
182 it = SWFMovie_add(mo, (SWFBlock)mc_coverart);
183 SWFDisplayItem_setName(it, "coverart");
184 SWFDisplayItem_moveTo(it, 3800, 500);
186 /*****************************************************
188 * Output movie
190 *****************************************************/
192 puts("Saving " OUTPUT_FILENAME );
194 SWFMovie_nextFrame(mo); /* showFrame */
196 SWFMovie_save(mo, OUTPUT_FILENAME);
198 return 0;