1 /*
2  *   Copyright (C) 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16  *
17  */
18 
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <ming.h>
22 
23 #include "ming_utils.h"
24 
25 #define OUTPUT_VERSION 8
26 #define OUTPUT_FILENAME "BitmapDataTest.swf"
27 
28 void addRedSquareExport(SWFMovie mo);
29 
30 const char* mediadir=".";
31 
32 void
addRedSquareExport(SWFMovie mo)33 addRedSquareExport(SWFMovie mo)
34 {
35 	SWFShape sh;
36 	SWFMovieClip mc;
37 
38 	sh = make_fill_square (0, 0, 60, 60, 255, 0, 0, 255, 0, 0);
39 	mc = newSWFMovieClip();
40 
41 	SWFMovieClip_add(mc, (SWFBlock)sh);
42 	/* This is here just to turn the clip into an active one */
43 	add_clip_actions(mc, "onRollOver = function() {};");
44 	SWFMovieClip_nextFrame(mc);
45 
46 	SWFMovie_addExport(mo, (SWFBlock)mc, "redsquare");
47 
48 	SWFMovie_writeExports(mo);
49 }
50 
51 
52 int
main(int argc,char ** argv)53 main(int argc, char** argv)
54 {
55   SWFMovie mo;
56   SWFMovieClip dejagnuclip, staticSquare;
57   SWFShape shape;
58   SWFDisplayItem it;
59 
60   if ( argc>1 ) mediadir=argv[1];
61   else
62   {
63     fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
64     return 1;
65   }
66 
67   Ming_init();
68   Ming_useSWFVersion (OUTPUT_VERSION);
69 
70   mo = newSWFMovie();
71   SWFMovie_setDimension(mo, 800, 600);
72 
73   if (mo == NULL) return -1;
74 
75   addRedSquareExport(mo);
76 
77   add_actions(mo, "_root.onKeyDown = _root.onMouseUp = function() {"
78 	                "play(); }; "
79                     "Key.addListener(_root);");
80 
81   SWFMovie_setRate(mo, 12);
82     dejagnuclip = get_dejagnu_clip(
83             (SWFBlock)get_default_font(mediadir), 10, 10, 150, 800, 600);
84     SWFMovie_add(mo, (SWFBlock)dejagnuclip);
85 
86   SWFMovie_nextFrame(mo);
87 
88   add_actions(mo, "BitmapData = flash.display.BitmapData;"
89 		  "Rectangle = flash.geom.Rectangle;"
90 		  "bmp = new BitmapData(150, 150, false);"
91 		  "rect = new Rectangle(10, 10, 100, 100);"
92 		  "bmp.fillRect(rect, 0x00ff00);"
93 		  "mc = _root.createEmptyMovieClip('mc', getNextHighestDepth());"
94           "d = mc.getNextHighestDepth();"
95           "mc.attachBitmap(bmp, d);"
96           "bmp2 = new BitmapData(20, 20, true);"
97           "rect2 = new Rectangle (10, 10, 20, 20);"
98           "bmp2.fillRect(rect2, 0xffffff00);"
99           "d2 = mc.getNextHighestDepth();"
100           "mc.attachBitmap(bmp2, d2);"
101           "note('1. You should see a small yellow square in the top left "
102                 "corner of a larger green square. Click to proceed.');"
103           "stop();"
104           );
105 
106     SWFMovie_nextFrame(mo);
107 
108     add_actions(mo, "rect = new Rectangle (90, 90, 120, 120);"
109 		    "bmp.fillRect(rect, 0x0000FF);"
110             "note('2. You should see a new blue square covering the "
111                 "bottom right corner of the large green square. Click"
112                 " to proceed.');"
113             "stop();"
114             );
115 
116     SWFMovie_nextFrame(mo);
117 
118     add_actions(mo, "mc.createEmptyMovieClip('d', d);"
119             "note('3. You should see just the small yellow square in the top "
120                 "left corner. Click to proceed.');");
121 
122     add_actions(mo, "stop();");
123 
124     SWFMovie_nextFrame(mo);
125 
126     // Place a dynamic DisplayObject at depth 4
127     add_actions(mo, "mc.removeMovieClip();"
128             "_root.attachMovie('redsquare', 'rs', 4);");
129 
130     // Place a static DisplayObject at depth 3
131     staticSquare = newSWFMovieClip();
132     shape = make_fill_square (300, 0, 60, 60, 255, 0, 255, 255, 0, 255);
133     SWFMovieClip_add(staticSquare, (SWFBlock)shape);
134     SWFMovieClip_nextFrame(staticSquare);
135 
136     it = SWFMovie_add(mo, (SWFBlock)staticSquare);
137     SWFDisplayItem_setDepth(it, 3);
138     SWFDisplayItem_setName(it, "staticSquare");
139 
140     add_actions(mo,
141             "note('4. You should see a red square in the top left and a "
142             "purple square in the top right. Click to proceed.');");
143     add_actions(mo, "stop();");
144 
145     SWFMovie_nextFrame(mo);
146 
147     add_actions(mo, "staticSquare.swapDepths(20);"
148             "note('5. There should have been no change. Click to proceed.');"
149             "stop();"
150             );
151 
152     SWFMovie_nextFrame(mo);
153 
154     add_actions(mo, "_root.attachBitmap(bmp, 2);"
155             "note('6. You should see the green and blue squares "
156             "under the red square. The purple square should still be there. "
157             "Click to proceed.');"
158             "stop();"
159             );
160 
161     SWFMovie_nextFrame(mo);
162 
163     add_actions(mo, "_root.attachBitmap(bmp, 3);"
164             "note('7. There should have been no change. Click to proceed.');"
165             "stop();"
166             );
167 
168     SWFMovie_nextFrame(mo);
169 
170     SWFDisplayItem_remove(it);
171 
172     add_actions(mo, "_root.attachBitmap(bmp2, 20);"
173             "note('8. The purple square should have gone. The small yellow "
174             "square should have replaced the top left corner of the red "
175             "square. The green and blue squares should still be there. "
176             "Click to proceed.');"
177             "stop();"
178             );
179 
180     SWFMovie_nextFrame(mo);
181 
182     add_actions(mo, "bmp.dispose(); bmp2.dispose();"
183             "note('9. You should see just the red square. Click to proceed.');"
184             "stop();"
185             );
186 
187     SWFMovie_nextFrame(mo);
188 
189     add_actions(mo, "bmp = new BitmapData(100, 100, false, 0x0000ff);"
190             "note('10. There should have been no change. Click to proceed.');"
191             "stop();"
192             );
193 
194     SWFMovie_nextFrame(mo);
195 
196     add_actions(mo, "bmp3 = new BitmapData(100, 100, false);"
197             "rect3 = new Rectangle(20, 20, 90, 90);"
198             "bmp3.fillRect(rect3, 0x0000ff);"
199             "ch = _root.createEmptyMovieClip('original', 40);"
200             "original.attachBitmap(bmp3, getNextHighestDepth());"
201             "ch._name = 'duplicate';"
202             "newch = _root.createEmptyMovieClip('original', "
203                     "getNextHighestDepth());"
204             "note('11. You should see a large blue square only. "
205             "Click to proceed.');"
206             "stop();"
207             );
208 
209     SWFMovie_nextFrame(mo);
210 
211     add_actions(mo,
212             "original.removeMovieClip();"
213             "note('12. There should have been no change. Click to proceed.');"
214             "stop();"
215             );
216 
217     SWFMovie_nextFrame(mo);
218 
219     add_actions(mo,
220             "duplicate.removeMovieClip();"
221             "note('13. You should see the red square again. Click to "
222             "proceed.');"
223             "stop();"
224             );
225 
226     SWFMovie_nextFrame(mo);
227 
228     add_actions(mo,
229             "_root.createEmptyMovieClip('mcLeft', getNextHighestDepth());"
230             "mcLeft.duplicateMovieClip('mcMiddle', getNextHighestDepth(),"
231                         " { _x: 300, _y: 0 } );"
232             "mcLeft.attachBitmap(bmp3, getNextHighestDepth());"
233             "mcMiddle.attachBitmap(bmp3, getNextHighestDepth());"
234             "mcMiddle.duplicateMovieClip('mcRight', getNextHighestDepth(),"
235                         " { _x: 600, _y: 0 } );"
236             "note('14. You should see two blue squares. Click to proceed.');"
237             "stop();"
238             );
239 
240     SWFMovie_nextFrame(mo);
241 
242     add_actions(mo,
243             "bmp3.noise(293);"
244             "note('15. You should see two noise patterns where the two "
245             "squares were. Click to proceed.');"
246             "stop();"
247             );
248 
249     add_actions(mo, "_root.onKeyDown = _root.onMouseUp = undefined;"
250             "_root.eof = true;" // hook for test runner...
251             "note(' - END OF TEST - thanks for flying with us ! ');"
252             //"totals(6);" // no AS based tests...
253             );
254 
255     SWFMovie_nextFrame(mo);
256 
257   //Output movie
258   puts("Saving " OUTPUT_FILENAME );
259   SWFMovie_save(mo, OUTPUT_FILENAME);
260 
261   return 0;
262 }
263