1 /***********************************************************************
2  *
3  *   Copyright (C) 2005, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  *
19  *
20  ***********************************************************************
21  *
22  * Test case for the RemoveObject2 tag
23  * It places and removes 3 squares every 5 frames.
24  *
25  ***********************************************************************/
26 
27 #include <stdio.h>
28 #include <ming.h>
29 
30 #define OUTPUT_VERSION 6
31 #define OUTPUT_FILENAME "RemoveObject2Test.swf"
32 
33 static SWFShape
make_square(int x,int y,int width,int height,byte r,byte g,byte b)34 make_square(int x, int y, int width, int height, byte r, byte g, byte b)
35 {
36 	SWFShape sh = newSWFShape();
37 	SWFShape_setLineStyle(sh, 1, r, g, b, 255);
38 	SWFShape_movePenTo(sh, x, y);
39 	SWFShape_drawLineTo(sh, x, y+height);
40 	SWFShape_drawLineTo(sh, x+width, y+height);
41 	SWFShape_drawLineTo(sh, x+width, y);
42 	SWFShape_drawLineTo(sh, x, y);
43 
44 	return sh;
45 }
46 
main(void)47 int main(void)
48 {
49 	SWFMovie mo;
50 	SWFDisplayItem it1, it2, it3;
51 	SWFShape sh1, sh2, sh3;
52 	int framenum;
53 
54 	/*********************************************
55 	 *
56 	 * Initialization
57 	 *
58 	 *********************************************/
59 
60 	puts("Setting things up");
61 
62 	Ming_init();
63         Ming_useSWFVersion (OUTPUT_VERSION);
64 	Ming_setScale(20.0);
65 
66 	mo = newSWFMovie();
67 
68 	/*****************************************************
69 	 *
70 	 * Add the square named
71 	 *
72 	 *****************************************************/
73 
74 	SWFMovie_setDimension(mo, 100, 100);
75 
76 #define FRAMESGAP 5
77 
78 	sh1 = make_square(10, 10, 20, 20, 255, 0, 0);
79 	it1 = SWFMovie_add(mo, (SWFBlock)sh1);
80 	SWFDisplayItem_setDepth(it1, 1);
81 	SWFDisplayItem_setName(it1, "Name1");
82 
83 	for (framenum=0; framenum<FRAMESGAP; framenum++) {
84 		SWFMovie_nextFrame(mo);
85 	}
86 
87 	sh2 = make_square(35, 10, 20, 20, 0, 255, 0);
88 	it2 = SWFMovie_add(mo, (SWFBlock)sh2);
89 	SWFDisplayItem_setDepth(it2, 2);
90 	SWFDisplayItem_setName(it2, "Name2");
91 
92 	for (framenum=0; framenum<FRAMESGAP; framenum++) {
93 		SWFMovie_nextFrame(mo);
94 	}
95 
96 	sh3 = make_square(10, 35, 45, 20, 0, 0, 255);
97 	it3 = SWFMovie_add(mo, (SWFBlock)sh3);
98 	SWFDisplayItem_setDepth(it3, 3);
99 	SWFDisplayItem_setName(it3, "Name3");
100 
101 	for (framenum=0; framenum<FRAMESGAP; framenum++) {
102 		SWFMovie_nextFrame(mo);
103 	}
104 
105 	SWFMovie_remove(mo, it1);
106 
107 	for (framenum=0; framenum<FRAMESGAP; framenum++) {
108 		SWFMovie_nextFrame(mo);
109 	}
110 
111 	SWFMovie_remove(mo, it2);
112 
113 	for (framenum=0; framenum<FRAMESGAP; framenum++) {
114 		SWFMovie_nextFrame(mo);
115 	}
116 
117 	SWFMovie_remove(mo, it3);
118 
119 	puts("Saving " OUTPUT_FILENAME );
120 
121 	SWFMovie_nextFrame(mo); /* showFrame */
122 
123 	SWFMovie_save(mo, OUTPUT_FILENAME);
124 
125 	return 0;
126 }
127