
#include "ming.h"

int main()
{
  SWFMorph p;
  SWFBitmap b;
  SWFShape s;
  SWFMovie m;
  SWFFill f;
  SWFDisplayItem i;
  
  int n, width, height;
  
  Ming_init();
  Ming_setScale(1.0);

  p = newSWFMorphShape();

  b = newSWFJpegBitmap(fopen("../common/alphafill.jpg", "rb"));
  width = SWFBitmap_getWidth(b);
  height = SWFBitmap_getHeight(b);

  s = SWFMorph_getShape1(p);
  f = SWFShape_addBitmapFill(s, b, SWFFILL_TILED_BITMAP);

  SWFFill_moveTo(f, -width/2, -height/4);
  SWFFill_scaleXYTo(f, 1.0, 0.5);
  SWFShape_setLeftFill(s, f);
  SWFShape_movePenTo(s, -width/2, -height/4);
  SWFShape_drawLine(s, width, 0);
  SWFShape_drawLine(s, 0, height/2);
  SWFShape_drawLine(s, -width, 0);
  SWFShape_drawLine(s, 0, -height/2);

  s = SWFMorph_getShape2(p);
  f = SWFShape_addBitmapFill(s, b, SWFFILL_TILED_BITMAP);

  /* flash player buglet: these two have no effect! */
  SWFFill_moveTo(f, -width/4, -height/2);
  SWFFill_scaleXYTo(f, 0.5, 1.0);

  SWFShape_setLeftFill(s, f);
  SWFShape_movePenTo(s, -width/4, -height/2);
  SWFShape_drawLine(s, width/2, 0);
  SWFShape_drawLine(s, 0, height);
  SWFShape_drawLine(s, -width/2, 0);
  SWFShape_drawLine(s, 0, -height);

  m = newSWFMovie();
  SWFMovie_setDimension(m, width, height);

  i = SWFMovie_add(m, p);
  SWFDisplayItem_moveTo(i, width/2, height/2);

  for(n=0; n<100; n+=3)
  {
    SWFDisplayItem_setRatio(i, n/100.0);
    SWFMovie_nextFrame(m);
  }

  SWFMovie_save(m, "test.swf");

  exit(0);
}
