At last... this merge should finally do the trick!
[blender.git] / source / blender / editors / animation / anim_channels.c
index 05d50f98e8e8e7e991d82d6c9fb8230854153979..4ac1648361e8bcb5d21aa92d14ea2936e1dbb7f1 100644 (file)
 /* ************************************************************************** */
 /* CHANNELS API */
 
-/* -------------------------- Internal Macros ------------------------------- */
-
-/* set/clear/toggle macro 
- *     - channel - channel with a 'flag' member that we're setting
- *     - smode - 0=clear, 1=set, 2=toggle
- *     - sflag - bitflag to set
- */
-#define ACHANNEL_SET_FLAG(channel, smode, sflag) \
-       { \
-               if (smode == ACHANNEL_SETFLAG_TOGGLE)   (channel)->flag ^= (sflag); \
-               else if (smode == ACHANNEL_SETFLAG_ADD) (channel)->flag |= (sflag); \
-               else                                                                    (channel)->flag &= ~(sflag); \
-       }
-       
-/* set/clear/toggle macro, where the flag is negative 
- *     - channel - channel with a 'flag' member that we're setting
- *     - smode - 0=clear, 1=set, 2=toggle
- *     - sflag - bitflag to set
- */
-#define ACHANNEL_SET_FLAG_NEG(channel, smode, sflag) \
-       { \
-               if (smode == ACHANNEL_SETFLAG_TOGGLE)   (channel)->flag ^= (sflag); \
-               else if (smode == ACHANNEL_SETFLAG_ADD) (channel)->flag &= ~(sflag); \
-               else                                                                    (channel)->flag |= (sflag); \
-       }
-
 /* -------------------------- Exposed API ----------------------------------- */
 
 /* Set the given animation-channel as the active one for the active context */
-void ANIM_set_active_channel (void *data, short datatype, int filter, void *channel_data, short channel_type)
+void ANIM_set_active_channel (bAnimContext *ac, void *data, short datatype, int filter, void *channel_data, short channel_type)
 {
        ListBase anim_data = {NULL, NULL};
        bAnimListElem *ale;
        
        /* try to build list of filtered items */
-       // XXX we don't need/supply animcontext for now, since in this case, there's nothing really essential there that isn't already covered
-       ANIM_animdata_filter(NULL, &anim_data, filter, data, datatype);
+       ANIM_animdata_filter(ac, &anim_data, filter, data, datatype);
        if (anim_data.first == NULL)
                return;
                
@@ -149,6 +122,13 @@ void ANIM_set_active_channel (void *data, short datatype, int filter, void *chan
                                ACHANNEL_SET_FLAG(fcu, ACHANNEL_SETFLAG_CLEAR, FCURVE_ACTIVE);
                        }
                                break;
+                       case ANIMTYPE_NLATRACK:
+                       {
+                               NlaTrack *nlt= (NlaTrack *)ale->data;
+                               
+                               ACHANNEL_SET_FLAG(nlt, ACHANNEL_SETFLAG_CLEAR, NLATRACK_ACTIVE);
+                       }
+                               break;
                }
        }
        
@@ -167,6 +147,12 @@ void ANIM_set_active_channel (void *data, short datatype, int filter, void *chan
                                fcu->flag |= FCURVE_ACTIVE;
                        }
                                break;
+                       case ANIMTYPE_NLATRACK:
+                       {
+                               NlaTrack *nlt= (NlaTrack *)channel_data;
+                               nlt->flag |= NLATRACK_ACTIVE;
+                       }
+                               break;
                }
        }
        
@@ -217,6 +203,10 @@ void ANIM_deselect_anim_channels (void *data, short datatype, short test, short
                                        if (ale->flag & FCURVE_SELECTED)
                                                sel= ACHANNEL_SETFLAG_CLEAR;
                                        break;
+                               case ANIMTYPE_NLATRACK:
+                                       if (ale->flag & NLATRACK_SELECTED)
+                                               sel= ACHANNEL_SETFLAG_CLEAR;
+                                       break;
                        }
                }
        }
@@ -263,6 +253,14 @@ void ANIM_deselect_anim_channels (void *data, short datatype, short test, short
                                fcu->flag &= ~FCURVE_ACTIVE;
                        }
                                break;
+                       case ANIMTYPE_NLATRACK:
+                       {
+                               NlaTrack *nlt= (NlaTrack *)ale->data;
+                               
+                               ACHANNEL_SET_FLAG(nlt, sel, NLATRACK_SELECTED);
+                               nlt->flag &= ~NLATRACK_ACTIVE;
+                       }
+                               break;
                }
        }
        
@@ -273,6 +271,47 @@ void ANIM_deselect_anim_channels (void *data, short datatype, short test, short
 /* ************************************************************************** */
 /* OPERATORS */
 
+/* ****************** Operator Utilities ********************************** */
+
+/* poll callback for being in an Animation Editor channels list region */
+int animedit_poll_channels_active (bContext *C)
+{
+       ScrArea *sa= CTX_wm_area(C);
+       
+       /* channels region test */
+       // TODO: could enhance with actually testing if channels region?
+       if (ELEM(NULL, sa, CTX_wm_region(C)))
+               return 0;
+       /* animation editor test */
+       if (ELEM3(sa->spacetype, SPACE_ACTION, SPACE_IPO, SPACE_NLA) == 0)
+               return 0;
+               
+       return 1;
+}
+
+/* poll callback for Animation Editor channels list region + not in NLA-tweakmode for NLA */
+int animedit_poll_channels_nla_tweakmode_off (bContext *C)
+{
+       ScrArea *sa= CTX_wm_area(C);
+       Scene *scene = CTX_data_scene(C);
+       
+       /* channels region test */
+       // TODO: could enhance with actually testing if channels region?
+       if (ELEM(NULL, sa, CTX_wm_region(C)))
+               return 0;
+       /* animation editor test */
+       if (ELEM3(sa->spacetype, SPACE_ACTION, SPACE_IPO, SPACE_NLA) == 0)
+               return 0;
+       
+       /* NLA TweakMode test */        
+       if (sa->spacetype == SPACE_NLA) {
+               if ((scene == NULL) || (scene->flag & SCE_NLA_EDIT_ON))
+                       return 0;
+       }
+               
+       return 1;
+}
+
 /* ****************** Rearrange Channels Operator ******************* */
 /* This operator only works for Action Editor mode for now, as having it elsewhere makes things difficult */
 
@@ -963,7 +1002,7 @@ void ANIM_OT_channels_setting_enable (wmOperatorType *ot)
        /* api callbacks */
        ot->invoke= WM_menu_invoke;
        ot->exec= animchannels_setflag_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= animedit_poll_channels_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -984,7 +1023,7 @@ void ANIM_OT_channels_setting_disable (wmOperatorType *ot)
        /* api callbacks */
        ot->invoke= WM_menu_invoke;
        ot->exec= animchannels_setflag_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= animedit_poll_channels_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1005,7 +1044,7 @@ void ANIM_OT_channels_setting_toggle (wmOperatorType *ot)
        /* api callbacks */
        ot->invoke= WM_menu_invoke;
        ot->exec= animchannels_setflag_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= animedit_poll_channels_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1026,7 +1065,7 @@ void ANIM_OT_channels_editable_toggle (wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= animchannels_setflag_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= animedit_poll_channels_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1070,7 +1109,7 @@ void ANIM_OT_channels_expand (wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= animchannels_expand_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= animedit_poll_channels_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1111,7 +1150,7 @@ void ANIM_OT_channels_collapse (wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= animchannels_collapse_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= animedit_poll_channels_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1150,7 +1189,7 @@ void ANIM_OT_channels_select_all_toggle (wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= animchannels_deselectall_exec;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= animedit_poll_channels_nla_tweakmode_off;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1218,6 +1257,14 @@ static void borderselect_anim_channels (bAnimContext *ac, rcti *rect, short sele
                                        ACHANNEL_SET_FLAG(gpl, selectmode, GP_LAYER_SELECT);
                                }
                                        break;
+                                       
+                               case ANIMTYPE_NLATRACK: /* nla-track */
+                               {
+                                       NlaTrack *nlt= (NlaTrack *)ale->data;
+                                       
+                                       ACHANNEL_SET_FLAG(nlt, selectmode, NLATRACK_SELECTED);
+                               }
+                                       break;
                        }
                }
                
@@ -1271,7 +1318,7 @@ void ANIM_OT_channels_select_border(wmOperatorType *ot)
        ot->exec= animchannels_borderselect_exec;
        ot->modal= WM_border_select_modal;
        
-       ot->poll= ED_operator_areaactive;
+       ot->poll= animedit_poll_channels_nla_tweakmode_off;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1474,7 +1521,7 @@ static void mouse_anim_channels (bAnimContext *ac, float x, int channel_index, s
                                
                                /* if group is selected now, make group the 'active' one in the visible list */
                                if (agrp->flag & AGRP_SELECTED)
-                                       ANIM_set_active_channel(ac->data, ac->datatype, filter, agrp, ANIMTYPE_GROUP);
+                                       ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, agrp, ANIMTYPE_GROUP);
                        }
                }
                        break;
@@ -1520,7 +1567,7 @@ static void mouse_anim_channels (bAnimContext *ac, float x, int channel_index, s
                                
                                /* if F-Curve is selected now, make F-Curve the 'active' one in the visible list */
                                if (fcu->flag & FCURVE_SELECTED)
-                                       ANIM_set_active_channel(ac->data, ac->datatype, filter, fcu, ANIMTYPE_FCURVE);
+                                       ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, fcu, ANIMTYPE_FCURVE);
                        }
                }
                        break;
@@ -1630,7 +1677,7 @@ void ANIM_OT_channels_click (wmOperatorType *ot)
        
        /* api callbacks */
        ot->invoke= animchannels_mouseclick_invoke;
-       ot->poll= ED_operator_areaactive;
+       ot->poll= animedit_poll_channels_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;