Initial revision
[swftools.git] / lib / modules / swfbutton.c
1 /* swfbutton.c\r
2 \r
3    Button functions\r
4 \r
5    Extension module for the rfxswf library.\r
6    Part of the swftools package.\r
7 \r
8    Copyright (c) 2000, 2001 Rainer Böhme <rfxswf@reflex-studio.de>\r
9  \r
10    This file is distributed under the GPL, see file COPYING for details \r
11 \r
12 */\r
13 \r
14 int ButtonSetRecord(LPTAG t,U8 state,U16 id,U16 layer,LPMATRIX m,LPCXFORM cx)\r
15 \r
16 { SetU8(t,state);\r
17   SetU16(t,id);\r
18   SetU16(t,layer);\r
19   SetMatrix(t,m);\r
20 //  SetCXForm(t,cx,0);\r
21   return 0;\r
22 }\r
23 \r
24 int ButtonSetCondition(LPTAG t,U16 condition)\r
25 { SetU16(t,0); // dummy for Action Offset -> later set by ButtonPostProcess\r
26   SetU16(t,condition);\r
27   return 0;\r
28 }\r
29 \r
30 int ButtonSetFlags(LPTAG t,U8 flags)\r
31 { if (GetTagID(t)==ST_DEFINEBUTTON2)\r
32   { SetU8(t,flags);\r
33     SetU16(t,0); // dummy for Action Offset -> later set by ButtonPostProcess\r
34   }\r
35   return 0;\r
36 }\r
37 \r
38 void SetButtonOffset(LPTAG t,U32 offsetpos)\r
39 { U32 now = GetTagPos(t);\r
40   U16 diff = now-offsetpos;\r
41   SetTagPos(t,offsetpos);\r
42   t->data[t->pos++] = (U8)(diff&0xff);\r
43   t->data[t->pos++] = (U8)(diff>>8);\r
44   SetTagPos(t,now);\r
45 }\r
46 \r
47 int ButtonPostProcess(LPTAG t,int anz_action)\r
48 { if (GetTagID(t)==ST_DEFINEBUTTON2)\r
49   { U32 oldTagPos;\r
50     U32 offsetpos;\r
51 \r
52     oldTagPos = GetTagPos(t);\r
53 \r
54     // scan DefineButton2 Record\r
55     \r
56     GetU16(t);          // Character ID\r
57     GetU8(t);           // Flags;\r
58 \r
59     offsetpos = GetTagPos(t);  // first offset\r
60     GetU16(t);\r
61 \r
62     while (GetU8(t))      // state  -> parse ButtonRecord\r
63     { GetU16(t);          // id\r
64       GetU16(t);          // layer\r
65       GetMatrix(t,NULL);  // matrix\r
66       // evtl.: CXForm\r
67     }\r
68 \r
69     SetButtonOffset(t,offsetpos);\r
70 \r
71     while(anz_action)\r
72     { U8 a;\r
73         \r
74       offsetpos = GetTagPos(t); // offset\r
75       GetU16(t);\r
76 \r
77       GetU16(t);                // condition\r
78       \r
79       while (a=GetU8(t))        // skip action records\r
80       { if (a&0x80)\r
81         { U16 l = GetU16(t);\r
82           GetBlock(t,NULL,l);\r
83         }\r
84       }\r
85       \r
86       if (--anz_action) SetButtonOffset(t,offsetpos);\r
87     }\r
88     \r
89     SetTagPos(t,oldTagPos);\r
90   }\r
91   return 0;\r
92 }\r