added (long) GPL headers.
[swftools.git] / lib / modules / swfbutton.c
1 /* swfbutton.c
2
3    Button functions
4
5    Extension module for the rfxswf library.
6    Part of the swftools package.
7
8    Copyright (c) 2000, 2001 Rainer Böhme <rfxswf@reflex-studio.de>
9  
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
23
24 int swf_ButtonSetRecord(TAG * t,U8 state,U16 id,U16 layer,MATRIX * m,CXFORM * cx)
25
26 { swf_SetU8(t,state);
27   swf_SetU16(t,id);
28   swf_SetU16(t,layer);
29   swf_SetMatrix(t,m);
30   if (swf_GetTagID(t)==ST_DEFINEBUTTON2) swf_SetCXForm(t,cx,0);
31   return 0;
32 }
33
34 int swf_ButtonSetCondition(TAG * t,U16 condition)
35 { swf_SetU16(t,0); // dummy for Action Offset -> later set by ButtonPostProcess
36   swf_SetU16(t,condition);
37   return 0;
38 }
39
40 int swf_ButtonSetFlags(TAG * t,U8 flags)
41 { if (swf_GetTagID(t)==ST_DEFINEBUTTON2)
42   { swf_SetU8(t,flags);
43     swf_SetU16(t,0); // dummy for Action Offset -> later set by ButtonPostProcess
44   }
45   return 0;
46 }
47
48 void swf_SetButtonOffset(TAG * t,U32 offsetpos)
49 { U32 now = swf_GetTagPos(t);
50   U16 diff = now-offsetpos;
51   swf_SetTagPos(t,offsetpos);
52   t->data[t->pos++] = (U8)(diff&0xff);
53   t->data[t->pos++] = (U8)(diff>>8);
54   swf_SetTagPos(t,now);
55 }
56
57 int swf_ButtonPostProcess(TAG * t,int anz_action)
58 { if (swf_GetTagID(t)==ST_DEFINEBUTTON2)
59   { U32 oldTagPos;
60     U32 offsetpos;
61
62     oldTagPos = swf_GetTagPos(t);
63
64     // scan DefineButton2 Record
65     
66     swf_GetU16(t);          // Character ID
67     swf_GetU8(t);           // Flags;
68
69     offsetpos = swf_GetTagPos(t);  // first offset
70     swf_GetU16(t);
71
72     while (swf_GetU8(t))      // state  -> parse ButtonRecord
73     { swf_GetU16(t);          // id
74       swf_GetU16(t);          // layer
75       swf_GetMatrix(t,NULL);  // matrix
76       swf_GetCXForm(t,NULL,0);// CXForm
77     }
78
79     swf_SetButtonOffset(t,offsetpos);
80
81     while(anz_action)
82     { U8 a;
83         
84       offsetpos = swf_GetTagPos(t); // offset
85       swf_GetU16(t);
86
87       swf_GetU16(t);                // condition
88       
89       while ((a=swf_GetU8(t)))        // skip action records
90       { if (a&0x80)
91         { U16 l = swf_GetU16(t);
92           swf_GetBlock(t,NULL,l);
93         }
94       }
95       
96       if (--anz_action) swf_SetButtonOffset(t,offsetpos);
97     }
98     
99     swf_SetTagPos(t,oldTagPos);
100   }
101   return 0;
102 }