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
20 * Sandro Santilli, strk@keybit.net
22 * Test "Jumping backward to the midle of a DisplayObject's lifetime after moving it to a static depth"
24 * run as ./displaylist_depths_test3
28 * Frame | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
29 * --------+---+---+---+---+---+---+---+
30 * Event | | P | | T*| T | M | J |
32 * P = place (by PlaceObject2)
33 * T = transform matrix (by PlaceObject2)
34 * M = move to another depth (by swapDepth)
40 * frame2: DisplayObject placed at depth -16381 at position (10,200)
41 * frame4: position of instance at depth -16381 shifted to the right (50,200)
42 * frame5: position of instance at depth -16381 shifted to the right (100,200)
43 * frame6: depth of instance changed to -10 (static zone)
44 * frame7: jump back to frame 4 and stop.
46 * Expected behaviour on jump back:
48 * Before the jump we have a single instance at depth -10 and position 100,200.
49 * After the jump we have a single instances at depth -16381 and position 20,200.
50 * Two distinct instances have been constructed in total.
51 * Soft references to the old instance created before the jump-back now point to the new instance.
55 #include "ming_utils.h"
61 // We need version 7 to use getInstanceAtDepth()
62 #define OUTPUT_VERSION 7
63 #define OUTPUT_FILENAME "displaylist_depths_test3.swf"
65 SWFDisplayItem
add_static_mc(SWFMovie mo
, const char* name
, int depth
, int x
, int y
, int width
, int height
);
68 add_static_mc(SWFMovie mo
, const char* name
, int depth
, int x
, int y
, int width
, int height
)
74 sh
= make_fill_square (-(width
/2), -(height
/2), width
, height
, 255, 0, 0, 255, 0, 0);
75 mc
= newSWFMovieClip();
76 SWFMovieClip_add(mc
, (SWFBlock
)sh
);
78 SWFMovieClip_nextFrame(mc
);
80 it
= SWFMovie_add(mo
, (SWFBlock
)mc
);
81 SWFDisplayItem_setDepth(it
, depth
);
82 SWFDisplayItem_moveTo(it
, x
, y
);
83 SWFDisplayItem_setName(it
, name
);
84 SWFDisplayItem_addAction(it
, newSWFAction(
85 "_root.note(this+' onClipConstruct');"
86 " _root.check_equals(typeof(_root), 'movieclip');"
87 " if ( isNaN(_root.depth3Constructed) ) {"
88 " _root.depth3Constructed=1; "
89 " _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
91 " _root.depth3Constructed++;"
92 " _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
94 ), SWFACTION_CONSTRUCT
);
101 main(int argc
, char** argv
)
104 SWFMovieClip dejagnuclip
;
108 const char *srcdir
=".";
113 //fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
118 mo
= newSWFMovieWithVersion(OUTPUT_VERSION
);
119 SWFMovie_setDimension(mo
, 800, 600);
120 SWFMovie_setRate (mo
, 2);
122 dejagnuclip
= get_dejagnu_clip((SWFBlock
)get_default_font(srcdir
), 10, 0, 0, 800, 600);
123 SWFMovie_add(mo
, (SWFBlock
)dejagnuclip
);
124 SWFMovie_nextFrame(mo
);
126 // Frame 2: Add a static movieclip at depth 3 with origin at 10,200
127 it1
= add_static_mc(mo
, "static3", 3, 10, 200, 20, 20);
129 "static3.myThing = 'guess';"
130 "check_equals(static3._x, 10);"
131 "check_equals(static3.myThing, 'guess');"
132 "check_equals(static3.getDepth(), -16381);"
134 SWFMovie_nextFrame(mo
);
136 // Frame 3: nothing new
137 SWFMovie_nextFrame(mo
);
139 // Frame 4: move DisplayObject at depth 3 to position 50,200
140 SWFDisplayItem_moveTo(it1
, 50, 200);
142 "check_equals(static3._x, 50);"
143 "check_equals(static3.getDepth(), -16381);"
145 SWFMovie_nextFrame(mo
);
147 // Frame 5: move DisplayObject at depth 3 to position 100,200
148 SWFDisplayItem_moveTo(it1
, 200, 200);
150 "check_equals(static3.myThing, 'guess');"
151 "check_equals(static3._x, 200);"
152 "check_equals(static3.getDepth(), -16381);"
154 SWFMovie_nextFrame(mo
);
156 // Frame 6: change depth DisplayObject at depth 3 to depth 10 (dynamic zone)
158 "static3.swapDepths(-10);"
159 "check_equals(static3.getDepth(), -10);"
160 "static3._rotation = 45;"
161 "check_equals(static3.myThing, 'guess');"
163 SWFMovie_nextFrame(mo
);
165 // Frame 7: go to frame 4
168 "check_equals(static3.myThing, 'guess');"
170 // Store a reference to the static3 instance
171 // before overriding its name
174 // this repopulates depth -16381 with a *new* instance
177 // Static3 doesn't refer to the moved object anymore !
178 "check_equals(typeof(static3.myThing), 'undefined');"
180 // And neither the reference does !!
181 "check_equals(typeof(dynRef.myThing), 'undefined');"
183 // ... Rather, the reference now points to the newly created instance !!
184 // (see http://www.gnashdev.org/wiki/index.php/SoftReferences)
185 "check_equals(typeof(dynRef), 'movieclip');"
186 "check_equals(dynRef._x, 50);"
187 "check_equals(dynRef, static3);"
189 // We can verify nothing is at depth -10 with getInstanceAtDepth
190 "check_equals(typeof(getInstanceAtDepth(-16381)), 'movieclip');"
191 "check_equals(typeof(getInstanceAtDepth(-10)), 'undefined');"
193 "check_equals(static3.getDepth(), -16381);"
194 "check_equals(static3._x, 50);"
195 "check_equals(depth3Constructed, 2);"
198 SWFMovie_nextFrame(mo
);
201 puts("Saving " OUTPUT_FILENAME
);
202 SWFMovie_save(mo
, OUTPUT_FILENAME
);