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 start of a DisplayObject's lifetime after static transformation"
24 * run as ./displaylist_depths_test5
28 * Frame | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
29 * --------+---+---+---+---+---+---+---+
30 * Event | | P*| | T | | | J |
32 * P = place (by PlaceObject2)
33 * T = transform matrix (by PlaceObject2)
39 * frame2: DisplayObject placed at depth -16381 at position (10,200)
40 * frame4: position of instance at depth -16381 shifted to the right (50,200)
41 * frame7: jump back to frame 2
43 * Expected behaviour on jump back:
45 * Before the jump we have a single instance at depth -16381 and position 50,200.
46 * After the jump we have the same instances at depth -16381, repositioned at 10,200.
47 * A single instance has been constructed in total.
48 * Soft references to the instance created before the jump-back still point to the same instance.
52 #include "ming_utils.h"
58 // We need version 7 to use getInstanceAtDepth()
59 #define OUTPUT_VERSION 7
60 #define OUTPUT_FILENAME "displaylist_depths_test5.swf"
62 SWFDisplayItem
add_static_mc(SWFMovie mo
, const char* name
, int depth
, int x
, int y
, int width
, int height
);
65 add_static_mc(SWFMovie mo
, const char* name
, int depth
, int x
, int y
, int width
, int height
)
71 sh
= make_fill_square (-(width
/2), -(height
/2), width
, height
, 255, 0, 0, 255, 0, 0);
72 mc
= newSWFMovieClip();
73 SWFMovieClip_add(mc
, (SWFBlock
)sh
);
75 SWFMovieClip_nextFrame(mc
);
77 it
= SWFMovie_add(mo
, (SWFBlock
)mc
);
78 SWFDisplayItem_setDepth(it
, depth
);
79 SWFDisplayItem_moveTo(it
, x
, y
);
80 SWFDisplayItem_setName(it
, name
);
81 SWFDisplayItem_addAction(it
, newSWFAction(
82 "_root.note(this+' onClipConstruct');"
83 " _root.check_equals(typeof(_root), 'movieclip');"
84 " if ( isNaN(_root.depth3Constructed) ) {"
85 " _root.depth3Constructed=1; "
86 " _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
88 " _root.depth3Constructed++;"
89 " _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
91 ), SWFACTION_CONSTRUCT
);
98 main(int argc
, char** argv
)
101 SWFMovieClip dejagnuclip
;
105 const char *srcdir
=".";
110 //fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
115 mo
= newSWFMovieWithVersion(OUTPUT_VERSION
);
116 SWFMovie_setDimension(mo
, 800, 600);
117 SWFMovie_setRate (mo
, 2);
119 dejagnuclip
= get_dejagnu_clip((SWFBlock
)get_default_font(srcdir
), 10, 0, 0, 800, 600);
120 SWFMovie_add(mo
, (SWFBlock
)dejagnuclip
);
121 SWFMovie_nextFrame(mo
);
123 // Frame 2: Add a static movieclip at depth 3 with origin at 10,200
124 it1
= add_static_mc(mo
, "static3", 3, 10, 200, 20, 20);
126 "static3.myThing = 'guess';"
127 "check_equals(static3._x, 10);"
128 "check_equals(static3.myThing, 'guess');"
129 "check_equals(static3.getDepth(), -16381);"
131 SWFMovie_nextFrame(mo
);
133 // Frame 3: nothing new
134 SWFMovie_nextFrame(mo
);
136 // Frame 4: move DisplayObject at depth 3 to position 50,200
137 SWFDisplayItem_moveTo(it1
, 50, 200);
139 "check_equals(static3._x, 50);"
140 "check_equals(static3.getDepth(), -16381);"
142 SWFMovie_nextFrame(mo
);
144 // Frame 5: nothing new
145 SWFMovie_nextFrame(mo
);
147 // Frame 6: nothing new
148 SWFMovie_nextFrame(mo
);
150 // Frame 7: go to frame 2
153 "check_equals(static3.myThing, 'guess');"
154 "check_equals(static3._x, 50);"
156 // Store a reference to the static3 instance
157 // before jumping back
160 // this reset char at depth -16381 to be at position 10,200
163 // Static3 refers to same instance
164 "check_equals(static3.myThing, 'guess');"
165 "check_equals(static3.getDepth(), -16381);"
167 // But it has now be reset to position 10,100 as specified
168 // by PlaceObject2 tag in frame 2.
169 // Note that the PlaceObject2 in frame 2 has the "move" flag
170 // set to off as it's really intended to be used to *create*
171 // an instance. Instead, since that depth is already occupied,
172 // it behave as if it was a transforming PlaceObject2
173 "check_equals(static3._x, 10);"
175 // The reference still refers to the same instance
176 // (see http://www.gnashdev.org/wiki/index.php/SoftReferences)
177 "check_equals(dynRef.myThing, 'guess');"
178 "check_equals(dynRef.getDepth(), -16381);"
179 "check_equals(typeof(dynRef), 'movieclip');"
180 "check_equals(dynRef._x, 10);"
181 "check_equals(dynRef, static3);"
183 // A single instance is created in total
184 "check_equals(depth3Constructed, 1);"
188 SWFMovie_nextFrame(mo
);
191 puts("Saving " OUTPUT_FILENAME
);
192 SWFMovie_save(mo
, OUTPUT_FILENAME
);