Update with current status
[gnash.git] / testsuite / misc-ming.all / ButtonPropertiesTest.c
blob3bb53bf596741c64af33f50842054d6b0cdba243
1 /***********************************************************************
3 * Copyright (C) 2005, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
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.
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.
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
22 #include "ming_utils.h"
24 #include <ming.h>
25 #include <stdio.h>
26 #include <stdlib.h>
28 #define OUTPUT_VERSION 6
29 #define OUTPUT_FILENAME "ButtonPropertiesTest.swf"
31 SWFFont font;
33 void add_event(SWFMovie mo, const char* name, const char* event, const char* action);
34 SWFDisplayItem add_button(SWFMovie mo);
36 SWFDisplayItem
37 add_button(SWFMovie mo)
39 SWFDisplayItem it;
40 SWFMovieClip mc, mc1;
41 SWFButtonRecord br;
42 SWFShape sh1, sh2, sh3, sh4, sh1a, sh2a, sh3a, sh4a;
43 SWFButton bu = newSWFButton();
44 mc = newSWFMovieClip();
46 sh1 = make_fill_square(0, 0, 40, 40, 0, 0, 0, 0, 0, 0);
47 sh1a = make_fill_square(30, 30, 5, 5, 128, 128, 128, 128, 128, 128);
48 sh2 = make_fill_square(0, 0, 40, 40, 255, 0, 0, 255, 0, 0);
49 sh2a = make_fill_square(30, 30, 5, 5, 128, 0, 0, 128, 0, 0);
50 sh3 = make_fill_square(0, 0, 40, 40, 0, 255, 0, 0, 255, 0);
51 sh3a = make_fill_square(30, 30, 5, 5, 0, 128, 0, 0, 128, 0);
52 sh4 = make_fill_square(0, 0, 40, 40, 255, 255, 0, 255, 255, 0);
53 sh4a = make_fill_square(30, 30, 5, 5, 128, 128, 0, 128, 128, 0);
55 /* Higher depth DisplayObject is intentionally added before lower depth one */
56 br = SWFButton_addCharacter(bu, (SWFCharacter)sh1a, SWFBUTTON_HIT);
57 SWFButtonRecord_setDepth(br, 2);
58 br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_HIT);
59 SWFButtonRecord_setDepth(br, 1);
61 /* Higher depth DisplayObject is intentionally added before lower depth one */
62 br = SWFButton_addCharacter(bu, (SWFCharacter)sh2a, SWFBUTTON_UP );
63 SWFButtonRecord_setDepth(br, 2);
64 br = SWFButton_addCharacter(bu, (SWFCharacter)sh2, SWFBUTTON_UP );
65 SWFButtonRecord_setDepth(br, 1);
67 mc1 = newSWFMovieClip();
68 br = SWFButton_addCharacter(bu, (SWFCharacter)mc1, SWFBUTTON_UP);
69 SWFButtonRecord_setDepth(br, 8);
71 br = SWFButton_addCharacter(bu, (SWFCharacter)mc1, SWFBUTTON_DOWN);
72 SWFButtonRecord_setDepth(br, 7);
74 br = SWFButton_addCharacter(bu, (SWFCharacter)mc1, SWFBUTTON_HIT);
75 SWFButtonRecord_setDepth(br, 9);
77 it = SWFMovieClip_add(mc, (SWFBlock)bu);
78 SWFDisplayItem_setName(it, "button");
79 SWFMovieClip_nextFrame(mc); /* showFrame */
82 it = SWFMovie_add(mo, (SWFBlock)mc);
83 return it;
86 int
87 main(int argc, char **argv)
89 SWFMovie mo;
90 SWFDisplayItem it;
91 const char *srcdir=".";
92 SWFMovieClip dejagnuclip;
94 /*********************************************
96 * Initialization
98 *********************************************/
100 puts("Setting things up");
102 Ming_init();
103 Ming_useSWFVersion (OUTPUT_VERSION);
104 Ming_setScale(20.0);
106 mo = newSWFMovie();
107 SWFMovie_setDimension(mo, 800, 600);
108 SWFMovie_setRate(mo, 12);
110 if ( argc>1 ) srcdir=argv[1];
111 else
113 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
114 return 1;
117 font = get_default_font(srcdir);
119 /* Dejagnu equipment */
120 dejagnuclip = get_dejagnu_clip((SWFBlock)font, 10, 0, 0, 800, 600);
121 it = SWFMovie_add(mo, (SWFBlock)dejagnuclip);
122 SWFDisplayItem_setDepth(it, 200);
123 SWFDisplayItem_move(it, 200, 0);
125 SWFMovie_nextFrame(mo); /* showFrame */
127 /*****************************************************
129 * Add button
131 *****************************************************/
133 it = add_button(mo);
134 SWFDisplayItem_moveTo(it, 40, 30);
135 SWFDisplayItem_setName(it, "square1");
136 SWFDisplayItem_setDepth(it, 2);
138 /* This button has one character per state. It shows that each state
139 * except HIT generates one new instance and deletes the old one.
140 * HIT deletes the old instance property and does not add a new one.
143 add_actions(mo, "note('This is a very simple test. Do anything you like "
144 "with the buttons and you should get no failures');");
146 add_actions(mo, "var c = 2;");
147 add_actions(mo,
148 "props = function() {"
149 " s=''; "
150 " for (i in square1.button) { "
151 " if (i.substr(0, 8) == 'instance') { s += i; }; "
152 " };"
153 " return s;"
154 "};");
155 add_actions(mo, "check_equals(props(), 'instance' + c++);");
156 add_actions(mo,
157 "square1.button.onRollOver = function() {"
158 " check_equals(props(), '');"
159 "};"
160 "square1.button.onRollOut = function() {"
161 " check_equals(props(), 'instance' + c++);"
162 "};"
163 "square1.button.onMouseDown = function() {"
164 " check_equals(props(), 'instance' + c++);"
165 "};"
166 "square1.button.onPress = function() {"
167 " check_equals(props(), 'instance' + c++);"
168 "};"
169 "square1.button.onRelease = function() {"
170 " check_equals(props(), '');"
171 "};"
172 "square1.button.onReleaseOutside = function() {"
173 " check_equals(props(), 'instance' + c++);"
174 "};"
177 check_equals(mo, "square1.button.getDepth()", "-16383");
178 add_actions(mo, "stop();");
179 SWFMovie_nextFrame(mo); /* showFrame */
181 /*****************************************************
183 * Save it...
185 *****************************************************/
187 puts("Saving " OUTPUT_FILENAME );
189 SWFMovie_save(mo, OUTPUT_FILENAME);
191 return 0;