X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fswfc.c;h=1a1afb4c71d5522eb63cb855bc95388c33127558;hb=12c0a48dd16767c28e87d21b2265ba1de9837f60;hp=3bf8a73f0ca4fe449ae42d52d7e90505de3af57d;hpb=843ede6dfb99d5da7d2a87b9036ec631d0fd5a1b;p=swftools.git diff --git a/src/swfc.c b/src/swfc.c index 3bf8a73..1a1afb4 100644 --- a/src/swfc.c +++ b/src/swfc.c @@ -48,7 +48,6 @@ static struct options_t options[] = { {"V", "version"}, {"v", "verbose"}, {"o", "output"}, -{"O", "optimize"}, {0,0} }; @@ -806,16 +805,18 @@ void s_box(char*name, int width, int height, RGBA color, int linewidth, char*tex r2.ymax = height; tag = swf_InsertTag(tag, ST_DEFINESHAPE3); swf_ShapeNew(&s); - if(linewidth) - ls1 = swf_ShapeAddLineStyle(s,linewidth>=20?linewidth-20:0,&color); + if(linewidth) { + linewidth = linewidth>=20?linewidth-20:0; + ls1 = swf_ShapeAddLineStyle(s,linewidth,&color); + } if(texture) fs1 = addFillStyle(s, &r2, texture); swf_SetU16(tag,id); - r.xmin = r2.xmin-linewidth-linewidth/2; - r.ymin = r2.ymin-linewidth-linewidth/2; - r.xmax = r2.xmax+linewidth+linewidth/2; - r.ymax = r2.ymax+linewidth+linewidth/2; + r.xmin = r2.xmin-linewidth/2; + r.ymin = r2.ymin-linewidth/2; + r.xmax = r2.xmax+linewidth/2; + r.ymax = r2.ymax+linewidth/2; swf_SetRect(tag,&r); swf_SetShapeHeader(tag,s); swf_ShapeSetAll(tag,s,0,0,ls1,fs1,0); @@ -844,22 +845,24 @@ void s_filled(char*name, char*outlinename, RGBA color, int linewidth, char*textu tag = swf_InsertTag(tag, ST_DEFINESHAPE3); swf_ShapeNew(&s); - if(linewidth) - ls1 = swf_ShapeAddLineStyle(s,linewidth>=20?linewidth-20:0,&color); + if(linewidth) { + linewidth = linewidth>=20?linewidth-20:0; + ls1 = swf_ShapeAddLineStyle(s,linewidth,&color); + } if(texture) fs1 = addFillStyle(s, &r2, texture); swf_SetU16(tag,id); - rect.xmin = r2.xmin-linewidth-linewidth/2; - rect.ymin = r2.ymin-linewidth-linewidth/2; - rect.xmax = r2.xmax+linewidth+linewidth/2; - rect.ymax = r2.ymax+linewidth+linewidth/2; + rect.xmin = r2.xmin-linewidth/2; + rect.ymin = r2.ymin-linewidth/2; + rect.xmax = r2.xmax+linewidth/2; + rect.ymax = r2.ymax+linewidth/2; swf_SetRect(tag,&rect); swf_SetShapeStyles(tag, s); swf_ShapeCountBits(s,0,0); - swf_RecodeShapeData(outline->shape->data, outline->shape->bitlen, 1, 1, - &s->data, &s->bitlen, s->bits.fill, s->bits.line); + swf_RecodeShapeData(outline->shape->data, outline->shape->bitlen, outline->shape->bits.fill, outline->shape->bits.line, + &s->data, &s->bitlen, s->bits.fill, s->bits.line); swf_SetShapeBits(tag, s); swf_SetBlock(tag, s->data, (s->bitlen+7)/8); swf_ShapeFree(s); @@ -879,15 +882,17 @@ void s_circle(char*name, int r, RGBA color, int linewidth, char*texture) tag = swf_InsertTag(tag, ST_DEFINESHAPE3); swf_ShapeNew(&s); - if(linewidth) - ls1 = swf_ShapeAddLineStyle(s,linewidth>=20?linewidth-20:0,&color); + if(linewidth) { + linewidth = linewidth>=20?linewidth-20:0; + ls1 = swf_ShapeAddLineStyle(s,linewidth,&color); + } if(texture) fs1 = addFillStyle(s, &r2, texture); swf_SetU16(tag,id); - rect.xmin = r2.xmin-linewidth-linewidth/2; - rect.ymin = r2.ymin-linewidth-linewidth/2; - rect.xmax = r2.xmax+linewidth+linewidth/2; - rect.ymax = r2.ymax+linewidth+linewidth/2; + rect.xmin = r2.xmin-linewidth/2; + rect.ymin = r2.ymin-linewidth/2; + rect.xmax = r2.xmax+linewidth/2; + rect.ymax = r2.ymax+linewidth/2; swf_SetRect(tag,&rect); swf_SetShapeHeader(tag,s); @@ -1291,6 +1296,24 @@ void s_action(const char*text) swf_ActionFree(a); } +void s_initaction(const char*character, const char*text) +{ + ActionTAG* a = 0; + character_t*c = 0; + a = swf_ActionCompile(text, stack[0].swf->fileVersion); + if(!a) { + syntaxerror("Couldn't compile ActionScript"); + } + + c = (character_t*)dictionary_lookup(&characters, character); + + tag = swf_InsertTag(tag, ST_DOINITACTION); + swf_SetU16(tag, c->id); + swf_ActionSet(tag, a); + + swf_ActionFree(a); +} + int s_swf3action(char*name, char*action) { ActionTAG* a = 0; @@ -1324,7 +1347,9 @@ void s_outline(char*name, char*format, char*source) SHAPE2* shape2; SRECT bounds; + //swf_Shape10DrawerInit(&draw, 0); swf_Shape11DrawerInit(&draw, 0); + draw_string(&draw, source); draw.finish(&draw); shape = swf_ShapeDrawerToShape(&draw); @@ -2717,6 +2742,23 @@ static int c_edittext(map_t*args) static int c_morphshape(map_t*args) {return fakechar(args);} static int c_movie(map_t*args) {return fakechar(args);} +static char* readfile(const char*filename) +{ + FILE*fi = fopen(filename, "rb"); + int l; + char*text; + if(!fi) + syntaxerror("Couldn't find file %s: %s", filename, strerror(errno)); + fseek(fi, 0, SEEK_END); + l = ftell(fi); + fseek(fi, 0, SEEK_SET); + text = rfx_alloc(l+1); + fread(text, l, 1, fi); + text[l]=0; + fclose(fi); + return text; +} + static int c_action(map_t*args) { char* filename = map_lookup(args, "filename"); @@ -2727,20 +2769,24 @@ static int c_action(map_t*args) } s_action(text); } else { - FILE*fi = fopen(filename, "rb"); - int l; - char*text; - if(!fi) - syntaxerror("Couldn't find file %s: %s", filename, strerror(errno)); - fseek(fi, 0, SEEK_END); - l = ftell(fi); - fseek(fi, 0, SEEK_SET); - text = rfx_alloc(l+1); - fread(text, l, 1, fi); - text[l]=0; - fclose(fi); + s_action(readfile(filename)); + } + + return 0; +} - s_action(text); +static int c_initaction(map_t*args) +{ + char* character = lu(args, "name"); + char* filename = map_lookup(args, "filename"); + if(!filename ||!*filename) { + readToken(); + if(type != RAWDATA) { + syntaxerror("colon (:) expected"); + } + s_initaction(character, text); + } else { + s_initaction(character, readfile(filename)); } return 0; @@ -2809,6 +2855,7 @@ static struct { //startclip (see above) {"sprite", c_sprite, "name"}, {"action", c_action, "filename="}, + {"initaction", c_initaction, "name filename="}, {"end", c_end, ""} };