Example #1
0
static void swf_ShapeDrawerFinish(drawer_t*draw)
{
    SWFSHAPEDRAWER*sdraw = (SWFSHAPEDRAWER*)draw->internal;
    if(sdraw->isfinished)
	return;
	
    fixEndPoint(draw);

    if(sdraw->bbox.xmin == SCOORD_MAX) {
	/* no points at all -> empty bounding box */
	sdraw->bbox.xmin = sdraw->bbox.ymin = 
	sdraw->bbox.xmax = sdraw->bbox.ymax = 0;
    }
    sdraw->isfinished = 1;
    swf_ShapeSetEnd(sdraw->tag);
}
Example #2
0
int main (int argc,char ** argv)
{ SWF swf;
  TAG* t;
  RGBA rgb;
  SRECT r;
  SHAPE* s;
  S32 width = 800,height = 800;
  int fs,ls; // line & fillstyle
  JPEGBITS* jpeg;
  MATRIX m;  
  
  int f,i,j,frame;
  
  memset(&swf,0x00,sizeof(SWF));

  swf.fileVersion    = 4;
  swf.frameRate      = 0x4000;
  swf.movieSize.xmax = 4*width;
  swf.movieSize.ymax = 4*height;

  swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
  t = swf.firstTag;

        rgb.r = 0xff;
        rgb.g = 0xff;
        rgb.b = 0xff;
        swf_SetRGB(t,&rgb);

    t = swf_InsertTag(t,ST_DEFINEBITSJPEG2);

         swf_SetU16(t,ID_BITMAP);
         
         if (FAILED(swf_SetJPEGBits(t,"texture.jpg",QUALITY)))
         { fprintf(stderr,"Error: texture.jpg (256x256) not found in work directory.\n");
           exit(1);
         }
         
    t = swf_InsertTag(t,ST_DEFINESHAPE);
    
         swf_ShapeNew(&s);
         rgb.b = rgb.g = rgb.r = 0x00;
         ls = 0;
         rgb.b = 0xff;
  
         fs = swf_ShapeAddBitmapFillStyle(s,NULL,ID_BITMAP,0);
    
         swf_SetU16(t,ID_SHAPE);    // ID   
         
         r.xmin = 0;
         r.ymin = 0;
         r.xmax = 2*width;
         r.ymax = 2*height;
         
         swf_SetRect(t,&r);

         swf_SetShapeHeader(t,s);
         
         swf_ShapeSetAll(t,s,0,0,ls,fs,0);
         swf_ShapeSetLine(t,s,width,0);
         swf_ShapeSetLine(t,s,-width,height);
         swf_ShapeSetLine(t,s,0,-height);
         swf_ShapeSetEnd(t);

         swf_ShapeFree(s);
    
  for (frame=0;frame<64;frame++)
  {

    /* Test procedure for swf_MatrixJoin

    MATRIX m1,m2;

    // set m1 to left rotation
     
    m1.sy = m1.sx = (int)(cos(((float)(frame))/32*3.141)*0x10000);
    m1.r0 = (int)(sin(((float)(frame))/32*3.141)*0x10000);
    m1.r1 = -m1.r0;
    m1.tx = width+frame*4; m1.ty = height;

    // set m2 to right rotation

    m2.sy = m2.sx = (int)(cos(((float)(64-frame))/32*3.141)*0x10000);
    m2.r0 = (int)(sin(((float)(64-frame))/32*3.141)*0x10000);
    m2.r1 = -m2.r0;
    m2.tx = width; m2.ty = height;

    // joining m1 and m2 should lead to no transformation

    swf_MatrixJoin(&m,&m1,&m2);

    */

    int dx0 = width;    // constants of shape 
    int dy0 = width;

    int px0 = 2*width;  // destination of mapping
    int py0 = 2*width;

    int px1 = 3*width;
    int py1 = 2*width-frame*4;

    int px2 = 2*width-frame*8;
    int py2 = 3*width;

    swf_MatrixMapTriangle(&m,dx0,dy0,px0,py0,px1,py1,px2,py2);

    t = swf_InsertTag(t,ST_PLACEOBJECT2);

        if (!frame)
         swf_ObjectPlace(t,ID_SHAPE,1,&m,NULL,NULL);
        else
          swf_ObjectMove(t,1,&m,NULL);
 
    t = swf_InsertTag(t,ST_SHOWFRAME);
  }
  
  
  t = swf_InsertTag(t,ST_END);
  
//  swf_WriteCGI(&swf);

  f = open("transtest.swf",O_RDWR|O_CREAT|O_TRUNC|O_BINARY,0644);
  if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
  close(f);

  swf_FreeTags(&swf);

#ifdef __NT__
  system("start ..\\transtest.swf");
#endif
  
  return 0;
}
Example #3
0
int main (int argc,char ** argv)
{ SWF swf;
  TAG* t;
  RGBA rgb;
  SRECT r;
  SHAPE* s;
  S32 width=300,height = 300;
  
  int f,i,ls1,ls2;

  memset(&swf,0x00,sizeof(SWF));        // set global movie parameters

  swf.fileVersion    = 4;               // make flash 4 compatible swf
  swf.frameRate      = 0x1900;          // about 0x19 frames per second
  
  swf.movieSize.xmax = 20*width;        // flash units: 1 pixel = 20 units
  swf.movieSize.ymax = 20*height;

  swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);

                                        // now create a tag list be connecting one after another
  
  t = swf.firstTag;

        rgb.r = 0xff;
        rgb.g = 0xff;
        rgb.b = 0xff;
        swf_SetRGB(t,&rgb);

  t = swf_InsertTag(t,ST_DEFINESHAPE);

        swf_ShapeNew(&s);               // create new shape instance

                                        // add two different linestyles
        rgb.b = rgb.g = 0x00;           
        ls1 = swf_ShapeAddLineStyle(s,40,&rgb);
        
        rgb.r = 0; rgb.b = 0xff;
        ls2 = swf_ShapeAddLineStyle(s,40,&rgb);

        swf_SetU16(t,1);                // now set character ID

        r.xmin = 0;
        r.ymin = 0;
        r.xmax = 20*width;
        r.ymax = 20*height;
        
        swf_SetRect(t,&r);              // set shape bounds


        swf_SetShapeHeader(t,s);        // write all styles to tag

        swf_ShapeSetAll(t,s,0,0,ls1,0,0); // move to (0,0), select linestyle ls1 and no fillstyle

                                        
        swf_ShapeSetLine(t,s,10*width,10*height);    // draw something
        swf_ShapeSetStyle(t,s,ls2,0,0);            // change to second linestyle 
        
        for (i=1;i<10;i++)
          swf_ShapeSetCircle(t,s,10*width,10*height,i*width,i*height);
          
        swf_ShapeSetEnd(t);                 // finish drawing

        swf_ShapeFree(s);                   // clean shape structure (which isn't needed anymore after writing the tag)

  t = swf_InsertTag(t,ST_PLACEOBJECT2);     // append tag to place your shape into the scene

        swf_ObjectPlace(t,1,1,NULL,NULL,NULL); // set character with id 1 (our shape) to depth 1 (upper most layer)

  t = swf_InsertTag(t,ST_SHOWFRAME);        // finish current frame

  t = swf_InsertTag(t,ST_END);              // finish current movie (which has just one frame)
  
//  swf_WriteCGI(&swf);    <- use this to create direct CGI output
  
                                            // write movie to file

  f = open("shape1.swf",O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
  if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
  close(f);

  swf_FreeTags(&swf);                       // cleanup

#ifdef __NT__                               // start flash player to show result on windows systems
  system("start ..\\shape1.swf");
#endif
  
  return 0;
}