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 /*
20  * Zou Lunkai, zoulunkai@gmail.com
21  *
22  * Test "Jumping backward to the midle of a DisplayObject's lifetime after swap to same depth"
23  *
24  * run as ./displaylist_depths_test7
25  *
26  * Timeline:
27  *
28  *   Frame  | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
29  *  --------+---+---+---+---+---+---+---+
30  *   Event  |   |PM |   | T*| T |   | J |
31  *
32  *  P = place (by PlaceObject2)
33  *  T = transform matrix (by PlaceObject2)
34  *  M = move to another (or same) depth (by swapDepth)
35  *  J = jump
36  *  * = jump target
37  *
38  * Description:
39  *
40  *  frame2: DisplayObject placed at depth -16381 at position (10,200);
41  *          swap the DisplayObject to depth -16381 (YES: SAME DEPTH!)
42  *  frame4: try to transform the DisplayObject to the right (50,200)
43  *  frame5: try to transform the DisplayObject to the right (200,200)
44  *  frame7: jump back to frame 4 and stop
45  *
46  * Expected behaviour:
47  *
48  *  Depth swapping in frame2 have NO effect. In particular doesn't prevent subsequent static transformations to apply.
49  *  In frame 4 the instance is positioned at 50,200
50  *  In frame 5 and 6 the instance is positioned at 200,200
51  *  After the jump we have the same instances at depth -16381, and positioned at 50,200.
52  *  A single instance has been constructed in total.
53  *
54  */
55 
56 #include "ming_utils.h"
57 
58 #include <stdlib.h>
59 #include <stdio.h>
60 #include <ming.h>
61 
62 #define OUTPUT_VERSION 6
63 #define OUTPUT_FILENAME "displaylist_depths_test7.swf"
64 
65 SWFDisplayItem add_static_mc(SWFMovie mo, const char* name, int depth, int x, int y, int width, int height);
66 
67 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)
69 {
70   SWFShape sh;
71   SWFMovieClip mc;
72   SWFDisplayItem it;
73 
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);
77 
78   SWFMovieClip_nextFrame(mc);
79 
80   it = SWFMovie_add(mo, (SWFBlock)mc);
81   SWFDisplayItem_setDepth(it, depth);
82   SWFDisplayItem_moveTo(it, x, y);
83   SWFDisplayItem_setName(it, name);
84 
85   return it;
86 }
87 
88 
89 int
main(int argc,char ** argv)90 main(int argc, char** argv)
91 {
92   SWFMovie mo;
93   SWFMovieClip dejagnuclip;
94   SWFDisplayItem it1;
95 
96 
97   const char *srcdir=".";
98   if ( argc>1 )
99     srcdir=argv[1];
100   else
101   {
102       //fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
103       //return 1;
104   }
105 
106   Ming_init();
107   mo = newSWFMovieWithVersion(OUTPUT_VERSION);
108   SWFMovie_setDimension(mo, 800, 600);
109   SWFMovie_setRate (mo, 2);
110 
111   dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
112   SWFMovie_add(mo, (SWFBlock)dejagnuclip);
113   add_actions(mo, "loopback = false;");
114   SWFMovie_nextFrame(mo);
115 
116   // Frame 2: Add a static movieclip at depth 3 with origin at 10,200, swap to depth -10 and swap back
117   it1 = add_static_mc(mo, "static3", 3, 10, 200, 20, 20);
118   add_actions(mo,
119     "static3.myThing = 'guess';"
120     "check_equals(static3.getDepth(), -16381);"
121     // swap to another depth
122     "static3.swapDepths(-16381);"
123     "check_equals(static3.getDepth(), -16381);"
124     );
125   SWFMovie_nextFrame(mo);
126 
127   // Frame 3: nothing new
128   SWFMovie_nextFrame(mo);
129 
130   // Frame 4: move DisplayObject at depth 3 to position 50,200
131   SWFDisplayItem_moveTo(it1, 50, 200);
132   add_actions(mo,
133     "check_equals(static3._x, 50);"
134     "check_equals(static3.getDepth(), -16381);"
135     );
136   SWFMovie_nextFrame(mo);
137 
138   // Frame 5: move DisplayObject at depth 3 to position 100,200
139   SWFDisplayItem_moveTo(it1, 200, 200);
140   SWFMovie_nextFrame(mo);
141 
142   // Frame 6: nothing new, just tests
143   add_actions(mo,
144     "check_equals(static3._x, 200);"
145     "check_equals(static3.getDepth(), -16381);"
146     );
147   SWFMovie_nextFrame(mo);
148 
149   // Frame 7: go to frame 4
150   add_actions(mo,
151     " if(loopback == false) "
152     " { "
153     // this does not reset any thing
154     "   gotoAndStop(4); "
155     "   loopback = true; "
156     " } "
157 
158     // Static3 refers to same instance
159     "check_equals(static3.myThing, 'guess');"
160     "check_equals(static3._x, 50);"
161 
162     "check_equals(static3.getDepth(), -16381);"
163     "totals();"
164     );
165   SWFMovie_nextFrame(mo);
166 
167   //Output movie
168   puts("Saving " OUTPUT_FILENAME );
169   SWFMovie_save(mo, OUTPUT_FILENAME);
170 
171   return 0;
172 }
173