Graph Editor: NKEY panel - added code to retrieve 'active F-Curve'
authorJoshua Leung <aligorith@gmail.com>
Sat, 21 Feb 2009 11:22:06 +0000 (11:22 +0000)
committerJoshua Leung <aligorith@gmail.com>
Sat, 21 Feb 2009 11:22:06 +0000 (11:22 +0000)
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.

source/blender/editors/animation/anim_filter.c
source/blender/editors/include/ED_anim_api.h
source/blender/editors/space_graph/graph_buttons.c

index 3d97eaa84461370fb896f9eb10c63d46e8ddc091..05fa1f3bc977dec8bc74bd994e4c0e97596697ed 100644 (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++;
+                                               }
                                        }
                                }
                        }
index 12be7582b19fb04fe479a53ddee7e76103e664c2..5fceea63d322b61b07890ea85e1dc5330fca5d19 100644 (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;
 
 
index e43c378401e1e2ce23ae086eda8c10af5d0af8de..577ff79c40255b84c9cca8fa710c8c4d33e8b112 100644 (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);
 }