From e1a61c82d0d1c2303041370fc1d8f4c66b22d586 Mon Sep 17 00:00:00 2001
From: boehme <boehme>
Date: Thu, 1 Nov 2001 16:39:13 +0000
Subject: [PATCH] bugfix: ST_DEFINEBUTTON2 and CXForms

---
 lib/example/Makefile     |    8 +-
 lib/example/buttontest.c |   49 ++++++------
 lib/modules/swfbutton.c  |  184 +++++++++++++++++++++++-----------------------
 3 files changed, 120 insertions(+), 121 deletions(-)

diff --git a/lib/example/Makefile b/lib/example/Makefile
index 164e5e6..b2e9525 100644
--- a/lib/example/Makefile
+++ b/lib/example/Makefile
@@ -9,11 +9,14 @@ DBFLAGS	= -g2
 .c.o:
 		$(CC) -c $(CFLAGS) $(DBFLAGS) -o $@ $<
 
-all: jpegtest box shape1 transtest zlibtest sprites
+all: jpegtest box shape1 transtest zlibtest sprites buttontest
 
 box: $(RFXSWF) box.o
 		$(CC) -o box box.o $(RFXSWF) $(LDLIBS) $(DBFLAGS)
 
+buttontest: $(RFXSWF) buttontest.o
+		$(CC) -o buttontest buttontest.o $(RFXSWF) $(LDLIBS) $(DBFLAGS)
+
 jpegtest: $(RFXSWF) jpegtest.o
 		$(CC) -o jpegtest jpegtest.o $(RFXSWF) $(LDLIBS) $(DBFLAGS)
 
@@ -31,7 +34,8 @@ zlibtest: $(RFXSWF) zlibtest.o
 
 clean:
 		rm -f jpegtest.o box.o shape1.o trastest.o zlibtest.o sprites.o\
+		buttontest.o \
 		jpegtest.swf box.swf shape1.swf trastest.swf zlibtest.swf \
-                sprites.swf
+                sprites.swf buttontest.swf
 
 
diff --git a/lib/example/buttontest.c b/lib/example/buttontest.c
index 99ad495..daf0a2c 100644
--- a/lib/example/buttontest.c
+++ b/lib/example/buttontest.c
@@ -1,4 +1,4 @@
-/* shape1.c
+/* buttontest.c
 
    Example implementation for creating a button with rfxswf
    
@@ -17,8 +17,10 @@
 
 TAG* t;
 
+#define ID_BUTTON 31
+
 int useDefineButton2 = 0; // set this to 1 to use DefineButton2 Tags
-			  // instead of DefineButton1
+                          // instead of DefineButton1
                
 int main (int argc,char ** argv)
 { SWF swf;
@@ -46,7 +48,7 @@ int main (int argc,char ** argv)
   rgb.b = 0xff;
   swf_SetRGB(t,&rgb);
 
-  for(count=0;count<4;count++)
+  for(count=1;count<4;count++)
   {
       t = swf_InsertTag(t,ST_DEFINESHAPE);
       swf_ShapeNew(&s);               // create new shape instance
@@ -92,45 +94,38 @@ int main (int argc,char ** argv)
   {
       t = swf_InsertTag(t,ST_DEFINEBUTTON);
       swf_SetU16(t,31); //id
-      swf_ButtonSetFlags(t, 0); //menu=no
-      swf_ButtonSetRecord(t,0x01,33,1,0,0);
-      swf_ButtonSetRecord(t,0x02,34,1,0,0);
-      swf_ButtonSetRecord(t,0x04,35,1,0,0);
-      swf_ButtonSetRecord(t,0x08,36,1,0,0);
-      swf_SetU8(t,0);
+      swf_ButtonSetRecord(t,BS_UP|BS_HIT,34,1,NULL,NULL);
+      swf_ButtonSetRecord(t,BS_OVER,35,1,NULL,NULL);
+      swf_ButtonSetRecord(t,BS_DOWN,36,1,NULL,NULL);
+      swf_SetU8(t,0); // end of button records
+      
       swf_SetActions(t,actiontoset);
-      swf_SetU8(t,0);
   }
   else
   {
       t = swf_InsertTag(t,ST_DEFINEBUTTON2);
-      swf_SetU16(t,31); //id
+      swf_SetU16(t,ID_BUTTON); //id
       swf_ButtonSetFlags(t, 0); //menu=no
-      swf_ButtonSetRecord(t,0x01,33,1,0,0);
-      swf_ButtonSetRecord(t,0x02,34,1,0,0);
-      swf_ButtonSetRecord(t,0x04,35,1,0,0);
-      swf_ButtonSetRecord(t,0x08,36,1,0,0);
-      swf_SetU8(t,0);
+      swf_ButtonSetRecord(t,BS_UP|BS_HIT,34,1,NULL,NULL);
+      swf_ButtonSetRecord(t,BS_OVER,35,1,NULL,NULL);
+      swf_ButtonSetRecord(t,BS_DOWN,36,1,NULL,NULL);
+      swf_SetU8(t,0); // end of button records
 
-      swf_ButtonSetCondition(t, 4);
+      swf_ButtonSetCondition(t, BC_OVERDOWN_OVERUP);
        swf_SetActions(t,actiontoset);
-       swf_SetU8(t,0);
-
-      swf_ButtonSetCondition(t, 0);
-       swf_SetU8(t,0);
-
-      swf_SetU8(t,0);
-
-      swf_ButtonPostProcess(t, 2);
+       
+      swf_ButtonPostProcess(t, 1); // don't forget!
   }
 
+  // FIXME: Free Action Tag lists
+
   t = swf_InsertTag(t,ST_PLACEOBJECT2);
-  swf_ObjectPlace(t, 31, 2,0,0,0);
+  swf_ObjectPlace(t, ID_BUTTON, 2,0,0,0);
 
   t = swf_InsertTag(t,ST_SHOWFRAME);
   t = swf_InsertTag(t,ST_END);
 
-  f = open("button.swf",O_WRONLY|O_CREAT, 0644);
+  f = open("buttontest.swf",O_WRONLY|O_CREAT, 0644);
   if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
   close(f);
 
diff --git a/lib/modules/swfbutton.c b/lib/modules/swfbutton.c
index 4929c8c..84528a4 100644
--- a/lib/modules/swfbutton.c
+++ b/lib/modules/swfbutton.c
@@ -1,92 +1,92 @@
-/* swfbutton.c
-
-   Button functions
-
-   Extension module for the rfxswf library.
-   Part of the swftools package.
-
-   Copyright (c) 2000, 2001 Rainer Böhme <rfxswf@reflex-studio.de>
- 
-   This file is distributed under the GPL, see file COPYING for details 
-
-*/
-
-int swf_ButtonSetRecord(TAG * t,U8 state,U16 id,U16 layer,MATRIX * m,CXFORM * cx)
-
-{ swf_SetU8(t,state);
-  swf_SetU16(t,id);
-  swf_SetU16(t,layer);
-  swf_SetMatrix(t,m);
-//  SetCXForm(t,cx,0);
-  return 0;
-}
-
-int swf_ButtonSetCondition(TAG * t,U16 condition)
-{ swf_SetU16(t,0); // dummy for Action Offset -> later set by ButtonPostProcess
-  swf_SetU16(t,condition);
-  return 0;
-}
-
-int swf_ButtonSetFlags(TAG * t,U8 flags)
-{ if (swf_GetTagID(t)==ST_DEFINEBUTTON2)
-  { swf_SetU8(t,flags);
-    swf_SetU16(t,0); // dummy for Action Offset -> later set by ButtonPostProcess
-  }
-  return 0;
-}
-
-void swf_SetButtonOffset(TAG * t,U32 offsetpos)
-{ U32 now = swf_GetTagPos(t);
-  U16 diff = now-offsetpos;
-  swf_SetTagPos(t,offsetpos);
-  t->data[t->pos++] = (U8)(diff&0xff);
-  t->data[t->pos++] = (U8)(diff>>8);
-  swf_SetTagPos(t,now);
-}
-
-int swf_ButtonPostProcess(TAG * t,int anz_action)
-{ if (swf_GetTagID(t)==ST_DEFINEBUTTON2)
-  { U32 oldTagPos;
-    U32 offsetpos;
-
-    oldTagPos = swf_GetTagPos(t);
-
-    // scan DefineButton2 Record
-    
-    swf_GetU16(t);          // Character ID
-    swf_GetU8(t);           // Flags;
-
-    offsetpos = swf_GetTagPos(t);  // first offset
-    swf_GetU16(t);
-
-    while (swf_GetU8(t))      // state  -> parse ButtonRecord
-    { swf_GetU16(t);          // id
-      swf_GetU16(t);          // layer
-      swf_GetMatrix(t,NULL);  // matrix
-      // evtl.: CXForm
-    }
-
-    swf_SetButtonOffset(t,offsetpos);
-
-    while(anz_action)
-    { U8 a;
-        
-      offsetpos = swf_GetTagPos(t); // offset
-      swf_GetU16(t);
-
-      swf_GetU16(t);                // condition
-      
-      while (a=swf_GetU8(t))        // skip action records
-      { if (a&0x80)
-        { U16 l = swf_GetU16(t);
-          swf_GetBlock(t,NULL,l);
-        }
-      }
-      
-      if (--anz_action) swf_SetButtonOffset(t,offsetpos);
-    }
-    
-    swf_SetTagPos(t,oldTagPos);
-  }
-  return 0;
-}
+/* swfbutton.c
+
+   Button functions
+
+   Extension module for the rfxswf library.
+   Part of the swftools package.
+
+   Copyright (c) 2000, 2001 Rainer Böhme <rfxswf@reflex-studio.de>
+ 
+   This file is distributed under the GPL, see file COPYING for details 
+
+*/
+
+int swf_ButtonSetRecord(TAG * t,U8 state,U16 id,U16 layer,MATRIX * m,CXFORM * cx)
+
+{ swf_SetU8(t,state);
+  swf_SetU16(t,id);
+  swf_SetU16(t,layer);
+  swf_SetMatrix(t,m);
+  if (swf_GetTagID(t)==ST_DEFINEBUTTON2) swf_SetCXForm(t,cx,0);
+  return 0;
+}
+
+int swf_ButtonSetCondition(TAG * t,U16 condition)
+{ swf_SetU16(t,0); // dummy for Action Offset -> later set by ButtonPostProcess
+  swf_SetU16(t,condition);
+  return 0;
+}
+
+int swf_ButtonSetFlags(TAG * t,U8 flags)
+{ if (swf_GetTagID(t)==ST_DEFINEBUTTON2)
+  { swf_SetU8(t,flags);
+    swf_SetU16(t,0); // dummy for Action Offset -> later set by ButtonPostProcess
+  }
+  return 0;
+}
+
+void swf_SetButtonOffset(TAG * t,U32 offsetpos)
+{ U32 now = swf_GetTagPos(t);
+  U16 diff = now-offsetpos;
+  swf_SetTagPos(t,offsetpos);
+  t->data[t->pos++] = (U8)(diff&0xff);
+  t->data[t->pos++] = (U8)(diff>>8);
+  swf_SetTagPos(t,now);
+}
+
+int swf_ButtonPostProcess(TAG * t,int anz_action)
+{ if (swf_GetTagID(t)==ST_DEFINEBUTTON2)
+  { U32 oldTagPos;
+    U32 offsetpos;
+
+    oldTagPos = swf_GetTagPos(t);
+
+    // scan DefineButton2 Record
+    
+    swf_GetU16(t);          // Character ID
+    swf_GetU8(t);           // Flags;
+
+    offsetpos = swf_GetTagPos(t);  // first offset
+    swf_GetU16(t);
+
+    while (swf_GetU8(t))      // state  -> parse ButtonRecord
+    { swf_GetU16(t);          // id
+      swf_GetU16(t);          // layer
+      swf_GetMatrix(t,NULL);  // matrix
+      swf_GetCXForm(t,NULL,0);// CXForm
+    }
+
+    swf_SetButtonOffset(t,offsetpos);
+
+    while(anz_action)
+    { U8 a;
+        
+      offsetpos = swf_GetTagPos(t); // offset
+      swf_GetU16(t);
+
+      swf_GetU16(t);                // condition
+      
+      while (a=swf_GetU8(t))        // skip action records
+      { if (a&0x80)
+        { U16 l = swf_GetU16(t);
+          swf_GetBlock(t,NULL,l);
+        }
+      }
+      
+      if (--anz_action) swf_SetButtonOffset(t,offsetpos);
+    }
+    
+    swf_SetTagPos(t,oldTagPos);
+  }
+  return 0;
+}
-- 
1.7.10.4