File: swfbutton.c

package info (click to toggle)
swftools 0.9.2%2Bds1-3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 9,488 kB
  • sloc: ansic: 122,576; sh: 8,494; cpp: 8,020; yacc: 2,260; lisp: 904; makefile: 581; python: 304
file content (148 lines) | stat: -rw-r--r-- 3,921 bytes parent folder | download | duplicates (3)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* swfbutton.c

   Button functions

   Extension module for the rfxswf library.
   Part of the swftools package.

   Copyright (c) 2000, 2001 Rainer Bhme <rfxswf@reflex-studio.de>
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#include "../rfxswf.h"

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,1);
  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,1);// 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;
}

ActionTAG* swf_Button1GetAction(TAG*tag)
{
    swf_GetU16(tag); //button id
    while(1)
    {
        U8 flags = swf_GetU8(tag);
        if(!flags)
            break; 
        swf_GetU16(tag); //char
        swf_GetU16(tag); //layer
        swf_ResetReadBits(tag);
        swf_GetMatrix(tag, NULL);
    }
    return swf_ActionGet(tag);
}

ActionTAG* swf_Button2GetAction(TAG*tag)
{
    swf_GetU16(tag); //button id
    swf_GetU8(tag); //flag
    U16 offset = swf_GetU16(tag); //offset
    swf_SetTagPos(tag, offset);
    swf_GetU16(tag); // next offset
    swf_GetU16(tag); // condition

    /* notice: this only returns the *first* action block.
       For the current appliances, this is enough.
     */
    return swf_ActionGet(tag);
}

ActionTAG* swf_ButtonGetAction(TAG*t)
{
    if(t->id == ST_DEFINEBUTTON) {
        return swf_Button1GetAction(t);
    } else if(t->id == ST_DEFINEBUTTON2) { 
        return swf_Button2GetAction(t);
    } else {
        fprintf(stderr, "error in buttongetaction: not a button tag\n");
        return 0;
    }
}