style cleanup: follow style guide for formatting of if/for/while loops, and else...
[blender.git] / source / blender / editors / space_nla / nla_channels.c
index 1bc07811bf8cb102dfd9f20cd3f9b63f61a356da..c242a1c1323d33c64881b863f935084224f1adf0 100644 (file)
@@ -1,6 +1,4 @@
-/**
- * $Id$
- *
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/editors/space_nla/nla_channels.c
+ *  \ingroup spnla
+ */
+
+
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
 
-#include "DNA_listBase.h"
 #include "DNA_anim_types.h"
-#include "DNA_action_types.h"
-#include "DNA_armature_types.h"
-#include "DNA_camera_types.h"
-#include "DNA_curve_types.h"
 #include "DNA_object_types.h"
-#include "DNA_particle_types.h"
-#include "DNA_screen_types.h"
 #include "DNA_scene_types.h"
-#include "DNA_space_types.h"
-#include "DNA_key_types.h"
-#include "DNA_lamp_types.h"
-#include "DNA_material_types.h"
-#include "DNA_meta_types.h"
-#include "DNA_userdef_types.h"
-#include "DNA_windowmanager_types.h"
-#include "DNA_world_types.h"
-
-#include "MEM_guardedalloc.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 #include "BLI_rand.h"
+#include "BLI_utildefines.h"
 
 #include "BKE_animsys.h"
 #include "BKE_nla.h"
 #include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_screen.h"
-#include "BKE_utildefines.h"
 
 #include "ED_anim_api.h"
 #include "ED_keyframes_edit.h"
-#include "ED_markers.h"
-#include "ED_space_api.h"
 #include "ED_screen.h"
 
 #include "RNA_access.h"
@@ -75,9 +59,6 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
-#include "UI_interface.h"
-#include "UI_interface_icons.h"
-#include "UI_resources.h"
 #include "UI_view2d.h"
 
 #include "nla_intern.h"        // own include
@@ -98,13 +79,14 @@ static int mouse_nla_channels (bAnimContext *ac, float x, int channel_index, sho
        ListBase anim_data = {NULL, NULL};
        bAnimListElem *ale;
        int filter;
+       
        View2D *v2d= &ac->ar->v2d;
        int notifierFlags = 0;
        
        /* get the channel that was clicked on */
                /* filter channels */
-       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CHANNELS);
-       filter= ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
+       filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
+       ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
        
                /* get channel from index */
        ale= BLI_findlink(&anim_data, channel_index);
@@ -136,7 +118,7 @@ static int mouse_nla_channels (bAnimContext *ac, float x, int channel_index, sho
                                if (adt) adt->flag |= ADT_UI_SELECTED;
                        }
                        
-                       notifierFlags |= ND_ANIMCHAN_SELECT;
+                       notifierFlags |= (ND_ANIMCHAN|NA_SELECTED);
                }
                        break;
                case ANIMTYPE_OBJECT:
@@ -177,7 +159,7 @@ static int mouse_nla_channels (bAnimContext *ac, float x, int channel_index, sho
                                        adt->flag |= ADT_UI_ACTIVE;
                                
                                /* notifiers - channel was selected */
-                               notifierFlags |= ND_ANIMCHAN_SELECT;
+                               notifierFlags |= (ND_ANIMCHAN|NA_SELECTED);
                        }
                }
                        break;
@@ -195,6 +177,8 @@ static int mouse_nla_channels (bAnimContext *ac, float x, int channel_index, sho
                case ANIMTYPE_DSARM:
                case ANIMTYPE_DSMESH:
                case ANIMTYPE_DSTEX:
+               case ANIMTYPE_DSLAT:
+               case ANIMTYPE_DSSPK:
                {
                        /* sanity checking... */
                        if (ale->adt) {
@@ -214,7 +198,7 @@ static int mouse_nla_channels (bAnimContext *ac, float x, int channel_index, sho
                                        ale->adt->flag |= ADT_UI_ACTIVE;
                        }
                        
-                       notifierFlags |= ND_ANIMCHAN_SELECT;
+                       notifierFlags |= (ND_ANIMCHAN|NA_SELECTED);
                }       
                        break;
                        
@@ -240,21 +224,21 @@ static int mouse_nla_channels (bAnimContext *ac, float x, int channel_index, sho
                                nlt->flag ^= NLATRACK_PROTECTED;
                                
                                /* notifier flags - channel was edited */
-                               notifierFlags |= ND_ANIMCHAN_EDIT;
+                               notifierFlags |= (ND_ANIMCHAN|NA_EDITED);
                        }
                        else if (x >= (v2d->cur.xmax-2*NLACHANNEL_BUTTON_WIDTH)) {
                                /* toggle mute */
                                nlt->flag ^= NLATRACK_MUTED;
                                
                                /* notifier flags - channel was edited */
-                               notifierFlags |= ND_ANIMCHAN_EDIT;
+                               notifierFlags |= (ND_ANIMCHAN|NA_EDITED);
                        }
                        else if (x <= ((NLACHANNEL_BUTTON_WIDTH*2)+offset)) {
                                /* toggle 'solo' */
                                BKE_nlatrack_solo_toggle(adt, nlt);
                                
                                /* notifier flags - channel was edited */
-                               notifierFlags |= ND_ANIMCHAN_EDIT;
+                               notifierFlags |= (ND_ANIMCHAN|NA_EDITED);
                        }
                        else if (nlaedit_is_tweakmode_on(ac) == 0) {
                                /* set selection */
@@ -273,7 +257,7 @@ static int mouse_nla_channels (bAnimContext *ac, float x, int channel_index, sho
                                        ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, nlt, ANIMTYPE_NLATRACK);
                                        
                                /* notifier flags - channel was selected */
-                               notifierFlags |= ND_ANIMCHAN_SELECT;
+                               notifierFlags |= (ND_ANIMCHAN|NA_SELECTED);
                        }
                }
                        break;
@@ -317,10 +301,10 @@ static int mouse_nla_channels (bAnimContext *ac, float x, int channel_index, sho
 static int nlachannels_mouseclick_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        bAnimContext ac;
-       Scene *scene;
+       SpaceNla *snla;
        ARegion *ar;
        View2D *v2d;
-       int mval[2], channel_index;
+       int channel_index;
        int notifierFlags = 0;
        short selectmode;
        float x, y;
@@ -330,14 +314,10 @@ static int nlachannels_mouseclick_invoke(bContext *C, wmOperator *op, wmEvent *e
                return OPERATOR_CANCELLED;
                
        /* get useful pointers from animation context data */
-       scene= ac.scene;
+       snla= (SpaceNla *)ac.sl;
        ar= ac.ar;
        v2d= &ar->v2d;
        
-       /* get mouse coordinates (in region coordinates) */
-       mval[0]= (event->x - ar->winrct.xmin);
-       mval[1]= (event->y - ar->winrct.ymin);
-       
        /* select mode is either replace (deselect all, then add) or add/extend */
        if (RNA_boolean_get(op->ptr, "extend"))
                selectmode= SELECT_INVERT;
@@ -349,8 +329,8 @@ static int nlachannels_mouseclick_invoke(bContext *C, wmOperator *op, wmEvent *e
         *              so that the tops of channels get caught ok. Since NLACHANNEL_FIRST is really NLACHANNEL_HEIGHT, we simply use
         *              NLACHANNEL_HEIGHT_HALF.
         */
-       UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y);
-       UI_view2d_listview_view_to_cell(v2d, NLACHANNEL_NAMEWIDTH, NLACHANNEL_STEP, 0, (float)NLACHANNEL_HEIGHT_HALF, x, y, NULL, &channel_index);
+       UI_view2d_region_to_view(v2d, event->mval[0], event->mval[1], &x, &y);
+       UI_view2d_listview_view_to_cell(v2d, NLACHANNEL_NAMEWIDTH, NLACHANNEL_STEP(snla), 0, (float)NLACHANNEL_HEIGHT_HALF(snla), x, y, NULL, &channel_index);
        
        /* handle mouse-click in the relevant channel then */
        notifierFlags= mouse_nla_channels(&ac, x, channel_index, selectmode);
@@ -364,15 +344,16 @@ static int nlachannels_mouseclick_invoke(bContext *C, wmOperator *op, wmEvent *e
 void NLA_OT_channels_click (wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Mouse Click on Channels";
-       ot->idname= "NLA_OT_channels_click";
+       ot->name = "Mouse Click on NLA Channels";
+       ot->idname = "NLA_OT_channels_click";
+       ot->description = "Handle clicks to select NLA channels";
        
        /* api callbacks */
-       ot->invoke= nlachannels_mouseclick_invoke;
-       ot->poll= ED_operator_nla_active;
+       ot->invoke = nlachannels_mouseclick_invoke;
+       ot->poll = ED_operator_nla_active;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* id-props */
        RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); // SHIFTKEY
@@ -400,25 +381,27 @@ static int nlaedit_add_tracks_exec (bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
                
        /* get a list of the AnimData blocks being shown in the NLA */
-       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_SEL);
+       filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_SEL);
        ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
        
        /* add tracks... */
        for (ale= anim_data.first; ale; ale= ale->next) {
-               NlaTrack *nlt= (NlaTrack *)ale->data;
-               AnimData *adt= ale->adt;
-               
-               /* check if just adding a new track above this one,
-                * or whether we're adding a new one to the top of the stack that this one belongs to
-                */
-               if (above_sel) {
-                       /* just add a new one above this one */
-                       add_nlatrack(adt, nlt);
-               }
-               else if ((lastAdt == NULL) || (adt != lastAdt)) {
-                       /* add one track to the top of the owning AnimData's stack, then don't add anymore to this stack */
-                       add_nlatrack(adt, NULL);
-                       lastAdt= adt;
+               if (ale->type == ANIMTYPE_NLATRACK) {
+                       NlaTrack *nlt= (NlaTrack *)ale->data;
+                       AnimData *adt= ale->adt;
+                       
+                       /* check if just adding a new track above this one,
+                        * or whether we're adding a new one to the top of the stack that this one belongs to
+                        */
+                       if (above_sel) {
+                               /* just add a new one above this one */
+                               add_nlatrack(adt, nlt);
+                       }
+                       else if ((lastAdt == NULL) || (adt != lastAdt)) {
+                               /* add one track to the top of the owning AnimData's stack, then don't add anymore to this stack */
+                               add_nlatrack(adt, NULL);
+                               lastAdt= adt;
+                       }
                }
        }
        
@@ -426,7 +409,7 @@ static int nlaedit_add_tracks_exec (bContext *C, wmOperator *op)
        BLI_freelistN(&anim_data);
        
        /* set notifier that things have changed */
-       WM_event_add_notifier(C, NC_ANIMATION|ND_NLA_EDIT, NULL);
+       WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_EDITED, NULL);
        
        /* done */
        return OPERATOR_FINISHED;
@@ -435,25 +418,25 @@ static int nlaedit_add_tracks_exec (bContext *C, wmOperator *op)
 void NLA_OT_tracks_add (wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Add Track(s)";
-       ot->idname= "NLA_OT_tracks_add";
-       ot->description= "Add NLA-Tracks above/after the selected tracks";
+       ot->name = "Add Track(s)";
+       ot->idname = "NLA_OT_tracks_add";
+       ot->description = "Add NLA-Tracks above/after the selected tracks";
        
        /* api callbacks */
-       ot->exec= nlaedit_add_tracks_exec;
-       ot->poll= nlaop_poll_tweakmode_off;
+       ot->exec = nlaedit_add_tracks_exec;
+       ot->poll = nlaop_poll_tweakmode_off;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* properties */
-       RNA_def_boolean(ot->srna, "above_selected", 0, "Above Selected", "Add a new NLA Track above every existing selected one.");
+       RNA_def_boolean(ot->srna, "above_selected", 0, "Above Selected", "Add a new NLA Track above every existing selected one");
 }
 
 /* ******************** Delete Tracks Operator ***************************** */
 /* Delete selected NLA Tracks */
 
-static int nlaedit_delete_tracks_exec (bContext *C, wmOperator *op)
+static int nlaedit_delete_tracks_exec (bContext *C, wmOperator *UNUSED(op))
 {
        bAnimContext ac;
        
@@ -466,23 +449,31 @@ static int nlaedit_delete_tracks_exec (bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
                
        /* get a list of the AnimData blocks being shown in the NLA */
-       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_SEL);
+       filter= (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_SEL);
        ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
        
        /* delete tracks */
        for (ale= anim_data.first; ale; ale= ale->next) {
-               NlaTrack *nlt= (NlaTrack *)ale->data;
-               AnimData *adt= ale->adt;
-               
-               /* call delete on this track - deletes all strips too */
-               free_nlatrack(&adt->nla_tracks, nlt);
+               if (ale->type == ANIMTYPE_NLATRACK) {
+                       NlaTrack *nlt= (NlaTrack *)ale->data;
+                       AnimData *adt= ale->adt;
+                       
+                       /* if track is currently 'solo', then AnimData should have its
+                        * 'has solo' flag disabled
+                        */
+                       if (nlt->flag & NLATRACK_SOLO)
+                               adt->flag &= ~ADT_NLA_SOLO_TRACK;
+                       
+                       /* call delete on this track - deletes all strips too */
+                       free_nlatrack(&adt->nla_tracks, nlt);
+               }
        }
        
        /* free temp data */
        BLI_freelistN(&anim_data);
        
        /* set notifier that things have changed */
-       WM_event_add_notifier(C, NC_ANIMATION|ND_NLA_EDIT, NULL);
+       WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_EDITED, NULL);
        
        /* done */
        return OPERATOR_FINISHED;
@@ -491,16 +482,16 @@ static int nlaedit_delete_tracks_exec (bContext *C, wmOperator *op)
 void NLA_OT_delete_tracks (wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Delete Tracks";
-       ot->idname= "NLA_OT_delete_tracks";
-       ot->description= "Delete selected NLA-Tracks and the strips they contain";
+       ot->name = "Delete Tracks";
+       ot->idname = "NLA_OT_delete_tracks";
+       ot->description = "Delete selected NLA-Tracks and the strips they contain";
        
        /* api callbacks */
-       ot->exec= nlaedit_delete_tracks_exec;
-       ot->poll= nlaop_poll_tweakmode_off;
+       ot->exec = nlaedit_delete_tracks_exec;
+       ot->poll = nlaop_poll_tweakmode_off;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
 /* *********************************************** */