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 flags = (id?PF_CHAR:0)|(m?PF_MATRIX:0)|(cx?PF_CXFORM:0)|(name?PF_NAME:0)|((m||cx)&&(!id)?PF_MOVE:0);
31 if (flags&PF_CHAR) swf_SetU16(t,id);
32 if (flags&PF_MATRIX) swf_SetMatrix(t,m);
33 if (flags&PF_CXFORM) swf_SetCXForm(t,cx,(cx->a0!=256)||(cx->a1));
34 if (flags&PF_RATIO) swf_SetU16(t,0);
35 if (flags&PF_NAME) swf_SetString(t,name);
40 int swf_ObjectPlaceClip(TAG * t,U16 id,U16 depth,MATRIX * m,CXFORM * cx,U8 * name, U16 clipaction)
44 flags = (id?PF_CHAR:0)|(m?PF_MATRIX:0)|(cx?PF_CXFORM:0)|(name?PF_NAME:0)|
45 ((m||cx)&&(!id)?PF_MOVE:0)|(clipaction?PF_CLIPACTION:0);
49 if (flags&PF_CHAR) swf_SetU16(t,id);
50 if (flags&PF_MATRIX) swf_SetMatrix(t,m);
51 if (flags&PF_CXFORM) swf_SetCXForm(t,cx,(cx->a0!=256)||(cx->a1));
52 if (flags&PF_RATIO) swf_SetU16(t,0);
53 if (flags&PF_NAME) swf_SetString(t,name);
54 if (flags&PF_CLIPACTION) swf_SetU16(t, clipaction);
58 int swf_ObjectMove(TAG * t,U16 depth,MATRIX * m,CXFORM * cx)
59 { return swf_ObjectPlace(t,0,depth,m,cx,NULL);
62 int isUnitMatrix(MATRIX* m)
64 /* a matrix with all zeros is also considered
65 "unit matrix", as a zeroed out MATRIX structure
66 usually means that the caller doesn't want to
68 if(( (m->sx == 0x10000 && m->sy == 0x10000)
69 || (m->sx == 0 && m->sy == 0))
70 && ((m->r0|m->r1|m->tx|m->ty) == 0)
76 int isUnitCXForm(CXFORM* cx)
78 if((cx->a0==256 && cx->r0==256 && cx->g0==256 && cx->b0==256) &&
79 (cx->a1==0 && cx->r1==0 && cx->g1==0 && cx->b1==0))
81 /* A CXForm of all zeros is, unfortunately, not as unlikely
82 as a matrix of all zeros. However, we still treat it
83 as non-existent/uniform transform */
84 if((cx->a0==0 && cx->r0==0 && cx->g0==0 && cx->b0==0) &&
85 (cx->a1==0 && cx->r1==0 && cx->g1==0 && cx->b1==0))
90 void swf_SetPlaceObject(TAG * t,SWFPLACEOBJECT* obj)
94 if(t->id == ST_PLACEOBJECT) {
95 swf_SetU16(t, obj->id);
96 swf_SetU16(t, obj->depth);
97 swf_SetMatrix(t, &obj->matrix);
98 swf_SetCXForm(t, &obj->cxform, 0);
100 int m = !isUnitMatrix(&obj->matrix);
101 int cx = !isUnitCXForm(&obj->cxform);
103 flags = (obj->id?PF_CHAR:0)|(m?PF_MATRIX:0)|(cx?PF_CXFORM:0)|
104 (obj->name?PF_NAME:0)|(obj->move?PF_MOVE:0)|
105 (obj->clipdepth?PF_CLIPACTION:0);
108 swf_SetU16(t,obj->depth);
109 if (flags&PF_CHAR) swf_SetU16(t,obj->id);
110 if (flags&PF_MATRIX) swf_SetMatrix(t,&obj->matrix);
111 if (flags&PF_CXFORM) swf_SetCXForm(t,&obj->cxform,(obj->cxform.a0!=256)||
113 if (flags&PF_RATIO) swf_SetU16(t,obj->ratio);
114 if (flags&PF_NAME) swf_SetString(t,obj->name);
115 if (flags&PF_CLIPACTION) swf_SetU16(t,obj->clipdepth);
116 if (flags&PF_ACTIONEVENT) {
122 void swf_GetPlaceObject(TAG * tag,SWFPLACEOBJECT* obj)
124 U8 flags = swf_GetU8(tag);
125 memset(obj,0,sizeof(SWFPLACEOBJECT));
127 swf_GetMatrix(0,&obj->matrix);
128 swf_GetCXForm(0,&obj->cxform,1);
131 obj->depth = swf_GetU16(tag);
133 if(flags&2) obj->id = swf_GetU16(tag);
134 if(flags&4) swf_GetMatrix(tag, &obj->matrix);
135 if(flags&8) swf_GetCXForm(tag, &obj->cxform,1);
136 if(flags&16) obj->ratio = swf_GetU16(tag);
138 int l = strlen(&tag->data[tag->pos]);
140 U8*data = malloc(l+1);
142 while((data[t++] = swf_GetU8(tag)));
145 obj->clipdepth = swf_GetU16(tag); //clip
147 /* Actionscript ignored (for now) */
151 void swf_PlaceObjectFree(SWFPLACEOBJECT* obj)