Commit: 1b5cc34ebaf23c7ad480b55a7e5e30cd05eb81a1
Author: Julian Eisel
Date:   Thu Feb 19 19:30:38 2015 +0100
Branches: experimental-build
https://developer.blender.org/rB1b5cc34ebaf23c7ad480b55a7e5e30cd05eb81a1

Auto-Focus Channels, squashed commit

===================================================================

M       release/scripts/startup/bl_ui/space_graph.py
M       source/blender/editors/animation/anim_channels_edit.c
M       source/blender/editors/include/ED_anim_api.h
M       source/blender/editors/space_graph/graph_edit.c
M       source/blender/makesdna/DNA_space_types.h
M       source/blender/makesrna/intern/rna_space.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_graph.py 
b/release/scripts/startup/bl_ui/space_graph.py
index d3e1a86..22cb005 100644
--- a/release/scripts/startup/bl_ui/space_graph.py
+++ b/release/scripts/startup/bl_ui/space_graph.py
@@ -94,6 +94,7 @@ class GRAPH_MT_view(Menu):
         layout.prop(st, "show_sliders")
         layout.prop(st, "show_group_colors")
         layout.prop(st, "use_auto_merge_keyframes")
+        layout.prop(st, "use_auto_focus_channels")
 
         layout.separator()
         layout.prop(st, "use_beauty_drawing")
diff --git a/source/blender/editors/animation/anim_channels_edit.c 
b/source/blender/editors/animation/anim_channels_edit.c
index d8ad650..ff98276 100644
--- a/source/blender/editors/animation/anim_channels_edit.c
+++ b/source/blender/editors/animation/anim_channels_edit.c
@@ -221,8 +221,9 @@ void ANIM_set_active_channel(bAnimContext *ac, void *data, 
eAnimCont_Types datat
  *     - datatype: the type of data that 'data' represents (eAnimCont_Types)
  *     - test: check if deselecting instead of selecting
  *     - sel: eAnimChannels_SetFlag;
+ * returns sel to give feedback on the type of the performed selection
  */
-void ANIM_deselect_anim_channels(bAnimContext *ac, void *data, eAnimCont_Types 
datatype, bool test, eAnimChannels_SetFlag sel)
+short ANIM_deselect_anim_channels(bAnimContext *ac, void *data, 
eAnimCont_Types datatype, bool test, eAnimChannels_SetFlag sel)
 {
        ListBase anim_data = {NULL, NULL};
        bAnimListElem *ale;
@@ -405,6 +406,8 @@ void ANIM_deselect_anim_channels(bAnimContext *ac, void 
*data, eAnimCont_Types d
        
        /* Cleanup */
        ANIM_animdata_freelist(&anim_data);
+       
+       return sel;
 }
 
 /* ---------------------------- Graph Editor 
------------------------------------- */
@@ -2222,24 +2225,40 @@ static void ANIM_OT_channels_find(wmOperatorType *ot)
 
 static int animchannels_deselectall_exec(bContext *C, wmOperator *op)
 {
+       ListBase anim_data = {NULL, NULL};
        bAnimContext ac;
+       int filter;
        
        /* get editor data */
        if (ANIM_animdata_get_context(C, &ac) == 0)
                return OPERATOR_CANCELLED;
+       
+       filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | 
ANIMFILTER_LIST_CHANNELS);
+       ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
                
        /* 'standard' behavior - check if selected, then apply relevant 
selection */
-       if (RNA_boolean_get(op->ptr, "invert"))
+       if (RNA_boolean_get(op->ptr, "invert")) {
                ANIM_deselect_anim_channels(&ac, ac.data, ac.datatype, false, 
ACHANNEL_SETFLAG_INVERT);
-       else
-               ANIM_deselect_anim_channels(&ac, ac.data, ac.datatype, true, 
ACHANNEL_SETFLAG_ADD);
+               
+               graph_channel_focus_selection(C, &ac, &anim_data, true);
+       }
+       else {
+               short setflag = ANIM_deselect_anim_channels(&ac, ac.data, 
ac.datatype, true, ACHANNEL_SETFLAG_ADD);
+               
+               /* don't use "Auto-Focus Channels" after deselecting */
+               if (setflag != ACHANNEL_SETFLAG_CLEAR)
+                       graph_channel_focus_selection(C, &ac, &anim_data, 
false);
+       }
+       
+       /* free channels */
+       ANIM_animdata_freelist(&anim_data);
        
        /* send notifier that things have changed */
        WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_SELECTED, 
NULL);
        
        return OPERATOR_FINISHED;
 }
- 
+
 static void ANIM_OT_channels_select_all_toggle(wmOperatorType *ot)
 {
        /* identifiers */
@@ -2260,7 +2279,7 @@ static void 
ANIM_OT_channels_select_all_toggle(wmOperatorType *ot)
 
 /* ******************** Borderselect Operator *********************** */
 
-static void borderselect_anim_channels(bAnimContext *ac, rcti *rect, short 
selectmode)
+static void borderselect_anim_channels(bContext *C, bAnimContext *ac, rcti 
*rect, short selectmode)
 {
        ListBase anim_data = {NULL, NULL};
        bAnimListElem *ale;
@@ -2354,6 +2373,8 @@ static void borderselect_anim_channels(bAnimContext *ac, 
rcti *rect, short selec
                ymax = ymin;
        }
        
+       graph_channel_focus_selection(C, ac, &anim_data, false);
+       
        /* cleanup */
        ANIM_animdata_freelist(&anim_data);
 }
@@ -2387,7 +2408,7 @@ static int animchannels_borderselect_exec(bContext *C, 
wmOperator *op)
                selectmode = ACHANNEL_SETFLAG_CLEAR;
        
        /* apply borderselect animation channels */
-       borderselect_anim_channels(&ac, &rect, selectmode);
+       borderselect_anim_channels(C, &ac, &rect, selectmode);
        
        /* send notifier that things have changed */
        WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_SELECTED, 
NULL);
@@ -2839,6 +2860,8 @@ static int mouse_anim_channels(bContext *C, bAnimContext 
*ac, int channel_index,
                        break;
        }
        
+       graph_channel_focus_selection(C, ac, &anim_data, true);
+       
        /* free channels */
        ANIM_animdata_freelist(&anim_data);
        
diff --git a/source/blender/editors/include/ED_anim_api.h 
b/source/blender/editors/include/ED_anim_api.h
index 5058142..f73e368 100644
--- a/source/blender/editors/include/ED_anim_api.h
+++ b/source/blender/editors/include/ED_anim_api.h
@@ -490,7 +490,7 @@ void ANIM_flush_setting_anim_channels(bAnimContext *ac, 
ListBase *anim_data, bAn
 
 
 /* Deselect all animation channels */
-void ANIM_deselect_anim_channels(bAnimContext *ac, void *data, eAnimCont_Types 
datatype, bool test, eAnimChannels_SetFlag sel);
+short ANIM_deselect_anim_channels(bAnimContext *ac, void *data, 
eAnimCont_Types datatype, bool test, eAnimChannels_SetFlag sel);
 
 /* Set the 'active' channel of type channel_type, in the given action */
 void ANIM_set_active_channel(bAnimContext *ac, void *data, eAnimCont_Types 
datatype, eAnimFilter_Flags filter, void *channel_data, eAnim_ChannelType 
channel_type);
@@ -585,6 +585,8 @@ void ANIM_nla_mapping_apply_fcurve(struct AnimData *adt, 
struct FCurve *fcu, boo
 // NOTE: defined in space_nla/nla_edit.c, not in animation/
 void ED_nla_postop_refresh(bAnimContext *ac);
 
+void graph_channel_focus_selection(struct bContext *C, bAnimContext *ac, 
ListBase *anim_data, const bool unhide);
+
 /* ------------- Unit Conversion Mappings ------------- */
 /* anim_draw.c */
 
diff --git a/source/blender/editors/space_graph/graph_edit.c 
b/source/blender/editors/space_graph/graph_edit.c
index 2944901..92e1df9 100644
--- a/source/blender/editors/space_graph/graph_edit.c
+++ b/source/blender/editors/space_graph/graph_edit.c
@@ -167,6 +167,51 @@ void get_graph_keyframe_extents(bAnimContext *ac, float 
*xmin, float *xmax, floa
        }
 }
 
+
+/* ****************** Auto-Focus Channel ****************** */
+
+void graph_channel_focus_selection(bContext *C, bAnimContext *ac, ListBase 
*anim_data, const bool unhide)
+{
+       const SpaceIpo *sipo = CTX_wm_space_graph(C);
+       bAnimListElem *ale;
+       bool is_any_visible = false;
+
+       /* graph editor only */
+       if (sipo == NULL)
+               return;
+
+       /* only if auto-focus channels is enabled */
+       if ((sipo->flag & SIPO_AUTO_FOCUS_CHANNELS) == 0)
+               return;
+
+       for (ale = anim_data->first; ale; ale = ale->next) {
+               /* make selected elements visible */
+               if (ANIM_channel_setting_get(ac, ale, ACHANNEL_SETTING_SELECT)) 
{
+                       /* unhiding selected channels and thereby overriding 
their visibility is not always wanted */
+                       if (unhide) {
+                               ANIM_channel_setting_set(ac, ale, 
ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_ADD);
+                               ANIM_flush_setting_anim_channels(ac, anim_data, 
ale, ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_ADD);
+                       }
+               }
+               /* make unselected elements hidden */
+               else {
+                       ANIM_channel_setting_set(ac, ale, 
ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_CLEAR);
+                       ANIM_flush_setting_anim_channels(ac, anim_data, ale, 
ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_CLEAR);
+               }
+
+               if (!(ELEM(ale->type, ANIMTYPE_OBJECT, ANIMTYPE_FILLACTD)) && 
/* XXX more cases? - need help! */
+                   (ANIM_channel_setting_get(ac, ale, 
ACHANNEL_SETTING_VISIBLE)))
+               {
+                       is_any_visible = true;
+               }
+       }
+
+       /* align the view to visible curves using view_all operator, but only 
if there is a visible channel */
+       if (is_any_visible) {
+               WM_operator_name_call(C, "GRAPH_OT_view_all", 
WM_OP_EXEC_REGION_WIN, NULL);
+       }
+}
+
 /* ****************** Automatic Preview-Range Operator ****************** */
 
 static int graphkeys_previewrange_exec(bContext *C, wmOperator *UNUSED(op))
diff --git a/source/blender/makesdna/DNA_space_types.h 
b/source/blender/makesdna/DNA_space_types.h
index 69affc7..55b514a 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -371,6 +371,8 @@ typedef enum eGraphEdit_Flag {
        /* normalize curves on display */
        SIPO_NORMALIZE            = (1 << 14),
        SIPO_NORMALIZE_FREEZE     = (1 << 15),
+       /* automatically focus on selected channels */
+       SIPO_AUTO_FOCUS_CHANNELS  = (1 << 16),
 } eGraphEdit_Flag;
 
 /* SpaceIpo->mode (Graph Editor Mode) */
diff --git a/source/blender/makesrna/intern/rna_space.c 
b/source/blender/makesrna/intern/rna_space.c
index 13ec2dd..8216db7 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -3234,7 +3234,11 @@ static void rna_def_space_graph(BlenderRNA *brna)
        RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", 
SIPO_NOTRANSKEYCULL);
        RNA_def_property_ui_text(prop, "AutoMerge Keyframes", "Automatically 
merge nearby keyframes");
        RNA_def_property_update(prop, NC_SPACE | ND_SPACE_GRAPH, NULL);
-       
+
+       prop = RNA_def_property(srna, "use_auto_focus_channels", PROP_BOOLEAN, 
PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", 
SIPO_AUTO_FOCUS_CHANNELS);
+       RNA_def_property_ui_text(prop, "Auto-Focus Channels", "Automatically 
focus on selected channels");
+
        prop = RNA_def_property(srna, "use_realtime_update", PROP_BOOLEAN, 
PROP_NONE);
        RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", 
SIPO_NOREALTIMEUPDATES);
        RNA_def_property_ui_text(prop, "Realtime Updates",

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to