static int graph_panel_context(const bContext *C, bAnimListElem **ale, FCurve **fcu) { bAnimContext ac; bAnimListElem *elem = NULL; /* 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; /* try to find 'active' F-Curve */ elem = get_active_fcurve_channel(&ac); if (elem == NULL) return 0; if (fcu) *fcu = (FCurve *)elem->data; if (ale) *ale = elem; else MEM_freeN(elem); return 1; }
/* has active F-Curve that's editable */ int graphop_active_fcurve_poll(bContext *C) { bAnimContext ac; bAnimListElem *ale; ScrArea *sa = CTX_wm_area(C); bool has_fcurve = 0; /* firstly, check if in Graph Editor */ // TODO: also check for region? if ((sa == NULL) || (sa->spacetype != SPACE_IPO)) return 0; /* try to init Anim-Context stuff ourselves and check */ if (ANIM_animdata_get_context(C, &ac) == 0) return 0; /* try to get the Active F-Curve */ ale = get_active_fcurve_channel(&ac); if (ale == NULL) return 0; /* free temp data... */ has_fcurve = ((ale->data) && (ale->type == ANIMTYPE_FCURVE)); if (has_fcurve) { FCurve *fcu = (FCurve *)ale->data; has_fcurve = (fcu->flag & FCURVE_VISIBLE) != 0; } MEM_freeN(ale); /* return success */ return has_fcurve; }
static int graphkeys_deselectall_exec(bContext *C, wmOperator *op) { bAnimContext ac; bAnimListElem *ale_active = NULL; /* get editor data */ if (ANIM_animdata_get_context(C, &ac) == 0) return OPERATOR_CANCELLED; /* find active F-Curve, and preserve this for later * or else it becomes annoying with the current active * curve keeps fading out even while you're editing it */ ale_active = get_active_fcurve_channel(&ac); /* 'standard' behavior - check if selected, then apply relevant selection */ if (RNA_boolean_get(op->ptr, "invert")) deselect_graph_keys(&ac, 0, SELECT_INVERT, true); else deselect_graph_keys(&ac, 1, SELECT_ADD, true); /* restore active F-Curve... */ if (ale_active) { FCurve *fcu = (FCurve *)ale_active->data; /* all others should not be disabled, so we should be able to just set this directly... * - selection needs to be set too, or else this won't work... */ fcu->flag |= (FCURVE_SELECTED | FCURVE_ACTIVE); MEM_freeN(ale_active); ale_active = NULL; } /* set notifier that things have changed */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL); return OPERATOR_FINISHED; }