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);
61 if (flags&PF_NAME) swf_SetString(t,name);
62 if (flags&PF_CLIPACTION) swf_SetU16(t, clipaction);
66 int swf_ObjectMove(TAG * t,U16 depth,MATRIX * m,CXFORM * cx)
67 { return swf_ObjectPlace(t,0,depth,m,cx,NULL);
70 int isUnitMatrix(MATRIX* m)
72 /* a matrix with all zeros is also considered
73 "unit matrix", as a zeroed out MATRIX structure
74 usually means that the caller doesn't want to
76 if(( (m->sx == 0x10000 && m->sy == 0x10000)
77 || (m->sx == 0 && m->sy == 0))
78 && ((m->r0|m->r1|m->tx|m->ty) == 0)
84 int isUnitCXForm(CXFORM* cx)
86 if((cx->a0==256 && cx->r0==256 && cx->g0==256 && cx->b0==256) &&
87 (cx->a1==0 && cx->r1==0 && cx->g1==0 && cx->b1==0))
89 /* A CXForm of all zeros is, unfortunately, not as unlikely
90 as a matrix of all zeros. However, we still treat it
91 as non-existent/uniform transform */
92 if((cx->a0==0 && cx->r0==0 && cx->g0==0 && cx->b0==0) &&
93 (cx->a1==0 && cx->r1==0 && cx->g1==0 && cx->b1==0))
98 void swf_SetPlaceObject(TAG * t,SWFPLACEOBJECT* obj)
102 if(t->id == ST_PLACEOBJECT) {
103 swf_SetU16(t, obj->id);
104 swf_SetU16(t, obj->depth);
105 swf_SetMatrix(t, &obj->matrix);
106 swf_SetCXForm(t, &obj->cxform, 0);
108 int m = !isUnitMatrix(&obj->matrix);
109 int cx = !isUnitCXForm(&obj->cxform);
111 flags = (obj->id?PF_CHAR:0)|(m?PF_MATRIX:0)|(cx?PF_CXFORM:0)|
112 (obj->name?PF_NAME:0)|(obj->move?PF_MOVE:0)|
113 (obj->clipdepth?PF_CLIPACTION:0);
116 swf_SetU16(t,obj->depth);
117 if (flags&PF_CHAR) swf_SetU16(t,obj->id);
118 if (flags&PF_MATRIX) swf_SetMatrix(t,&obj->matrix);
119 if (flags&PF_CXFORM) swf_SetCXForm(t,&obj->cxform,1);
120 if (flags&PF_RATIO) swf_SetU16(t,obj->ratio);
121 if (flags&PF_NAME) swf_SetString(t,obj->name);
122 if (flags&PF_CLIPACTION) swf_SetU16(t,obj->clipdepth);
123 if (flags&PF_ACTIONEVENT) {
129 void swf_GetPlaceObject(TAG * tag,SWFPLACEOBJECT* obj)
131 U8 flags = swf_GetU8(tag);
132 memset(obj,0,sizeof(SWFPLACEOBJECT));
134 swf_GetMatrix(0,&obj->matrix);
135 swf_GetCXForm(0,&obj->cxform,1);
137 obj->depth = swf_GetU16(tag);
139 if(flags&2) obj->id = swf_GetU16(tag);
140 if(flags&4) swf_GetMatrix(tag, &obj->matrix);
141 if(flags&8) swf_GetCXForm(tag, &obj->cxform,1);
142 if(flags&16) obj->ratio = swf_GetU16(tag);
146 swf_ResetReadBits(tag);
147 l = strlen(&tag->data[tag->pos]);
151 while((data[t++] = swf_GetU8(tag)));
154 obj->clipdepth = swf_GetU16(tag); //clip
156 /* Actionscript ignored (for now) */
160 void swf_PlaceObjectFree(SWFPLACEOBJECT* obj)