big merge from master, fix rpm creation, drop fetching swfdec
[gnash.git] / testsuite / misc-ming.all / DefineTextTest.c
blob2cc4cd17dc80a4df4e3c5ba05e1ffc51f1512b94
1 /*
2 * Copyright (C) 2005, 2006, 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
18 */
21 * Test DefineText tag.
23 * run as ./DefineTextTest <mediadir> to produce DefineTextTest.swf
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <ming.h>
30 #include "ming_utils.h"
32 #define OUTPUT_VERSION 7
33 #define OUTPUT_FILENAME "DefineTextTest.swf"
35 int
36 main(int argc, char** argv)
38 SWFMovie mo;
39 const char *srcdir=".";
40 char fdbfont[256];
41 SWFMovieClip dejagnuclip;
43 /*********************************************
45 * Initialization
47 *********************************************/
49 if ( argc>1 ) srcdir=argv[1];
50 else
52 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
53 return 1;
56 sprintf(fdbfont, "%s/Bitstream-Vera-Sans.fdb", srcdir);
58 puts("Setting things up");
60 Ming_init();
61 Ming_useSWFVersion (OUTPUT_VERSION);
62 //Ming_setScale(20.0); /* so we talk twips */
64 mo = newSWFMovie();
65 SWFMovie_setRate(mo, 1.0);
66 SWFMovie_setDimension(mo, 800, 600);
68 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
69 SWFMovie_add(mo, (SWFBlock)dejagnuclip);
70 SWFMovie_nextFrame(mo); // 1st frame
72 /*********************************************
74 * Add some textfields
76 *********************************************/
78 SWFMovieClip mc; // to check sizes
79 SWFDisplayItem it;
80 SWFText tf;
82 FILE *font_file = fopen(fdbfont, "r");
83 if ( font_file == NULL )
85 perror(fdbfont);
86 exit(1);
88 SWFFont efont = loadSWFFontFromFile(font_file);
90 tf = newSWFText();
92 SWFText_setFont(tf, efont);
93 SWFText_setHeight(tf, 200);
94 SWFText_setColor(tf, 0, 255, 0, 0xff);
95 SWFText_addString(tf, "O", NULL);
97 SWFText_setFont(tf, efont);
98 SWFText_setHeight(tf, 200);
99 SWFText_setColor(tf, 255, 0, 0, 0xff);
100 SWFText_addString(tf, "X", NULL);
102 mc = newSWFMovieClip();
103 it = SWFMovieClip_add(mc, (SWFBlock)tf);
104 SWFDisplayItem_setName(it, "stext1");
105 SWFMovieClip_nextFrame(mc);
107 it = SWFMovie_add(mo, mc);
108 SWFDisplayItem_setName(it, "mc");
109 SWFDisplayItem_moveTo(it, 0, 400);
111 SWFMovie_nextFrame(mo); // 2nd frame
114 add_actions(mo,
115 "_root.note('Follow the instructions. "
116 "Click means press and release');"
117 "instructions = [ "
118 " 'Move the mouse onto the green O',"
119 " 'Click',"
120 " 'Move the mouse to the centre of the O',"
121 " 'Click as much as you like then move back onto the green O',"
122 " 'Click',"
123 " 'Move outside the green O' ];"
124 "_global.events = 0;"
125 "_global.clicks = 0;"
126 "_global.mouseInOut = 0;"
127 "checkEvents = function() {"
128 " if (_global.events == instructions.length) {"
129 " play();"
130 " }"
131 " else { _root.note(instructions[_global.events++]); };"
132 "};"
133 "mc.onPress = function() {"
134 " _global.clicks++;"
135 " checkEvents();"
136 "};"
137 "mc.onRollOver = function() {"
138 " _global.mouseInOut++;"
139 " checkEvents();"
140 "};"
141 "mc.onRollOut = function() {"
142 " _global.mouseInOut++;"
143 " checkEvents();"
144 "};"
145 "checkEvents();"
149 // static text is not a referenceable char
150 check_equals(mo, "mc.stext1", "mc");
151 check_equals(mo, "typeof(mc.stext1)", "'movieclip'");
152 check_equals(mo, "mc.stext1._target", "'/mc'");
154 check_equals(mo, "mc._width", "288.05");
156 // Wait for mouse clicks.
157 add_actions(mo, "stop();");
159 SWFMovie_nextFrame(mo);
161 xcheck_equals(mo, "_global.clicks", "2");
162 xcheck_equals(mo, "_global.mouseInOut", "4");
163 add_actions(mo, "endoftest=true; totals(); stop();");
164 SWFMovie_nextFrame(mo); // 3rd frame
166 /*****************************************************
168 * Output movie
170 *****************************************************/
171 puts("Saving " OUTPUT_FILENAME );
173 SWFMovie_save(mo, OUTPUT_FILENAME);
175 return 0;