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"
28 #define OUTPUT_VERSION 6
29 #define OUTPUT_FILENAME "ButtonPropertiesTest.swf"
33 void add_event(SWFMovie mo
, const char* name
, const char* event
, const char* action
);
34 SWFDisplayItem
add_button(SWFMovie mo
);
37 add_button(SWFMovie mo
)
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
);
87 main(int argc
, char **argv
)
91 const char *srcdir
=".";
92 SWFMovieClip dejagnuclip
;
94 /*********************************************
98 *********************************************/
100 puts("Setting things up");
103 Ming_useSWFVersion (OUTPUT_VERSION
);
107 SWFMovie_setDimension(mo
, 800, 600);
108 SWFMovie_setRate(mo
, 12);
110 if ( argc
>1 ) srcdir
=argv
[1];
113 fprintf(stderr
, "Usage: %s <mediadir>\n", argv
[0]);
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 /*****************************************************
131 *****************************************************/
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;");
148 "props = function() {"
150 " for (i in square1.button) { "
151 " if (i.substr(0, 8) == 'instance') { s += i; }; "
155 add_actions(mo
, "check_equals(props(), 'instance' + c++);");
157 "square1.button.onRollOver = function() {"
158 " check_equals(props(), '');"
160 "square1.button.onRollOut = function() {"
161 " check_equals(props(), 'instance' + c++);"
163 "square1.button.onMouseDown = function() {"
164 " check_equals(props(), 'instance' + c++);"
166 "square1.button.onPress = function() {"
167 " check_equals(props(), 'instance' + c++);"
169 "square1.button.onRelease = function() {"
170 " check_equals(props(), '');"
172 "square1.button.onReleaseOutside = function() {"
173 " check_equals(props(), 'instance' + c++);"
177 check_equals(mo
, "square1.button.getDepth()", "-16383");
178 add_actions(mo
, "stop();");
179 SWFMovie_nextFrame(mo
); /* showFrame */
181 /*****************************************************
185 *****************************************************/
187 puts("Saving " OUTPUT_FILENAME
);
189 SWFMovie_save(mo
, OUTPUT_FILENAME
);