Esempio n. 1
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFDisplayItem it1, it2, it3;
  SWFDisplayItem it41;
  SWFDisplayItem it51;
  SWFMovieClip mc1, mc2, mc3, dejagnuclip;
  SWFMovieClip mc4, mc41;
  SWFMovieClip mc5, mc51;
  SWFShape  sh1, sh2, sh3;

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

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

  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  add_actions(mo, " haslooped1=false; haslooped2=false; haslooped3=false;"
                  " mc1Initialized=0; mc1Unloaded=0;"
                  " mc2Initialized=0; mc2Unloaded=0;"
                  " mc3Initialized=0; mc3Unloaded=0;"
                  " asOrder='0+';");
  SWFMovie_nextFrame(mo); // frame1


  sh1 = make_fill_square (100, 100, 60, 60, 255, 0, 0, 255, 0, 0);
  mc1 = newSWFMovieClip();
  SWFMovieClip_add(mc1, (SWFBlock)sh1); 
  SWFMovieClip_nextFrame(mc1);
  
  sh2 = make_fill_square (200, 200, 60, 60, 0, 0, 0, 0, 0, 0);
  mc2 = newSWFMovieClip();
  SWFMovieClip_add(mc2, (SWFBlock)sh2);  
  SWFMovieClip_nextFrame(mc2); 

  sh3 = make_fill_square (300, 300, 60, 60, 0, 0, 0, 0, 0, 0);
  mc3 = newSWFMovieClip();
  SWFMovieClip_add(mc3, (SWFBlock)sh3);  
  SWFMovieClip_nextFrame(mc3); 
 
  it1 = SWFMovie_add(mo, (SWFBlock)mc1);  
  SWFDisplayItem_setName(it1, "mc1"); 
  SWFDisplayItem_setDepth(it1, 100); 
  SWFDisplayItem_addAction(it1, newSWFAction(
        "_root.note(this+' initialized');"
        "_root.mc1Initialized++;"
        "_root.asOrder += '1+';"
        ), SWFACTION_INIT); 
  SWFDisplayItem_addAction(it1, newSWFAction(
        "_root.note(this+' unloaded');"
        "_root.mc1Unloaded++;"
        "_root.asOrder += '3+';"
        ), SWFACTION_UNLOAD);
  SWFMovie_nextFrame(mo); // frame2
  
    
  SWFDisplayItem_remove(it1);
  it2 = SWFMovie_add(mo, (SWFBlock)mc2); 
  SWFDisplayItem_setName(it2, "mc2"); 
  SWFDisplayItem_setRatio(it2, 0.1); 
  SWFDisplayItem_setDepth(it2, 100); 
  SWFDisplayItem_addAction(it2, newSWFAction(
        "_root.note(this+' initialized');"
        "_root.mc2Initialized++;"
        "_root.asOrder += '2+';"
        ), SWFACTION_INIT);
  SWFDisplayItem_addAction(it2, newSWFAction(
        "_root.note(this+' unloaded');"
        "_root.mc2Unloaded++;"
        "_root.asOrder += '5+';"
        ), SWFACTION_UNLOAD);
  SWFMovie_nextFrame(mo);  // frame3


  SWFDisplayItem_remove(it2);
  it3 = SWFMovie_add(mo, (SWFBlock)mc3); 
  SWFDisplayItem_setName(it3, "mc3"); 
  SWFDisplayItem_setRatio(it3, 0.2); 
  SWFDisplayItem_setDepth(it3, 100); 
  SWFDisplayItem_addAction(it3, newSWFAction(
        "_root.note(this+' initialized');"
        "_root.mc3Initialized++;"
        "_root.asOrder += '4+';"
        ), SWFACTION_INIT);
  SWFDisplayItem_addAction(it3, newSWFAction(
        "_root.note(this+' unloaded');"
        "_root.mc3Unloaded++;"
        ), SWFACTION_UNLOAD);
  SWFMovie_nextFrame(mo);  // frame4


  SWFMovie_nextFrame(mo);  // frame 5

  
  add_actions(mo, "if(! haslooped1) {"
                  "   gotoAndPlay(5);"
                  "   haslooped1 = true;"
                  "}" );
  SWFMovie_nextFrame(mo);  // frame 6
  
  
  check_equals(mo, "mc1Initialized", "2");
  check_equals(mo, "mc2Initialized", "2");
  check_equals(mo, "mc3Initialized", "1");
  check_equals(mo, "mc1Unloaded", "2");
  check_equals(mo, "mc2Unloaded", "2");
  check_equals(mo, "mc3Unloaded", "0");
  
  xcheck_equals(mo, "asOrder", "'0+1+2+3+4+5+1+2+3+5+'");
  SWFMovie_nextFrame(mo);  // frame 7
  
  //
  // ==case 2==
  //
  mc4 = newSWFMovieClip();
    mc41 = newSWFMovieClip(); 
    SWFMovieClip_nextFrame(mc41);
    
    it41 = SWFMovieClip_add(mc4, (SWFBlock)mc41); 
    add_clip_actions(mc4, 
        "_root.check_equals(this._target, '/instance3');"
        "inst = this.getInstanceAtDepth(-16383);"
        "if(! haslooped2) {"
        "   haslooped2 = true;"
        "   _root.check_equals(inst._target, '/instance3/instance4');"
        "} else {"
        "   _root.check_equals(inst._target, '/instance3/instance5');"
        "   stop();"
        "}"
   );
  SWFMovieClip_nextFrame(mc4);
    SWFDisplayItem_remove(it41);
  SWFMovieClip_nextFrame(mc4);  
  
  SWFMovie_add(mo, mc4);
  SWFMovie_nextFrame(mo);  // frame 9
  
  SWFMovie_nextFrame(mo);  // frame 10
  
  //
  // ==case 3==
  //
  mc5 = newSWFMovieClip();
    mc51 = newSWFMovieClip(); 
    SWFMovieClip_nextFrame(mc51);
    
    it51 = SWFMovieClip_add(mc5, (SWFBlock)mc51); 
    add_clip_actions(mc5, 
        "_root.check_equals(this._target, '/instance6');"
        "inst = this.getInstanceAtDepth(-16383);"
        "if(! haslooped3) {"
        "   haslooped3 = true;"
        "   _root.check_equals(inst._target, '/instance6/instance7');"
        "} else {"
        "   _root.check_equals(inst._target, '/instance6/instance7');"
        "   stop();"
        "}"
   );
  SWFMovieClip_nextFrame(mc5);
  SWFMovieClip_nextFrame(mc5); 
  
  SWFMovie_add(mo, mc5);
  SWFMovie_nextFrame(mo);  // frame 11
  
  SWFMovie_nextFrame(mo);  // frame 12
  
  SWFMovie_nextFrame(mo);  // frame 13
  
  mc5 = newSWFMovieClip();
  add_clip_actions(mc5, "_root.check_equals(this._target, '/instance9');");
  SWFMovieClip_nextFrame(mc5);
  
  SWFMovie_add(mo, mc5);
  SWFMovie_nextFrame(mo);  // frame 14
  
  add_actions(mo, "totals(16); stop();");
  SWFMovie_nextFrame(mo);  // frame 15
  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

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

  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);

  puts("Setting things up");

  Ming_init();
  Ming_useSWFVersion (OUTPUT_VERSION);
  //Ming_setScale(20.0); /* so we talk twips */
 
  mo = newSWFMovie();
  SWFMovie_setRate(mo, 1.0);
  SWFMovie_setDimension(mo, 800, 600);
  
  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  SWFMovie_nextFrame(mo); // 1st frame 

  // Check that the dejagnu clip is really a TextField.
  check_equals(mo, "_root.getInstanceAtDepth(-16383)",
          "_level0.instance1");
  check(mo, "_level0.instance1._xtrace_win "
          "instanceof TextField");

  // Note: the dejagnuclip already placed some texts, so the following
  // should be true.
  check(mo, "TextField.prototype.hasOwnProperty('background')");
  check(mo, "TextField.prototype.hasOwnProperty('backgroundColor')");
  check(mo, "TextField.prototype.hasOwnProperty('text')");
  check(mo, "TextField.prototype.hasOwnProperty('textColor')");

  /*********************************************
   *
   * Add some textfields
   *
   *********************************************/
  {
    SWFDisplayItem it;
    FILE *font_file = fopen(fdbfont, "r");
    if ( font_file == NULL )
    {
      perror(fdbfont);
      exit(1);
    }
    SWFBrowserFont bfont = newSWFBrowserFont("_sans");
    SWFFont efont = loadSWFFontFromFile(font_file);

    it = add_text_field(mo, (SWFBlock)bfont, "Hello", 1, 2, 3, SWFTEXTFIELD_ALIGN_LEFT, 10, 100, 101, 102, 50);
    SWFDisplayItem_setName(it, "dtext1");
    SWFDisplayItem_moveTo(it, 0, 200);
    it = add_text_field(mo, (SWFBlock)efont, "Hello", 4, 5, 6, SWFTEXTFIELD_ALIGN_CENTER, 11, 110, 111, 112, 51);
    SWFDisplayItem_setName(it, "etext1");
    SWFDisplayItem_moveTo(it, 0, 300);

    SWFBrowserFont bfont2 = newSWFBrowserFont("times");
    it = add_text_field(mo, (SWFBlock)bfont2, "Hello", 7, 8, 9, SWFTEXTFIELD_ALIGN_RIGHT, 12, 120, 121, 122, 52);
    SWFDisplayItem_setName(it, "dtext2");
    SWFDisplayItem_moveTo(it, 0, 400);
  }
  SWFMovie_nextFrame(mo); 

  check_equals(mo, "dtext1.embedFonts", "false");
  check_equals(mo, "etext1.embedFonts", "true");
  check_equals(mo, "etext1.hasOwnProperty('embedFonts')", "false");

  add_actions(mo, "ret = Selection.setFocus(dtext1);"
                  "check_equals(ret, false);"
                  "check_equals(Selection.getFocus(), '_level0.dtext1');");
  add_actions(mo, "ret = Selection.setFocus(etext1);"
                  "check_equals(ret, false);"
                  "check_equals(Selection.getFocus(), '_level0.etext1');");

  add_actions(mo, "createTextField('dynamictext1', 99, 10, 10, 10, 10);");

  add_actions(mo, "ret = Selection.setFocus(dynamictext1);"
               "check_equals(ret, false);"
               "check_equals(Selection.getFocus(), '_level0.dynamictext1');");

  check_equals(mo, "dtext1.__proto__", "TextField.prototype");
  check_equals(mo, "etext1.__proto__", "TextField.prototype");
  check_equals(mo, "etext1.__proto__", "dynamictext1.__proto__");

  // checks after placing some swf defined TextField
  check(mo, "TextField.prototype.hasOwnProperty('background')");
  check(mo, "TextField.prototype.hasOwnProperty('backgroundColor')");
  check(mo, "TextField.prototype.hasOwnProperty('text')");
  check(mo, "TextField.prototype.hasOwnProperty('textColor')");
  check(mo, "!TextField.prototype.hasOwnProperty('_parent')");
  check(mo, "!TextField.prototype.hasOwnProperty('_xmouse')");
  check(mo, "!TextField.prototype.hasOwnProperty('_ymouse')");
  check(mo, "!TextField.prototype.hasOwnProperty('_xscale')");
  check(mo, "!TextField.prototype.hasOwnProperty('_yscale')");
  
  check_equals(mo, "typeof(dtext1)", "'object'");
  check_equals(mo, "typeof(dtext1.text)", "'string'");
  check_equals(mo, "typeof(dtext1.background)", "'boolean'");
  check_equals(mo, "typeof(dtext1.backgroundColor)", "'number'");
  check_equals(mo, "typeof(dtext1.textColor)", "'number'");
  check_equals(mo, "typeof(dtext1._alpha)", "'number'");
  check_equals(mo, "typeof(dtext1.type)", "'string'");
  check_equals(mo, "dtext1.type", "'input'");
  
  check_equals(mo, "typeof(dtext1.__proto__.text)", "'undefined'");
  check_equals(mo, "typeof(dtext1.__proto__.background)", "'undefined'");
  check_equals(mo, "typeof(dtext1.__proto__.backgroundColor)", "'undefined'");
  check_equals(mo, "typeof(dtext1.__proto__.textColor)", "'undefined'");
  check_equals(mo, "typeof(dtext1.__proto__._alpha)", "'undefined'");

  check_equals(mo, "dtext1.hasOwnProperty('text')", "false");
  check_equals(mo, "dtext1.hasOwnProperty('background')", "false");
  check_equals(mo, "dtext1.hasOwnProperty('backgroundColor')", "false");
  check_equals(mo, "dtext1.hasOwnProperty('textColor')", "false");
  check_equals(mo, "dtext1.hasOwnProperty('_alpha')", "false");
  check(mo, "!dtext1.hasOwnProperty('_parent')");
  check(mo, "!dtext1.hasOwnProperty('_xmouse')");
  check(mo, "!dtext1.hasOwnProperty('_ymouse')");
  check(mo, "!dtext1.hasOwnProperty('_xscale')");
  check(mo, "!dtext1.hasOwnProperty('_yscale')");
  check(mo, "!etext1.hasOwnProperty('_parent')");
  check(mo, "!etext1.hasOwnProperty('_xmouse')");
  check(mo, "!etext1.hasOwnProperty('_ymouse')");
  check(mo, "!etext1.hasOwnProperty('_xscale')");
  check(mo, "!etext1.hasOwnProperty('_yscale')");
  
  check(mo, "dtext1.__proto__.hasOwnProperty('text')");
  check_equals(mo, "dtext1.__proto__.hasOwnProperty('background')", "true");
  check_equals(mo, "dtext1.__proto__.hasOwnProperty('backgroundColor')", "true");
  check_equals(mo, "dtext1.__proto__.hasOwnProperty('textColor')", "true");
  // Why _alpha is special???
  check_equals(mo, "dtext1.__proto__.hasOwnProperty('_alpha')", "false");
  
  check_equals(mo, "dtext1.text", "'Hello'");
  check_equals(mo, "etext1.text", "'Hello'");
  check_equals(mo, "dtext2.text", "'Hello'");
  check_equals(mo, "dtext1.background", "false");
  check_equals(mo, "etext1.background", "false");
  check_equals(mo, "dtext2.background", "false");
  check_equals(mo, "dtext1.backgroundColor", "0xffffff");
  check_equals(mo, "etext1.backgroundColor", "0xffffff");
  check_equals(mo, "dtext2.backgroundColor", "0xffffff");
  check_equals(mo, "dtext1.textColor", "6579558");
  check_equals(mo, "etext1.textColor", "7237488");
  check_equals(mo, "dtext2.textColor", "7895418");
  check_equals(mo, "dtext1._alpha", "100");
  check_equals(mo, "etext1._alpha", "100");
  check_equals(mo, "dtext2._alpha", "100");
  check_equals(mo, "etext1._parent", "_root");
  check_equals(mo, "dtext2._parent", "_root");
  check_equals(mo, "etext1._xscale", "100");
  check_equals(mo, "dtext2._xscale", "100");
  check_equals(mo, "etext1._yscale", "100");
  check_equals(mo, "dtext2._yscale", "100");
  check_equals(mo, "typeof(etext1._xmouse)", "'number'");
  check_equals(mo, "typeof(dtext2._xmouse)", "'number'");
  check_equals(mo, "typeof(etext1._ymouse)", "'number'"); 
  check_equals(mo, "typeof(dtext2._ymouse)", "'number'"); 

  // TextFormat objects are created on the fly
  add_actions(mo,
	"etext1.tf = etext1.getTextFormat();"
	"dtext2.tf = dtext2.getTextFormat();"
	);
  check_equals(mo, "typeof(etext1.tf)", "'object'"); 
  check_equals(mo, "typeof(dtext2.tf)", "'object'"); 
  check_equals(mo, "etext1.tf.size", "12"); 
  check_equals(mo, "dtext2.tf.size", "12"); 
  check_equals(mo, "etext1.tf.font", "'Bitstream Vera Sans'");
  check_equals(mo, "dtext2.tf.font", "'times'"); 
  check_equals(mo, "typeof(etext1.tf.bold)", "'boolean'");
  check_equals(mo, "typeof(dtext2.tf.bold)", "'boolean'");
  check_equals(mo, "etext1.tf.bold", "false");
  check_equals(mo, "dtext2.tf.bold", "false"); 
  check_equals(mo, "typeof(etext1.tf.italic)", "'boolean'");
  check_equals(mo, "typeof(dtext2.tf.italic)", "'boolean'");
  check_equals(mo, "etext1.tf.italic", "false");
  check_equals(mo, "dtext2.tf.italic", "false"); 
  check_equals(mo, "typeof(etext1.tf.indent)", "'number'");
  check_equals(mo, "typeof(dtext2.tf.indent)", "'number'");
  check_equals(mo, "etext1.tf.indent", "4");
  check_equals(mo, "dtext2.tf.indent", "7"); 
  check_equals(mo, "typeof(etext1.tf.leftMargin)", "'number'");
  check_equals(mo, "typeof(dtext2.tf.leftMargin)", "'number'");
  check_equals(mo, "etext1.tf.leftMargin", "5");
  check_equals(mo, "dtext2.tf.leftMargin", "8"); 
  check_equals(mo, "typeof(etext1.tf.rightMargin)", "'number'");
  check_equals(mo, "typeof(dtext2.tf.rightMargin)", "'number'");
  check_equals(mo, "etext1.tf.rightMargin", "6");
  check_equals(mo, "dtext2.tf.rightMargin", "9"); 
  check_equals(mo, "typeof(etext1.tf.align)", "'string'");
  check_equals(mo, "typeof(dtext2.tf.align)", "'string'");
  check_equals(mo, "etext1.tf.align", "'center'");
  check_equals(mo, "dtext2.tf.align", "'right'"); 
  check_equals(mo, "typeof(etext1.tf.leading)", "'number'");
  check_equals(mo, "typeof(dtext2.tf.leading)", "'number'");
  check_equals(mo, "etext1.tf.leading", "11");
  check_equals(mo, "dtext2.tf.leading", "12"); 
  check_equals(mo, "typeof(etext1.tf.color)", "'number'");
  check_equals(mo, "typeof(dtext2.tf.color)", "'number'");
  check_equals(mo, "etext1.tf.color", "7237488");
  check_equals(mo, "dtext2.tf.color", "7895418");
  check_equals(mo, "typeof(etext1.tf.blockIndent)", "'number'");
  check_equals(mo, "typeof(dtext2.tf.blockIndent)", "'number'");
  check_equals(mo, "etext1.tf.blockIndent", "0");
  check_equals(mo, "dtext2.tf.blockIndent", "0");
  check_equals(mo, "typeof(etext1.tf.underline)", "'boolean'");
  check_equals(mo, "typeof(dtext2.tf.underline)", "'boolean'");
  check_equals(mo, "etext1.tf.underline", "false");
  check_equals(mo, "dtext2.tf.underline", "false");

  add_actions(mo, "dtext1.background = true;"
                  "etext1.background = true;"
                  "dtext2.background = true;"
                  "dtext1.backgroundColor = 0xff0000;"
                  "etext1.backgroundColor = 0x00ff00;"
                  "dtext2.backgroundColor = 0x0000ff;"
                  "dtext1.textColor = 0x00ffff;"
                  "etext1.textColor = 0xff00ff;"
                  "dtext2.textColor = 0xffff00;"
                  "dtext1.text += ' world';"
                  "etext1.text += ' world';"
                  "dtext2.text += ' world';" );

  check_equals(mo, "etext1.getTextFormat().color", "0xff00ff");
  check_equals(mo, "dtext2.getTextFormat().color", "0xffff00"); 

  check_equals(mo, "dtext1.text", "'Hello world'");
  check_equals(mo, "etext1.text", "'Hello world'");
  check_equals(mo, "dtext2.text", "'Hello world'");
  check_equals(mo, "dtext1.background", "true");
  check_equals(mo, "etext1.background", "true");
  check_equals(mo, "dtext2.background", "true");
  check_equals(mo, "dtext1.backgroundColor", "0xff0000");
  check_equals(mo, "etext1.backgroundColor", "0x00ff00");
  check_equals(mo, "dtext2.backgroundColor", "0x0000ff");
  check_equals(mo, "dtext1.textColor", "0x00ffff");
  check_equals(mo, "etext1.textColor", "0xff00ff");
  check_equals(mo, "dtext2.textColor", "0xffff00");
  SWFMovie_nextFrame(mo); 
  
  add_actions(mo, "dtext1._alpha = 0;"
                  "etext1._alpha = 0;"
                  "dtext2._alpha = 0;" );
  check_equals(mo, "dtext1._alpha", "0");
  check_equals(mo, "etext1._alpha", "0");
  check_equals(mo, "dtext2._alpha", "0");
  SWFMovie_nextFrame(mo); 

  add_actions(mo, "dtext1._alpha = 100; dtext1.embedFonts=true; dtext1.text = 'embedFonts';"
                  "etext1._alpha = 100; etext1.embedFonts=false; etext1.text = '!embedFonts';"
                  "dtext2._alpha = 100;" );

  check_equals(mo, "dtext1.embedFonts", "true");
  check_equals(mo, "etext1.embedFonts", "false");

  add_actions(mo, "totals(); stop();");
  SWFMovie_nextFrame(mo); 

  /*****************************************************
   *
   * Output movie
   *
   *****************************************************/
  puts("Saving " OUTPUT_FILENAME );

  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Esempio n. 3
0
int
main(int argc, char** argv)
{
	SWFMovie mo;
	SWFMovieClip dejagnuclip;
	SWFDisplayItem it1;


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

	Ming_init();
	mo = newSWFMovieWithVersion(OUTPUT_VERSION);
	SWFMovie_setDimension(mo, 800, 600);
	SWFMovie_setRate (mo, 2);

	dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
	SWFMovie_add(mo, (SWFBlock)dejagnuclip);
	SWFMovie_nextFrame(mo); 

	// Frame 2: Add a static movieclip at depth 3 with origin at 10,200
	it1 = add_static_mc(mo, "static3", 3, 10, 200, 20, 20);
	add_actions(mo,
		"static3.myThing = 'guess';"
		"check_equals(static3._x, 10);"
		"check_equals(static3.myThing, 'guess');"
		"check_equals(static3.getDepth(), -16381);" 
		);
	SWFMovie_nextFrame(mo); 

	// Frame 3: nothing new
	SWFMovie_nextFrame(mo); 

	// Frame 4: move DisplayObject at depth 3 to position 50,200
	SWFDisplayItem_moveTo(it1, 50, 200); 
	add_actions(mo,
		"check_equals(static3._x, 50);"
		"check_equals(static3.getDepth(), -16381);" 
		);
	SWFMovie_nextFrame(mo); 

	// Frame 5: nothing new
	SWFMovie_nextFrame(mo); 

	// Frame 6: nothing new
	SWFMovie_nextFrame(mo); 

	// Frame 7: go to frame 2
	add_actions(mo,

		"check_equals(static3.myThing, 'guess');"
		"check_equals(static3._x, 50);"

		// Store a reference to the static3 instance
		// before jumping back
		"dynRef = static3;"

		// this reset char at depth -16381 to be at position 10,200
		"gotoAndStop(2);"

		// Static3 refers to same instance
		"check_equals(static3.myThing, 'guess');" 
		"check_equals(static3.getDepth(), -16381);" 

		// But it has now be reset to position 10,100 as specified
		// by PlaceObject2 tag in frame 2.
		// Note that the PlaceObject2 in frame 2 has the "move" flag
		// set to off as it's really intended to be used to *create*
		// an instance. Instead, since that depth is already occupied,
		// it behave as if it was a transforming PlaceObject2
		"check_equals(static3._x, 10);" 

		// The reference still refers to the same instance
		//  (see http://www.gnashdev.org/wiki/index.php/SoftReferences)
		"check_equals(dynRef.myThing, 'guess');" 
		"check_equals(dynRef.getDepth(), -16381);" 
		"check_equals(typeof(dynRef), 'movieclip');"
		"check_equals(dynRef._x, 10);"
		"check_equals(dynRef, static3);"

		// A single instance is created in total
		"check_equals(depth3Constructed, 1);"  

		"totals();"
		);
	SWFMovie_nextFrame(mo); 

	//Output movie
	puts("Saving " OUTPUT_FILENAME );
	SWFMovie_save(mo, OUTPUT_FILENAME);

	return 0;
}
Esempio n. 4
0
int
main(int argc, char** argv)
{
  
  SWFMovie mo;
  SWFMovieClip dejagnuclip;
  SWFMovieClip mc1, mc11;
  SWFDisplayItem it1, it11;


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

  Ming_init();
  mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  SWFMovie_setDimension(mo, 800, 600);
  SWFMovie_setRate (mo, 12.0);

  // _root.frame1
  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  add_actions(mo, " x1=0; x2=0; x3=0; x4=0; x5=0; x6=0; x7=0; x8=0; x9=0; x10=0; ");
  SWFMovie_nextFrame(mo); 

  //
  // _root.frame2: define movieclips and some functions.
  //
  // Define mc11
  mc11 = newSWFMovieClip();
  add_clip_actions(mc11, " func1 =  function () { _root.x1=1;  _root.x2=this; }; "
                          "stop();");
  SWFMovieClip_nextFrame(mc11); 
  add_clip_actions(mc11, "_root.x3 = 1; stop();");
  SWFMovieClip_nextFrame(mc11); 
  add_clip_actions(mc11, "_root.x4 = 1; stop();");
  SWFMovieClip_nextFrame(mc11); 
  
  // Define mc1, add mc11 to mc1   
  mc1 = newSWFMovieClip();
  it11 = SWFMovieClip_add(mc1, (SWFBlock)mc11);  
  SWFDisplayItem_setDepth(it11, 3); 
  SWFDisplayItem_setName(it11, "mc11"); 
  add_clip_actions(mc1, " func2 =  function () { _root.x5=1;  _root.x6=this; }; "
                        "stop();");
  SWFMovieClip_nextFrame(mc1); 
  add_clip_actions(mc1, "_root.x7 = 1; stop();");
  SWFMovieClip_nextFrame(mc1); 
  add_clip_actions(mc1, "_root.x8 = 1; stop();");
  SWFMovieClip_nextFrame(mc1);
  
  // place mc1 
  it1 = SWFMovie_add(mo, (SWFBlock)mc1); 
  SWFDisplayItem_setDepth(it1, 4); 
  SWFDisplayItem_setName(it1, "mc1"); 
  SWFMovie_nextFrame(mo); 
  
  //
  // _root.frame3: invoke function calls
  //
  add_actions(mo,  "asm{"
                   "push 0 "
                   "push  '_root.mc1.mc11.func1' " // valid format
                   "callfunction " 
                   "};");
  add_actions(mo,  "asm{"
                   "push 2 "
                   "push 1 "
                   "push  '_root.mc1.mc11.gotoAndStop' " // valid format
                   "callfunction " 
                   "};");
  add_actions(mo,  "asm{"
                   "push 0 "
                   "push  '_root.mc1:func2' " // valid format
                   "callfunction " 
                   "};");
  add_actions(mo,  "asm{"
                   "push 2 "
                   "push 1 "
                   "push  '/mc1/:gotoAndStop' " // valid format
                   "callfunction " 
                   "};");
  add_actions(mo,  "asm{"
                   "push 3 "
                   "push 1 "
                   "push  '/_root/mc1/mc11/gotoAndStop' " // *invalid* format
                   "callfunction " 
                   "};");
 add_actions(mo,  "asm{"
                   "push 3 "
                   "push 1 "
                   "push  '_root:mc1:gotoAndStop' " // valid format
                   "callfunction " 
                   "};");
  SWFMovie_nextFrame(mo); 
  
  //
  // _root.frame4: check if the function call succeeded
  //
  check_equals(mo, "_root.x1", "1");
  check_equals(mo, "_root.x2", "_root.mc1.mc11");
  check_equals(mo, "_root.x3", "1");
  check_equals(mo, "_root.x4", "0");
  check_equals(mo, "_root.x5", "1");
  check_equals(mo, "_root.x6", "_root.mc1");
  check_equals(mo, "_root.x7", "1");
  check_equals(mo, "_root.x8", "1");
  
  add_actions(mo, " _root.totals(); stop(); ");
  SWFMovie_nextFrame(mo); 
  
  
  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Esempio n. 5
0
int
main(int argc, char** argv)
{
	SWFMovie mo;
	const char *srcdir=".";
	SWFMovieClip dejagnuclip;


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

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

	puts("Setting things up");

	Ming_init();
        Ming_useSWFVersion (OUTPUT_VERSION);
	Ming_setScale(20.0); /* let's talk pixels */
 
	mo = newSWFMovie();
	SWFMovie_setRate(mo, 12);
	//SWFMovie_setDimension(mo, 6400, 4000);
	SWFMovie_setDimension(mo, 640, 400);

	/*********************************************
	 *
	 * Body
	 *
	 *********************************************/

	dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 80, 800, 600);
	SWFMovie_add(mo, (SWFBlock)dejagnuclip);

	addRedSquareExport(mo);
	/* it seems we need a SHOWFRAME for this to be effective */
	/* (maybe it's related to loop-back handling ?) */
	SWFMovie_nextFrame(mo); 

    // This should run for four frames. The counter should only be reset
    // on the first frame, i.e. when start is undefined. This should
    // work for all swf versions, unlike "if (undefined < 4);"

	add_actions(mo, "initObj = new Object();");
	add_actions(mo, "if (!started) { counter = 0; started = true; }");
	add_actions(mo, "redsquare = function() { "
            "           trace('hello redsquare'); "
            "           if (counter > 0) {"
            "               check_equals(this._x, counter * 70);"
            "               check_equals(Math.round(this._xscale), 99);"
            "               check_equals(Math.round(this._yscale), "
            "                       Math.round((10 * counter +5) / 60 * 100));"
            "		        check_equals(this._height, 10 * counter + 5); "
            "		        check_equals(this.aProperty, 6); "
            "           } else {"
            "               check_equals(this._x, 0);"
            "               check_equals(this._xscale, 100);"
            "               check_equals(this._height, 60.1);"
            "		        check_equals(this.aProperty, undefined); "
            "           };"
            "       };"
            "redsquare.prototype = new MovieClip();"
            "Object.registerClass('redsquare', redsquare);"
            );

	add_actions(mo,
		"if ( counter < 4 ) {"
		"	if ( counter > 0 ) { "
		"		initObj.aProperty = 6;"
		"		initObj._xscale = 99;"
		"		initObj._x = 70*counter;"
		"		initObj._height = 10*counter + 5; "
		"		attachMovie('redsquare', "
		"			'square'+counter, 70+counter, initObj);"
		"	} else {"
		/* We don't use an initObject for the first attachMovie call
		 * to verify that the DisplayObject will be kept in DisplayList
		 * at loopback time anyway
		 */
		"		attachMovie('redsquare', "
		"			'square'+counter, 70+counter);"
		"	}"
		" 	check_equals(this['square'+counter]._x, 70*counter);"
        "   if (counter > 0) {"
		" 	    check_equals(this['square'+counter]._height, 10 * counter + 5);"
		"   };"
        "	note('Depth is '+70*counter);"
		"	counter++;"
		"	note('Next counter is '+counter);"
		"} else {"
		"	totals(26); stop();"
		"}"
		);

	SWFMovie_nextFrame(mo); /* showFrame */


	/*****************************************************
	 *
	 * Output movie
	 *
	 *****************************************************/

	puts("Saving " OUTPUT_FILENAME );

	SWFMovie_save(mo, OUTPUT_FILENAME);

	return 0;
}
Esempio n. 6
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip dejagnuclip;
  SWFShape static1, static2;
  SWFDisplayItem it1;


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

  Ming_init();
  mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  SWFMovie_setDimension(mo, 800, 600);
  SWFMovie_setRate (mo, 2);

  static1 = get_shape(60, 60, 255, 0, 0);
  static2 = get_shape(60, 60, 0, 255, 0);

  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  SWFMovie_nextFrame(mo); 

  // Frame 2: place DisplayObject at depth 3 (-16381)
  it1 = SWFMovie_add(mo, (SWFBlock)static1);
  SWFDisplayItem_setDepth(it1, 3);
  SWFDisplayItem_moveTo(it1, 100, 300);
  SWFDisplayItem_setName(it1, "static1");
  SWFDisplayItem_addAction(it1, newSWFAction(
			"_root.note(this+' onClipConstruct');"
			" _root.check_equals(typeof(_root), 'movieclip');"
		        " if ( isNaN(_root.depth3Constructed) ) {"
			"	_root.depth3Constructed=1; "
			" } else {"
			"	_root.depth3Constructed++;"
			" }"
			" _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
			), SWFACTION_CONSTRUCT);
  add_actions(mo, "static1.name='static1';"); 

  check_equals(mo, "typeof(static1)", "'movieclip'"); 
  check_equals(mo, "static1", "_root");
  check_equals(mo, "static1.name", "'static1'");
  check_equals(mo, "_root.name", "'static1'");

  // Gnash allows custom members to shape DisplayObjects...
  // this is important to verify, see next check for it after REPLACE
  check_equals(mo, "static1.name", "'static1'");

  check_equals(mo, "static1._target", "'/'");
  SWFMovie_nextFrame(mo); 

  // Frame 3: replace instance at depth -16381 with DisplayObject 2
  if ( SWFMovie_replace(mo, it1, (SWFBlock)static2) )
  {
	  abort(); // grace and beauty...
  }
  SWFDisplayItem_moveTo(it1, 130, 330);
  SWFDisplayItem_setName(it1, "static2");
  SWFDisplayItem_addAction(it1, newSWFAction(
			"_root.note(this+' onClipConstruct');"
			" _root.check_equals(typeof(_root), 'movieclip');"
		        " if ( isNaN(_root.depth3Constructed) ) {"
			"	_root.depth3Constructed=1; "
			" } else {"
			"	_root.depth3Constructed++;"
			" }"
			" _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
			), SWFACTION_CONSTRUCT);


  // Can still reference the old DisplayObject and it's variables, after replace
  xcheck_equals(mo, "typeof(static1)", "'movieclip'"); 
  xcheck_equals(mo, "static1", "_root");
  xcheck_equals(mo, "static1.name", "'static1'");
  check_equals(mo, "_root.name", "'static1'");

  // While the new name results undefined...
  xcheck_equals(mo, "typeof(static2)", "'undefined'"); // the name wasn't changed

  // Everything suggests that a new instance is NOT created on replace !!!
  // Gnash here fails because it creates a NEW instance

  // We can't check the color or the _x in a self-contained testcase unfortunately,
  // we'll need a MovieTester-based runner for this.
  // It is expected the color of the current instane is GREEN, and the boundaries
  // are from 130 to 190 for X and 330 to 390 for Y.
  // TODO: implement a MovieTester based runner !!

  SWFMovie_nextFrame(mo); 
 
  // Frame 4: jump to frame 2, stop and check

  add_actions(mo,

    "gotoAndStop(2); " 

    // Shapes don't get their onConstruct event invoked !
    "check_equals(typeof(_root.depth3Constructed), 'undefined');"

    // Original DisplayObject name is still referenceable
    "check_equals(typeof(static1), 'movieclip');"

    // And it still has it's user-provided property
    "check_equals(static1.name, 'static1');"

    // We can't check the color or the _x in a self-contained testcase unfortunately,
    // we'll need a MovieTester-based runner for this.
    // It is expected the color of the current instance is RED, and the boundaries
    // are from 100 to 120 for both X and Y.
    // TODO: implement a MovieTester based runner !!

    "totals();"
    );
  SWFMovie_nextFrame(mo); 

  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Esempio n. 7
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip mc;
  SWFMovieClip dejagnuclip, staticSquare;
  SWFShape shape;
  SWFDisplayItem it;

  if ( argc>1 ) mediadir=argv[1];
  else
  {
    fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
    return 1;
  }
	
  Ming_init();
  Ming_useSWFVersion (OUTPUT_VERSION);
	
  mo = newSWFMovie();
  SWFMovie_setDimension(mo, 800, 600);

  if (mo == NULL) return -1;

  addRedSquareExport(mo);

  add_actions(mo, "_root.onKeyDown = _root.onMouseUp = function() {"
	                "play(); }; "
                    "Key.addListener(_root);");

  SWFMovie_setRate(mo, 12);
    dejagnuclip = get_dejagnu_clip(
            (SWFBlock)get_default_font(mediadir), 10, 10, 150, 800, 600);
    SWFMovie_add(mo, (SWFBlock)dejagnuclip);
 
  SWFMovie_nextFrame(mo);

  add_actions(mo, "BitmapData = flash.display.BitmapData;"
		  "Rectangle = flash.geom.Rectangle;"
		  "bmp = new BitmapData(150, 150, false);"
		  "rect = new Rectangle(10, 10, 100, 100);"
		  "bmp.fillRect(rect, 0x00ff00);"
		  "mc = _root.createEmptyMovieClip('mc', getNextHighestDepth());"
          "d = mc.getNextHighestDepth();"
          "mc.attachBitmap(bmp, d);"
          "bmp2 = new BitmapData(20, 20, true);"
          "rect2 = new Rectangle (10, 10, 20, 20);"
          "bmp2.fillRect(rect2, 0xffffff00);"
          "d2 = mc.getNextHighestDepth();"
          "mc.attachBitmap(bmp2, d2);"
          "note('1. You should see a small yellow square in the top left "
                "corner of a larger green square. Click to proceed.');"
          "stop();"
          );

    SWFMovie_nextFrame(mo);

    add_actions(mo, "rect = new Rectangle (90, 90, 120, 120);"
		    "bmp.fillRect(rect, 0x0000FF);"
            "note('2. You should see a new blue square covering the "
                "bottom right corner of the large green square. Click"
                " to proceed.');"
            "stop();"
            );

    SWFMovie_nextFrame(mo);

    add_actions(mo, "mc.createEmptyMovieClip('d', d);"
            "note('3. You should see just the small yellow square in the top "
                "left corner. Click to proceed.');");

    add_actions(mo, "stop();");

    SWFMovie_nextFrame(mo);
    
    // Place a dynamic DisplayObject at depth 4
    add_actions(mo, "mc.removeMovieClip();"
            "_root.attachMovie('redsquare', 'rs', 4);");

    // Place a static DisplayObject at depth 3
    staticSquare = newSWFMovieClip();
    shape = make_fill_square (300, 0, 60, 60, 255, 0, 255, 255, 0, 255);
    SWFMovieClip_add(staticSquare, (SWFBlock)shape);  
    SWFMovieClip_nextFrame(staticSquare);
    
    it = SWFMovie_add(mo, (SWFBlock)staticSquare);  
    SWFDisplayItem_setDepth(it, 3); 
    SWFDisplayItem_setName(it, "staticSquare");

    add_actions(mo, 
            "note('4. You should see a red square in the top left and a "
            "purple square in the top right. Click to proceed.');");
    add_actions(mo, "stop();");

    SWFMovie_nextFrame(mo);

    add_actions(mo, "staticSquare.swapDepths(20);"
            "note('5. There should have been no change. Click to proceed.');"
            "stop();"
            );

    SWFMovie_nextFrame(mo);

    add_actions(mo, "_root.attachBitmap(bmp, 2);"
            "note('6. You should see the green and blue squares "
            "under the red square. The purple square should still be there. "
            "Click to proceed.');"
            "stop();"
            );

    SWFMovie_nextFrame(mo);

    add_actions(mo, "_root.attachBitmap(bmp, 3);"
            "note('7. There should have been no change. Click to proceed.');"
            "stop();"
            );

    SWFMovie_nextFrame(mo);

    SWFDisplayItem_remove(it);
    
    add_actions(mo, "_root.attachBitmap(bmp2, 20);"
            "note('8. The purple square should have gone. The small yellow "
            "square should have replaced the top left corner of the red "
            "square. The green and blue squares should still be there. "
            "Click to proceed.');"
            "stop();"
            );

    SWFMovie_nextFrame(mo);    

    add_actions(mo, "bmp.dispose(); bmp2.dispose();"
            "note('9. You should see just the red square. Click to proceed.');"
            "stop();"
            );

    SWFMovie_nextFrame(mo);    

    add_actions(mo, "bmp = new BitmapData(100, 100, false, 0x0000ff);"
            "note('10. There should have been no change. Click to proceed.');"
            "stop();"
            );

    SWFMovie_nextFrame(mo);    
    
    add_actions(mo, "bmp3 = new BitmapData(100, 100, false);"
            "rect3 = new Rectangle(20, 20, 90, 90);"
            "bmp3.fillRect(rect3, 0x0000ff);"
            "ch = _root.createEmptyMovieClip('original', 40);"
            "original.attachBitmap(bmp3, getNextHighestDepth());"
            "ch._name = 'duplicate';"
            "newch = _root.createEmptyMovieClip('original', "
                    "getNextHighestDepth());"
            "note('11. You should see a large blue square only. "
            "Click to proceed.');"
            "stop();"
            );

    SWFMovie_nextFrame(mo);    
    
    add_actions(mo, 
            "original.removeMovieClip();"
            "note('12. There should have been no change. Click to proceed.');"
            "stop();"
            );

    SWFMovie_nextFrame(mo);    
    
    add_actions(mo, 
            "duplicate.removeMovieClip();"
            "note('13. You should see the red square again. Click to "
            "proceed.');"
            "stop();"
            );

    SWFMovie_nextFrame(mo);

    add_actions(mo,
            "_root.createEmptyMovieClip('mcLeft', getNextHighestDepth());"
            "mcLeft.duplicateMovieClip('mcMiddle', getNextHighestDepth(),"
                        " { _x: 300, _y: 0 } );"
            "mcLeft.attachBitmap(bmp3, getNextHighestDepth());"
            "mcMiddle.attachBitmap(bmp3, getNextHighestDepth());"
            "mcMiddle.duplicateMovieClip('mcRight', getNextHighestDepth(),"
                        " { _x: 600, _y: 0 } );"
            "note('14. You should see two blue squares. Click to proceed.');"
            "stop();"
            );

    SWFMovie_nextFrame(mo);

    add_actions(mo,
            "bmp3.noise(293);"
            "note('15. You should see two noise patterns where the two "
            "squares were. Click to proceed.');"
            "stop();"
            );

    add_actions(mo, "_root.onKeyDown = _root.onMouseUp = undefined;"
            "_root.eof = true;" // hook for test runner...
            "note(' - END OF TEST - thanks for flying with us ! ');"
            //"totals(6);" // no AS based tests...
            );

    SWFMovie_nextFrame(mo);

  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Esempio n. 8
0
int main(void)
{
        // Create local variables
        int i;
        SWFDisplayItem image_display_item;
        SWFFont font_object;
        SWFMovie test_movie;
        SWFText text_object;


        // Initialise the movie structure in memory
        Ming_init();
        test_movie = newSWFMovieWithVersion(7);

        // Set the desired compression level 
		// for the output (9 = maximum compression)
        Ming_setSWFCompression(9);

        // Set the background color for the movie
        SWFMovie_setBackground(test_movie, 0x00, 0x00, 0x00);

        // Adjust the dimensions of the movie
        SWFMovie_setDimension(test_movie, 800, 600);

        // Set the frame rate for the movie to 24 frames per second
        SWFMovie_setRate(test_movie, 24.0);

        // Load a font from disk
        font_object = newSWFFont_fromFile("../../fonts/vera/Vera.ttf");
        if (NULL == font_object)
        {
                // Something went wrong, so exit
                printf("Unable to load font from file.\n");
                return EXIT_FAILURE;
        }

        // Create a new, empty text object
        text_object = newSWFText();

        // Tell the text object to use the font previously loaded
        SWFText_setFont(text_object, font_object);

        // Set the height of the text
        SWFText_setHeight(text_object, 18.0);

        // Set the color of the text
        SWFText_setColor(text_object, 0x00, 0x00, 0xff, 0xff);

        // Add a string to the text object
        SWFText_addString(text_object, "This is some example text", NULL);

        // Add the text object to the movie (at 0,0)
        image_display_item = SWFMovie_add(test_movie, (SWFBlock) text_object);

        // Move to 100, 100
        SWFDisplayItem_moveTo(image_display_item, 100.00, 100.0);

        // Progressively move the text down and to the right
        for (i = 0; i <= 250; i++)
        {
                SWFMovie_nextFrame(test_movie);
                SWFDisplayItem_move(image_display_item, 2, 2);
        }

        // Save the swf movie file to disk
        SWFMovie_save(test_movie, "ming-test-text.swf");

        // Free the swf movie in memory
        destroySWFMovie(test_movie);

        // Free the swf text object
        destroySWFText(text_object);

        return EXIT_SUCCESS;
}
Esempio n. 9
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip  mc1, mc2, dejagnuclip;
  SWFShape  sh1, sh2;

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

  Ming_init();
  mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  SWFMovie_setDimension(mo, 800, 600);
  SWFMovie_setRate (mo, 12.0);

  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);

  add_actions(mo, " _root.x = '0+'; ");
  SWFMovie_nextFrame(mo); /* 1st frame */


  mc1 = newSWFMovieClip();
  sh1 = make_fill_square (300, 300, 60, 60, 255, 0, 0, 255, 0, 0);
  SWFMovieClip_add(mc1, (SWFBlock)sh1);
  /* add init actions */
  add_clip_init_actions(mc1, " _root.note('mc1.init_actions'); "
                             " _root.x += '1+'; " 
                             " y = 'var_of_root'; " );

  /* add actions */
  add_clip_actions(mc1, " _root.note('mc1.actions');  _root.x += '9+'; ");
  SWFMovieClip_nextFrame(mc1);//1st frame

  mc2 = newSWFMovieClip();
  sh2 = make_fill_square (600, 600, 60, 60, 255, 0, 0, 255, 0, 0);
  SWFMovieClip_add(mc2, (SWFBlock)sh2);
  /* add init actions */
  add_clip_init_actions(mc2, " _root.note('mc2.init_actions'); _root.x += '3+'; ");
  /* add actions */
  add_clip_actions(mc2, " _root.note('mc2.actions');  _root.x += '11+'; ");
  SWFMovieClip_nextFrame(mc2);//1st frame
  

  /* add mc1 to _root */
  SWFDisplayItem it1;
  it1 = SWFMovie_add(mo, (SWFBlock)mc1);
  SWFDisplayItem_setDepth(it1, 10);
  SWFDisplayItem_setName(it1, "mc1");

  SWFDisplayItem_addAction(it1,
    newSWFAction(" _root.note('mc1.onClipInitialize'); _root.x += '2+'; "
	"_root.check_equals(this.__proto__, MovieClip.prototype);"
	),
    SWFACTION_INIT);
    
  SWFDisplayItem_addAction(it1,
    newSWFAction(" _root.note('mc1.onClipConstruct');  _root.x += '5+'; "),
    SWFACTION_CONSTRUCT);
    
  SWFDisplayItem_addAction(it1,
    newSWFAction(" _root.note('mc1.onClipLoad');  _root.x += '8+'; "),
    SWFACTION_ONLOAD);


  /* add mc2 to _root */
  SWFDisplayItem it2;
  it2 = SWFMovie_add(mo, (SWFBlock)mc2);
  SWFDisplayItem_setDepth(it2, 11);
  SWFDisplayItem_setName(it2, "mc2");
 
   SWFDisplayItem_addAction(it2,
    newSWFAction(" _root.note('mc2.onClipInitialize'); _root.x += '4+'; "),
    SWFACTION_INIT);
    
  SWFDisplayItem_addAction(it2,
    newSWFAction(" _root.note('mc2.onClipConstruct');  _root.x += '6+'; "),
    SWFACTION_CONSTRUCT);
    
  SWFDisplayItem_addAction(it2,
    newSWFAction(" _root.note('mc2.onClipLoad');  _root.x += '10+'; "),
    SWFACTION_ONLOAD);
    
    
  /* add main timeline actions */
  add_actions(mo, "_root.note('_root.actions');  _root.x += '7+'; ");
  SWFMovie_nextFrame(mo); /* 2nd frame */

  /* The check below used to succeeds, and started failing when
   * executing init actions "after" DLIST tags.
   * Should be fixed if we postpone the call to ::construct
   * to "after" init actions are executed, which would require
   * some book keeping in sprite_instance class
   */
  check_equals(mo, "_root.x", "'0+1+2+3+4+5+6+7+8+9+10+11+'");

  check_equals(mo, "_root.y", "'var_of_root'");
  add_actions(mo, " _root.totals(); stop(); ");
  SWFMovie_nextFrame(mo); /* 3rd frame */
  

  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Esempio n. 10
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip  mc1, mc2, dejagnuclip;
  SWFShape  sh1, sh2;
  SWFDisplayItem it1, it2;
  
  const char *srcdir=".";
  if ( argc>1 ) 
    srcdir=argv[1];
  else
  {
      fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
      return 1;
  }

  Ming_init();
  mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  SWFMovie_setDimension(mo, 800, 600);
  SWFMovie_setRate (mo, 12.0);
  
  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  add_actions(mo, "testvar1 = 0; testvar2 = 0;");
  SWFMovie_nextFrame(mo); // frame1
  
  //
  // Define movieClips
  //
  mc1 = newSWFMovieClip();
  sh1 = make_fill_square (100, 100, 60, 60, 255, 0, 0, 255, 0, 0);
  SWFMovieClip_add(mc1, (SWFBlock)sh1);  
  SWFMovieClip_nextFrame(mc1);
  
  mc2 = newSWFMovieClip();
  sh2 = make_fill_square (300, 100, 60, 60, 255, 0, 0, 0, 255, 0);
  SWFMovieClip_add(mc2, (SWFBlock)sh2);  
  SWFMovieClip_nextFrame(mc2);
    
  SWFMovie_nextFrame(mo); // frame2

  //
  // Place mc1 at depth 3, place mc1 at depth3 again with a different name;
  // Observed behaviour:  later place does not create a new DisplayObject
  //
  it1 = SWFMovie_add(mo, (SWFBlock)mc1);  
  SWFDisplayItem_setDepth(it1, 3); 
  SWFDisplayItem_setName(it1, "static_mc1");
  SWFDisplayItem_addAction(it1,
    newSWFAction(" _root.testvar1++; trace(this); trace(_root.testvar1); "),
    SWFACTION_INIT | SWFACTION_CONSTRUCT | SWFACTION_ONLOAD);  
  
  it2 = SWFMovie_add(mo, (SWFBlock)mc2); 
  SWFDisplayItem_setDepth(it2, 3); 
  SWFDisplayItem_setName(it2, "static_mc2");
  SWFDisplayItem_addAction(it2,
    newSWFAction(" _root.testvar2++; trace(this); trace(_root.testvar2); "),
    SWFACTION_INIT | SWFACTION_CONSTRUCT | SWFACTION_ONLOAD); 
  
  check_equals(mo, "typeof(static_mc1)", "'movieclip'");
  if(OUTPUT_VERSION > 5)
  {
    // check that "static_mc2" doesn't get placed
    check_equals(mo, "typeof(static_mc2)", "'undefined'");
  }
  else
  {
    // check that "static_mc2" does get placed
    check_equals(mo, "typeof(static_mc2)", "'movieclip'");
  }
  SWFMovie_nextFrame(mo); // frame3
  
  if(OUTPUT_VERSION > 5)
  {
    check_equals(mo, "testvar1", "3");
    check_equals(mo, "testvar2", "0");
  }
  else
  {
    // swf5 does not support CONSTRUCT event
    check_equals(mo, "testvar1", "2");
    check_equals(mo, "testvar2", "2");
  }
  
  //
  // Place mc2 at depth 3 again.
  // Observed behaviour: no new DisplayObject gets created
  //
  it2 = SWFMovie_add(mo, (SWFBlock)mc2); 
  SWFDisplayItem_setDepth(it2, 3); 
  SWFDisplayItem_setName(it2, "static_mc3");
  
  check_equals(mo, "typeof(static_mc1)", "'movieclip'");
  if(OUTPUT_VERSION > 5)
  {
    // check that "static_mc3" doesn't get placed
    check_equals(mo, "typeof(static_mc3)", "'undefined'");
  }
  else
  {
    // check that "static_mc3" does get placed
    check_equals(mo, "typeof(static_mc3)", "'movieclip'");
  }
  SWFMovie_nextFrame(mo); // frame4
  
  //
  // Place mc1 at depth 3 again with ratio set to 0.2
  // Observed behaviour: no new DisplayObject get placed(created).
  //
  it2 = SWFMovie_add(mo, (SWFBlock)mc1); 
  SWFDisplayItem_setDepth(it2, 3); 
  SWFDisplayItem_setName(it2, "static_mc4");
  SWFDisplayItem_setRatio(it2, 0.2); 
  
  check_equals(mo, "typeof(static_mc1)", "'movieclip'");
  if(OUTPUT_VERSION > 5)
  {
    // check that "static_mc4" doesn't get placed.
    check_equals(mo, "typeof(static_mc4)", "'undefined'");
  }
  else
  {
    // check that "static_mc4" does get placed.
    check_equals(mo, "typeof(static_mc4)", "'movieclip'");
  }
  SWFMovie_nextFrame(mo); // frame5
  
  //
  // Place mc2 at depth 3 again with ratio set to 0.2
  // Observed behaviour: no new DisplayObject get placed(created).
  //
  it2 = SWFMovie_add(mo, (SWFBlock)mc2); 
  SWFDisplayItem_setDepth(it2, 3); 
  SWFDisplayItem_setName(it2, "static_mc5");
  SWFDisplayItem_setRatio(it2, 0.2); 
  
  check_equals(mo, "typeof(static_mc1)", "'movieclip'");
  if(OUTPUT_VERSION > 5)
  {
    // check that "static_mc5" doesn't get placed.
    check_equals(mo, "typeof(static_mc5)", "'undefined'");
  }
  else
  {
    // check that "static_mc5" does get placed.
    check_equals(mo, "typeof(static_mc5)", "'movieclip'");
  }
  SWFMovie_nextFrame(mo); // frame6
  
  
  //
  // Odd, where are the movieclips now?
  // Note that all those movieclips are defined above but not now.
  //
  if(OUTPUT_VERSION <= 5)
  {
    add_actions(mo, 
      "check_equals(typeof(static_m1), 'undefined');"
      "check_equals(typeof(static_m2), 'undefined');"
      "check_equals(typeof(static_m3), 'undefined');"
      "check_equals(typeof(static_m4), 'undefined');"
      "check_equals(typeof(static_m5), 'undefined');"
      );
  }
  add_actions(mo, " _root.totals(); stop(); ");
  SWFMovie_nextFrame(mo); // frame7  
  
  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Esempio n. 11
0
int
main(int argc, char** argv)
{
	SWFMovie mo;
	SWFMovieClip dejaclip;
	const char *srcdir=".";
	SWFFont bfont; 


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

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

	puts("Setting things up");

	Ming_init();
        Ming_useSWFVersion (OUTPUT_VERSION);
	Ming_setScale(20.0); /* let's talk pixels */
 
	mo = newSWFMovie();
	SWFMovie_setRate(mo, 1);
	SWFMovie_setDimension(mo, 628, 1024);

	bfont = get_default_font(srcdir);

	/*********************************************
	 *
	 * Body
	 *
	 *********************************************/

	dejaclip = get_dejagnu_clip((SWFBlock)bfont, 3000, 0, 50, 800, 800);

	SWFMovie_add(mo, (SWFBlock)dejaclip);
	SWFMovie_addExport(mo, (SWFBlock)dejaclip, "dejagnu");
	SWFMovie_addExport(mo, (SWFBlock)SWFMovie_addFont(mo, bfont),
		"dejafont");

	SWFMovie_nextFrame(mo); /* showFrame */


	/*****************************************************
	 *
	 * Output movie
	 *
	 *****************************************************/

	puts("Saving " OUTPUT_FILENAME );

	SWFMovie_save(mo, OUTPUT_FILENAME);

	return 0;
}
Esempio n. 12
0
int
main(int argc, char** argv)
{
    SWFMovie mo;
    const char *srcdir=".";
    SWFMovieClip  dejagnuclip;

    char loadvars[1048];
    char loademptyvars[1048];

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

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

    sprintf(loadvars, "e = l.load('%s/vars2.txt');", srcdir);
    sprintf(loademptyvars, "e = l.load('%s/empty.txt');", srcdir);
    puts("Setting things up");

    Ming_init();
    Ming_useSWFVersion (OUTPUT_VERSION);
    Ming_setScale(20.0); /* let's talk pixels */

    mo = newSWFMovie();
    SWFMovie_setRate(mo, 12);
    SWFMovie_setDimension(mo, 640, 400);

    /*********************************************
     *
     * Body
     *
     *********************************************/

    dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir),
                 10, 0, 80, 800, 600);
    SWFMovie_add(mo, (SWFBlock)dejagnuclip);

    add_actions(mo, 
                 "odatB = LoadVars.prototype.onData;"
                 "olB = LoadVars.prototype.onLoad;"
                 "odecB = LoadVars.prototype.decode;"
                 "loadString = '';"
                 "decodeString = '';"
                 "dataString = '';"
                 "callCount = 0;");

    add_actions(mo, "ourLoad = function(arg) {"
                 "loadString += callCount + ': onLoad called with ' + "
                 "typeof(arg) + ' argument ' + arg;"
                 "callCount++;"
                 "play();"
                 "};");

    add_actions(mo, "ourData = function(arg) {"
                 "trace('onData called');"
                 "dataString += callCount + ': onData called with ' + "
                 "typeof(arg) + ' argument ' + arg;"
                 "callCount++;"
                 "play();"
                 "};");

   
    add_actions(mo, "decodeCalled = 0;");
    add_actions(mo, "ourDecode = function(arg) {"
                 "decodeString += 'decode called with ' + typeof(arg)"
                 "+ ' argument ' + arg;"
                 "decodeCalled++;"
                 "};");

    /// The decode method is overwritten to see where it gets
    /// called from. We don't call it ourselves. Don't forget to 
    /// overwrite it again when the LoadVars object is constructed again.

    /// What happens when load fails?
    //
    /// The onLoad method is called from the default implementation of
    /// onData. The "loaded" property is immediately set to false on a 
    /// call to "load".
   
    SWFMovie_nextFrame(mo);

    /// onData
    add_actions(mo, "l = new LoadVars;");
    check_equals(mo, "l.loaded", "undefined");
    add_actions(mo, "l.decode = ourDecode;");

    add_actions(mo, "l.onData = ourData;"
                 "dataString = '';"
                 "e = l.load('fail');");
    check_equals(mo, "e", "true");
    add_actions(mo, "stop();");

    /// Wait for data before proceeding to next frame.
    SWFMovie_nextFrame(mo);
   
    // Check result, restore state.
    check_equals(mo, "dataString",
                 "'0: onData called with undefined argument undefined'");
    check_equals(mo, "l.loaded", "false");
    add_actions(mo, "l.onData = odatB;");

    /// onLoad
    add_actions(mo, "l = new LoadVars;");
    check_equals(mo, "l.loaded", "undefined");
    add_actions(mo, "l.decode = ourDecode;");

    add_actions(mo, "l.onLoad = ourLoad;"
                 "loadString = '';"
                 "e = l.load('fail');");
    check_equals(mo, "e", "true");
    add_actions(mo, "stop();");

    SWFMovie_nextFrame(mo);
          
    check_equals(mo, "loadString",
                 "'1: onLoad called with boolean argument false'");
    check_equals(mo, "l.loaded", "false");
    add_actions(mo, "l.onLoad = olB;");

    /// Both onData and onLoad
    add_actions(mo, "l = new LoadVars;");
    check_equals(mo, "l.loaded", "undefined");
    add_actions(mo, "l.decode = ourDecode;");

    add_actions(mo, "l.onLoad = ourLoad;"
                    "l.onData = ourData;"
                    "loadString = '';"
                    "dataString = '';"
                    "e = l.load('fail');");
    check_equals(mo, "e", "true");
    add_actions(mo, "stop();");

    SWFMovie_nextFrame(mo);
          
    check_equals(mo, "loadString", "''");
    check_equals(mo, "dataString",
                 "'2: onData called with undefined argument undefined'");
    check_equals(mo, "l.loaded", "false");
    add_actions(mo, "l.onLoad = olB;"
                    "l.onData = odatB;");

    /// What happens when load succeeds?
    //
    /// Both methods are called separately. The "loaded" property is set
    /// to true only when "onData" isn't overwritten.

    // onData
    add_actions(mo, "l = new LoadVars;");
    check_equals(mo, "l.loaded", "undefined");
    add_actions(mo, "l.decode = ourDecode;");

    add_actions(mo, "l.onData = ourData;"
                     "dataString = '';");
    add_actions(mo, loadvars);
    check_equals(mo, "e", "true");
    add_actions(mo, "stop();");

    SWFMovie_nextFrame(mo);
    // check_equals is too braindead to do this without escaping.
    check_equals(mo, "escape(dataString)",
           "'3%3A%20onData%20called%20with%20string%20argument%20v2%5Fvar1%3D"
        "val1%26v2%5Fvar2%3Dval2%26%0A'");
    check_equals(mo, "l.loaded", "false");
    add_actions(mo, "l.onData = odatB;");

    check_equals(mo, "decodeCalled", "0");
    check_equals(mo, "decodeString", "''");

    // onLoad
    add_actions(mo, "l = new LoadVars;");
    check_equals(mo, "l.loaded", "undefined");
    add_actions(mo, "l.decode = ourDecode;");

    add_actions(mo, "l.onLoad = ourLoad;"
                    "loadString = '';");
    add_actions(mo, loadvars);
    check_equals(mo, "e", "true");
    add_actions(mo, "stop();");

    SWFMovie_nextFrame(mo);
    check_equals(mo, "loadString",
                 "'4: onLoad called with boolean argument true'");
    add_actions(mo, "l.onLoad = olB;");

    /// decode is called from onData (i.e. it's called when we overwrite
    /// onLoad, not onData).
    check_equals(mo, "decodeCalled", "1");
    // check_equals is too braindead to do this without escaping.
    check_equals(mo, "escape(decodeString)",
              "'decode%20called%20with%20string%20argument%20v2%5Fvar1%3D"
        "val1%26v2%5Fvar2%3Dval2%26%0A'");


    /// What happens on load of empty data?
    //
    /// Same as a load failure.

    // onData
    add_actions(mo, "l = new LoadVars;");
    check_equals(mo, "l.loaded", "undefined");
    add_actions(mo, "l.decode = ourDecode;");

    add_actions(mo, "l.onData = ourData;"
                     "dataString = '';");
    add_actions(mo, loademptyvars);
    check_equals(mo, "e", "true");
    add_actions(mo, "stop();");

    SWFMovie_nextFrame(mo);
    // check_equals is too braindead to do this without escaping.
    check_equals(mo, "escape(dataString)",
           "'5%3A%20onData%20called%20with%20undefined%20"
           "argument%20undefined'");
    check_equals(mo, "l.loaded", "false");
    add_actions(mo, "l.onData = odatB;");

    // No more calls to decode.
    check_equals(mo, "decodeCalled", "1");


    /// End of tests.

   add_actions(mo, "totals(29);");
   add_actions(mo, "stop();");

   /*****************************************************
    *
    * Output movie
    *
    *****************************************************/

   puts("Saving " OUTPUT_FILENAME );

   SWFMovie_save(mo, OUTPUT_FILENAME);

   return 0;
}
Esempio n. 13
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip dejagnuclip, static3;
  SWFDisplayItem it1;


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

  Ming_init();
  mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  SWFMovie_setDimension(mo, 800, 600);
  SWFMovie_setRate (mo, 2);

  static3 = get_static_mc(20, 20);

  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  SWFMovie_nextFrame(mo); 

  // Frame 2: place a static DisplayObject at depth 3 (-16381)
  it1 = SWFMovie_add(mo, (SWFBlock)static3);
  SWFDisplayItem_setDepth(it1, 3);
  SWFDisplayItem_setName(it1, "static1");
  SWFDisplayItem_addAction(it1, newSWFAction(
			"_root.note(this+' onClipConstruct');"
			" _root.check_equals(typeof(_root), 'movieclip');"
		        " if ( isNaN(_root.depth3Constructed) ) {"
			"	_root.depth3Constructed=1; "
			" } else {"
			"	_root.depth3Constructed++;"
			" }"
			" _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
			), SWFACTION_CONSTRUCT);
  SWFMovie_nextFrame(mo); 

  // Frame 3: remove DisplayObject at depth -16381 
  SWFDisplayItem_remove(it1);
  add_actions(mo, "check_equals(typeof(static1), 'undefined');"); // the replacement failed
  SWFMovie_nextFrame(mo); 
 
  // Frame 4: place same static DisplayObject at depth 3 (-16381)
  it1 = SWFMovie_add(mo, (SWFBlock)static3);
  SWFDisplayItem_setDepth(it1, 3);
  SWFDisplayItem_setName(it1, "static2");
  SWFDisplayItem_addAction(it1, newSWFAction(
			"_root.note(this+' onClipConstruct');"
			" _root.check_equals(typeof(_root), 'movieclip');"
		        " if ( isNaN(_root.depth3Constructed) ) {"
			"	_root.depth3Constructed=1; "
			" } else {"
			"	_root.depth3Constructed++;"
			" }"
			" _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
			), SWFACTION_CONSTRUCT);

  // Frame 5: jump to frame 2, stop and check
  add_actions(mo,
    "check_equals(typeof(static1), 'undefined');"
    "check_equals(typeof(static2), 'movieclip');"

    "gotoAndStop(2); " 

    // two instances were placed in total, the second instance is not
    // supposed to be removed on jump back, being on a depth supposed
    // to contain a timeline instance at that time
    // Gnash fails here by removing the instance placed in a later frame
    "check_equals(_root.depth3Constructed, 2);"

    // Gnash fails here by removing the instance placed in a later frame
    "check_equals(typeof(static1), 'undefined');"

    // Gnash fails here by removing the instance placed in a later frame
    // (thus placing a new instance)
    "check_equals(typeof(static2), 'movieclip');"

    "totals();"
    );
  SWFMovie_nextFrame(mo); 

  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Esempio n. 14
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); 

	SWFMovie_nextFrame(mo); /* showFrame */

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

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

    /* This button has one character per state. It shows that each state
     * except HIT generates one new instance and deletes the old one.
     * HIT deletes the old instance property and does not add a new one.
     */

    add_actions(mo, "note('This is a very simple test. Do anything you like "
            "with the buttons and you should get no failures');");

    add_actions(mo, "var c = 2;");
    add_actions(mo,
            "props = function() {"
            "   s=''; "
            "   for (i in square1.button) { "
            "       if (i.substr(0, 8) == 'instance') { s += i; }; "
            "   };"
            "   return s;"
            "};");
    add_actions(mo, "check_equals(props(), 'instance' + c++);");
    add_actions(mo,
            "square1.button.onRollOver = function() {"
            "   check_equals(props(), '');"
            "};"
            "square1.button.onRollOut = function() {"
            "   check_equals(props(), 'instance' + c++);"
            "};"
            "square1.button.onMouseDown = function() {"
            "   check_equals(props(), 'instance' + c++);"
            "};"
            "square1.button.onPress = function() {"
            "   check_equals(props(), 'instance' + c++);"
            "};"
            "square1.button.onRelease = function() {"
            "   check_equals(props(), '');"
            "};"
            "square1.button.onReleaseOutside = function() {"
            "   check_equals(props(), 'instance' + c++);"
            "};"
            );
                   
    //add_actions(mo, "onEnterFrame = function() { props(); trace (s); };");
    add_actions(mo, "stop();");
	SWFMovie_nextFrame(mo); /* showFrame */

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

	puts("Saving " OUTPUT_FILENAME );

	SWFMovie_save(mo, OUTPUT_FILENAME);

	return 0;
}
Esempio n. 15
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. 16
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip dejagnuclip;
  SWFDisplayItem it1;


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

  Ming_init();
  mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  SWFMovie_setDimension(mo, 800, 600);
  SWFMovie_setRate (mo, 2);

  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  SWFMovie_nextFrame(mo); 

  // Frame 2: Add a static movieclip at depth 3 with origin at 10,200, then change it's _y to 202 with AS code.
  it1 = add_static_mc(mo, "static3", 3, 10, 200, 20, 20);
  add_actions(mo,
    "check_equals(static3.getDepth(), -16381);" 
    "static3.myThing = 'guess';"
    // dynamically transform it
    "static3._y += 2;"
    );
  SWFMovie_nextFrame(mo); 

  // Frame 3: nothing new, just checks, and end of test on second run
  SWFMovie_nextFrame(mo); 
  add_actions(mo,
    "if ( typeof(_root.runs) == 'undefined' ) {"
    " check_equals(static3._y, 202);" 
    " _root.runs=1;"
    "} else {"
    " check_equals(static3._y, 204);"  
    " totals();"
    " stop();"
    "}"
    );

  // Frame 4: move DisplayObject at depth 3 to position 50,200
  SWFDisplayItem_moveTo(it1, 50, 200); 
  add_actions(mo,
    // immune to MOVE after _y set by AS
    "check_equals(static3._x, 10);" 
    "check_equals(static3.getDepth(), -16381);" 
    );
  SWFMovie_nextFrame(mo); 

  // Frame 5: nothing new
  SWFMovie_nextFrame(mo); 

  // Frame 6: nothing new
  SWFMovie_nextFrame(mo); 

  // Frame 7: go to frame 2  and playe (movie will end on second execution of frame 3 actions)
  add_actions(mo,

    "   gotoAndPlay(2); " // The movie will be ended in frame 5
    
    // Static3 refers to same instance
    "check_equals(static3.myThing, 'guess');" 
    "check_equals(static3._x, 10);" // Probably PlaceObject was a no-op...

    // actions in frame 2 would be executed again, making this a 204, but only *after* this action block terminates..
    "check_equals(static3._y, 202);" 

    "check_equals(static3.getDepth(), -16381);" 
    );
  SWFMovie_nextFrame(mo); 

  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Esempio n. 17
0
int
main(int argc, char** argv)
{
    SWFMovie mo;
    SWFMovieClip mc3, mc2, dejagnuclip;
    SWFAction ac, ac1, initac;
    SWFDisplayItem it;
    SWFShape sha;

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

    Ming_init();
    mo = newSWFMovieWithVersion(OUTPUT_VERSION);
    SWFMovie_setDimension(mo, 800, 600);
    SWFMovie_setRate (mo, 12.0);


    sha = newSWFShape();

    // Character ID 2. Has 1 showframe. Is exported first.
    mc2 = newSWFMovieClip();
    SWFMovieClip_add(mc2, (SWFBlock)sha);
    SWFMovieClip_nextFrame(mc2);

    // Export it.
    SWFMovie_addExport(mo, (SWFBlock)mc2, "C2");
    SWFMovie_writeExports(mo);

    // Main timeline actions for frame 1
    add_actions(mo, "var c = 0; var i = 0; trace('frame 1'); gotoAndStop(3);");
    initac = newSWFAction("trace('onInitialize'); _root.i++;");
    
    // ID 3 is defined here. It has no showframe. It is exported immediately.
    mc3 = newSWFMovieClip();
    SWFMovie_addExport(mo, (SWFBlock)mc3, "ctor");
    SWFMovie_writeExports(mo);

    dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10,
    		    0, 0, 800, 600);
    SWFMovie_add(mo, (SWFBlock)dejagnuclip);

    // Init actions for ID 3. This only exists to create the constructor
    // for mc2 in its initactions.
    ac = newSWFAction(
    "   _global.ctor = function () {"
    "       super();"
    "       trace('Object ID 2 is constructed');"
    "       c += 1;"
    "   };"
    );
    SWFInitAction ia = newSWFInitAction_withId(ac, 3);
    SWFMovie_add(mo, (SWFBlock)ia);
    
    // Init actions for ID 2 (registered class)
    ac1 = newSWFAction("Object.registerClass('C2', ctor); "
            "trace('Registered class');");
    ia = newSWFInitAction_withId(ac1, 2);
    SWFMovie_add(mo, (SWFBlock)ia);
	
    
    // Frame 2
    SWFMovie_nextFrame(mo);
    add_actions(mo, "trace('Frame 2');");
    
    // Place object ID 2.
    it = SWFMovie_add(mo, (SWFBlock)mc2);
    SWFDisplayItem_setName(it, "mc2");
    SWFDisplayItem_addAction(it, initac, SWFACTION_INIT);

    // Frame 3
    SWFMovie_nextFrame(mo);

    // Remove object ID 2
    SWFMovie_remove(mo, it);

    add_actions(mo, "trace('frame 3');");
    
    // The class should not be constructed if the object is removed after
    // being placed. It should be constructed if it's not removed. MovieClips
    // with an onUnload handler are always constructed.
    check_equals(mo, "c", "0");
    check_equals(mo, "i", "0");
    check(mo, "_root.mc2 == undefined");
    add_actions(mo, "gotoAndPlay(5);");

    // Frame 4
    SWFMovie_nextFrame(mo);
    add_actions(mo, "trace('Frame 4');");
    
    // Place object ID 2 again
    it = SWFMovie_add(mo, (SWFBlock)mc2);
    SWFDisplayItem_setName(it, "mc2a");
    SWFDisplayItem_addAction(it, initac, SWFACTION_INIT);

    // Frame 5
    SWFMovie_nextFrame(mo);

    // This time the MovieClip was not removed before we get here,
    // so it should be present and the constructor should be
    // called.
    add_actions(mo, "trace('frame 5');");
    check_equals(mo, "c", "1");
    check_equals(mo, "i", "1");
    check(mo, "typeof(_root.mc2a) == 'movieclip'");
    add_actions(mo, "stop();");

    SWFMovie_nextFrame(mo);
  
    puts("Saving " OUTPUT_FILENAME );
    SWFMovie_save(mo, OUTPUT_FILENAME);

    return 0;
}
Esempio n. 18
0
int main(void)
{
	SWFMovie mo;
	SWFDisplayItem it1, it2, it3;
	SWFShape sh1, sh2, sh3;
	int framenum;

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

	puts("Setting things up");

	Ming_init();
        Ming_useSWFVersion (OUTPUT_VERSION);
	Ming_setScale(20.0); 
 
	mo = newSWFMovie();

	/*****************************************************
	 *
	 * Add the square named 
	 *
	 *****************************************************/

	SWFMovie_setDimension(mo, 100, 100);

#define FRAMESGAP 5

	sh1 = make_square(10, 10, 20, 20, 255, 0, 0);
	it1 = SWFMovie_add(mo, (SWFBlock)sh1);
	SWFDisplayItem_setDepth(it1, 1);
	SWFDisplayItem_setName(it1, "Name1");

	for (framenum=0; framenum<FRAMESGAP; framenum++) {
		SWFMovie_nextFrame(mo); 
	}

	sh2 = make_square(35, 10, 20, 20, 0, 255, 0);
	it2 = SWFMovie_add(mo, (SWFBlock)sh2);
	SWFDisplayItem_setDepth(it2, 2);
	SWFDisplayItem_setName(it2, "Name2");

	for (framenum=0; framenum<FRAMESGAP; framenum++) {
		SWFMovie_nextFrame(mo); 
	}

	sh3 = make_square(10, 35, 45, 20, 0, 0, 255);
	it3 = SWFMovie_add(mo, (SWFBlock)sh3);
	SWFDisplayItem_setDepth(it3, 3);
	SWFDisplayItem_setName(it3, "Name3");

	for (framenum=0; framenum<FRAMESGAP; framenum++) {
		SWFMovie_nextFrame(mo); 
	}

	SWFMovie_remove(mo, it1);

	for (framenum=0; framenum<FRAMESGAP; framenum++) {
		SWFMovie_nextFrame(mo); 
	}

	SWFMovie_remove(mo, it2);

	for (framenum=0; framenum<FRAMESGAP; framenum++) {
		SWFMovie_nextFrame(mo); 
	}

	SWFMovie_remove(mo, it3);

	puts("Saving " OUTPUT_FILENAME );

	SWFMovie_nextFrame(mo); /* showFrame */

	SWFMovie_save(mo, OUTPUT_FILENAME);

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

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

    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);

    puts("Setting things up");

    Ming_init();
    Ming_useSWFVersion (OUTPUT_VERSION);
    //Ming_setScale(20.0); /* so we talk twips */

    mo = newSWFMovie();
    SWFMovie_setRate(mo, 1.0);
    SWFMovie_setDimension(mo, 800, 600);

    dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
    SWFMovie_add(mo, (SWFBlock)dejagnuclip);
    SWFMovie_nextFrame(mo); // 1st frame


    /*********************************************
     *
     * Add some textfields
     *
     *********************************************/
    {
        SWFDisplayItem it;
        FILE *font_file = fopen(fdbfont, "r");
        if ( font_file == NULL )
        {
            perror(fdbfont);
            exit(1);
        }
        SWFFont efont = loadSWFFontFromFile(font_file);

        it = add_text_field(mo, efont, "First text");
        SWFDisplayItem_setName(it, "dtext1");
        SWFDisplayItem_moveTo(it, 0, 200);
        it = add_text_field(mo, efont, "Zweites Textfeld");
        SWFDisplayItem_setName(it, "etext1");
        SWFDisplayItem_moveTo(it, 0, 300);

        it = add_text_field(mo, efont, "Some more static text here... abcdefgh");
        SWFDisplayItem_setName(it, "dtext2");
        SWFDisplayItem_moveTo(it, 0, 400);
    }
    SWFMovie_nextFrame(mo);

    add_actions(mo, "createTextField('dynamictext1', 99, 10, 10, 10, 10);"
                "this.dynamictext1.text = 'Dynamic Text';");

    add_actions(mo, "ts = this.getTextSnapshot();");
    check(mo, "ts instanceof TextSnapshot");
    check_equals(mo, "ts.getCount()", "64");

    check_equals(mo, "ts.getText(0, 1)", "'F'");
    check_equals(mo, "ts.getText(3, 3)", "'s'");
    check_equals(mo, "ts.getText(-5, 5)", "'First'");
    check_equals(mo, "ts.getText(10, 6)", "'Z'");
    check_equals(mo, "ts.getText(0, 100)", "'First textZweites TextfeldSome more "
                 "static text here... abcdefgh'");
    add_actions(mo, "ss = ts.getText(100, 110);");
    check_equals(mo, "typeof(ss)", "'string'");
    check_equals(mo, "ss", "'h'");
    check_equals(mo, "ss.length", "1");

    check_equals(mo, "ts.getText(0, 100, true)",
                 "'First text\nZweites Textfeld\nSome more "
                 "static text here... abcdefgh'");

    check_equals(mo, "ts.getText(0, 14, true)", "'First text\nZwei'");

    check_equals(mo, "ts.findText(0, '', false)", "-1");
    check_equals(mo, "ts.findText(0, 'f', false)", "0");
    check_equals(mo, "ts.findText(0, 'f', true)", "22");
    check_equals(mo, "ts.findText(1, 'Rst', false)", "2");
    check_equals(mo, "ts.findText(3, 'RSt', false)", "-1");
    check_equals(mo, "ts.findText(100, 'h', false)", "-1");
    check_equals(mo, "ts.findText(64, 'h', false)", "-1");
    check_equals(mo, "ts.findText(-5, 'Zwei', true)", "-1");
    check_equals(mo, "ts.findText(-5, 'gh', true)", "-1");

    add_actions(mo, "ts.setSelected(5, 30, true);");
    check_equals(mo, "ts.getSelectedText()", "' textZweites TextfeldSome'");
    check_equals(mo, "ts.getSelectedText(true)", "' text\nZweites "
                 "Textfeld\nSome'");
    check_equals(mo, "ts.getSelectedText(false)", "' textZweites TextfeldSome'");
    check_equals(mo, "ts.getSelected(0, 4)", "false");
    check_equals(mo, "ts.getSelected(1, 9)", "true");
    check_equals(mo, "ts.getSelected(-4, 10)", "true");
    check_equals(mo, "ts.getSelected(-4, 6)", "true");
    check_equals(mo, "ts.getSelected(28, 23)", "true");
    check_equals(mo, "ts.getSelected(20, 20)", "true");
    check_equals(mo, "ts.getSelected(20, 27)", "true");
    check_equals(mo, "ts.getSelected(-3, -1)", "false");
    check_equals(mo, "ts.getSelected(30, 31)", "false");
    check_equals(mo, "ts.getSelected(0, 5)", "false");
    check_equals(mo, "ts.getSelected(40, 45)", "false");
    check_equals(mo, "ts.getSelected(31, 34)", "false");

    check_equals(mo, "ts.getSelected(0)", "undefined");
    check_equals(mo, "ts.getSelected(1)", "undefined");
    check_equals(mo, "ts.getSelected(-4)", "undefined");
    check_equals(mo, "ts.getSelected(-4)", "undefined");
    check_equals(mo, "ts.getSelected(28)", "undefined");
    check_equals(mo, "ts.getSelected(20)", "undefined");

    // Selected text is stored in the textfield and reset when a new
    // snapshot is taken.
    add_actions(mo, "ts2 = new TextSnapshot(this);");
    check_equals(mo, "ts.getSelectedText(false)", "''");
    check_equals(mo, "ts2.getCount()", "64");
    check_equals(mo, "ts2.getSelectedText()", "''");
    add_actions(mo, "ts2 = this.getTextSnapshot();");
    check_equals(mo, "ts2.getCount()", "64");
    check_equals(mo, "ts2.getSelectedText()", "''");

    add_actions(mo, "ts2.setSelected(3, 10, true);");
    check_equals(mo, "ts2.getSelectedText(false).length", "7");
    check_equals(mo, "ts.getSelectedText(false).length", "7");

    add_actions(mo, "ts.setSelectedColor(0xffff00);");
    add_actions(mo, "ts2.setSelectedColor(0x0000ff);");

    check_equals(mo, "ts.getSelectedText(false)", "'st text'");
    add_actions(mo, "ri = ts.getTextRunInfo(4, 10);");
    check_equals(mo, "typeof(ri)", "'object'");
    check(mo, "ri instanceof Array");
    check_equals(mo, "ri.length", "7");

    add_actions(mo, "el = ri[1];");
    check_equals(mo, "typeof(el)", "'object'");
    check(mo, "!el.hasOwnProperty('indexInRun')");
    check_equals(mo, "el.indexInRun", "5");
    check_equals(mo, "el.selected", "true");
    check_equals(mo, "el.font", "'Bitstream Vera Sans'");
    check_equals(mo, "el.color", "0");
    check_equals(mo, "el.height", "12");
    check_equals(mo, "el.matrix_a", "1");
    check_equals(mo, "el.matrix_b", "0");
    check_equals(mo, "el.matrix_c", "0");
    check_equals(mo, "el.matrix_d", "1");
    check_equals(mo, "el.matrix_tx", "25.95");
    check_equals(mo, "el.matrix_ty", "200");
    xcheck_equals(mo, "el.corner0x", "25.95");
    xcheck_equals(mo, "el.corner0y", "202.8");
    xcheck_equals(mo, "el.corner1x", "29.75");
    xcheck_equals(mo, "el.corner1y", "202.8");
    xcheck_equals(mo, "el.corner2x", "29.75");
    xcheck_equals(mo, "el.corner2y", "188.85");
    xcheck_equals(mo, "el.corner3x", "25.95");
    xcheck_equals(mo, "el.corner3y", "188.85");

    // Check properties individually
    check_equals(mo, "ri[2].height", "12");
    check_equals(mo, "ri[3].height", "12");
    check_equals(mo, "ri[4].height", "12");
    check_equals(mo, "ri[5].height", "12");
    check_equals(mo, "ri[6].height", "12");

    check_equals(mo, "ri[2].selected", "true");
    check_equals(mo, "ri[3].selected", "true");
    check_equals(mo, "ri[4].selected", "true");
    check_equals(mo, "ri[5].selected", "true");
    check_equals(mo, "ri[6].selected", "false");

    check_equals(mo, "ri[2].matrix_tx", "29.75");
    check_equals(mo, "ri[2].matrix_ty", "200");
    check_equals(mo, "ri[3].matrix_tx", "34.4");
    check_equals(mo, "ri[3].matrix_ty", "200");
    check_equals(mo, "ri[4].matrix_tx", "41.75");
    check_equals(mo, "ri[4].matrix_ty", "200");

    xcheck_equals(mo, "ri[2].corner0x", "29.75");
    xcheck_equals(mo, "ri[2].corner0y", "202.8");
    xcheck_equals(mo, "ri[3].corner0x", "34.4");
    xcheck_equals(mo, "ri[3].corner0y", "202.8");
    xcheck_equals(mo, "ri[4].corner0x", "41.75");
    xcheck_equals(mo, "ri[4].corner0y", "202.8");

    xcheck_equals(mo, "ri[2].corner2y", "188.85");
    xcheck_equals(mo, "ri[3].corner2y", "188.85");
    xcheck_equals(mo, "ri[4].corner2y", "188.85");

    add_actions(mo, "ts.setSelected(0, 10, true);");
    add_actions(mo, "ts.setSelected(15, 20, false);");
    check_equals(mo, "ts2.getSelectedText().length", "10");

    add_actions(mo, "ri2 = ts.getTextRunInfo(0, 100);");

    check_equals(mo, "ri2[0].selected", "true");
    check_equals(mo, "ri2[1].selected", "true");
    check_equals(mo, "ri2[2].selected", "true");
    check_equals(mo, "ri2[3].selected", "true");
    check_equals(mo, "ri2[4].selected", "true");
    check_equals(mo, "ri2[5].selected", "true");
    check_equals(mo, "ri2[6].selected", "true");
    check_equals(mo, "ri2[15].selected", "false");
    check_equals(mo, "ri2[16].selected", "false");
    check_equals(mo, "ri2[17].selected", "false");
    check_equals(mo, "ri2[18].selected", "false");

    xcheck_equals(mo, "ri2[50].corner2y", "388.85");
    xcheck_equals(mo, "ri2[50].corner2x", "156.6");
    xcheck_equals(mo, "ri2[51].corner2y", "388.85");
    xcheck_equals(mo, "ri2[51].corner2x", "163.95");

    check_equals(mo, "ri2[50].matrix_tx", "151.65");
    check_equals(mo, "ri2[51].matrix_tx", "156.55");

    add_actions(mo, "ts = this.getTextSnapshot();");
    check_equals(mo, "typeof(ts)", "'object'");
    add_actions(mo, "backup = TextSnapshot;");
    add_actions(mo, "TextSnapshot = undefined;");
    add_actions(mo, "t = new TextSnapshot();");
    check_equals(mo, "typeof(t)", "'undefined'");

    check_equals(mo, "typeof(TextSnapshot)", "'undefined'");
    add_actions(mo, "ts = this.getTextSnapshot();");
    xcheck_equals(mo, "typeof(ts)", "'undefined'");
    add_actions(mo, "TextSnapshot = backup;");
    add_actions(mo, "ts = this.getTextSnapshot();");
    check_equals(mo, "typeof(ts)", "'object'");

    add_actions(mo, "backup = TextSnapshot.prototype;");
    add_actions(mo, "TextSnapshot.prototype = undefined;");
    add_actions(mo, "ts = this.getTextSnapshot();");
    check_equals(mo, "typeof(ts)", "'object'");
    add_actions(mo, "TextSnapshot.prototype = backup;");
    add_actions(mo, "ts = this.getTextSnapshot();");
    check_equals(mo, "typeof(ts)", "'object'");

    add_actions(mo, "totals(); stop();");

    SWFMovie_nextFrame(mo);

    /*****************************************************
     *
     * Output movie
     *
     *****************************************************/
    puts("Saving " OUTPUT_FILENAME );

    SWFMovie_save(mo, OUTPUT_FILENAME);

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

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

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

  sprintf(fdefont, "%s/Bitstream-Vera-Sans.fdb", srcdir);
  FILE *font_file = fopen(fdefont, "r");
  if ( font_file == NULL )
  {
    perror(fdefont);
    exit(1);
  }
  SWFFont efont = loadSWFFontFromFile(font_file);

  puts("Setting things up");

  Ming_init();
  Ming_useSWFVersion (OUTPUT_VERSION);
 
  mo = newSWFMovie();
  SWFMovie_setRate(mo, 1.0);
  SWFMovie_setDimension(mo, 800, 600);
  
  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10,
          0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  SWFMovie_nextFrame(mo); // 1st frame 

  /*********************************************
   *
   * Add some textfields
   *
   *********************************************/

  int y = 30;
  int inc = 30;

  it = add_text_field(mo, (SWFBlock)efont, "Normal", 1, 2, 3,
          SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_setName(it, "tf1");
  
  y += inc;

  it = add_text_field(mo, (SWFBlock)efont, "Transparent", 1, 2, 3,
          SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 0);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_setName(it, "tf2");
  
  y += inc;
  
  it = add_text_field(mo, (SWFBlock)efont, "X scaled by 16, no indent or "
          "margin", 0, 0, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 16, 1);
  SWFDisplayItem_setName(it, "tf3");

  y += inc;
  
  it = add_text_field(mo, (SWFBlock)efont, "X scaled by 16, indent 4",
          4, 0, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 16, 1);
  SWFDisplayItem_setName(it, "tf4");
  
  y += inc;
  
  it = add_text_field(mo, (SWFBlock)efont, "X scaled by 16, left margin 4",
          0, 4, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 16, 1);
  SWFDisplayItem_setName(it, "tf5");
  
  y += inc;
  it = add_text_field(mo, (SWFBlock)efont, "X scaled by 16, right margin 4",
          0, 0, 4, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 16, 1);
  SWFDisplayItem_setName(it, "tf6");
  
  y += inc;
  
  it = add_text_field(mo, (SWFBlock)efont, "X scaled by 16, left margin 4, "
          "indent 4", 4, 4, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 16, 1);
  SWFDisplayItem_setName(it, "tf7");
  
  y += inc;
  
  it = add_text_field(mo, (SWFBlock)efont, "X scaled by 8, no indent or margin",
          0, 0, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 8, 1);
  SWFDisplayItem_setName(it, "tf8");

  y += inc;
  
  it = add_text_field(mo, (SWFBlock)efont, "X scaled by 8, indent 4", 4, 0, 0,
          SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 8, 1);
  SWFDisplayItem_setName(it, "tf9");
  y += inc;
  
  it = add_text_field(mo, (SWFBlock)efont, "X scaled by 0.2", 8, 8, 8,
          SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 0.2, 1);
  SWFDisplayItem_setName(it, "tf10");
  
  y += inc;
  
  it = add_text_field(mo, (SWFBlock)efont, "Y scaled by 4", 4, 4, 0,
          SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 1, 4);
  SWFDisplayItem_setName(it, "tf11");
  
  y += inc * 3;
  
  it = add_text_field(mo, (SWFBlock)efont, "Y scaled by 8", 4, 4, 0,
          SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 1, 8);
  SWFDisplayItem_setName(it, "tf12");


  // It's not clear how consistent the textWidth or textHeight
  // values are. As they are embedded, it may be possible to reproduce
  // exactly, in which case the test can be made more precise.

  check_equals(mo, "tf1._width", "84");
  check_equals(mo, "tf1._height", "20");
  xcheck_equals(mo, "tf1._x", "48");
  xcheck_equals(mo, "tf1._y", "28");
  xcheck_equals(mo, "tf1.textHeight", "23");
  // Approx 46
  add_actions(mo, "trace(tf1.textWidth);");
  xcheck(mo, "tf1.textWidth >= 44 && tf1.textWidth <= 48");

  check_equals(mo, "tf2._width", "84");
  check_equals(mo, "tf2._height", "20");
  xcheck_equals(mo, "tf2._x", "48");
  xcheck_equals(mo, "tf2._y", "58");
  xcheck_equals(mo, "tf2.textHeight", "23");
  // Approx 78
  add_actions(mo, "trace(tf2.textWidth);");
  xcheck(mo, "tf2.textWidth >= 76 && tf2.textWidth <= 80");

  check_equals(mo, "tf3._width", "1344");
  check_equals(mo, "tf3._height", "20");
  xcheck_equals(mo, "tf3._x", "18");
  xcheck_equals(mo, "tf3._y", "88");
  xcheck_equals(mo, "tf3.textHeight", "23");
  // Approx 230
  add_actions(mo, "trace(tf3.textWidth);");
  xcheck(mo, "tf3.textWidth >= 225 && tf3.textWidth <= 235");

  check_equals(mo, "tf4._width", "1344");
  check_equals(mo, "tf4._height", "20");
  xcheck_equals(mo, "tf4._x", "18");
  xcheck_equals(mo, "tf4._y", "118");
  xcheck_equals(mo, "tf4.textHeight", "23");
  // Approx 156
  add_actions(mo, "trace(tf4.textWidth);");
  xcheck(mo, "tf4.textWidth >= 153 && tf4.textWidth <= 159");

  check_equals(mo, "tf5._width", "1344");
  check_equals(mo, "tf5._height", "20");
  xcheck_equals(mo, "tf5._x", "18");
  xcheck_equals(mo, "tf5._y", "148");
  xcheck_equals(mo, "tf5.textHeight", "23");
  // Approx 186
  add_actions(mo, "trace(tf5.textWidth);");
  xcheck(mo, "tf5.textWidth >= 183 && tf5.textWidth <= 189");

  check_equals(mo, "tf6._width", "1344");
  check_equals(mo, "tf6._height", "20");
  xcheck_equals(mo, "tf6._x", "18");
  xcheck_equals(mo, "tf6._y", "178");
  xcheck_equals(mo, "tf6.textHeight", "23");
  // Approx 194
  add_actions(mo, "trace(tf6.textWidth);");
  xcheck(mo, "tf6.textWidth >= 189 && tf6.textWidth <= 199");

  check_equals(mo, "tf7._width", "1344");
  check_equals(mo, "tf7._height", "20");
  xcheck_equals(mo, "tf7._x", "18");
  xcheck_equals(mo, "tf7._y", "208");
  xcheck_equals(mo, "tf7.textHeight", "23");
  // Approx 247
  add_actions(mo, "trace(tf7.textWidth);");
  xcheck(mo, "tf7.textWidth >= 240 && tf7.textWidth <= 254");

  check_equals(mo, "tf8._width", "672");
  check_equals(mo, "tf8._height", "20");
  xcheck_equals(mo, "tf8._x", "34");
  xcheck_equals(mo, "tf8._y", "238");
  xcheck_equals(mo, "tf8.textHeight", "23");
  // Approx 222
  add_actions(mo, "trace(tf8.textWidth);");
  xcheck(mo, "tf8.textWidth >= 217 && tf8.textWidth <= 227");

  check_equals(mo, "tf9._width", "672");
  check_equals(mo, "tf9._height", "20");
  xcheck_equals(mo, "tf9._x", "34");
  xcheck_equals(mo, "tf9._y", "268");
  xcheck_equals(mo, "tf9.textHeight", "23");
  // Approx 148
  add_actions(mo, "trace(tf9.textWidth);");
  xcheck(mo, "tf9.textWidth >= 144 && tf9.textWidth <= 152");

  check_equals(mo, "tf10._width", "16.8");
  check_equals(mo, "tf10._height", "20");
  xcheck_equals(mo, "tf10._x", "49.6");
  xcheck_equals(mo, "tf10._y", "298");
  xcheck_equals(mo, "tf10.textHeight", "23");
  // Approx 99
  add_actions(mo, "trace(tf10.textWidth);");
  xcheck(mo, "tf10.textWidth >= 95 && tf10.textWidth <= 103");

  // The textHeight for the following two fields varies.
  check_equals(mo, "tf11._width", "84");
  check_equals(mo, "tf11._height", "80");
  xcheck_equals(mo, "tf11._x", "48");
  xcheck_equals(mo, "tf11._y", "322");
  xcheck_equals(mo, "tf11.textHeight", "23");
  // Approx 86
  add_actions(mo, "trace(tf11.textWidth);");
  xcheck(mo, "tf11.textWidth >= 84 && tf11.textWidth <= 88");

  check_equals(mo, "tf12._width", "84");
  check_equals(mo, "tf12._height", "160");
  xcheck_equals(mo, "tf12._x", "48");
  xcheck_equals(mo, "tf12._y", "404");
  xcheck_equals(mo, "tf12.textHeight", "23");
  // Approx 86
  add_actions(mo, "trace(tf12.textWidth);");
  xcheck(mo, "tf12.textWidth >= 84 && tf12.textWidth <= 88");

  add_actions(mo, "totals(); stop();");

  SWFMovie_nextFrame(mo); 

  /*****************************************************
   *
   * Output movie
   *
   *****************************************************/
  puts("Saving " OUTPUT_FILENAME );

  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Esempio n. 21
0
int
main (int argc, char **argv)
{
	int width=640, height=480;    /* default stage size */
	int i;
	int swfcompression = DEFSWFCOMPRESSION;
	float framerate = 12.0;
	/*
	 * Allow network access from locally-loaded movies.
	 *
	 *   0 = file access
	 *   1 = network access
	 *  -1 = unspecified (omit the tag if SWF < 8, file access otherwise)
	 *
	 *  By default is unspecified.
	 */
	int networkAccess = -1;
	int usedfiles = 0;
	struct stat statbuf;
	int debug_parser = 0;	
#ifdef HAVE_GETOPT_LONG
	struct option opts[] =
	{
		{"dont-preprocess", 0, 0, 'p'},
		{"frame-rate", 1, 0, 'r'},
		{"swfversion", 1, 0, 'v'},
		{"bgcolor", 1, 0, 'b'},
		{"compression", 1, 0, 'c'},
		{"includepath", 1, 0, 'I'},
		{"define", 1, 0, 'D'},
		{"size", 1, 0, 's'},
		{"network-access", 1, 0, 'n'},
		{"output", 1, 0, 'o'},
		{"import", 1, 0, 'i'},
		{"version", 0, 0, 'V'},
		{"help", 0, 0, 'h'},
		{"debug", 0, 0, 'd'},
		{"init-action", 1, 0, 'a'},
		{0, 0, 0, 0}
	};
	int opts_idx;
#endif
	int c;
	char *me;

	cppargs = malloc(cppargsize);
	sprintf(cppargs, "%s", DEFAULT_FLAGS);
	//cppargs[0] = '\0';


	me = argv[0];

	while (1)
	{
#define BUFSIZE 1024
		char buf [BUFSIZE];

		const char *optstring = "Vhpds:r:D:I:v:c:b:i:o:a:n:";
#ifdef HAVE_GETOPT_LONG
		c = getopt_long (argc, argv, optstring, opts, &opts_idx);
#else
		c = getopt (argc, argv, optstring);
#endif
		if (c == -1) break;

		switch (c)
		{
			case 'p':
				makeswf_set_dopreprocess(0);
				break;
			case 's':
				if ( sscanf(optarg, "%dx%d", &width, &height) != 2 )
				{
					usage(argv[0], EXIT_FAILURE);
				}
				break;
			case 'n':
			{
				if ( ! strcasecmp(optarg, "network") )
				{
					networkAccess = 1;
				}
				else if ( ! strcasecmp(optarg, "file") )
				{
					networkAccess = 0;
				}
				else
				{
					fprintf(stderr, "Network access must be 'network' or 'file'\n");
					exit(1);
				}
				break;
			}
			case 'v':
				if ( sscanf(optarg, "%d", &swfversion) != 1 )
				{
					usage(argv[0], EXIT_FAILURE);
				}
				makeswf_set_swfversion(swfversion);
				break;
			case 'b':
				if ( sscanf(optarg, "%lx", &bgcolor) != 1 )
				{
					usage(argv[0], EXIT_FAILURE);
				}
				useBgColor=1;
				break;
			case 'c':
				if ( sscanf(optarg, "%d", &swfcompression) != 1 )
				{
					usage(argv[0], EXIT_FAILURE);
				}
				if ( swfcompression < -1 || swfcompression > 9 )
				{
					fprintf(stderr, "Compression level must be in the range -1..9\n");
					exit(1);
				}
				break;
			case 'r':
				if ( sscanf(optarg, "%f", &framerate) != 1 )
				{
					usage(argv[0], EXIT_FAILURE);
				}
				break;
			case 'I':
				snprintf(buf, BUFSIZE-1, " -I%s", optarg);
				buf[BUFSIZE-1]='\0';
				makeswf_append_cpparg(buf);
				break;
			case 'i':
				add_import_spec(optarg);
				break;
			case 'o':
				outputfile = optarg;
				break;
			case 'D':
				// yes, you can smash the stack ... 
				snprintf(buf, BUFSIZE-1, " -D%s", optarg);
				buf[BUFSIZE-1]='\0';
				makeswf_append_cpparg(buf);
				break;
			case 'd':
				debug_parser = 1;
				break;
			case 'a':
				add_init_action_spec(optarg);
				break;
			case 'V':
				printf("%s\n", RCSID);
				printf("Copyright (C) 2001-2006 \"Sandro Santilli\" <*****@*****.**>.\n");
				printf("Released under the GNU General Public License.\n");
				exit(EXIT_SUCCESS);
			case 'h':
				usage(argv[0], EXIT_SUCCESS);
			default:
				usage(argv[0], EXIT_FAILURE);
				break;
		}
	}
	argv+=optind;
	argc-=optind;

	if ( argc < 1 ) usage(me, EXIT_FAILURE);

	if ( stat(outputfile, &statbuf) )
	{
		// should warn about overriding (-f ?)
	}

	if ( Ming_init() )
	{
		fprintf(stderr, "Ming initialization error\n");
		exit(EXIT_FAILURE);
	}
	Ming_setWarnFunction(warningHandler);
	//Ming_setErrorFunction(compileError);
	Ming_useSWFVersion(swfversion);
	Ming_setSWFCompression(swfcompression);

	mo = newSWFMovie();
	if ( networkAccess >= 0 ) SWFMovie_setNetworkAccess(mo, networkAccess);
	SWFMovie_setDimension(mo, (float)width, (float)height);
	SWFMovie_setRate(mo, framerate);

	if ( useBgColor )
	{
		SWFMovie_setBackground(mo,
			bgcolor >> 16,
			(bgcolor&0x00FF00) >> 8,
			(bgcolor&0x0000FF));
	}

	printf("Output file name: %s\n", outputfile);
	printf("Output compression level: %d\n", swfcompression);
	printf("Output SWF version: %d\n", swfversion);
	
	 /* 
	 * Add imports
	 */
	if ( numimport_specs ) add_imports();

	for ( i=0; i<argc; i++ )
	{
		SWFAction ac;
		char *filename = argv[i];
		char ppfile[PATH_MAX];

		FileType type = getFileType(filename);

		compile_init_actions(i, debug_parser);

		if ( type == SWF )
		{
			printf("Adding prebuilt clip %s to frame %d... ",
					filename, i);
			embed_swf(mo, filename);
		}
		else if ( type == BITMAP )
		{
			printf("Adding bitmap %s to frame %d... ",
					filename, i);
			embed_image(mo, filename);
		}
		else
		{
			sprintf(ppfile, "%s.frame%d.pp", outputfile, i);
			ac = makeswf_compile_source(filename, ppfile, 
				debug_parser);
			printf("Adding %s to frame %d... ", filename, i);
			SWFMovie_add(mo, (SWFBlock)ac);
		}

		printf("done.\n"); 
		usedfiles++;
		SWFMovie_nextFrame(mo);

	}

	if ( i <= max_init_action_frame )
	{
		fprintf(stderr, "WARNING: following init actions for frames > %d have been discarded:\n", i-1);
		for (;i<=max_init_action_frame; ++i)
		{
			print_init_actions(i, stderr);
		}
	}

	if ( ! usedfiles )
	{
		printf("No valid input files\n");
		return 1;
	}

	printf("Saving output to %s... ", outputfile);
	fflush(stdout);
	SWFMovie_save(mo, outputfile);
	printf("done.\n"); 

	return 0;
}
Esempio n. 22
0
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip  mc1, mc2, dejagnuclip;
  SWFDisplayItem it1, it2;
  
  const char *srcdir=".";
  if ( argc>1 ) 
    srcdir=argv[1];
  else
  {
      fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
      return 1;
  }

  Ming_init();
  mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  SWFMovie_setDimension(mo, 800, 600);
  SWFMovie_setRate (mo, 12.0);
  
  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  add_actions(mo, "testvar1 = 0; testvar2 = 0;");
  SWFMovie_nextFrame(mo); // frame1
  

  mc1 = newSWFMovieClip();
  SWFMovieClip_nextFrame(mc1);
  it1 = SWFMovie_add(mo, (SWFBlock)mc1);  
  SWFDisplayItem_setName(it1, "static_mc1");
  SWFDisplayItem_addAction(it1,
    newSWFAction(
        " this.createEmptyMovieClip('dyn1', 100); "
        " _root.check_equals(dyn1.getDepth(), 100);"
        " _root.dyn1Ref = dyn1;"
        // shouldn't be executed.
        " dyn1.onUnload = function () { _root.check(false); } ;"
        "trace(this);"
    ),
    SWFACTION_UNLOAD);  
  
  mc2 = newSWFMovieClip();
  SWFMovieClip_nextFrame(mc2);
  it2 = SWFMovie_add(mo, (SWFBlock)mc2);  
  SWFDisplayItem_setName(it2, "static_mc2");
  SWFDisplayItem_addAction(it2,
    newSWFAction(
       " this.createEmptyMovieClip('dyn2', 200); "
       " _root.check_equals(dyn2.getDepth(), 200);"
       " dyn2.onUnload = function () {_root.dyn2testvar = 'executed'; } ;"
    ),
    SWFACTION_ONLOAD);  
  SWFDisplayItem_addAction(it2,
    newSWFAction(
      " _root.check_equals(_level0.dyn1Ref.getDepth(), 100);"
      " _level0.dyn1Ref.swapDepths(101); "
      // Check that we can still swap the new child created in onClipUnload(mc1)
      // Note mc1 is already unloaded(this is in mc2.unload).
      " _root.check_equals(_level0.dyn1Ref.getDepth(), 101);"
    ),
    SWFACTION_UNLOAD); 
  SWFMovie_nextFrame(mo); // frame2

  SWFDisplayItem_remove(it1);
  SWFDisplayItem_remove(it2);
  SWFMovie_nextFrame(mo); // frame3
  
  check_equals(mo, "typeof(_root.dyn1Ref)", "'movieclip'");
  check_equals(mo, "_root.dyn1Ref.valueof()", "null");
  // check that dyn2.onUnload was triggered
  check_equals(mo, "_root.dyn2testvar", "'executed'");
  SWFMovie_nextFrame(mo); // frame4

  add_actions(mo, " _root.totals(7); stop(); ");
  SWFMovie_nextFrame(mo); // frame5 
  
  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Esempio n. 23
0
int
main(int argc, char** argv)
{
	SWFMovie mo;
	SWFMovieClip dejagnuclip;
	SWFDisplayItem it;

	char url_png[512];
    char url_indexpng[512];
    char url_greypng[512];
    char url_gif[512];
    char url_igif[512];

    char png_action[256];
    char indexpng_action[256];
    char greypng_action[256];
    char gif_action[256];
    char igif_action[256];


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

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

	sprintf(url_png, "%s/png.png", mediadir);
	sprintf(url_indexpng, "%s/indexed.png", mediadir);
	sprintf(url_greypng, "%s/greyscale.png", mediadir);
	sprintf(url_gif, "%s/gif.gif", mediadir);
	sprintf(url_igif, "%s/gif-interlaced.gif", mediadir);

	puts("Setting things up");

	Ming_init();
    Ming_useSWFVersion (OUTPUT_VERSION);
	Ming_setScale(20.0); /* so we talk pixels */
 
	mo = newSWFMovie();
    SWFMovie_setDimension (mo, 800, 600); 
    SWFMovie_setRate (mo, 12.0); 
    SWFMovie_setBackground (mo, 255, 255, 255); 

	/*****************************************************
	 *
	 * Add Dejagnu clip
	 *
	 *****************************************************/

	dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(mediadir), 10, 0, 0, 800, 600);
	it = SWFMovie_add(mo, (SWFBlock)dejagnuclip);
	SWFDisplayItem_moveTo(it, 0, 250);
	SWFMovie_nextFrame(mo); 

	/*****************************************************
	 *
	 * Add the clips
	 *
	 *****************************************************/

    sprintf(png_action, "_root.window.loadMovie(\"%s\");", url_png);
    add_button(mo, 50, 100, "Load PNG", newSWFAction(png_action));

    sprintf(indexpng_action, "_root.window.loadMovie(\"%s\");", url_indexpng);
    add_button(mo, 50, 125, "Load indexed PNG", newSWFAction(indexpng_action));

    sprintf(greypng_action, "_root.window.loadMovie(\"%s\");", url_greypng);
    add_button(mo, 50, 150, "Load greyscale PNG", newSWFAction(greypng_action));

    sprintf(gif_action, "_root.window.loadMovie(\"%s\");", url_gif);
    add_button(mo, 50, 175, "Load GIF", newSWFAction(gif_action));

    sprintf(igif_action, "_root.window.loadMovie(\"%s\");", url_igif);
    add_button(mo, 50, 200, "Load interlaced GIF", newSWFAction(igif_action));


	/*****************************************************
	 *
	 * Add the window clip
	 *
	 *****************************************************/

	puts("Adding window");

	add_window(mo, 600, 100);

	add_actions(mo, "stop();");
	SWFMovie_nextFrame(mo); /* showFrame */

	/*****************************************************
	 *
	 * Output movie
	 *
	 *****************************************************/

	puts("Saving " OUTPUT_FILENAME );

	SWFMovie_save(mo, OUTPUT_FILENAME);

	return 0;
}
Esempio n. 24
0
/// This test checks the event order of key events.
//
/// Known listeners are:
/// 1. MovieClips with a defined key event
/// 2. Button with a defined key event
/// 3. Anything added to Key listeners in ActionScript.
//
/// The test adds objects in this order:
//
/// Frame 1:
/// 1. mc1
/// 3. button1 (responds to 'a')
/// 3. o1 (actionscript key listener object)
/// 4. mc2
///
/// Frame 2:
/// 5. button2 (responds to 'a')
/// 6. button3 (responds to 'b')
/// 3. o2 (actionscript key listener object)
//
/// The test shows that, irrespective of construction order:
/// 1. MovieClips are notified first
/// 2. ActionScript listeners are notified second.
/// 3. Buttons are notified last.
//
/// Additionally:
//
/// 1. Only one button action can respond to any key.
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip mc, dejagnuclip;
  SWFButtonRecord br;
  SWFButton bu;
  SWFDisplayItem it1, it, it2;
  SWFShape sh1, sh2;

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

  Ming_init();
  mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  SWFMovie_setDimension(mo, 800, 600);

  SWFMovie_setRate (mo, 12.0);

  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir),
          10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);

  SWFMovie_nextFrame(mo);

  add_actions(mo,
          "_root.order = '';"
          "_root.note('Press \"a\" then \"b\"');"
          "_root.note('Do not press any other keys!');"
          );

  mc = newSWFMovieClip();
  it = SWFMovie_add(mo, (SWFBlock)mc);
  SWFDisplayItem_setName(it, "mc1");
  SWFDisplayItem_addAction(it,
          newSWFAction("trace('mc1'); _root.order += 'mc1,';"),
          SWFACTION_KEYDOWN);

  bu = newSWFButton();
  
  sh1 = make_fill_square(200, 0, 40, 40, 0, 0, 0, 0, 0, 0);
  sh2 = make_fill_square(200, 0, 40, 40, 0, 0, 0, 0, 255, 0);

  br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_HIT);
  SWFButtonRecord_setDepth(br, 3);
  
  br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_UP);
  SWFButtonRecord_setDepth(br, 4);

  br = SWFButton_addCharacter(bu, (SWFCharacter)sh2, SWFBUTTON_OVER);
  SWFButtonRecord_setDepth(br, 5);

  SWFButton_addAction(bu,
          newSWFAction("trace('button1'); _root.order += 'button1,';"),
		  SWFBUTTON_KEYPRESS('a'));

  it1 = SWFMovie_add(mo, (SWFBlock)bu);
  SWFDisplayItem_setName(it, "button1");

  SWFMovie_add(mo, newSWFAction(
              "o1 = {};"
              "o1.onKeyDown = function() {"
              "    trace('o1'); "
              "    _root.order += 'o1,';"
              "};"
              "Key.addListener(o1);"
              ));

  mc = newSWFMovieClip();
  it = SWFMovie_add(mo, (SWFBlock)mc);
  SWFDisplayItem_setName(it, "mc2");
  SWFDisplayItem_addAction(it,
          newSWFAction("trace('mc2'); _root.order += 'mc2,';"),
          SWFACTION_KEYDOWN);

  SWFMovie_nextFrame(mo); // Frame 2

  bu = newSWFButton();
  
  sh1 = make_fill_square(240, 0, 40, 40, 0, 0, 0, 0, 0, 0);
  sh2 = make_fill_square(240, 0, 40, 40, 0, 0, 0, 0, 255, 0);

  br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_HIT);
  SWFButtonRecord_setDepth(br, 3);
  
  br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_UP);
  SWFButtonRecord_setDepth(br, 4);

  br = SWFButton_addCharacter(bu, (SWFCharacter)sh2, SWFBUTTON_OVER);
  SWFButtonRecord_setDepth(br, 5);

  SWFButton_addAction(bu,
          newSWFAction("trace('button2'); _root.order += 'button2,';"),
		  SWFBUTTON_KEYPRESS('a'));

  it2 = SWFMovie_add(mo, (SWFBlock)bu);
  SWFDisplayItem_setName(it, "button2");
  
  bu = newSWFButton();
  
  sh1 = make_fill_square(280, 0, 40, 40, 0, 0, 0, 0, 0, 0);
  sh2 = make_fill_square(280, 0, 40, 40, 0, 0, 0, 0, 255, 0);

  br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_HIT);
  SWFButtonRecord_setDepth(br, 3);
  
  br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_UP);
  SWFButtonRecord_setDepth(br, 4);

  br = SWFButton_addCharacter(bu, (SWFCharacter)sh2, SWFBUTTON_OVER);
  SWFButtonRecord_setDepth(br, 5);

  SWFButton_addAction(bu,
          newSWFAction(
              "trace('button3'); "
              "_root.order += 'button3,';"
              "play();"
              ),
		  SWFBUTTON_KEYPRESS('b'));

  it = SWFMovie_add(mo, (SWFBlock)bu);
  SWFDisplayItem_setName(it, "button3");
  
  SWFMovie_add(mo, newSWFAction(
              "o2 = {};"
              "o2.onKeyDown = function() {"
              "    trace('o2'); "
              "    _root.order += 'o2,';"
              "};"
              "Key.addListener(o2);"
              "stop();"
              ));

  SWFMovie_nextFrame(mo);

  xcheck_equals(mo, "_root.order",
          "'mc2,mc1,o1,o2,button1,mc2,mc1,o1,o2,button3,'");
  
  SWFMovie_nextFrame(mo);

  SWFDisplayItem_remove(it2);
  
  add_actions(mo,
          "_root.order = '';"
          "_root.note('Press \"a\" then \"b\" again');"
          "_root.note('Do not press any other keys!');"
          "stop();"
          );
  SWFMovie_nextFrame(mo);

  // Check that removing the second button associated with 'a' does not
  // remove the key trigger for button2. There's no reason to think it should,
  // but it could happen if it's implemented badly!
  check_equals(mo, "_root.order",
          "'mc2,mc1,o1,o2,button1,mc2,mc1,o1,o2,button3,'");

  SWFMovie_add(mo, newSWFAction("stop();"));

  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
int
main(int argc, char** argv)
{
    SWFMovie mo;
    SWFMovieClip  mc_red, dejagnuclip;
    SWFShape  sh_red;

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

    Ming_init();
    mo = newSWFMovieWithVersion(OUTPUT_VERSION);
    SWFMovie_setDimension(mo, 800, 600);
    SWFMovie_setRate (mo, 1.0);

    dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
    SWFMovie_add(mo, (SWFBlock)dejagnuclip);
    SWFMovie_nextFrame(mo); /* 1st frame -  so we can use _root.note */

    mc_red = newSWFMovieClip();
    sh_red = make_fill_square (0, 300, 60, 60, 255, 0, 0, 255, 0, 0);
    SWFMovieClip_add(mc_red, (SWFBlock)sh_red);
    add_clip_actions(mc_red, " _root.note('frm1 of mc_red - gotoAndStop(2)'); "
                     "x = 'as_in_frm1_of_mc_red'; "
                     "gotoAndStop(2); ");
    SWFMovieClip_nextFrame(mc_red); /* 1st frame */
    add_clip_actions(mc_red, " _root.note('frm2 of mc_red - gotoAndStop(3)'); "
                     "x = 'as_in_frm2_of_mc_red'; "
                     "gotoAndStop(3); ");
    SWFMovieClip_nextFrame(mc_red); /* 2nd frame */
    add_clip_actions(mc_red, " _root.note('frm3 of mc_red - gotoAndStop(4)'); "
                     "x = 'as_in_frm3_of_mc_red'; "
                     "gotoAndStop(4); ");
    SWFMovieClip_nextFrame(mc_red); /* 3rd frame */
    SWFMovieClip_nextFrame(mc_red); /* 4th frame */


    SWFDisplayItem it_red;
    it_red = SWFMovie_add(mo, (SWFBlock)mc_red);
    SWFDisplayItem_setDepth(it_red, 3);
    SWFDisplayItem_setName(it_red, "mc_red");

    add_actions(mo, " _root.note('frm2 of root - gotoAndStop(3)'); "
                "mc_red.x = 'as_in_frm2_of_root'; "
                "gotoAndStop(3); ");
    SWFMovie_nextFrame(mo); /* 2nd frame */

    /* mc_red.x has been set after playing the 1st frame, check it here */
    add_actions(mo, " check_equals(mc_red.x, 'as_in_frm1_of_mc_red'); "
                " _root.note('frm3 of root - gotoAndStop(4)');"
                "mc_red.x = 'as_in_frm3_of_root'; "
                "gotoAndStop(4); ");
    SWFMovie_nextFrame(mo); /* 3rd frame */

    /* mc_red.x has been set again after playing the 2nd frame, check it again */
    add_actions(mo, " check_equals(mc_red.x, 'as_in_frm2_of_mc_red'); "
                " _root.note('frm4 of root - gotoAndStop(5)');"
                " mc_red.x = \"as_in_frm4_of_root\"; "
                " gotoAndStop(5); ");
    SWFMovie_nextFrame(mo); /* 4th frame */

    /* mc_red.x has been set again after playing the 3rd frame, check it again */
    check_equals(mo, "mc_red.x", "'as_in_frm3_of_mc_red'");
    add_actions(mo, " _root.totals(); stop(); ");
    SWFMovie_nextFrame(mo); /* 5th frame */

    /* Output movie */
    puts("Saving " OUTPUT_FILENAME );
    SWFMovie_save(mo, OUTPUT_FILENAME);

    return 0;
}
Esempio n. 26
0
int
main(int argc, char** argv)
{
  
  SWFMovie mo;
  SWFMovieClip dejagnuclip;
  SWFMorph morph;
  SWFShape startShape, endShape;
  SWFDisplayItem it;
  float ratio;


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

  Ming_init();
  mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  SWFMovie_setDimension(mo, 800, 600);
  SWFMovie_setRate (mo, 1.0);

  // _root.frame1
  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  SWFMovie_nextFrame(mo); 

  // _root.frame2, define and place a morph
  morph =  newSWFMorphShape();
  startShape = SWFMorph_getShape1(morph);
  make_shape(startShape, 0, 0, 100, 100, 255, 0 ,0);
  endShape = SWFMorph_getShape2(morph);
  make_shape(endShape, 700, 500, 100, 100, 0, 255 ,0);

  it = SWFMovie_add(mo, (SWFBlock)morph); 
  SWFMovie_nextFrame(mo); 
  
  // update the morph with different ratios
  for(ratio=0.2; ratio<1.01; ratio+=0.2)
  {
     SWFDisplayItem_remove(it);
     it = SWFMovie_add(mo, (SWFBlock)morph);
     SWFDisplayItem_setRatio(it, ratio);
     SWFMovie_nextFrame(mo);     
  }

  /* Test for #39989 by adding an empty morph shape. */
  morph = newSWFMorphShape();
  startShape = SWFMorph_getShape1(morph);
  endShape = SWFMorph_getShape2(morph);
  it = SWFMovie_add(mo, (SWFBlock)morph);
  SWFMovie_nextFrame(mo);
  
  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Esempio n. 27
0
int
main(int argc, char** argv)
{
	SWFMovie mo;
	const char *srcdir=".";
	SWFMovieClip  dejagnuclip;


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

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

	puts("Setting things up");

	Ming_init();
  Ming_useSWFVersion (OUTPUT_VERSION);
	Ming_setScale(20.0); /* let's talk pixels */
 
	mo = newSWFMovie();
	SWFMovie_setRate(mo, 12);
	SWFMovie_setDimension(mo, 640, 400);

	/*********************************************
	 *
	 * Body
	 *
	 *********************************************/

	dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 80, 800, 600);
	SWFMovie_add(mo, (SWFBlock)dejagnuclip);
	addRedSquareExport(mo);
	/* it seems we need a SHOWFRAME for this to be effective */
	/* (maybe it's related to loop-back handling ?) */
	SWFMovie_nextFrame(mo);  /* end of frame1 */

	add_actions(mo, "counter = 1; onLoadCalled = new Array();");

	add_actions(mo,
		"var name1 = 'square'+counter;"
		"attachMovie('redsquare', name1, 70+counter);"
		"var clip1 = this[name1];"
		"counter++;"
		);

	SWFMovie_nextFrame(mo); /* end of frame2 */

	add_actions(mo,
		"function CustomClass() { this._x = 80; }"
		"CustomClass.prototype.onLoad = function() { note(this+'.onLoad called'); _root.onLoadCalled.push(this); };"
		"registerClassRet = Object.registerClass('redsquare', CustomClass);"
		);

	check_equals(mo, "typeof(registerClassRet)", "'boolean'");
	check_equals(mo, "registerClassRet", "true");

	add_actions(mo,
		"var name2 = 'square'+counter;"
		"attachMovie('redsquare', name2, 70+counter);"
		"var clip2 = this[name2];"
		"counter++;"
		);


	SWFMovie_nextFrame(mo); /* end of frame3 */

	add_actions(mo,
		"function CustomClass2() { this._x = 160; check_equals(typeof(super.lineTo), 'function'); }"
		"CustomClass2.prototype = new MovieClip;"
		"registerClassRet = Object.registerClass('redsquare', CustomClass2);"
		);

	check_equals(mo, "_root.onLoadCalled.length", "1");
	check_equals(mo, "_root.onLoadCalled[0]", "_level0.square2");
	check_equals(mo, "typeof(registerClassRet)", "'boolean'");
	check_equals(mo, "registerClassRet", "true");

	add_actions(mo,
		"var name3 = 'square'+counter;"
		"attachMovie('redsquare', name3, 70+counter);"
		"var clip3 = this[name3];"
		"counter++;"
		);

	SWFMovie_nextFrame(mo); /* end of frame4 */

	add_actions(mo,
		"registerClassRet = Object.registerClass('redsquare');"
		);

	check_equals(mo, "typeof(registerClassRet)", "'boolean'");
	check_equals(mo, "registerClassRet", "false");

	add_actions(mo,
		"var name4 = 'square'+counter;"
		"attachMovie('redsquare', name4, 70+counter);"
		"var clip4 = this[name4];"
		"clip4._x = 240;"
		"counter++;"
		);

	SWFMovie_nextFrame(mo); /* end of frame5 */

	check_equals(mo, "typeof(clip1)", "'movieclip'");
	check(mo, "clip1 instanceOf MovieClip");
	check_equals(mo, "clip1._x", "0");
	check(mo, "! clip1 instanceOf CustomClass");
	
	// Check that non-enumerable properties (unnamed instances,
	// constructor, __constructor__) are not enumerated.
	add_actions(mo, "var s = ''; for (i in clip1) { s += i + ','; };");
	check_equals(mo, "s", "'onRollOver,'");

	check_equals(mo, "typeof(clip2)", "'movieclip'");
	check(mo, "clip2 instanceOf CustomClass");
	check(mo, "clip2.hasOwnProperty('__constructor__')");
	check(mo, "clip2.hasOwnProperty('constructor')");
	check(mo, "clip2.hasOwnProperty('__proto__')");
	check_equals(mo, "clip2.__proto__", "CustomClass.prototype");
	check_equals(mo, "clip2.__constructor__", "CustomClass");
	check_equals(mo, "clip2.constructor", "CustomClass");
	check_equals(mo, "clip2._x", "80");
	check_equals(mo, "typeof(clip2.lineTo)", "'undefined'");
	check(mo, "! clip2 instanceOf MovieClip");
	
	// Check that non-enumerable properties (unnamed instances,
	// constructor, __constructor__) are not enumerated.
	add_actions(mo, "var s = ''; for (i in clip2) { s += i + ','; };");
	check_equals(mo, "s", "'onLoad,onRollOver,'");

	check(mo, "clip3.hasOwnProperty('__constructor__')");
	check(mo, "clip3.hasOwnProperty('constructor')");
	check(mo, "clip3.hasOwnProperty('__proto__')");
	check_equals(mo, "clip3.__proto__", "CustomClass2.prototype");
	check_equals(mo, "clip3.__constructor__", "CustomClass2");
	check_equals(mo, "clip3.constructor", "CustomClass2");
	check_equals(mo, "typeof(clip3)", "'movieclip'");
	check_equals(mo, "clip3._x", "160");
	check(mo, "clip3 instanceOf CustomClass2");
	check(mo, "clip3 instanceOf MovieClip");
	
	// Check that non-enumerable properties (unnamed instances,
	// constructor, __constructor__) are not enumerated.
	add_actions(mo, "var s = ''; for (i in clip3) { s += i + ','; };");
	check_equals(mo, "s", "'onRollOver,'");

	check(mo, "clip4.hasOwnProperty('__constructor__')");
	check(mo, "clip4.hasOwnProperty('constructor')");
	check(mo, "clip4.hasOwnProperty('__proto__')");
	check_equals(mo, "clip4.__proto__", "CustomClass2.prototype");
	check_equals(mo, "clip4.__constructor__", "CustomClass2");
	check_equals(mo, "clip4.constructor", "CustomClass2");
	check_equals(mo, "typeof(clip4)", "'movieclip'");
	check_equals(mo, "clip4._x", "240");
	check(mo, "clip4 instanceOf MovieClip");

	add_actions(mo,
		"totals(47);"
		"stop();"
		);

	SWFMovie_nextFrame(mo); /* end of frame5 */

	/*****************************************************
	 *
	 * Output movie
	 *
	 *****************************************************/

	puts("Saving " OUTPUT_FILENAME );

	SWFMovie_save(mo, OUTPUT_FILENAME);

	return 0;
}
Esempio n. 28
0
SWFDisplayItem
add_button(SWFMovie mo)
{
	SWFDisplayItem it;
	SWFMovieClip mc;
	SWFButtonRecord br;
	SWFShape sh1, sh2, sh3, sh4, sh1a, sh2a, sh3a, sh4a;
	SWFButton bu = newSWFButton();
	static SWFMovieClip ermc; /* Events-reporting mc */
	mc = newSWFMovieClip();

	if ( ! ermc )
	{
		ermc = newSWFMovieClip();
		SWFMovieClip_add(ermc, newSWFAction(
			"_global.dumpObj = function(o,indent) {"
			"	var s = '';"
			"	if ( typeof(o) == 'object' ) {"
			"		s += '{';"
			"		var first=1;"
			"		for (var i in o) {"
			"			if (!first) s+=',';"
			"			s+= i+':'+dumpObj(o[i]);"
			"			first=0;"
			"		}"
			"		s += '}';"
			"	} else {"
			"		s += o;"
			"	}"
			"	return s;"
			"};"
			"if ( _root.buttonChild == undefined ) _root.buttonChild = [];"
			"var myDepth = getDepth()+16383;"
			"var myName = ''+this;"
			"if ( _root.buttonChild[myDepth] == undefined ) _root.buttonChild[myDepth] = {nam:myName,exe:1,uld:0};"
			"else _root.buttonChild[myDepth]['exe']++;"
			 //"_root.note('Actions in frame0 of '+this+' at depth '+myDepth+' executed.');" 
			"this.onUnload = function() {"
			"	var myDepth = -(getDepth()+32769-16383);"
			//"	_root.note(''+this+' at depth '+myDepth+' unloaded.');"
			"	_root.buttonChild[myDepth]['uld']++;"
			"};"
            "for (i in _level0.square1.button) { trace (i); };"
			//"_root.note('buttonChilds:'+dumpObj(_root.buttonChild));"
		));
		SWFMovieClip_nextFrame(ermc);
	}

	sh1 = make_fill_square(0, 0, 40, 40, 0, 0, 0, 0, 0, 0);
	sh1a = make_fill_square(30, 30, 5, 5, 128, 128, 128, 128, 128, 128);
	sh2 = make_fill_square(0, 0, 40, 40, 255, 0, 0, 255, 0, 0);
	sh2a = make_fill_square(30, 30, 5, 5, 128, 0, 0, 128, 0, 0);
	sh3 = make_fill_square(0, 0, 40, 40, 0, 255, 0, 0, 255, 0);
	sh3a = make_fill_square(30, 30, 5, 5, 0, 128, 0, 0, 128, 0);
	sh4 = make_fill_square(0, 0, 40, 40, 255, 255, 0, 255, 255, 0);
	sh4a = make_fill_square(30, 30, 5, 5, 128, 128, 0, 128, 128, 0);

	/* Higher depth DisplayObject is intentionally added before lower depth one */
	br = SWFButton_addCharacter(bu, (SWFCharacter)sh1a, SWFBUTTON_HIT);
	SWFButtonRecord_setDepth(br, 2);
	br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_HIT);
	SWFButtonRecord_setDepth(br, 1);

	/* Higher depth DisplayObject is intentionally added before lower depth one */
	br = SWFButton_addCharacter(bu, (SWFCharacter)sh2a, SWFBUTTON_UP );
	SWFButtonRecord_setDepth(br, 2);
	br = SWFButton_addCharacter(bu, (SWFCharacter)sh2, SWFBUTTON_UP );
	SWFButtonRecord_setDepth(br, 1);

	/* Higher depth DisplayObject is intentionally added before lower depth one */
	br = SWFButton_addCharacter(bu, (SWFCharacter)sh3a, SWFBUTTON_DOWN );
	SWFButtonRecord_setDepth(br, 2);
	br = SWFButton_addCharacter(bu, (SWFCharacter)sh3, SWFBUTTON_DOWN );
	SWFButtonRecord_setDepth(br, 1);

	/* Higher depth DisplayObject is intentionally added before lower depth one */
	br = SWFButton_addCharacter(bu, (SWFCharacter)sh4a, SWFBUTTON_OVER );
	SWFButtonRecord_setDepth(br, 2);
	br = SWFButton_addCharacter(bu, (SWFCharacter)sh4, SWFBUTTON_OVER );
	SWFButtonRecord_setDepth(br, 1);

	/* Add events reported DisplayObject in all states at depth 10 */
	br = SWFButton_addCharacter(bu, (SWFCharacter)ermc, SWFBUTTON_HIT|SWFBUTTON_DOWN|SWFBUTTON_OVER|SWFBUTTON_UP);
	SWFButtonRecord_setDepth(br, 10);

	/* Add events reported DisplayObject just HIT state at depth 11 */
	br = SWFButton_addCharacter(bu, (SWFCharacter)ermc, SWFBUTTON_HIT);
	SWFButtonRecord_setDepth(br, 11);

	/* Add events reported DisplayObject just UP state at depth 12 */
	br = SWFButton_addCharacter(bu, (SWFCharacter)ermc, SWFBUTTON_UP);
	SWFButtonRecord_setDepth(br, 12);

	/* Add events reported DisplayObject just OVER state at depth 13 */
	br = SWFButton_addCharacter(bu, (SWFCharacter)ermc, SWFBUTTON_OVER);
	SWFButtonRecord_setDepth(br, 13);

	/* Add events reported DisplayObject just DOWN state at depth 14 */
	br = SWFButton_addCharacter(bu, (SWFCharacter)ermc, SWFBUTTON_DOWN);
	SWFButtonRecord_setDepth(br, 14);


	SWFButton_addAction(bu, compileSWFActionCode(
		"_root.msg='MouseOut';"
		"if ( _root.testno == 4 || _root.testno == 9 || _root.testno == 14 ) {"
		"	_root.check_equals(_root.printBounds(getBounds()), '-0.05,-0.05 40.05,40.05');"
		/* Target of button action is the button's parent sprite */
		"	_root.check_equals(_target, '/square1');"
		"	setTarget('/');"
		"	_root.check_equals(_target, '/');"
		"	_root.testno++;"
		"	_root.note(_root.testno+'. Press mouse button inside the square, and release it outside.');"
		"} else {"
		//"	_root.note('SWFBUTTON_MOUSEOUT');"
		"	_root.xfail('Unexpectedly got SWFBUTTON_MOUSEOUT event (testno:'+_root.testno+')');"
		"}"
		), SWFBUTTON_MOUSEOUT);

	SWFButton_addAction(bu, compileSWFActionCode(
		"_root.msg='MouseOver';"

		"if ( _root.testno == 1 ) {" /* ONLY CHECK buttonChild on first frame */

		/* "_root.note('buttonChild is '+dumpObj(_root.buttonChild));" */

		/* added OVER state char */
		"	_root.check_equals(_root.buttonChild.realLength(), 3);"

		/* OVER state char loaded */
		"	_root.check_equals(typeof(_root.buttonChild[13]), 'object');"
		"	_root.check_equals(_root.buttonChild[13].nam, '_level0.square1.button.instance7');"
		"	_root.check_equals(_root.buttonChild[13].exe, 1);" /* OVER state char */
		"	_root.check_equals(_root.buttonChild[13].uld, 0);" /* OVER state char */

		/* UP state char unloaded */
		"	_root.check_equals(_root.buttonChild[12].exe, 1);"
		"	_root.check_equals(_root.buttonChild[12].uld, 1);"
		"	_root.check_equals(typeof(_level0.square1.button.instance6), 'movieclip');"
		"	_root.check_equals(_level0.square1.button.instance6._name, 'instance6');"
		"	_root.check_equals(_level0.square1.button.instance6.getDepth(), -16398);"

		/* ALL state char still there, not reloaded, not unloaded */
		"	_root.check_equals(_root.buttonChild[10].exe, 1);"
		"	_root.check_equals(_root.buttonChild[10].uld, 0);"

		"}"

		"if ( _root.testno == 1 || _root.testno == 6 || _root.testno == 11 ) {"

		//"	_root.note('buttonChild is '+dumpObj(_root.buttonChild));"
		"	_root.check_equals(_root.printBounds(getBounds()), '-0.05,-0.05 40.05,40.05');"
		/* Target of button action is the button's parent sprite */
		"	_root.check_equals(_target, '/square1');"
		"	setTarget('/');"
		"	_root.check_equals(_target, '/');"
		"	_root.testno++;"
		"	_root.note(_root.testno+'. Press (and keep pressed) the mouse button inside the square.');"
		"} else {"
		//"	_root.note('SWFBUTTON_MOUSEOVER');"
		// need MOUSEOVER for MOUSEUPOUTSIDE
		"	if ( _root.testno != 5 && _root.testno != 10 && _root.testno != 15 ) {"
		"		_root.fail('Unexpectedly got SWFBUTTON_MOUSEOVER event (testno:'+_root.testno+')');"
		"	}"
		"}"
		), SWFBUTTON_MOUSEOVER);

	SWFButton_addAction(bu, compileSWFActionCode(
		"_root.msg='MouseDown';"

		"if ( _root.testno == 2 ) {" /* ONLY CHECK buttonChild on first frame */

		/* Added DOWN state char */
		"	_root.check_equals(_root.buttonChild.realLength(), 4);"

		/* DOWN state char loaded */
		"	_root.check_equals(typeof(_root.buttonChild[14]), 'object');"
		"	_root.check_equals(_root.buttonChild[14].nam, '_level0.square1.button.instance8');"
		"	_root.check_equals(_root.buttonChild[14].exe, 1);" 
		"	_root.check_equals(_root.buttonChild[14].uld, 0);" 

		/* OVER state char unloaded */
		"	_root.check_equals(_root.buttonChild[13].exe, 1);" 
		"	_root.check_equals(_root.buttonChild[13].uld, 1);"

		/* ALL state char still there, not reloaded, not unloaded */
		"	_root.check_equals(_root.buttonChild[10].exe, 1);"
		"	_root.check_equals(_root.buttonChild[10].uld, 0);"

		"}"

		"if ( _root.testno == 2 || _root.testno == 7 || _root.testno == 12 ) {"
		"	_root.check_equals(_root.printBounds(getBounds()), '-0.05,-0.05 40.05,40.05');"
		/* Target (and name) of button action is the button's parent sprite */
		"	_root.check_equals(_target, '/square1');"
		"	_root.check_equals(_name, 'square1');"
		"	setTarget('/');"
		"	_root.check_equals(_target, '/');"
		"	_root.check_equals(typeof(_name), 'string');"
		"	_root.check_equals(_name, '');"
		"	_root.testno++;"
		"	_root.note(_root.testno+'. Depress the mouse button inside the square.');"
		"} else {"
		//"	_root.note('SWFBUTTON_MOUSEDOWN');"
		// need MOUSEDOWN for MOUSEUPOUTSIDE
		"	if ( _root.testno != 5 && _root.testno != 10 && _root.testno != 15 ) {"
		"		_root.fail('Unexpectedly got SWFBUTTON_MOUSEDOWN event (testno:'+_root.testno+')');"
		"	}"
		"}"
		), SWFBUTTON_MOUSEDOWN);

	SWFButton_addAction(bu, compileSWFActionCode(
		"_root.msg='MouseUp';"
		"if ( _root.testno == 3 || _root.testno == 8 || _root.testno == 13 ) {"
		"	_root.check_equals(_root.printBounds(getBounds()), '-0.05,-0.05 40.05,40.05');"
		/* Target of button action is the button's parent sprite */
		"	_root.check_equals(_target, '/square1');"
		"	setTarget('/');"
		"	_root.check_equals(_target, '/');"
		"	_root.testno++;"
		"	_root.note(_root.testno+'. Move the mouse pointer off the square.');"
		"} else {"
		//"	_root.note('SWFBUTTON_MOUSEUP');"
		"	_root.fail('Unexpectedly got SWFBUTTON_MOUSEUP event (testno:'+_root.testno+')');"
		"}"
		), SWFBUTTON_MOUSEUP);

	/* SWFBUTTON_MOUSEUPOUTSIDE *should* be invoked !! */
	SWFButton_addAction(bu, compileSWFActionCode(
		"_root.msg='MouseUpOutside';"
		"if ( _root.testno == 5 || _root.testno == 10 || _root.testno == 15 ) {"
		"	_root.check_equals(_root.printBounds(getBounds()), '-0.05,-0.05 40.05,40.05');"
		/* Target of button action is the button's parent sprite */
		"	_root.check_equals(_target, '/square1');"
		"	_root.check_equals(_name, 'square1');"
		"	setTarget('/');"
		"	_root.check_equals(_target, '/');"
		"	_root.nextFrame();"
		"} else {"
		//"	_root.note('SWFBUTTON_MOUSEUPOUTSIDE');"
		"	_root.fail('Unexpectedly got SWFBUTTON_MOUSEUPOUTSIDE event (testno:'+_root.testno+')');"
		"}"
		), SWFBUTTON_MOUSEUPOUTSIDE);

	/* Keypress */
	SWFButton_addAction(bu, compileSWFActionCode(
		"_root.note('KeyPress: a');"
		//"_root.check(Key.isDown('a'));"
	), SWFBUTTON_KEYPRESS('a'));
	SWFButton_addAction(bu, compileSWFActionCode(
		"_root.note('KeyPress: b');"
		//"_root.check(Key.isDown('b'));"
	), SWFBUTTON_KEYPRESS('b'));

	it = SWFMovieClip_add(mc, (SWFBlock)bu);
	SWFDisplayItem_setName(it, "button");
	SWFMovieClip_nextFrame(mc); /* showFrame */

	it = SWFMovie_add(mo, (SWFBlock)mc);
	return it;
}
int
main(int argc, char** argv)
{
  SWFMovie mo;
  SWFMovieClip  mc_red1, mc_red2, mc_red3, mc_red4, mc_red5, dejagnuclip;
  SWFDisplayItem it_red1, it_red2, it_red3, it_red4, it_red5;
  SWFShape  sh_red;

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

  Ming_init();
  mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  SWFMovie_setDimension(mo, 800, 600);
  SWFMovie_setRate (mo, 12.0);

  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  SWFMovie_nextFrame(mo); /* 1st frame */

  
  mc_red1 = newSWFMovieClip();
  sh_red = make_fill_square (0, 300, 60, 60, 255, 0, 0, 255, 0, 0);
  SWFMovieClip_add(mc_red1, (SWFBlock)sh_red);  
  add_clip_actions(mc_red1, " _root.x1 += \"depth10+\"; ");
  SWFMovieClip_nextFrame(mc_red1); /* mc_red1, 1st frame */
  add_clip_actions(mc_red1, " _root.x2 += \"depth10+\"; stop(); ");
  SWFMovieClip_nextFrame(mc_red1); /* mc_red1, 2nd frame */
 
  mc_red2 = newSWFMovieClip();
  sh_red = make_fill_square (80, 300, 60, 60, 255, 0, 0, 255, 0, 0);
  SWFMovieClip_add(mc_red2, (SWFBlock)sh_red); 
  add_clip_actions(mc_red2, " _root.x1 += \"depth12+\"; "); 
  SWFMovieClip_nextFrame(mc_red2); /* mc_red2, 1st frame */
  add_clip_actions(mc_red2, " _root.x2 += \"depth12+\"; stop(); "); 
  SWFMovieClip_nextFrame(mc_red2); /* mc_red2, 2nd frame */
  
  mc_red3 = newSWFMovieClip();
  sh_red = make_fill_square (160, 300, 60, 60, 255, 0, 0, 255, 0, 0);
  SWFMovieClip_add(mc_red3, (SWFBlock)sh_red);  
  add_clip_actions(mc_red3, " _root.x1 += \"depth11+\"; "); 
  SWFMovieClip_nextFrame(mc_red3); /* mc_red3, 1st frame */
  add_clip_actions(mc_red3, " _root.x2 += \"depth11+\";  stop();"); 
  SWFMovieClip_nextFrame(mc_red3); /* mc_red3, 2nd frame */
  
  
  /* add mc_red1 to _root and name it as "mc_red1" */
  it_red1 = SWFMovie_add(mo, (SWFBlock)mc_red1);  
  SWFDisplayItem_setDepth(it_red1, 10); 
  SWFDisplayItem_setName(it_red1, "mc_red1"); 
  
  /* add mc_red2 to _root and name it as "mc_red2" */
  it_red2 = SWFMovie_add(mo, (SWFBlock)mc_red2);  
  SWFDisplayItem_setDepth(it_red2, 12); 
  SWFDisplayItem_setName(it_red2, "mc_red2"); 
  
  /* add mc_red3 to _root and name it as "mc_red3" */
  it_red3 = SWFMovie_add(mo, (SWFBlock)mc_red3);  
  SWFDisplayItem_setDepth(it_red3, 11); 
  SWFDisplayItem_setName(it_red3, "mc_red3"); 
  
  SWFMovie_nextFrame(mo); /* 2nd frame */

  /* Action order is not dependent on DisplayList depth here! */
  check_equals(mo, "_root.x1", "'depth10+depth12+depth11+'");
  SWFMovie_nextFrame(mo); /* 3rd frame */

  mc_red4 = newSWFMovieClip();
  sh_red = make_fill_square (240, 300, 60, 60, 255, 0, 0, 255, 0, 0);
  SWFMovieClip_add(mc_red4, (SWFBlock)sh_red);  
  add_clip_actions(mc_red4, " _root.x2 += \"depth9+\"; "); 
  SWFMovieClip_nextFrame(mc_red4); /* mc_red4, 1st frame */
  
   /* add mc_red4 to _root and name it as "mc_red4" */
  it_red4 = SWFMovie_add(mo, (SWFBlock)mc_red4);  
  SWFDisplayItem_setDepth(it_red4, 9); 
  SWFDisplayItem_setName(it_red4, "mc_red4"); 
  
  mc_red5 = newSWFMovieClip();
  sh_red = make_fill_square (240, 300, 60, 60, 255, 0, 0, 255, 0, 0);
  SWFMovieClip_add(mc_red5, (SWFBlock)sh_red);  
  add_clip_actions(mc_red5, " _root.x2 += \"depth13+\"; "); 
  SWFMovieClip_nextFrame(mc_red5); /* mc_red4, 1st frame */
  
  /* add mc_red5 to _root and name it as "mc_red5" */
  it_red5 = SWFMovie_add(mo, (SWFBlock)mc_red5);  
  SWFDisplayItem_setDepth(it_red5, 13); 
  SWFDisplayItem_setName(it_red5, "mc_red4"); 
  
  SWFMovie_nextFrame(mo); /* 4th frame */


  check_equals(mo, "_root.x2", "'depth11+depth12+depth10+depth9+depth13+'");
  add_actions(mo, " _root.totals(); stop(); ");
  SWFMovie_nextFrame(mo); /* 5th frame */
  
  
  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

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

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

  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);

  puts("Setting things up");

  Ming_init();
  Ming_useSWFVersion (OUTPUT_VERSION);
 
  mo = newSWFMovie();
  SWFMovie_setRate(mo, 1.0);
  SWFMovie_setDimension(mo, 800, 600);
  
  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10,
          0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  SWFMovie_nextFrame(mo); // 1st frame 

  /*********************************************
   *
   * Add some textfields
   *
   *********************************************/
  SWFBrowserFont bfont = newSWFBrowserFont("_sans");

  int y = 30;
  int inc = 30;

  it = add_text_field(mo, (SWFBlock)bfont, "Normal", 1, 2, 3,
          SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_setName(it, "tf1");
  
  y += inc;

  it = add_text_field(mo, (SWFBlock)bfont, "Transparent", 1, 2, 3,
          SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 0);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_setName(it, "tf2");
  
  y += inc;
  
  it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 16, no indent or "
          "margin", 0, 0, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 16, 1);
  SWFDisplayItem_setName(it, "tf3");

  y += inc;
  
  it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 16, indent 4",
          4, 0, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 16, 1);
  SWFDisplayItem_setName(it, "tf4");
  
  y += inc;
  
  it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 16, left margin 4",
          0, 4, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 16, 1);
  SWFDisplayItem_setName(it, "tf5");
  
  y += inc;
  it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 16, right margin 4",
          0, 0, 4, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 16, 1);
  SWFDisplayItem_setName(it, "tf6");
  
  y += inc;
  
  it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 16, left margin 4, "
          "indent 4", 4, 4, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 16, 1);
  SWFDisplayItem_setName(it, "tf7");
  
  y += inc;
  
  it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 8, no indent or margin",
          0, 0, 0, SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 8, 1);
  SWFDisplayItem_setName(it, "tf8");

  y += inc;
  
  it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 8, indent 4", 4, 0, 0,
          SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 8, 1);
  SWFDisplayItem_setName(it, "tf9");
  y += inc;
  
  it = add_text_field(mo, (SWFBlock)bfont, "X scaled by 0.2", 8, 8, 8,
          SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 0.2, 1);
  SWFDisplayItem_setName(it, "tf10");
  
  y += inc;
  
  it = add_text_field(mo, (SWFBlock)bfont, "Y scaled by 4", 4, 4, 0,
          SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 1, 4);
  SWFDisplayItem_setName(it, "tf11");
  
  y += inc * 3;
  
  it = add_text_field(mo, (SWFBlock)bfont, "Y scaled by 8", 4, 4, 0,
          SWFTEXTFIELD_ALIGN_LEFT, 10, 0, 0, 0, 255);
  SWFDisplayItem_moveTo(it, 50, y);
  SWFDisplayItem_scale(it, 1, 8);
  SWFDisplayItem_setName(it, "tf12");


  // As these are device fonts, it's not clear how consistent the textWidth
  // value will be. It's not even clear that it's worth testing it.

  check_equals(mo, "tf1._width", "84");
  check_equals(mo, "tf1._height", "20");
  xcheck_equals(mo, "tf1._x", "48");
  xcheck_equals(mo, "tf1._y", "28");
  xcheck_equals(mo, "tf1.textHeight", "24");
  // Approx 42
  xcheck(mo, "tf1.textWidth >= 40 && tf1.textWidth <= 45");

  check_equals(mo, "tf2._width", "84");
  check_equals(mo, "tf2._height", "20");
  xcheck_equals(mo, "tf2._x", "48");
  xcheck_equals(mo, "tf2._y", "58");
  xcheck_equals(mo, "tf2.textHeight", "24");
  // Approx 69
  xcheck(mo, "tf2.textWidth >= 66 && tf2.textWidth <= 72");

  check_equals(mo, "tf3._width", "1344");
  check_equals(mo, "tf3._height", "20");
  xcheck_equals(mo, "tf3._x", "18");
  xcheck_equals(mo, "tf3._y", "88");
  xcheck_equals(mo, "tf3.textHeight", "24");
  // Approx 13
  xcheck(mo, "tf3.textWidth >= 11 && tf3.textWidth <= 15");

  check_equals(mo, "tf4._width", "1344");
  check_equals(mo, "tf4._height", "20");
  xcheck_equals(mo, "tf4._x", "18");
  xcheck_equals(mo, "tf4._y", "118");
  xcheck_equals(mo, "tf4.textHeight", "24");
  // Approx 9
  xcheck(mo, "tf4.textWidth >= 7 && tf4.textWidth <= 11");

  check_equals(mo, "tf5._width", "1344");
  check_equals(mo, "tf5._height", "20");
  xcheck_equals(mo, "tf5._x", "18");
  xcheck_equals(mo, "tf5._y", "148");
  xcheck_equals(mo, "tf5.textHeight", "24");
  // Approx 10
  xcheck(mo, "tf5.textWidth >= 8 && tf5.textWidth <= 12");

  check_equals(mo, "tf6._width", "1344");
  check_equals(mo, "tf6._height", "20");
  xcheck_equals(mo, "tf6._x", "18");
  xcheck_equals(mo, "tf6._y", "178");
  xcheck_equals(mo, "tf6.textHeight", "24");
  // Approx 11
  xcheck(mo, "tf6.textWidth >= 9 && tf6.textWidth <= 13");

  check_equals(mo, "tf7._width", "1344");
  check_equals(mo, "tf7._height", "20");
  xcheck_equals(mo, "tf7._x", "18");
  xcheck_equals(mo, "tf7._y", "208");
  xcheck_equals(mo, "tf7.textHeight", "24");
  // Approx 14
  xcheck(mo, "tf7.textWidth >= 14 && tf7.textWidth <= 16");

  check_equals(mo, "tf8._width", "672");
  check_equals(mo, "tf8._height", "20");
  xcheck_equals(mo, "tf8._x", "34");
  xcheck_equals(mo, "tf8._y", "238");
  xcheck_equals(mo, "tf8.textHeight", "24");
  // Approx 25
  xcheck(mo, "tf8.textWidth >= 21 && tf8.textWidth <= 27");

  check_equals(mo, "tf9._width", "672");
  check_equals(mo, "tf9._height", "20");
  xcheck_equals(mo, "tf9._x", "34");
  xcheck_equals(mo, "tf9._y", "268");
  xcheck_equals(mo, "tf9.textHeight", "24");
  // Approx 16
  xcheck(mo, "tf9.textWidth >= 14 && tf9.textWidth <= 18");

  check_equals(mo, "tf10._width", "16.8");
  check_equals(mo, "tf10._height", "20");
  xcheck_equals(mo, "tf10._x", "49.6");
  xcheck_equals(mo, "tf10._y", "298");
  xcheck_equals(mo, "tf10.textHeight", "24");
  // Approx 452
  xcheck(mo, "tf10.textWidth >= 440 && tf10.textWidth <= 460");

  // The textHeight for the following two fields varies.
  check_equals(mo, "tf11._width", "84");
  check_equals(mo, "tf11._height", "80");
  xcheck_equals(mo, "tf11._x", "48");
  xcheck_equals(mo, "tf11._y", "322");
  add_actions(mo, "trace(tf11.textWidth);");
  xcheck(mo, "tf11.textHeight >= 23 && tf11.textHeight <= 24");
  // Approx 315
  xcheck(mo, "tf11.textWidth >= 305 && tf11.textWidth <= 325");

  check_equals(mo, "tf12._width", "84");
  check_equals(mo, "tf12._height", "160");
  xcheck_equals(mo, "tf12._x", "48");
  xcheck_equals(mo, "tf12._y", "404");
  add_actions(mo, "trace(tf12.textWidth);");
  xcheck(mo, "tf12.textHeight >= 23 && tf12.textHeight <= 24");
  // Approx 640
  xcheck(mo, "tf12.textWidth >= 625 && tf12.textWidth <= 655");

  add_actions(mo, "totals(); stop();");

  SWFMovie_nextFrame(mo); 

  /*****************************************************
   *
   * Output movie
   *
   *****************************************************/
  puts("Saving " OUTPUT_FILENAME );

  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}