Example #1
0
bool nla_panel_context(const bContext *C, PointerRNA *adt_ptr, PointerRNA *nlt_ptr, PointerRNA *strip_ptr)
{
	bAnimContext ac;
	bAnimListElem *ale = NULL;
	ListBase anim_data = {NULL, NULL};
	short found = 0; /* not bool, since we need to indicate "found but not ideal" status */
	int filter;
	
	/* for now, only draw if we could init the anim-context info (necessary for all animation-related tools) 
	 * to work correctly is able to be correctly retrieved. There's no point showing empty panels?
	 */
	if (ANIM_animdata_get_context(C, &ac) == 0) 
		return false;
	
	/* extract list of active channel(s), of which we should only take the first one 
	 *	- we need the channels flag to get the active AnimData block when there are no NLA Tracks
	 */
	// XXX: double-check active!
	filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_ACTIVE | ANIMFILTER_LIST_CHANNELS);
	ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
	
	for (ale = anim_data.first; ale; ale = ale->next) {
		switch (ale->type) {
			case ANIMTYPE_NLATRACK: /* NLA Track - The primary data type which should get caught */
			{
				NlaTrack *nlt = (NlaTrack *)ale->data;
				AnimData *adt = ale->adt;
				
				/* found it, now set the pointers */
				if (adt_ptr) {
					/* AnimData pointer */
					RNA_pointer_create(ale->id, &RNA_AnimData, adt, adt_ptr);
				}
				if (nlt_ptr) {
					/* NLA-Track pointer */
					RNA_pointer_create(ale->id, &RNA_NlaTrack, nlt, nlt_ptr);
				}
				if (strip_ptr) {
					/* NLA-Strip pointer */
					NlaStrip *strip = BKE_nlastrip_find_active(nlt);
					RNA_pointer_create(ale->id, &RNA_NlaStrip, strip, strip_ptr);
				}
				
				found = 1;
				break;
			}
			case ANIMTYPE_SCENE:    /* Top-Level Widgets doubling up as datablocks */
			case ANIMTYPE_OBJECT:
			case ANIMTYPE_DSMAT:    /* Datablock AnimData Expanders */
			case ANIMTYPE_DSLAM:
			case ANIMTYPE_DSCAM:
			case ANIMTYPE_DSCACHEFILE:
			case ANIMTYPE_DSCUR:
			case ANIMTYPE_DSSKEY:
			case ANIMTYPE_DSWOR:
			case ANIMTYPE_DSNTREE:
			case ANIMTYPE_DSPART:
			case ANIMTYPE_DSMBALL:
			case ANIMTYPE_DSARM:
			case ANIMTYPE_DSMESH:
			case ANIMTYPE_DSTEX:
			case ANIMTYPE_DSLAT:
			case ANIMTYPE_DSLINESTYLE:
			case ANIMTYPE_DSSPK:
			case ANIMTYPE_DSGPENCIL:
			{
				/* for these channels, we only do AnimData */
				if (ale->adt && adt_ptr) {
					ID *id;
					
					if ((ale->data == NULL) || (ale->type == ANIMTYPE_OBJECT)) {
						/* ale->data is not an ID block! */
						id = ale->id;
					}
					else {
						/* ale->data is always the proper ID block we need, but ale->id may not be (i.e. for textures) */
						id = (ID *)ale->data;
					}
					
					/* AnimData pointer */
					if (adt_ptr) {
						RNA_pointer_create(id, &RNA_AnimData, ale->adt, adt_ptr);
					}
					
					/* set found status to -1, since setting to 1 would break the loop 
					 * and potentially skip an active NLA-Track in some cases...
					 */
					found = -1;
				}
				break;
			}
		}
		
		if (found > 0)
			break;
	}
	
	/* free temp data */
	ANIM_animdata_freelist(&anim_data);
	
	return (found != 0);
}
Example #2
0
static int nla_panel_context(const bContext *C, PointerRNA *adt_ptr, PointerRNA *nlt_ptr, PointerRNA *strip_ptr)
{
	bAnimContext ac;
	bAnimListElem *ale= NULL;
	ListBase anim_data = {NULL, NULL};
	short found=0;
	int filter;
	
	/* for now, only draw if we could init the anim-context info (necessary for all animation-related tools) 
	 * to work correctly is able to be correctly retrieved. There's no point showing empty panels?
	 */
	if (ANIM_animdata_get_context(C, &ac) == 0) 
		return 0;
	
	/* extract list of active channel(s), of which we should only take the first one 
	 *	- we need the channels flag to get the active AnimData block when there are no NLA Tracks
	 */
	filter= (ANIMFILTER_VISIBLE|ANIMFILTER_ACTIVE|ANIMFILTER_CHANNELS);
	ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
	
	for (ale= anim_data.first; ale; ale= ale->next) {
		switch (ale->type) {
			case ANIMTYPE_NLATRACK: /* NLA Track - The primary data type which should get caught */
			{
				NlaTrack *nlt= (NlaTrack *)ale->data;
				AnimData *adt= ale->adt;
				
				/* found it, now set the pointers */
				if (adt_ptr) {
					/* AnimData pointer */
					RNA_pointer_create(ale->id, &RNA_AnimData, adt, adt_ptr);
				}
				if (nlt_ptr) {
					/* NLA-Track pointer */
					RNA_pointer_create(ale->id, &RNA_NlaTrack, nlt, nlt_ptr);
				}
				if (strip_ptr) {
					/* NLA-Strip pointer */
					NlaStrip *strip= BKE_nlastrip_find_active(nlt);
					RNA_pointer_create(ale->id, &RNA_NlaStrip, strip, strip_ptr);
				}
				
				found= 1;
			}
				break;
				
			case ANIMTYPE_SCENE: 	/* Top-Level Widgets doubling up as datablocks */
			case ANIMTYPE_OBJECT:
			case ANIMTYPE_FILLACTD: /* Action Expander */
			case ANIMTYPE_DSMAT:	/* Datablock AnimData Expanders */
			case ANIMTYPE_DSLAM:
			case ANIMTYPE_DSCAM:
			case ANIMTYPE_DSCUR:
			case ANIMTYPE_DSSKEY:
			case ANIMTYPE_DSWOR:
			case ANIMTYPE_DSNTREE:
			case ANIMTYPE_DSPART:
			case ANIMTYPE_DSMBALL:
			case ANIMTYPE_DSARM:
			{
				/* for these channels, we only do AnimData */
				if (ale->id && ale->adt) {
					if (adt_ptr) {
						/* AnimData pointer */
						RNA_pointer_create(ale->id, &RNA_AnimData, ale->adt, adt_ptr);
						
						/* set found status to -1, since setting to 1 would break the loop 
						 * and potentially skip an active NLA-Track in some cases...
						 */
						found= -1;
					}
				}
			}	
				break;
		}
		
		if (found > 0)
			break;
	}
	
	/* free temp data */
	BLI_freelistN(&anim_data);
	
	return found;
}