Esempio n. 1
0
int
main(int argc, char **argv)
{
	SWFMovie mo;
	SWFDisplayItem it;
	const char *srcdir=".";
	SWFMovieClip dejagnuclip;

	/*********************************************
	 *
	 * Initialization
	 *
	 *********************************************/

	puts("Setting things up");

	Ming_init();
        Ming_useSWFVersion (OUTPUT_VERSION);
	Ming_setScale(20.0); 
 
	mo = newSWFMovie();
	SWFMovie_setDimension(mo, 800, 600);
	SWFMovie_setRate(mo, 12);

	if ( argc>1 ) srcdir=argv[1];
	else
	{
		fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
		return 1;
	}

	font = get_default_font(srcdir); 

	/* Dejagnu equipment */
	dejagnuclip = get_dejagnu_clip((SWFBlock)font, 10, 0, 0, 800, 600);
	it = SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  	SWFDisplayItem_setDepth(it, 200); 
  	SWFDisplayItem_move(it, 200, 0); 

	add_text_field(mo, "textfield", "_root.msg", "Button events", 10, 0, 5);
	add_text_field(mo, "textfield2", "_root.msg2", "Mouse events", 11, 0, 100);
	add_text_field(mo, "textfield3", "_root.msg3", "Key events", 12, 0, 80);

	SWFMovie_nextFrame(mo); /* showFrame */

	/*****************************************************
	 *
	 * Add button
	 *
	 *****************************************************/

	it = add_button(mo);
	SWFDisplayItem_moveTo(it, 40, 30);
	SWFDisplayItem_setName(it, "square1");
	SWFDisplayItem_setDepth(it, 2);

	add_actions(mo,
		"function printBounds(b) {"
		"   return ''+Math.round(b.xMin*100)/100+','+Math.round(b.yMin*100)/100+' '+Math.round(b.xMax*100)/100+','+Math.round(b.yMax*100)/100;"
		"}"
	);

	//
	// Mouse pointer events
	//

	add_actions(mo,
		"square1.button.onRollOver = function() { "
		"	_root.msg2 = 'RollOver'; "
		// Target is the one this function was defined in
		"	check_equals(_target, '/');"
		"};"
		);

	add_actions(mo,
		"square1.button.onRollOut = function() {"
		"	_root.msg2 = 'RollOut'; "
		// Target is the one this function was defined in
		"	check_equals(_target, '/');"
		"};"
		);

	//
	// Mouse buttons events
	//

	add_actions(mo,
		"square1.button.onPress = function() {"
		"	_root.msg2 = 'Press'; "
		// Target is the one this function was defined in
		"	check_equals(_target, '/');"
		"};"
		);

	add_actions(mo,
		"square1.button.onRelease = function() {"
		"	_root.msg2 = 'Release'; "
		// Target is the one this function was defined in
		"	check_equals(_target, '/');"
		"};"
		);

	add_actions(mo,
		"square1.button.onReleaseOutside = function() {"
		"	_root.msg2 = 'ReleaseOutside'; "
		// Target is the one this function was defined in
		"	check_equals(_target, '/');"
		"};"
		);

	//
	// Focus events
	//

	add_actions(mo,
		"square1.button.onSetFocus = function() {"
		"	_root.msg3 = 'SetFocus';"
		// Target is the one this function was defined in
		"	check_equals(_target, '/');"
		"};"
		);

	//
	// Key events - button needs focus for these to work
	//

	add_actions(mo,
		"square1.button.onKeyDown = function() {"
		"	_root.msg3 = 'KeyDown';"
		// Target is the one this function was defined in
		"	check_equals(_target, '/');"
		"};"
		);

	add_actions(mo, 
		"square1.button.onKeyUp = function() {"
		"	_root.msg3 = 'KeyUp';"
		// Target is the one this function was defined in
		"	check_equals(_target, '/');"
		"};"
		);

	SWFMovie_nextFrame(mo); /* showFrame */

	/*****************************************************
	 *
	 * On second frame, check construction of the button
	 * DisplayObject states and give instructions to proceed
	 *
	 *
	 *****************************************************/

	add_actions(mo, "Array.prototype.realLength = function() {"
		" var l=0; for (var i in this) { "
		"	if (Number(i) == i) l++;" /* count only numbers */
		" };"
		" return l;"
		"};");

	/* buttonChild was initialized with 2 elements */
	check_equals(mo, "typeof(_root.buttonChild)", "'object'");
	check(mo, "_root.buttonChild instanceof Array");
	check_equals(mo, "_root.buttonChild.realLength()", "2"); /* UP and ALL states */

	/* sprite for ALL states */
	check_equals(mo, "typeof(_root.buttonChild[10])", "'object'");
	check_equals(mo, "(_root.buttonChild[10].nam)", "'_level0.square1.button.instance5'"); 
	check_equals(mo, "(_root.buttonChild[10].exe)", "1");
	check_equals(mo, "(_root.buttonChild[10].uld)", "0");

	/* sprite for UP state */
	check_equals(mo, "typeof(_root.buttonChild[12])", "'object'");
	check_equals(mo, "(_root.buttonChild[12].nam)", "'_level0.square1.button.instance6'"); 
	check_equals(mo, "(_root.buttonChild[12].exe)", "1");
	check_equals(mo, "(_root.buttonChild[12].uld)", "0");
	check_equals(mo, "_level0.square1.button.instance6._name", "'instance6'");
	check_equals(mo, "_level0.square1.button.instance6.getDepth()", "-16371");

	/* sprite for HIT state not constructed */
	check_equals(mo, "typeof(_root.buttonChild[11])", "'undefined'");

	/* sprite for DOWN state not constructed */
	check_equals(mo, "typeof(_root.buttonChild[13])", "'undefined'"); 

	add_actions(mo,
		"stop();"
		/*"_root.note('buttonChild is '+dumpObj(_root.buttonChild));"*/
		"_root.testno=0;"
		"_root.square1.onRollOut = function() { _root.testno++; delete _root.square1.onRollOut; nextFrame(); };"
		"_root.note('"
		"0. Roll over and out the red square, not touching the small dark-red square in it."
		"');");

	/* hitTest should work on every child, not just first added */
	check(mo, "_level0.square1.hitTest(60,60,true)");

	SWFMovie_nextFrame(mo); /* showFrame */

	/*****************************************************
	 *
	 * On third frame, start the button event test
	 *
	 *****************************************************/

	add_actions(mo,
		"stop();"
		/*"_root.note('buttonChild is '+dumpObj(_root.buttonChild));"*/
		"_root.testno=1;"
		"_root.note('"
		"1. Roll over the red square."
		"');");

	SWFMovie_nextFrame(mo); /* showFrame */

	/*****************************************************
	 *
	 * On fourth frame, add a shape at lower depth,
	 * and check bounds of square1
	 *
	 *
	 *****************************************************/

	{
		SWFShape sh = make_fill_square(0, 0, 120, 120, 0, 0, 0, 0, 255, 0);
		SWFDisplayItem itsh = SWFMovie_add(mo, (SWFBlock)sh);
		SWFDisplayItem_setDepth(itsh, 1);

		check_equals(mo, "printBounds(square1.getBounds())", "'-0.05,-0.05 40.05,40.05'");

		/* buttonChild should now have a total of 4 elements (UP,DOWN, OVER and ALL states) */
		check_equals(mo, "typeof(_root.buttonChild)", "'object'");
		check(mo, "_root.buttonChild instanceof Array");
		check_equals(mo, "_root.buttonChild.realLength()", "4"); 

		/* sprite for ALL states */
		check_equals(mo, "typeof(_root.buttonChild[10])", "'object'");
		check_equals(mo, "(_root.buttonChild[10].nam)", "'_level0.square1.button.instance5'"); 
		check_equals(mo, "(_root.buttonChild[10].exe)", "1");
		check_equals(mo, "(_root.buttonChild[10].uld)", "0");

		/* sprite for UP state */
		check_equals(mo, "typeof(_root.buttonChild[12])", "'object'");
		check_equals(mo, "(_root.buttonChild[12].nam)", "'_level0.square1.button.instance6'"); 
		check_equals(mo, "(_root.buttonChild[12].exe)", "3"); 
		check_equals(mo, "(_root.buttonChild[12].uld)", "2");

		/* sprite for OVER state */
		check_equals(mo, "typeof(_root.buttonChild[13])", "'object'");
		check_equals(mo, "(_root.buttonChild[13].nam)", "'_level0.square1.button.instance7'"); 
		check_equals(mo, "(_root.buttonChild[13].exe)", "4");
		check_equals(mo, "(_root.buttonChild[13].uld)", "4");

		/* sprite for DOWN state */
		check_equals(mo, "typeof(_root.buttonChild[14])", "'object'");
		check_equals(mo, "(_root.buttonChild[14].nam)", "'_level0.square1.button.instance8'"); 
		check_equals(mo, "(_root.buttonChild[14].exe)", "2");
		check_equals(mo, "(_root.buttonChild[14].uld)", "2");

		/* sprite for HIT state never constructed */
		check_equals(mo, "typeof(_root.buttonChild[11])", "'undefined'"); 



		add_actions(mo,
			"stop();"
			"_root.note('-- Added shape at lower depth --');"
			"_root.testno++;"
			"_root.note(_root.testno+'. Roll over the square.');"
		);

		SWFMovie_nextFrame(mo); /* showFrame */
	}

	/*****************************************************
	 *
	 * On fifth frame, add a shape at higher depth 
	 *
	 *****************************************************/

	{
		SWFShape sh = make_fill_square(0, 0, 120, 120, 0, 0, 0, 0, 255, 0);
		SWFDisplayItem itsh = SWFMovie_add(mo, (SWFBlock)sh);
		SWFDisplayItem_setDepth(itsh, 3);
		SWFDisplayItem_setColorAdd(itsh, 0, 0, 0, -128);

		/* buttonChild should now have a total of 4 elements (UP,DOWN, OVER and ALL states) */
		check_equals(mo, "typeof(_root.buttonChild)", "'object'");
		check(mo, "_root.buttonChild instanceof Array");
		check_equals(mo, "_root.buttonChild.realLength()", "4"); 

		/* sprite for ALL states */
		check_equals(mo, "typeof(_root.buttonChild[10])", "'object'");
		check_equals(mo, "(_root.buttonChild[10].nam)", "'_level0.square1.button.instance5'"); 
		check_equals(mo, "(_root.buttonChild[10].exe)", "1");
		check_equals(mo, "(_root.buttonChild[10].uld)", "0");

		/* sprite for UP state */
		check_equals(mo, "typeof(_root.buttonChild[12])", "'object'");
		check_equals(mo, "(_root.buttonChild[12].nam)", "'_level0.square1.button.instance6'"); 
		check_equals(mo, "(_root.buttonChild[12].exe)", "5"); 
		check_equals(mo, "(_root.buttonChild[12].uld)", "4");

		/* sprite for OVER state */
		check_equals(mo, "typeof(_root.buttonChild[13])", "'object'");
		check_equals(mo, "(_root.buttonChild[13].nam)", "'_level0.square1.button.instance7'"); 
		check_equals(mo, "(_root.buttonChild[13].exe)", "8");
		check_equals(mo, "(_root.buttonChild[13].uld)", "8");

		/* sprite for DOWN state */
		check_equals(mo, "typeof(_root.buttonChild[14])", "'object'");
		check_equals(mo, "(_root.buttonChild[14].nam)", "'_level0.square1.button.instance8'"); 
		check_equals(mo, "(_root.buttonChild[14].exe)", "4");
		check_equals(mo, "(_root.buttonChild[14].uld)", "4");

		/* sprite for HIT state never constructed */
		check_equals(mo, "typeof(_root.buttonChild[11])", "'undefined'"); 

		add_actions(mo,
			"stop();"
			"_root.note('-- Added shape at higher depth --');"
			"_root.testno++;"
			"_root.note(_root.testno+'. Roll over the square.');"
		);

		SWFMovie_nextFrame(mo); /* showFrame */
	}

	/*****************************************************
	 *
	 * On sixth frame, disable the button
	 * and check total tests so far
	 *
	 *****************************************************/

	{

		add_actions(mo,
            "check_equals(square1.button.enabled, true);"
			"square1.button.enabled = 6;"
            "check_equals(square1.button.enabled, 6);"
			"square1.button.enabled = 'string';"
            "check_equals(square1.button.enabled, 'string');"
            "square1.button._visible = false;"
            "check_equals(square1.button.enabled, 'string');"
            "square1.button._visible = true;"
			"square1.button.enabled = false;"
			"stop();"
			"_root.totals(160);"
			"_root.note('-- Button disabled, try playing with it, nothing should happen --');"
		);
		SWFMovie_nextFrame(mo); /* showFrame */
	}

	/*****************************************************
	 *
	 * Save it...
	 *
	 *****************************************************/

	puts("Saving " OUTPUT_FILENAME );

	SWFMovie_save(mo, OUTPUT_FILENAME);

	return 0;
}
Esempio n. 2
0
int
main(int argc, char **argv)
{
	SWFMovie mo;
	SWFDisplayItem it;
	const char *srcdir=".";
	char fdbfont[256];
	SWFMovieClip dejagnuclip;

	/*********************************************
	 *
	 * Initialization
	 *
	 *********************************************/

	puts("Setting things up");

	Ming_init();
        Ming_useSWFVersion (OUTPUT_VERSION);
	Ming_setScale(20.0); 
 
	mo = newSWFMovie();
	SWFMovie_setDimension(mo, 800, 600);
	SWFMovie_setRate(mo, 1);

	if ( argc>1 ) srcdir=argv[1];
	else
	{
		fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
		return 1;
	}

	sprintf(fdbfont, "%s/Bitstream-Vera-Sans.fdb", srcdir);
	FILE *font_file = fopen(fdbfont, "r");
	if ( font_file == NULL )
	{
		perror(fdbfont);
		exit(1);
	}
	/*SWFBrowserFont bfont = newSWFBrowserFont("_sans");*/
	font = loadSWFFontFromFile(font_file);

	/* Dejagnu equipment */
	dejagnuclip = get_dejagnu_clip((SWFBlock)font, 10, 0, 0, 800, 600);
	it = SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  	SWFDisplayItem_setDepth(it, 200); 
  	SWFDisplayItem_move(it, 200, 0); 

	add_text_field(mo, "textfield", "_root.msg", "Button events", 10, 0, 5);
	add_text_field(mo, "textfield2", "_root.msg2", "Mouse events", 11, 0, 100);
	add_text_field(mo, "textfield3", "_root.msg3", "Key events", 12, 0, 80);

	SWFMovie_nextFrame(mo);

	/*****************************************************
	 *
	 * Add button
	 *
	 *****************************************************/

	it = add_button(mo);
	SWFDisplayItem_moveTo(it, 40, 30);
	SWFDisplayItem_setName(it, "square1");
	SWFDisplayItem_setDepth(it, 2);

	// Mouse pointer events
	//add_actions(mo, "square1.button.onRollOver = function() { _root.msg2 = 'RollOver'; };");
	//add_actions(mo, "square1.button.onRollOut = function() { _root.msg2 = 'RollOut'; };");

	// Mouse buttons events
	//add_actions(mo, "square1.button.onPress = function() { _root.msg2 = 'Press'; };");
	//add_actions(mo, "square1.button.onRelease = function() { _root.msg2 = 'Release'; gotoAndStop(1); };");
	//add_actions(mo, "square1.button.onReleaseOutside = function() { _root.msg2 = 'ReleaseOutside'; };");

	// Focus events
	add_actions(mo, "square1.button.onSetFocus = function() { _root.msg3 = 'SetFocus'; };");

	// Key events - button needs focus for these to work
	add_actions(mo, "square1.button.onKeyDown = function() { _root.msg3 = 'KeyDown'; };");
	add_actions(mo, "square1.button.onKeyUp = function() { _root.msg3 = 'KeyUp'; };");


	SWFMovie_nextFrame(mo); /* showFrame */

	/*****************************************************
	 *
	 * On second frame, add a shape at lower depth 
	 *
	 *****************************************************/

	{
		SWFShape sh = make_fill_square(0, 0, 120, 120, 0, 0, 0, 0, 255, 0);
		SWFDisplayItem itsh = SWFMovie_add(mo, (SWFBlock)sh);
		SWFDisplayItem_setDepth(itsh, 1);

		SWFMovie_nextFrame(mo); /* showFrame */
	}

	/*****************************************************
	 *
	 * On third frame, add a shape at higher depth 
	 *
	 *****************************************************/

	{
		SWFShape sh = make_fill_square(0, 0, 120, 120, 0, 0, 0, 0, 255, 0);
		SWFDisplayItem itsh = SWFMovie_add(mo, (SWFBlock)sh);
		SWFDisplayItem_setDepth(itsh, 3);
		SWFDisplayItem_setColorAdd(itsh, 0, 0, 0, -128);

		SWFMovie_nextFrame(mo); /* showFrame */
	}

	/*****************************************************
	 *
	 * On third frame, add a shape at higher depth 
	 *
	 *****************************************************/

	{

		add_actions(mo,
			"square1.button.enabled = false;"
			//"_root.msg = _root.msg2 = _root.msg3 = 'Idle';"
			"stop();"
			"totals();"
		);
		SWFMovie_nextFrame(mo); /* showFrame */
	}

	/*****************************************************
	 *
	 * Save it...
	 *
	 *****************************************************/

	puts("Saving " OUTPUT_FILENAME );

	SWFMovie_save(mo, OUTPUT_FILENAME);

	return 0;
}
Esempio n. 3
0
EXPORT BOOL WINAPI i_addColor(int r, int g, int b, int a)
{
	lstrcpy(funcname, "i_addColor");
	SWFDisplayItem_setColorAdd(mhsp_item, r, g, b, a);
	return 0;
}