⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commands.c

📁 一个用于智能手机的多媒体库适合S60 WinCE的跨平台开发库
💻 C
📖 第 1 页 / 共 2 页
字号:
			gf_sg_route_set_name(r, com->def_name);			free(com->def_name);			com->def_name = NULL;		}		break;	}	case GF_SG_INDEXED_INSERT:	{		u32 sftype;		if (!gf_list_count(com->command_fields)) return GF_OK;		inf = (GF_CommandField*)gf_list_get(com->command_fields, 0);		e = gf_node_get_field(com->node, inf->fieldIndex, &field);		if (e) return e;		/*rescale the MFField and parse the SFField*/		if (field.fieldType != GF_SG_VRML_MFNODE) {			if (inf->pos == -1) {				e = gf_sg_vrml_mf_append(field.far_ptr, field.fieldType, & slot_ptr);			} else {				e = gf_sg_vrml_mf_insert(field.far_ptr, field.fieldType, & slot_ptr, inf->pos);			}			if (e) return e;			sftype = gf_sg_vrml_get_sf_type(field.fieldType);			gf_sg_vrml_field_copy(slot_ptr, inf->field_ptr, sftype);		} else {			if (inf->new_node) {				if (inf->pos == -1) {					gf_node_list_add_child( (GF_ChildNodeItem **) field.far_ptr, inf->new_node);				} else {					gf_node_list_insert_child((GF_ChildNodeItem **) field.far_ptr, inf->new_node, inf->pos);				}				gf_node_register(inf->new_node, com->node);			}		}		if (!e) SG_CheckFieldChange(com->node, &field);		break;	}	case GF_SG_PROTO_INSERT:		/*destroy all proto*/		while (gf_list_count(com->new_proto_list)) {			GF_Proto *p = (GF_Proto*)gf_list_get(com->new_proto_list, 0);			gf_list_rem(com->new_proto_list, 0);			gf_list_del_item(graph->unregistered_protos, p);			gf_list_add(graph->protos, p);		}		return GF_OK;	case GF_SG_PROTO_DELETE:		{			u32 i;			for (i=0; i<com->del_proto_list_size; i++) {				/*note this will check for unregistered protos, but since IDs are unique we are sure we will 				not destroy an unregistered one*/				GF_Proto *proto = gf_sg_find_proto(graph, com->del_proto_list[i], NULL);				if (proto) gf_sg_proto_del(proto);			}		}		return GF_OK;	case GF_SG_PROTO_DELETE_ALL:		/*destroy all proto*/		while (gf_list_count(graph->protos)) {			GF_Proto *p = (GF_Proto*)gf_list_get(graph->protos, 0);			gf_list_rem(graph->protos, 0);			/*this will unregister the proto from the graph, so don't delete the chain entry*/			gf_sg_proto_del(p);		}		/*DO NOT TOUCH UNREGISTERED PROTOS*/		return GF_OK;	/*only used by BIFS*/	case GF_SG_GLOBAL_QUANTIZER:		return GF_OK;#ifndef GPAC_DISABLE_SVG	/*laser commands*/	case GF_SG_LSR_NEW_SCENE:		/*DO NOT TOUCH node registry*/		/*assign new root (no need to register/unregister)*/		graph->RootNode = com->node;		com->node = NULL;		break;	case GF_SG_LSR_DELETE:		if (!com->node) return GF_NON_COMPLIANT_BITSTREAM;		if (!gf_list_count(com->command_fields)) {			gf_node_replace(com->node, NULL, 0);			gf_node_deactivate(com->node);			return GF_OK;		}		inf = (GF_CommandField*)gf_list_get(com->command_fields, 0);		node = gf_node_list_get_child(((SVG_Element *)com->node)->children, inf->pos);		if (node) {			e = gf_node_replace_child(com->node, &((SVG_Element *)com->node)->children, inf->pos, NULL);			gf_node_deactivate(node);		}		break;	case GF_SG_LSR_INSERT:		inf = (GF_CommandField*)gf_list_get(com->command_fields, 0);		if (!com->node || !inf) return GF_NON_COMPLIANT_BITSTREAM;		if (inf->new_node) {			if (inf->pos<0) 				gf_node_list_add_child(& ((SVG_Element *)com->node)->children, inf->new_node);			else				gf_node_list_insert_child(& ((SVG_Element *)com->node)->children, inf->new_node, inf->pos);			gf_node_register(inf->new_node, com->node);			gf_node_activate(inf->new_node);			gf_node_changed(com->node, NULL);		} else {			/*NOT SUPPORTED*/			GF_LOG(GF_LOG_ERROR, GF_LOG_CODEC, ("[LASeR] VALUE INSERTION NOT SUPPORTED\n"));		}		break;	case GF_SG_LSR_ADD:	case GF_SG_LSR_REPLACE:		inf = (GF_CommandField*)gf_list_get(com->command_fields, 0);		if (!com->node || !inf) return GF_NON_COMPLIANT_BITSTREAM;		if (inf->new_node) {			if (inf->pos<0) {				/*if fieldIndex (eg attributeName) is set, this is children replacement*/				if (inf->fieldIndex>0) {					gf_node_unregister_children_deactivate(com->node, ((SVG_Element *)com->node)->children);					((SVG_Element *)com->node)->children = NULL;					gf_node_list_add_child(& ((SVG_Element *)com->node)->children, inf->new_node);					gf_node_register(inf->new_node, com->node);					gf_node_activate(inf->new_node);				} else {					e = gf_node_replace(com->node, inf->new_node, 0);					gf_node_activate(inf->new_node);				}			} else {				node = gf_node_list_get_child( ((SVG_Element *)com->node)->children, inf->pos);				gf_node_replace_child(com->node, & ((SVG_Element *)com->node)->children, inf->pos, inf->new_node);				gf_node_register(inf->new_node, com->node);				if (node) gf_node_deactivate(node);				gf_node_activate(inf->new_node);			}			/*signal node modif*/			gf_node_changed(com->node, NULL);			return e;		} else if (inf->node_list) {			GF_ChildNodeItem *child, *cur, *prev;			gf_node_unregister_children_deactivate(com->node, ((SVG_Element *)com->node)->children);			((SVG_Element *)com->node)->children = NULL;			prev = NULL;			child = inf->node_list;			while (child) {				cur = (GF_ChildNodeItem*)malloc(sizeof(GF_ChildNodeItem));				cur->next = NULL;				cur->node = child->node;				gf_node_register(child->node, com->node);				gf_node_activate(child->node);				if (prev) prev->next = cur;				else ((SVG_Element *)com->node)->children = cur;				prev = cur;				child = child->next;			}			/*signal node modif*/			gf_node_changed(com->node, NULL);			return GF_OK;		}		/*attribute modif*/		else if (inf->field_ptr) {			GF_FieldInfo a, b;			if (inf->fieldIndex==(u32) -2) {				GF_Point2D scale, translate;				Fixed rotate;				GF_Matrix2D *dest;				gf_node_get_field_by_name(com->node, "transform", &a);				dest = (GF_Matrix2D*)a.far_ptr;								if (com->tag==GF_SG_LSR_REPLACE) {					if (gf_mx2d_decompose(dest, &scale, &rotate, &translate)) {						gf_mx2d_init(*dest);						if (inf->fieldType==SVG_TRANSFORM_SCALE) scale = *(GF_Point2D *)inf->field_ptr;						else if (inf->fieldType==SVG_TRANSFORM_TRANSLATE) translate = *(GF_Point2D *)inf->field_ptr;						else if (inf->fieldType==SVG_TRANSFORM_ROTATE) rotate = ((SVG_Point_Angle*)inf->field_ptr)->angle;						gf_mx2d_add_scale(dest, scale.x, scale.y);						gf_mx2d_add_rotation(dest, 0, 0, rotate);						gf_mx2d_add_translation(dest, translate.x, translate.y);					}				} else {					GF_Point2D *pt = (GF_Point2D *)inf->field_ptr;					if (inf->fieldType==SVG_TRANSFORM_SCALE) gf_mx2d_add_scale(dest, pt->x, pt->y);					else if (inf->fieldType==SVG_TRANSFORM_TRANSLATE) gf_mx2d_add_translation(dest, pt->x, pt->y);					else if (inf->fieldType == SVG_TRANSFORM_ROTATE) gf_mx2d_add_rotation(dest, 0, 0, ((SVG_Point_Angle*)inf->field_ptr)->angle);				}			} else {				if ((inf->fieldIndex==(u32) -1) && (inf->fieldType==SVG_String_datatype)) {					char *str = *(SVG_String*)inf->field_ptr;					if (com->tag == GF_SG_LSR_REPLACE) {						GF_DOMText *t = ((SVG_Element*)com->node)->children ? (GF_DOMText*) ((SVG_Element*)com->node)->children->node :NULL; 						if (t && (t->sgprivate->tag==TAG_DOMText)) {							if (t->textContent) free(t->textContent);							t->textContent = NULL;							if (str) t->textContent = strdup(str);						}					} else {						if (str) gf_dom_add_text_node(com->node, strdup(str));					}				}				else if ((inf->fieldIndex==TAG_LSR_ATT_scale) 					|| (inf->fieldIndex==TAG_LSR_ATT_translation)					|| (inf->fieldIndex==TAG_LSR_ATT_rotation)				) {					SVG_Transform *mx;					gf_svg_get_attribute_by_tag(com->node, TAG_SVG_ATT_transform, 1, 0, &a);					mx = a.far_ptr;					if (com->tag == GF_SG_LSR_REPLACE) {						GF_Point2D scale, translate;						SVG_Point_Angle rotate;						if (gf_mx2d_decompose(&mx->mat, &scale, &rotate.angle, &translate)) {							gf_mx2d_init(mx->mat);							if (inf->fieldIndex==TAG_LSR_ATT_scale) scale = *(GF_Point2D *)inf->field_ptr;							else if (inf->fieldIndex==TAG_LSR_ATT_translation) translate = *(GF_Point2D *)inf->field_ptr;							else if (inf->fieldIndex==TAG_LSR_ATT_rotation) rotate = *(SVG_Point_Angle*)inf->field_ptr;							gf_mx2d_add_scale(&mx->mat, scale.x, scale.y);							gf_mx2d_add_rotation(&mx->mat, 0, 0, rotate.angle);							gf_mx2d_add_translation(&mx->mat, translate.x, translate.y);						}					} else {						if (inf->fieldIndex==TAG_LSR_ATT_scale) gf_mx2d_add_scale(&mx->mat, ((GF_Point2D*)inf->field_ptr)->x, ((GF_Point2D*)inf->field_ptr)->y);						if (inf->fieldIndex==TAG_LSR_ATT_translation) gf_mx2d_add_translation(&mx->mat, ((GF_Point2D*)inf->field_ptr)->x, ((GF_Point2D*)inf->field_ptr)->y);						if (inf->fieldIndex==TAG_LSR_ATT_rotation) gf_mx2d_add_rotation(&mx->mat, 0, 0, ((SVG_Point_Angle*)inf->field_ptr)->angle);					}				}				else if (gf_svg_get_attribute_by_tag(com->node, inf->fieldIndex, 1, 0, &a) == GF_OK) {					b = a;					b.far_ptr = inf->field_ptr;					if (com->tag == GF_SG_LSR_REPLACE) {						gf_svg_attributes_copy(&a, &b, 0);					} else {						gf_svg_attributes_add(&a, &b, &a, 0);					}				}				b = a;				b.far_ptr = inf->field_ptr;			}			/*signal node modif*/			gf_node_changed(com->node, &a);		} else if (com->fromNodeID) {			GF_FieldInfo a, b;			GF_Node *fromNode = gf_sg_find_node(graph, com->fromNodeID);			if (!fromNode) return GF_NON_COMPLIANT_BITSTREAM;			if (gf_node_get_field(fromNode, com->fromFieldIndex, &b) != GF_OK) return GF_NON_COMPLIANT_BITSTREAM;			if ((inf->fieldIndex==(u32) -1) && (inf->fieldType==SVG_String_datatype)) {				char *str = *(SVG_String*)inf->field_ptr;				if (com->tag == GF_SG_LSR_REPLACE) {					GF_DOMText *t = ((SVG_Element*)com->node)->children ? (GF_DOMText*) ((SVG_Element*)com->node)->children->node :NULL; 					if (t && (t->sgprivate->tag==TAG_DOMText)) {						if (t->textContent) free(t->textContent);						t->textContent = NULL;						if (str) t->textContent = strdup(str);					}				} else {					if (str) gf_dom_add_text_node(com->node, strdup(str));				}			} else {				gf_node_get_field(com->node, inf->fieldIndex, &a);				if (com->tag == GF_SG_LSR_REPLACE) {					e = gf_svg_attributes_copy(&a, &b, 0);				} else {					e = gf_svg_attributes_add(&a, &b, &a, 0);				}			}			gf_node_changed(com->node, &a);			return e;		} else {			return GF_NON_COMPLIANT_BITSTREAM;		}		break;	case GF_SG_LSR_ACTIVATE:		gf_node_activate(com->node);		break;	case GF_SG_LSR_DEACTIVATE:		gf_node_deactivate(com->node);		gf_node_changed(com->node, NULL);		break;#endif	default:		return GF_NOT_SUPPORTED;	}	if (e) return e;	if (com->scripts_to_load) {		while (gf_list_count(com->scripts_to_load)) {			GF_Node *script = (GF_Node *)gf_list_get(com->scripts_to_load, 0);			gf_list_rem(com->scripts_to_load, 0);			gf_sg_script_load(script);		}		gf_list_del(com->scripts_to_load);		com->scripts_to_load = NULL;	}	return GF_OK;}GF_CommandField *gf_sg_command_field_new(GF_Command *com){	GF_CommandField *ptr;	GF_SAFEALLOC(ptr, GF_CommandField);	gf_list_add(com->command_fields, ptr);	return ptr;}GF_EXPORTGF_Err gf_sg_command_apply_list(GF_SceneGraph *graph, GF_List *comList, Double time_offset){	GF_Err e;	GF_Command *com;	u32 i=0;	while ((com = (GF_Command *)gf_list_enum(comList, &i))) {		e = gf_sg_command_apply(graph, com, time_offset);		if (e) return e;	}	return GF_OK;}GF_Command *gf_sg_command_clone(GF_Command *com, GF_SceneGraph *inGraph){	u32 i, count;	GF_Command *dest;		if (com->tag==GF_SG_SCENE_REPLACE) return NULL;	/*FIXME - to do*/	if (gf_list_count(com->new_proto_list)) return NULL;	dest = gf_sg_command_new(inGraph, com->tag);	/*node the command applies to - may be NULL*/	dest->node = gf_node_clone(inGraph, com->node, NULL);	/*route insert, replace and delete*/	dest->RouteID = com->RouteID;	if (com->def_name) dest->def_name = strdup(com->def_name);	dest->fromNodeID = com->fromNodeID;	dest->fromFieldIndex = com->fromFieldIndex;	dest->toNodeID = com->toNodeID;	dest->toFieldIndex = com->toFieldIndex;	dest->del_proto_list_size = com->del_proto_list_size;	if (com->del_proto_list_size) {		dest->del_proto_list = (u32*)malloc(sizeof(u32) * com->del_proto_list_size);		memcpy(dest->del_proto_list, com->del_proto_list, sizeof(u32) * com->del_proto_list_size);	}	count = gf_list_count(com->command_fields);	for (i=0; i<count; i++) {		GF_CommandField *fo = (GF_CommandField *)gf_list_get(com->command_fields, i);		GF_CommandField *fd = (GF_CommandField *)gf_sg_command_field_new(dest);		fd->fieldIndex = fo->fieldIndex;		fd->fieldType = fo->fieldType;		fd->pos = fo->pos;		if (fo->field_ptr) {			fd->field_ptr = gf_sg_vrml_field_pointer_new(fd->fieldType);			gf_sg_vrml_field_copy(fd->field_ptr, fo->field_ptr, fo->fieldType);		}		if (fo->new_node) {			fd->new_node = gf_node_clone(inGraph, fo->new_node, dest->node);			fd->field_ptr = &fd->new_node;		}		if (fo->node_list) {			GF_ChildNodeItem *child, *cur, *prev;			prev = NULL;			child = fo->node_list;			while (child) {				cur = (GF_ChildNodeItem*) malloc(sizeof(GF_ChildNodeItem));				cur->node = gf_node_clone(inGraph, child->node, dest->node);				cur->next = NULL;				if (prev) prev->next = cur;				else fd->node_list = cur;				prev = cur;				child = child->next;			}			fd->field_ptr = &fd->node_list;		}	}	return dest;}

⌨️ 快捷键说明

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