movie_clips_ins.c.svn-base

来自「A Flash Player with ActionScript support」· SVN-BASE 代码 · 共 356 行

SVN-BASE
356
字号
#include "base_types.h"#include "instance.h"#include "movie_clips_ins.h"#include "movie_clips_def.h"#include "swf_file_pub.h"#include "spliter_pub.h"#include <glib.h>#include <assert.h>void mc_ins_change(GNode* node_p,struct PlaceObject *cmd_p) {    mc_ins_t		*data_p 	= node_p->data;    if (cmd_p->Flags & PlaceFlagHasClipActions) {        data_p->actions_p = cmd_p->ActionBlockP;    };};void mc_ins_evolve(GNode* node_p) {    GNode 		*p, *new_p;    mc_ins_t		*data_p 	= node_p->data;    struct MovieClip 	*def_p 		= (struct MovieClip*)(data_p->define_p);    switch(data_p->state) {    case MC_PLAY:    case MC_TO_STOP:        if (data_p->next_frame == def_p->TotalFrames) {            data_p->state = MC_STOP;            // 到头 非根节点 绕回, 根节点 停止.            /*                   if (node_p->parent) {                       data_p->last_frame = 0;                       data_p->next_frame = 1;                   } else {                       data_p->state = MC_STOP;                   };            */        } else {            // 迈开一步.            data_p->next_frame = data_p->last_frame + 1;        };    }};/* * 更新所指定的节点的子节点.即根据 MC 的 place and remove 队列 * 更新 mc 的第一层子节点. * 如果是由小号桢跳到大号桢,则将两号间的桢顺序跑遍 (forward). * 如果是由大号桢跳到小号桢,则由第一桢跑到小号桢 (backward). * 如果由 0 桢起跑,则将原有子节点全销毁,从头画. */void mc_ins_update_children(GNode* node_p) {    GNode 		*p, *new_p;    mc_ins_t		*data_p 	= node_p->data;    struct MovieClip 	*def_p 		= (struct MovieClip*)(data_p->define_p);    struct PAndRObjects	*cmd_list_p 	= NULL;    int 		from_frame 	= 0;	// 由哪桢起    int			to_frame	= 0;   	// 到哪桢去    int			frame_ip 	= 0;	// 正在处理哪一桢    /*    if (data_p->state == MC_STOP) {        return;    };    */    if (data_p->next_frame == data_p->last_frame) {        return;    };    if (data_p->next_frame < data_p->last_frame) {        from_frame = 0;        to_frame = data_p->next_frame;    } else {        from_frame = data_p->last_frame;        to_frame = data_p->next_frame;    };    if ((from_frame == 0) && (to_frame > 0)) {        GNode *p1;        p = g_node_first_child(node_p);        while (p != NULL) {            p1 = p;            p = p -> next;            ins_destory(p1);        };    };    for (frame_ip=from_frame; frame_ip < to_frame; frame_ip++) {        cmd_list_p = def_p->Frames[frame_ip].TagsListP;        while (cmd_list_p != NULL) {            for (p = g_node_first_child(node_p)                     ;((p != NULL) && (((instance_t*)(p->data))->depth < cmd_list_p->Depth))                    ; p = p -> next)                ;            switch (cmd_list_p->PlaceAndRemoveType) {            case TPlaceObjectOne:            case TPlaceObjectTwo:                if (p == NULL) {                    new_p = ins_new(data_p->swf_p,(struct PlaceObject*)cmd_list_p);                    g_node_append(node_p,new_p);                    ins_new_after(new_p);                    break;                }                if (((instance_t*)(p->data))->depth == cmd_list_p->Depth) {                    ins_change(p,(struct PlaceObject*)cmd_list_p);                    break;                };                if (((instance_t*)(p->data))->depth > cmd_list_p->Depth) {                    new_p = ins_new(data_p->swf_p,(struct PlaceObject*)cmd_list_p);                    g_node_insert_before(node_p,p,new_p);                    ins_new_after(new_p);                    break;                };            case TRemoveObjectOne:            case TRemoveObjectTwo:                if ((p != NULL) && (((instance_t*)(p->data))->depth == cmd_list_p->Depth)) {                    ins_destory(p);                } else {                    printf("warning: try to remove an unexisted object\n");                    //  assert(0);                };            };            cmd_list_p=cmd_list_p->NextP;        };        data_p->last_frame = frame_ip;    };    data_p->last_frame = data_p->next_frame;};int mc_ins_label_find(GNode* node_p,char *label_p) {    mc_ins_t            *data_p         = node_p->data;    struct MovieClip 	*def_p 		= (struct MovieClip*)(data_p->define_p);    struct FrameLabel   *l_p;    l_p = def_p->FrameLabelListP;    while (l_p != NULL) {        if (g_strcasecmp(label_p,l_p->NameP) == 0) {            return l_p->Frame;        };        l_p=l_p->NextP;    };    return -1;};void mc_ins_prev_frame(GNode* node_p) {    mc_ins_t            *data_p         = node_p->data;    struct MovieClip 	*def_p 		= (struct MovieClip*)(data_p->define_p);    data_p->next_frame = data_p->next_frame - 2;	// 自己算一桢,再往前一桢,共两桢.    if ((data_p->next_frame < 0) || (data_p->next_frame >= def_p->TotalFrames)) {        data_p->next_frame = 0;    };};void mc_ins_next_frame(GNode* node_p) {    mc_ins_t            *data_p         = node_p->data;    struct MovieClip 	*def_p 		= (struct MovieClip*)(data_p->define_p);    /*    //XXX 缺省即为下一桢,此命令何用?    data_p->next_frame = data_p->next_frame + 1;    if ((data_p->next_frame < 0) || (data_p->next_frame >= def_p->TotalFrames)) {        data_p->next_frame = 0;    }; */    data_p->next_frame = data_p->next_frame + 1;    if ((data_p->next_frame < 0) || (data_p->next_frame >= def_p->TotalFrames)) {        data_p->next_frame = 0;    };    if (data_p->state != MC_PLAY) {        data_p->state == MC_TO_STOP;    };};void mc_ins_play(GNode* node_p) {    mc_ins_t            *data_p         = node_p->data;    struct MovieClip 	*def_p 		= (struct MovieClip*)(data_p->define_p);    //    if ((data_p->state == MC_STOP) && (data_p->next_frame == data_p->last_frame)) {    /*    if (data_p->next_frame == data_p->last_frame) {    //    if ((data_p->state == MC_STOP) && (data_p->next_frame == data_p->last_frame)) {    if (data_p->next_frame == data_p->last_frame) {        data_p->next_frame = MIN((data_p->next_frame + 1),def_p->TotalFrames-1);    }*/    data_p->state = MC_PLAY;};void mc_ins_stop(GNode* node_p) {    mc_ins_t            *data_p         = node_p->data;    // data_p->next_frame = data_p->last_frame;    if (data_p->state != MC_TO_STOP)        data_p->state = MC_STOP;};void mc_ins_go_and_play(GNode* node_p,UI16 frame) {    mc_ins_t            *data_p         = node_p->data;    struct MovieClip 	*def_p 		= (struct MovieClip*)(data_p->define_p);    if ((frame < 0) || (frame >= def_p->TotalFrames)) {        frame = 0;    };    data_p->next_frame = frame;    mc_ins_update_children(node_p);    data_p->state = MC_PLAY;};void mc_ins_go_and_stop(GNode* node_p,UI16 frame) {    mc_ins_t            *data_p         = node_p->data;    struct MovieClip 	*def_p 		= (struct MovieClip*)(data_p->define_p);    if ((frame < 0) || (frame >= def_p->TotalFrames)) {        frame = 0;    };    data_p->next_frame = frame;    mc_ins_update_children(node_p);    data_p->state = MC_TO_STOP;    /*    frame = frame % def_p->TotalFrames;    assert(frame < def_p->TotalFrames);    data_p->next_frame = (frame - 1);    mc_ins_update_children(node_p);    data_p->state = MC_TO_STOP;    */};void mc_ins_duplicate(GNode* node_p,char* name_p,UI32 depth_in) {    mc_ins_t            *data_p         = node_p->data;    mc_ins_t		*new_data_p;    GNode		*new_node_p, *p, *p1 = NULL;    GNode		*node_parent_p	= node_p->parent;    long		depth = depth_in;// + 0x4000;		// 见 as 书 341 页,层号范围    new_data_p = g_memdup(data_p,sizeof(mc_ins_t));    new_node_p = g_node_new(new_data_p);    /*    if (new_data_p->name_p) {        g_free(new_data_p->name_p);    };    */    new_data_p->name_p = g_strdup(name_p);    new_data_p->depth = depth;    new_data_p->last_frame = 0;    new_data_p->next_frame = 0;    new_data_p->state = MC_PLAY;    for (p = g_node_first_child(node_parent_p)             ;((p != NULL) && (((instance_t*)(p->data))->depth < depth))            ; p = p -> next)        ;    if (p == NULL) {        g_node_append(node_parent_p,new_node_p);    } else {        if (((instance_t*)(p->data))->depth == depth) {            p1 = p->next;            //XXX 登记面积            ins_destory(p);            if (p1) {                g_node_insert_before(node_parent_p,p1,new_node_p);            } else {                g_node_append(node_parent_p,new_node_p);            };        } else {            if (((instance_t*)(p->data))->depth > depth) {                g_node_insert_before(node_parent_p,p,new_node_p);            };        }    };    // 把新建的 mc 节点的子节点生成.    swf_first_pass(new_node_p);    swf_second_pass(new_node_p);};void mc_ins_attach(GNode* node_p,UI16 c_id, char* name_p,UI32 depth) {    mc_ins_t            *data_p         = node_p->data;    GNode		*new_node_p, *p;    struct PlaceObject	po;    po.Depth = depth;    po.PlaceAndRemoveType = TPlaceObjectTwo;    po.Flags = PlaceFlagHasClipDepth               |PlaceFlagHasName               |PlaceFlagHasColorTransform               |PlaceFlagHasMatrix               |PlaceFlagHasCharacter;    po.CharacterID = c_id;    mat_new(&po.Matrix);    //    new_cxform(&po.ColorTransform);    po.NameP = name_p;    new_node_p = ins_new(data_p->swf_p,&po);    for (p = g_node_first_child(node_p)             ;((p != NULL) && (((instance_t*)(p->data))->depth < depth))            ; p = p -> next)        ;    if (p == NULL) {        g_node_append(node_p,new_node_p);    } else {        assert(((instance_t*)(p->data))->depth == depth);        g_node_insert_before(node_p,p,new_node_p);    };};void mc_ins_remove(GNode* node_p) {    ins_destory(node_p);};long mc_ins_get_bytes_loaded(GNode* node_p) {    mc_ins_t            *data_p         = node_p->data;    swf_file_t		*swf_p		= data_p->swf_p;    spliter_t		*spliter_p	= swf_p->spliter_p;    //XXX 均假定取整个 swf 文件的长度和进度.    //单个 mc 的长度和进度不知如何得到.    return spliter_p->current_reader->pos;};long mc_ins_get_bytes_total(GNode* node_p) {    mc_ins_t            *data_p         = node_p->data;    swf_file_t		*swf_p		= data_p->swf_p;    return swf_p->file_length;};void mc_ins_local_to_global(GNode* node_p,long *x_p, long *y_p) {    mc_ins_t            *data_p         = node_p->data;    long 		in_x = *x_p;    long 		in_y = *y_p;    *x_p = mat_getx(&data_p->ab_matrix,in_x,in_y);    *y_p = mat_gety(&data_p->ab_matrix,in_x,in_y);    return;};void mc_ins_global_to_local(GNode* node_p,long *x_p, long *y_p) {    mc_ins_t            *data_p         = node_p->data;    //XXX 将 ab_matrix 取反再计算,即为 global to local ??    struct Matrix	mat_inv		= mat_invert(&data_p->ab_matrix);    long 		in_x = *x_p;    long 		in_y = *y_p;    *x_p = mat_getx(&mat_inv,in_x,in_y);    *y_p = mat_gety(&mat_inv,in_x,in_y);    return;};gboolean mc_ins_hit_test(GNode* node_p,long x, long y) {    mc_ins_t            *data_p         = node_p->data;    return rect_is_point_in(&data_p->boundary,x,y);};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?