3 Object place and move routines
5 Extension module for the rfxswf library.
6 Part of the swftools package.
8 Copyright (c) 2001 Rainer Böhme <rfxswf@reflex-studio.de>
10 This file is distributed under the GPL, see file COPYING for details
16 #define PF_MATRIX 0x04
17 #define PF_CXFORM 0x08
20 #define PF_CLIPACTION 0x40
21 #define PF_ACTIONEVENT 0x80
23 int swf_ObjectPlace(TAG * t,U16 id,U16 depth,MATRIX * m,CXFORM * cx,U8 * name)
27 if(cx && cx->r1==0 && cx->g1==0 && cx->b1==0 && cx->a1==0
28 && cx->r0==256 && cx->g0==256 && cx->b0==256 && cx->a0==256)
31 flags = (id?PF_CHAR:0)|(m?PF_MATRIX:0)|(cx?PF_CXFORM:0)|(name?PF_NAME:0)|((m||cx)&&(!id)?PF_MOVE:0);
35 if (flags&PF_CHAR) swf_SetU16(t,id);
36 if (flags&PF_MATRIX) swf_SetMatrix(t,m);
37 if (flags&PF_CXFORM) swf_SetCXForm(t,cx,1);
38 if (flags&PF_RATIO) swf_SetU16(t,0);
39 if (flags&PF_NAME) swf_SetString(t,name);
44 int swf_ObjectPlaceClip(TAG * t,U16 id,U16 depth,MATRIX * m,CXFORM * cx,U8 * name, U16 clipaction)
48 if(cx && cx->r1==0 && cx->g1==0 && cx->b1==0 && cx->a1==0
49 && cx->r0==256 && cx->g0==256 && cx->b0==256 && cx->a0==256)
52 flags = (id?PF_CHAR:0)|(m?PF_MATRIX:0)|(cx?PF_CXFORM:0)|(name?PF_NAME:0)|
53 ((m||cx)&&(!id)?PF_MOVE:0)|(clipaction?PF_CLIPACTION:0);
57 if (flags&PF_CHAR) swf_SetU16(t,id);
58 if (flags&PF_MATRIX) swf_SetMatrix(t,m);
59 if (flags&PF_CXFORM) swf_SetCXForm(t,cx,1);
60 if (flags&PF_RATIO) swf_SetU16(t,0);
62 /* ??? The spec states that name comes first? */
63 if (flags&PF_CLIPACTION) swf_SetU16(t, clipaction);
64 if (flags&PF_NAME) swf_SetString(t,name);
68 int swf_ObjectMove(TAG * t,U16 depth,MATRIX * m,CXFORM * cx)
69 { return swf_ObjectPlace(t,0,depth,m,cx,NULL);
72 int isUnitMatrix(MATRIX* m)
74 /* a matrix with all zeros is also considered
75 "unit matrix", as a zeroed out MATRIX structure
76 usually means that the caller doesn't want to
78 if(( (m->sx == 0x10000 && m->sy == 0x10000)
79 || (m->sx == 0 && m->sy == 0))
80 && ((m->r0|m->r1|m->tx|m->ty) == 0)
86 int isUnitCXForm(CXFORM* cx)
88 if((cx->a0==256 && cx->r0==256 && cx->g0==256 && cx->b0==256) &&
89 (cx->a1==0 && cx->r1==0 && cx->g1==0 && cx->b1==0))
91 /* A CXForm of all zeros is, unfortunately, not as unlikely
92 as a matrix of all zeros. However, we still treat it
93 as non-existent/uniform transform */
94 if((cx->a0==0 && cx->r0==0 && cx->g0==0 && cx->b0==0) &&
95 (cx->a1==0 && cx->r1==0 && cx->g1==0 && cx->b1==0))
100 void swf_SetPlaceObject(TAG * t,SWFPLACEOBJECT* obj)
104 if(t->id == ST_PLACEOBJECT) {
105 swf_SetU16(t, obj->id);
106 swf_SetU16(t, obj->depth);
107 swf_SetMatrix(t, &obj->matrix);
108 swf_SetCXForm(t, &obj->cxform, 0);
110 int m = !isUnitMatrix(&obj->matrix);
111 int cx = !isUnitCXForm(&obj->cxform);
113 flags = (obj->id?PF_CHAR:0)|(m?PF_MATRIX:0)|(cx?PF_CXFORM:0)|
114 (obj->name?PF_NAME:0)|(obj->move?PF_MOVE:0)|
115 (obj->clipdepth?PF_CLIPACTION:0);
118 swf_SetU16(t,obj->depth);
119 if (flags&PF_CHAR) swf_SetU16(t,obj->id);
120 if (flags&PF_MATRIX) swf_SetMatrix(t,&obj->matrix);
121 if (flags&PF_CXFORM) swf_SetCXForm(t,&obj->cxform,1);
122 if (flags&PF_RATIO) swf_SetU16(t,obj->ratio);
124 /* ??? The spec states that name comes first? */
125 if (flags&PF_CLIPACTION) swf_SetU16(t,obj->clipdepth);
126 if (flags&PF_NAME) swf_SetString(t,obj->name);
127 if (flags&PF_ACTIONEVENT) {
133 void swf_GetPlaceObject(TAG * tag,SWFPLACEOBJECT* obj)
137 memset(obj, 0, sizeof(SWFPLACEOBJECT));
138 swf_GetMatrix(0, &obj->matrix);
139 swf_GetCXForm(0, &obj->cxform, 1);
143 flags = swf_GetU8(tag);
144 memset(obj,0,sizeof(SWFPLACEOBJECT));
146 swf_GetMatrix(0,&obj->matrix);
147 swf_GetCXForm(0,&obj->cxform,1);
149 obj->depth = swf_GetU16(tag);
151 if(flags&2) obj->id = swf_GetU16(tag);
152 if(flags&4) swf_GetMatrix(tag, &obj->matrix);
153 if(flags&8) swf_GetCXForm(tag, &obj->cxform,1);
154 if(flags&16) obj->ratio = swf_GetU16(tag);
156 obj->clipdepth = swf_GetU16(tag); //clip
160 swf_ResetReadBits(tag);
161 l = strlen(&tag->data[tag->pos]);
165 while((data[t++] = swf_GetU8(tag)));
168 /* Actionscript ignored (for now) */
172 void swf_PlaceObjectFree(SWFPLACEOBJECT* obj)