added overflow checking for text coordinates.
[swftools.git] / lib / modules / swfbutton.c
blob9a4cc39f38e802fb0b1766d8e0ca973517f27f7f
1 /* swfbutton.c
3 Button functions
5 Extension module for the rfxswf library.
6 Part of the swftools package.
8 Copyright (c) 2000, 2001 Rainer Böhme <rfxswf@reflex-studio.de>
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.
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.
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 */
24 int swf_ButtonSetRecord(TAG * t,U8 state,U16 id,U16 layer,MATRIX * m,CXFORM * cx)
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,1);
31 return 0;
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;
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
45 return 0;
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);
57 int swf_ButtonPostProcess(TAG * t,int anz_action)
58 { if (swf_GetTagID(t)==ST_DEFINEBUTTON2)
59 { U32 oldTagPos;
60 U32 offsetpos;
62 oldTagPos = swf_GetTagPos(t);
64 // scan DefineButton2 Record
66 swf_GetU16(t); // Character ID
67 swf_GetU8(t); // Flags;
69 offsetpos = swf_GetTagPos(t); // first offset
70 swf_GetU16(t);
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,1);// CXForm
79 swf_SetButtonOffset(t,offsetpos);
81 while(anz_action)
82 { U8 a;
84 offsetpos = swf_GetTagPos(t); // offset
85 swf_GetU16(t);
87 swf_GetU16(t); // condition
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);
96 if (--anz_action) swf_SetButtonOffset(t,offsetpos);
99 swf_SetTagPos(t,oldTagPos);
101 return 0;