more horizontal refactoring
[swftools.git] / lib / modules / swfbutton.c
index cd9f464..40684aa 100644 (file)
@@ -7,9 +7,21 @@
 
    Copyright (c) 2000, 2001 Rainer Böhme <rfxswf@reflex-studio.de>
  
-   This file is distributed under the GPL, see file COPYING for details 
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
 
-*/
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+#include "../rfxswf.h"
 
 int swf_ButtonSetRecord(TAG * t,U8 state,U16 id,U16 layer,MATRIX * m,CXFORM * cx)
 
@@ -17,7 +29,7 @@ int swf_ButtonSetRecord(TAG * t,U8 state,U16 id,U16 layer,MATRIX * m,CXFORM * cx
   swf_SetU16(t,id);
   swf_SetU16(t,layer);
   swf_SetMatrix(t,m);
-  if (swf_GetTagID(t)==ST_DEFINEBUTTON2) swf_SetCXForm(t,cx,0);
+  if (swf_GetTagID(t)==ST_DEFINEBUTTON2) swf_SetCXForm(t,cx,1);
   return 0;
 }
 
@@ -63,7 +75,7 @@ int swf_ButtonPostProcess(TAG * t,int anz_action)
     { swf_GetU16(t);          // id
       swf_GetU16(t);          // layer
       swf_GetMatrix(t,NULL);  // matrix
-      swf_GetCXForm(t,NULL,0);// CXForm
+      swf_GetCXForm(t,NULL,1);// CXForm
     }
 
     swf_SetButtonOffset(t,offsetpos);
@@ -90,3 +102,47 @@ int swf_ButtonPostProcess(TAG * t,int anz_action)
   }
   return 0;
 }
+
+ActionTAG* swf_Button1GetAction(TAG*tag)
+{
+    swf_GetU16(tag); //button id
+    while(1)
+    {
+        U8 flags = swf_GetU8(tag);
+        if(!flags)
+            break; 
+        swf_GetU16(tag); //char
+        swf_GetU16(tag); //layer
+        swf_ResetReadBits(tag);
+        swf_GetMatrix(tag, NULL);
+    }
+    return swf_ActionGet(tag);
+}
+
+ActionTAG* swf_Button2GetAction(TAG*tag)
+{
+    swf_GetU16(tag); //button id
+    swf_GetU8(tag); //flag
+    U16 offset = swf_GetU16(tag); //offset
+    swf_SetTagPos(tag, offset);
+    swf_GetU16(tag); // next offset
+    swf_GetU16(tag); // condition
+
+    /* notice: this only returns the *first* action block.
+       For the current appliances, this is enough.
+     */
+    return swf_ActionGet(tag);
+}
+
+ActionTAG* swf_ButtonGetAction(TAG*t)
+{
+    if(t->id == ST_DEFINEBUTTON) {
+        return swf_Button1GetAction(t);
+    } else if(t->id == ST_DEFINEBUTTON2) { 
+        return swf_Button2GetAction(t);
+    } else {
+        fprintf(stderr, "error in buttongetaction: not a button tag\n");
+        return 0;
+    }
+}
+