increased frame numbers by 1.
[swftools.git] / src / swfc.c
index 4d744ff..9e004fe 100644 (file)
@@ -40,6 +40,7 @@
 static char * filename = 0;
 static char * outputname = "output.swf";
 static int verbose = 2;
+static int optimize = 0;
 static int override_outputname = 0;
 
 static struct options_t options[] = {
@@ -47,6 +48,7 @@ static struct options_t options[] = {
 {"V", "version"},
 {"v", "verbose"},
 {"o", "output"},
+{"O", "optimize"},
 {0,0}
 };
     
@@ -61,6 +63,10 @@ int args_callback_option(char*name,char*val)
        override_outputname = 1;
        return 1;
     }
+    else if(!strcmp(name, "O")) {
+       optimize = 1;
+       return 0;
+    }
     else if(!strcmp(name, "v")) {
        verbose ++;
        return 0;
@@ -637,12 +643,15 @@ static void s_endSWF()
     swf = stack[stackpos].swf;
     filename = stack[stackpos].filename;
    
-    //tag = swf_InsertTag(tag, ST_SHOWFRAME); //?
-
+    tag = swf_InsertTag(tag, ST_SHOWFRAME);
     tag = swf_InsertTag(tag, ST_END);
 
     swf_OptimizeTagOrder(swf);
-
+   
+    if(optimize) {
+       swf_Optimize(swf);
+    }
+    
     if(!(swf->movieSize.xmax-swf->movieSize.xmin) || !(swf->movieSize.ymax-swf->movieSize.ymin)) {
        swf->movieSize = currentrect; /* "autocrop" */
     }
@@ -690,7 +699,7 @@ void s_close()
 
 int s_getframe()
 {
-    return currentframe;
+    return currentframe+1;
 }
 
 void s_frame(int nr, int cut, char*name)
@@ -698,6 +707,10 @@ void s_frame(int nr, int cut, char*name)
     int t;
     TAG*now = tag;
 
+    if(nr<1) 
+       syntaxerror("Illegal frame number");
+    nr--; // internally, frame 1 is frame 0
+
     for(t=currentframe;t<nr;t++) {
        tag = swf_InsertTag(tag, ST_SHOWFRAME);
        if(t==nr-1 && name && *name) {
@@ -705,6 +718,10 @@ void s_frame(int nr, int cut, char*name)
            swf_SetString(tag, name);
        }
     }
+    if(nr == 0 && currentframe == 0 && name) {
+        tag = swf_InsertTag(tag, ST_FRAMELABEL);
+        swf_SetString(tag, name);
+    }
 
     if(cut) {
        if(now == tag) {
@@ -924,6 +941,21 @@ void s_text(char*name, char*fontname, char*text, int size, RGBA color)
     incrementid();
 }
 
+void s_quicktime(char*name, char*url)
+{
+    SRECT r;
+    MATRIX _m,*m=0;
+
+    memset(&r, 0, sizeof(r));
+    
+    tag = swf_InsertTag(tag, ST_DEFINEMOVIE);
+    swf_SetU16(tag, id);
+    swf_SetString(tag, url);
+    
+    s_addcharacter(name, id, tag, r);
+    incrementid();
+}
+
 void s_edittext(char*name, char*fontname, int size, int width, int height, char*text, RGBA*color, int maxlength, char*variable, int flags)
 {
     SWFFONT*font;
@@ -1172,8 +1204,11 @@ void s_action(const char*text)
 int s_swf3action(char*name, char*action)
 {
     ActionTAG* a = 0;
-    instance_t* object = dictionary_lookup(&instances, name);
-    if(!object) {
+    instance_t* object = 0;
+    if(name) 
+       dictionary_lookup(&instances, name);
+    if(!object && name && *name) {
+       /* we have a name, but couldn't find it. Abort. */
        return 0;
     }
     a = action_SetTarget(0, name);
@@ -1221,7 +1256,10 @@ void s_outline(char*name, char*format, char*source)
 
 int s_playsound(char*name, int loops, int nomultiple, int stop)
 {
-    sound_t* sound = dictionary_lookup(&sounds, name);
+    sound_t* sound;
+    if(!name)
+       return 0;
+    sound = dictionary_lookup(&sounds, name);
     SOUNDINFO info;
     if(!sound)
        return 0;
@@ -1892,7 +1930,7 @@ static int c_play(map_t*args)
 
 static int c_stop(map_t*args) 
 {
-    char*name = lu(args, "name");
+    char*name = map_lookup(args, "name");
 
     if(s_playsound(name, 0,0,1)) {
        return 0;
@@ -2188,7 +2226,7 @@ static int c_frame(map_t*args)
     else {
        frame = parseInt(framestr);
        if(s_getframe() >= frame
-               && !(frame==0 && s_getframe()==frame)) // equality is o.k. for frame 0
+               && !(frame==1 && s_getframe()==frame)) // equality is o.k. for frame 0
            syntaxerror("frame expression must be >%d (is:%s)", s_getframe(), framestr);
     }
     s_frame(frame, cut, name);
@@ -2290,6 +2328,14 @@ static int c_soundtrack(map_t*args)
     return 0;
 }
 
+static int c_quicktime(map_t*args) 
+{
+    char*name = lu(args, "name");
+    char*url = lu(args, "url");
+    s_quicktime(name, url);
+    return 0;
+}
+
 static int c_image(map_t*args) 
 {
     char*command = lu(args, "commandname");
@@ -2513,6 +2559,7 @@ static struct {
  {"sound", c_sound, "name filename"},
  {"font", c_font, "name filename"},
  {"soundtrack", c_soundtrack, "filename"},
+ {"quicktime", c_quicktime, "url"},
 
     // generators of primitives
 
@@ -2540,7 +2587,7 @@ static struct {
  
     // control tags
  {"play", c_play, "name loop=0 @nomultiple=0"},
- {"stop", c_stop, "name"},
+ {"stop", c_stop, "name= "},
  {"nextframe", c_nextframe, "name"},
  {"previousframe", c_previousframe, "name"},