Graph Editor: NKEY panel - added code to retrieve 'active F-Curve'

Currently, this is just used to print the 'name' of the active F-Curve in a panel for verification purposes. This is the recommended way of getting this info.
This commit is contained in:
Joshua Leung
2009-02-21 11:22:06 +00:00
parent a9654c3e6a
commit 59b44cda51
3 changed files with 64 additions and 15 deletions

View File

@@ -511,12 +511,15 @@ static int animdata_filter_fcurves (ListBase *anim_data, FCurve *first, bActionG
if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_FCU(fcu)) {
/* only include this curve if selected */
if (!(filter_mode & ANIMFILTER_SEL) || (SEL_FCU(fcu))) {
/* owner/ownertype will be either object or action-channel, depending if it was dopesheet or part of an action */
ale= make_new_animlistelem(fcu, ANIMTYPE_FCURVE, owner, ownertype, owner_id);
if (ale) {
BLI_addtail(anim_data, ale);
items++;
/* only include if this curve is active */
if (!(filter_mode & ANIMFILTER_ACTIVE) || (fcu->flag & FCURVE_ACTIVE)) {
/* owner/ownertype will be either object or action-channel, depending if it was dopesheet or part of an action */
ale= make_new_animlistelem(fcu, ANIMTYPE_FCURVE, owner, ownertype, owner_id);
if (ale) {
BLI_addtail(anim_data, ale);
items++;
}
}
}
}

View File

@@ -154,6 +154,7 @@ typedef enum eAnimFilter_Flags {
ANIMFILTER_CHANNELS = (1<<4), /* make list for interface drawing */
ANIMFILTER_ACTGROUPED = (1<<5), /* belongs to the active actiongroup */
ANIMFILTER_CURVEVISIBLE = (1<<6), /* F-Curve is visible for editing/viewing in Graph Editor */
ANIMFILTER_ACTIVE = (1<<7), /* channel should be 'active' */ // FIXME: this is only relevant for F-Curves for now
} eAnimFilter_Flags;

View File

@@ -96,20 +96,24 @@ static void do_graph_region_buttons(bContext *C, void *arg, int event)
}
static void graph_panel_properties(const bContext *C, ARegion *ar, short cntrl) // GRAPH_HANDLER_SETTINGS
static void graph_panel_properties(const bContext *C, ARegion *ar, short cntrl, bAnimListElem *ale) // GRAPH_HANDLER_SETTINGS
{
//ScrArea *sa= CTX_wm_area(C);
//Scene *scene= CTX_data_scene(C);
uiBlock *block;
char name[128];
block= uiBeginBlock(C, ar, "graph_panel_properties", UI_EMBOSS, UI_HELV);
if(uiNewPanel(C, ar, block, "Properties", "Graph", 340, 30, 318, 254)==0) return;
uiBlockSetHandleFunc(block, do_graph_region_buttons, NULL);
/* to force height */
uiNewPanelHeight(block, 264);
uiNewPanelHeight(block, 204);
uiDefBut(block, LABEL, 1, "Testing", 10, 220, 150, 19, NULL, 0.0, 0.0, 0, 0, "");
// XXX testing buttons
uiDefBut(block, LABEL, 1, "Active F-Curve:", 10, 200, 150, 19, NULL, 0.0, 0.0, 0, 0, "");
getname_anim_fcurve(name, ale->id, (FCurve *)ale->data);
uiDefBut(block, LABEL, 1, name, 30, 180, 300, 19, NULL, 0.0, 0.0, 0, 0, "Name of Active F-Curve");
#if 0
uiBlockBeginAlign(block);
uiDefButF(block, NUM, B_REDR, "Spacing:", 10, 200, 140, 19, &v3d->grid, 0.001, 100.0, 10, 0, "Set the distance between grid lines");
@@ -119,24 +123,65 @@ static void graph_panel_properties(const bContext *C, ARegion *ar, short cntrl)
#endif
}
/* Find 'active' F-Curve. It must be editable, since that's the purpose of these buttons (subject to change).
* We return the 'wrapper' since it contains valuable context info (about hierarchy), which will need to be freed
* when the caller is done with it.
*/
// TODO: move this to anim api with another name?
static bAnimListElem *get_active_fcurve_channel (bAnimContext *ac)
{
ListBase anim_data = {NULL, NULL};
int filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_ACTIVE | ANIMFILTER_CURVESONLY);
int items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
/* We take the first F-Curve only, since some other ones may have had 'active' flag set
* if they were from linked data.
*/
if (items) {
bAnimListElem *ale= (bAnimListElem *)anim_data.first;
/* remove first item from list, then free the rest of the list and return the stored one */
BLI_remlink(&anim_data, ale);
BLI_freelistN(&anim_data);
return ale;
}
/* no active F-Curve */
return NULL;
}
void graph_region_buttons(const bContext *C, ARegion *ar)
{
SpaceIpo *sipo= (SpaceIpo *)CTX_wm_space_data(C);
bAnimContext ac;
bAnimListElem *ale= 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;
/* try to find 'active' F-Curve */
ale= get_active_fcurve_channel(&ac);
if (ale == NULL)
return;
// XXX temp panel for testing
graph_panel_properties(C, ar, 0);
graph_panel_properties(C, ar, 0, ale);
/* driver settings for active F-Curve (only for 'Drivers' mode) */
if (sipo->mode == SIPO_MODE_DRIVERS) {
//graph_panel_drivers(C, ar, 0);
}
uiDrawPanels(C, 1); /* 1 = align */
uiMatchPanelsView2d(ar); /* sets v2d->totrct */
/* free temp data */
MEM_freeN(ale);
}