stubs for setjpegbits2/setjpegbits3 if no jpeglib compiled in
[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 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.
14
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.
19
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 */
23
24 #include "../rfxswf.h"
25
26 int swf_ButtonSetRecord(TAG * t,U8 state,U16 id,U16 layer,MATRIX * m,CXFORM * cx)
27
28 { swf_SetU8(t,state);
29   swf_SetU16(t,id);
30   swf_SetU16(t,layer);
31   swf_SetMatrix(t,m);
32   if (swf_GetTagID(t)==ST_DEFINEBUTTON2) swf_SetCXForm(t,cx,1);
33   return 0;
34 }
35
36 int swf_ButtonSetCondition(TAG * t,U16 condition)
37 { swf_SetU16(t,0); // dummy for Action Offset -> later set by ButtonPostProcess
38   swf_SetU16(t,condition);
39   return 0;
40 }
41
42 int swf_ButtonSetFlags(TAG * t,U8 flags)
43 { if (swf_GetTagID(t)==ST_DEFINEBUTTON2)
44   { swf_SetU8(t,flags);
45     swf_SetU16(t,0); // dummy for Action Offset -> later set by ButtonPostProcess
46   }
47   return 0;
48 }
49
50 void swf_SetButtonOffset(TAG * t,U32 offsetpos)
51 { U32 now = swf_GetTagPos(t);
52   U16 diff = now-offsetpos;
53   swf_SetTagPos(t,offsetpos);
54   t->data[t->pos++] = (U8)(diff&0xff);
55   t->data[t->pos++] = (U8)(diff>>8);
56   swf_SetTagPos(t,now);
57 }
58
59 int swf_ButtonPostProcess(TAG * t,int anz_action)
60 { if (swf_GetTagID(t)==ST_DEFINEBUTTON2)
61   { U32 oldTagPos;
62     U32 offsetpos;
63
64     oldTagPos = swf_GetTagPos(t);
65
66     // scan DefineButton2 Record
67     
68     swf_GetU16(t);          // Character ID
69     swf_GetU8(t);           // Flags;
70
71     offsetpos = swf_GetTagPos(t);  // first offset
72     swf_GetU16(t);
73
74     while (swf_GetU8(t))      // state  -> parse ButtonRecord
75     { swf_GetU16(t);          // id
76       swf_GetU16(t);          // layer
77       swf_GetMatrix(t,NULL);  // matrix
78       swf_GetCXForm(t,NULL,1);// CXForm
79     }
80
81     swf_SetButtonOffset(t,offsetpos);
82
83     while(anz_action)
84     { U8 a;
85         
86       offsetpos = swf_GetTagPos(t); // offset
87       swf_GetU16(t);
88
89       swf_GetU16(t);                // condition
90       
91       while ((a=swf_GetU8(t)))        // skip action records
92       { if (a&0x80)
93         { U16 l = swf_GetU16(t);
94           swf_GetBlock(t,NULL,l);
95         }
96       }
97       
98       if (--anz_action) swf_SetButtonOffset(t,offsetpos);
99     }
100     
101     swf_SetTagPos(t,oldTagPos);
102   }
103   return 0;
104 }