2 * Copyright (C) 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
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.
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
23 #include "ming_utils.h"
25 #define OUTPUT_VERSION 8
26 #define OUTPUT_FILENAME "BitmapDataTest.swf"
28 void addRedSquareExport(SWFMovie mo
);
30 const char* mediadir
=".";
33 addRedSquareExport(SWFMovie mo
)
38 sh
= make_fill_square (0, 0, 60, 60, 255, 0, 0, 255, 0, 0);
39 mc
= newSWFMovieClip();
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
);
46 SWFMovie_addExport(mo
, (SWFBlock
)mc
, "redsquare");
48 SWFMovie_writeExports(mo
);
53 main(int argc
, char** argv
)
56 SWFMovieClip dejagnuclip
, staticSquare
;
60 if ( argc
>1 ) mediadir
=argv
[1];
63 fprintf(stderr
, "Usage: %s <mediadir>\n", argv
[0]);
68 Ming_useSWFVersion (OUTPUT_VERSION
);
71 SWFMovie_setDimension(mo
, 800, 600);
73 if (mo
== NULL
) return -1;
75 addRedSquareExport(mo
);
77 add_actions(mo
, "_root.onKeyDown = _root.onMouseUp = function() {"
79 "Key.addListener(_root);");
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
);
86 SWFMovie_nextFrame(mo
);
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.');"
106 SWFMovie_nextFrame(mo
);
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"
116 SWFMovie_nextFrame(mo
);
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.');");
122 add_actions(mo
, "stop();");
124 SWFMovie_nextFrame(mo
);
126 // Place a dynamic DisplayObject at depth 4
127 add_actions(mo
, "mc.removeMovieClip();"
128 "_root.attachMovie('redsquare', 'rs', 4);");
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
);
136 it
= SWFMovie_add(mo
, (SWFBlock
)staticSquare
);
137 SWFDisplayItem_setDepth(it
, 3);
138 SWFDisplayItem_setName(it
, "staticSquare");
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();");
145 SWFMovie_nextFrame(mo
);
147 add_actions(mo
, "staticSquare.swapDepths(20);"
148 "note('5. There should have been no change. Click to proceed.');"
152 SWFMovie_nextFrame(mo
);
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.');"
161 SWFMovie_nextFrame(mo
);
163 add_actions(mo
, "_root.attachBitmap(bmp, 3);"
164 "note('7. There should have been no change. Click to proceed.');"
168 SWFMovie_nextFrame(mo
);
170 SWFDisplayItem_remove(it
);
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.');"
180 SWFMovie_nextFrame(mo
);
182 add_actions(mo
, "bmp.dispose(); bmp2.dispose();"
183 "note('9. You should see just the red square. Click to proceed.');"
187 SWFMovie_nextFrame(mo
);
189 add_actions(mo
, "bmp = new BitmapData(100, 100, false, 0x0000ff);"
190 "note('10. There should have been no change. Click to proceed.');"
194 SWFMovie_nextFrame(mo
);
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.');"
209 SWFMovie_nextFrame(mo
);
212 "original.removeMovieClip();"
213 "note('12. There should have been no change. Click to proceed.');"
217 SWFMovie_nextFrame(mo
);
220 "duplicate.removeMovieClip();"
221 "note('13. You should see the red square again. Click to "
226 SWFMovie_nextFrame(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.');"
240 SWFMovie_nextFrame(mo
);
244 "note('15. You should see two noise patterns where the two "
245 "squares were. Click to proceed.');"
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...
255 SWFMovie_nextFrame(mo
);
258 puts("Saving " OUTPUT_FILENAME
);
259 SWFMovie_save(mo
, OUTPUT_FILENAME
);