
#include <mingpp.h>

SWFFont *f;
SWFSprite *p;

SWFTextField *label(char *string)
{
  SWFTextField *t = new SWFTextField();
  t->setFont(f);
  t->addString(string);
  t->setHeight(200);
  t->setBounds(3200,200);
  return t;
}

void addLabel(char *string)
{
  SWFDisplayItem *i = p->add(label(string));
  p->nextFrame();
  p->remove(i);
}

SWFShape *rect(int r, int g, int b)
{
  SWFShape *s = new SWFShape();
  s->setRightFill(s->addSolidFill(r, g, b));
  s->drawLine(600,0);
  s->drawLine(0,600);
  s->drawLine(-600,0);
  s->drawLine(0,-600);

  return s;
}

int main()
{
  Ming_init();
  Ming_setScale(1.0);

  f = new SWFFont("_serif");
  p = new SWFSprite();

  p->add(new SWFAction("stop();"));
  addLabel("NO ACTION");
  addLabel("SWFBUTTON_MOUSEUP");
  addLabel("SWFBUTTON_MOUSEDOWN");
  addLabel("SWFBUTTON_MOUSEOVER");
  addLabel("SWFBUTTON_MOUSEOUT");
  addLabel("SWFBUTTON_MOUSEUPOUTSIDE");
  addLabel("SWFBUTTON_DRAGOVER");
  addLabel("SWFBUTTON_DRAGOUT");

  SWFButton *b = new SWFButton();
  b->addShape(rect(0xff, 0, 0), SWFBUTTON_UP | SWFBUTTON_HIT);
  b->addShape(rect(0, 0xff, 0), SWFBUTTON_OVER);
  b->addShape(rect(0, 0, 0xff), SWFBUTTON_DOWN);

  b->addAction(new SWFAction("setTarget('/label'); gotoFrame(1);"),
	        SWFBUTTON_MOUSEUP);

  b->addAction(new SWFAction("setTarget('/label'); gotoFrame(2);"),
		SWFBUTTON_MOUSEDOWN);

  b->addAction(new SWFAction("setTarget('/label'); gotoFrame(3);"),
		SWFBUTTON_MOUSEOVER);

  b->addAction(new SWFAction("setTarget('/label'); gotoFrame(4);"),
		SWFBUTTON_MOUSEOUT);

  b->addAction(new SWFAction("setTarget('/label'); gotoFrame(5);"),
		SWFBUTTON_MOUSEUPOUTSIDE);

  b->addAction(new SWFAction("setTarget('/label'); gotoFrame(6);"),
		SWFBUTTON_DRAGOVER);

  b->addAction(new SWFAction("setTarget('/label'); gotoFrame(7);"),
		SWFBUTTON_DRAGOUT);

  SWFMovie *m = new SWFMovie();
  m->setDimension(4000,3000);

  SWFDisplayItem *i;

  i = m->add(p);
  i->setName("label");
  i->moveTo(400,1900);

  i = m->add(b);
  i->moveTo(400,900);

  m->save("test.swf");

  exit(0);
}
