cd9f464539db754f1206c5faf447bff16fe0034c
[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 file is distributed under the GPL, see file COPYING for details 
11
12 */
13
14 int swf_ButtonSetRecord(TAG * t,U8 state,U16 id,U16 layer,MATRIX * m,CXFORM * cx)
15
16 { swf_SetU8(t,state);
17   swf_SetU16(t,id);
18   swf_SetU16(t,layer);
19   swf_SetMatrix(t,m);
20   if (swf_GetTagID(t)==ST_DEFINEBUTTON2) swf_SetCXForm(t,cx,0);
21   return 0;
22 }
23
24 int swf_ButtonSetCondition(TAG * t,U16 condition)
25 { swf_SetU16(t,0); // dummy for Action Offset -> later set by ButtonPostProcess
26   swf_SetU16(t,condition);
27   return 0;
28 }
29
30 int swf_ButtonSetFlags(TAG * t,U8 flags)
31 { if (swf_GetTagID(t)==ST_DEFINEBUTTON2)
32   { swf_SetU8(t,flags);
33     swf_SetU16(t,0); // dummy for Action Offset -> later set by ButtonPostProcess
34   }
35   return 0;
36 }
37
38 void swf_SetButtonOffset(TAG * t,U32 offsetpos)
39 { U32 now = swf_GetTagPos(t);
40   U16 diff = now-offsetpos;
41   swf_SetTagPos(t,offsetpos);
42   t->data[t->pos++] = (U8)(diff&0xff);
43   t->data[t->pos++] = (U8)(diff>>8);
44   swf_SetTagPos(t,now);
45 }
46
47 int swf_ButtonPostProcess(TAG * t,int anz_action)
48 { if (swf_GetTagID(t)==ST_DEFINEBUTTON2)
49   { U32 oldTagPos;
50     U32 offsetpos;
51
52     oldTagPos = swf_GetTagPos(t);
53
54     // scan DefineButton2 Record
55     
56     swf_GetU16(t);          // Character ID
57     swf_GetU8(t);           // Flags;
58
59     offsetpos = swf_GetTagPos(t);  // first offset
60     swf_GetU16(t);
61
62     while (swf_GetU8(t))      // state  -> parse ButtonRecord
63     { swf_GetU16(t);          // id
64       swf_GetU16(t);          // layer
65       swf_GetMatrix(t,NULL);  // matrix
66       swf_GetCXForm(t,NULL,0);// CXForm
67     }
68
69     swf_SetButtonOffset(t,offsetpos);
70
71     while(anz_action)
72     { U8 a;
73         
74       offsetpos = swf_GetTagPos(t); // offset
75       swf_GetU16(t);
76
77       swf_GetU16(t);                // condition
78       
79       while ((a=swf_GetU8(t)))        // skip action records
80       { if (a&0x80)
81         { U16 l = swf_GetU16(t);
82           swf_GetBlock(t,NULL,l);
83         }
84       }
85       
86       if (--anz_action) swf_SetButtonOffset(t,offsetpos);
87     }
88     
89     swf_SetTagPos(t,oldTagPos);
90   }
91   return 0;
92 }