summaryrefslogtreecommitdiff
path: root/lib/modules/swfbutton.c
blob: 23bd3c772397d8c95155ed4d7368316dff5ccfb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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 ButtonSetRecord(LPTAG t,U8 state,U16 id,U16 layer,LPMATRIX m,LPCXFORM cx)

{ SetU8(t,state);
  SetU16(t,id);
  SetU16(t,layer);
  SetMatrix(t,m);
//  SetCXForm(t,cx,0);
  return 0;
}

int ButtonSetCondition(LPTAG t,U16 condition)
{ SetU16(t,0); // dummy for Action Offset -> later set by ButtonPostProcess
  SetU16(t,condition);
  return 0;
}

int ButtonSetFlags(LPTAG t,U8 flags)
{ if (GetTagID(t)==ST_DEFINEBUTTON2)
  { SetU8(t,flags);
    SetU16(t,0); // dummy for Action Offset -> later set by ButtonPostProcess
  }
  return 0;
}

void SetButtonOffset(LPTAG t,U32 offsetpos)
{ U32 now = GetTagPos(t);
  U16 diff = now-offsetpos;
  SetTagPos(t,offsetpos);
  t->data[t->pos++] = (U8)(diff&0xff);
  t->data[t->pos++] = (U8)(diff>>8);
  SetTagPos(t,now);
}

int ButtonPostProcess(LPTAG t,int anz_action)
{ if (GetTagID(t)==ST_DEFINEBUTTON2)
  { U32 oldTagPos;
    U32 offsetpos;

    oldTagPos = GetTagPos(t);

    // scan DefineButton2 Record
    
    GetU16(t);          // Character ID
    GetU8(t);           // Flags;

    offsetpos = GetTagPos(t);  // first offset
    GetU16(t);

    while (GetU8(t))      // state  -> parse ButtonRecord
    { GetU16(t);          // id
      GetU16(t);          // layer
      GetMatrix(t,NULL);  // matrix
      // evtl.: CXForm
    }

    SetButtonOffset(t,offsetpos);

    while(anz_action)
    { U8 a;
        
      offsetpos = GetTagPos(t); // offset
      GetU16(t);

      GetU16(t);                // condition
      
      while (a=GetU8(t))        // skip action records
      { if (a&0x80)
        { U16 l = GetU16(t);
          GetBlock(t,NULL,l);
        }
      }
      
      if (--anz_action) SetButtonOffset(t,offsetpos);
    }
    
    SetTagPos(t,oldTagPos);
  }
  return 0;
}