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
16 *
17 *
18 */
19
20 /*
21 * Test DefineText tag.
22 *
23 * run as ./DefineTextTest <mediadir> to produce DefineTextTest.swf
24 */
25
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <ming.h>
29
30 #include "ming_utils.h"
31
32 #define OUTPUT_VERSION 7
33 #define OUTPUT_FILENAME "DefineTextTest.swf"
34
35 int
main(int argc,char ** argv)36 main(int argc, char** argv)
37 {
38 SWFMovie mo;
39 const char *srcdir=".";
40 char fdbfont[256];
41 SWFMovieClip dejagnuclip;
42
43 /*********************************************
44 *
45 * Initialization
46 *
47 *********************************************/
48
49 if ( argc>1 ) srcdir=argv[1];
50 else
51 {
52 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
53 return 1;
54 }
55
56 sprintf(fdbfont, "%s/Bitstream-Vera-Sans.fdb", srcdir);
57
58 puts("Setting things up");
59
60 Ming_init();
61 Ming_useSWFVersion (OUTPUT_VERSION);
62 //Ming_setScale(20.0); /* so we talk twips */
63
64 mo = newSWFMovie();
65 SWFMovie_setRate(mo, 1.0);
66 SWFMovie_setDimension(mo, 800, 600);
67
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
71
72 /*********************************************
73 *
74 * Add some textfields
75 *
76 *********************************************/
77 {
78 SWFMovieClip mc; // to check sizes
79 SWFDisplayItem it;
80 SWFText tf;
81
82 FILE *font_file = fopen(fdbfont, "r");
83 if ( font_file == NULL )
84 {
85 perror(fdbfont);
86 exit(1);
87 }
88 SWFFont efont = loadSWFFontFromFile(font_file);
89
90 tf = newSWFText();
91
92 SWFText_setFont(tf, efont);
93 SWFText_setHeight(tf, 200);
94 SWFText_setColor(tf, 0, 255, 0, 0xff);
95 SWFText_addString(tf, "O", NULL);
96
97 SWFText_setFont(tf, efont);
98 SWFText_setHeight(tf, 200);
99 SWFText_setColor(tf, 255, 0, 0, 0xff);
100 SWFText_addString(tf, "X", NULL);
101
102 mc = newSWFMovieClip();
103 it = SWFMovieClip_add(mc, (SWFBlock)tf);
104 SWFDisplayItem_setName(it, "stext1");
105 SWFMovieClip_nextFrame(mc);
106
107 it = SWFMovie_add(mo, mc);
108 SWFDisplayItem_setName(it, "mc");
109 SWFDisplayItem_moveTo(it, 0, 400);
110 }
111 SWFMovie_nextFrame(mo); // 2nd frame
112
113
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();"
146 );
147
148
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'");
153
154 check_equals(mo, "mc._width", "288.05");
155
156 // Wait for mouse clicks.
157 add_actions(mo, "stop();");
158
159 SWFMovie_nextFrame(mo);
160
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
165
166 /*****************************************************
167 *
168 * Output movie
169 *
170 *****************************************************/
171 puts("Saving " OUTPUT_FILENAME );
172
173 SWFMovie_save(mo, OUTPUT_FILENAME);
174
175 return 0;
176 }
177