Revision: 20528
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20528
Author:   aligorith
Date:     2009-05-31 13:14:50 +0200 (Sun, 31 May 2009)

Log Message:
-----------
NLA SoC: Basic selection operators 

* Added click-select/left-right select and deselect all/invert all selection 
operators. For now, these basic operators will suffice (more advanced selection 
operators will be coded at a later stage).

* Fixed a few bugs in DopeSheet found while coding the relevant tools for NLA. 

* Added custom border-select operator for NLA channels (since the standard one 
assumes negative direction channel order)

* Added new API-method for NLA strips to check if the strip occurs within a 
given range, since this test needed to be performed in a few places...

* Tweaked the NLA Editor View2D ranges a bit to give saner default sizing. This 
still isn't right yet though.
 

Modified Paths:
--------------
    branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h
    branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c
    branches/soc-2009-aligorith/source/blender/editors/animation/anim_channels.c
    branches/soc-2009-aligorith/source/blender/editors/include/ED_anim_api.h
    
branches/soc-2009-aligorith/source/blender/editors/space_action/action_select.c
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_channels.c
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_draw.c
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_intern.h
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_ops.c
    branches/soc-2009-aligorith/source/blender/editors/space_nla/space_nla.c

Added Paths:
-----------
    branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_select.c

Modified: branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h     
2009-05-31 04:52:20 UTC (rev 20527)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/BKE_nla.h     
2009-05-31 11:14:50 UTC (rev 20528)
@@ -59,6 +59,8 @@
 short BKE_nlatrack_has_space(struct NlaTrack *nlt, float start, float end);
 void BKE_nlatrack_sort_strips(struct NlaTrack *nlt);
 
+short BKE_nlastrip_within_bounds(struct NlaStrip *strip, float min, float max);
+
 void BKE_nla_action_pushdown(struct AnimData *adt);
 
 #endif

Modified: branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c  
2009-05-31 04:52:20 UTC (rev 20527)
+++ branches/soc-2009-aligorith/source/blender/blenkernel/intern/nla.c  
2009-05-31 11:14:50 UTC (rev 20528)
@@ -455,6 +455,37 @@
 
 /* NLA Strips -------------------------------------- */
 
+/* Does the given NLA-strip fall within the given bounds (times)? */
+short BKE_nlastrip_within_bounds (NlaStrip *strip, float min, float max)
+{
+       const float stripLen= (strip) ? strip->end - strip->start : 0.0f;
+       const float boundsLen= (float)fabs(max - min);
+       
+       /* sanity checks */
+       if ((strip == NULL) || IS_EQ(stripLen, 0.0f) || IS_EQ(boundsLen, 0.0f))
+               return 0;
+       
+       /* only ok if at least part of the strip is within the bounding window
+        *      - first 2 cases cover when the strip length is less than the 
bounding area
+        *      - second 2 cases cover when the strip length is greater than 
the bounding area
+        */
+       if ( (stripLen < boundsLen) && 
+                !(IN_RANGE(strip->start, min, max) ||
+                  IN_RANGE(strip->end, min, max)) )
+       {
+               return 0;
+       }
+       if ( (stripLen > boundsLen) && 
+                !(IN_RANGE(min, strip->start, strip->end) ||
+                  IN_RANGE(max, strip->start, strip->end)) )
+       {
+               return 0;
+       }
+       
+       /* should be ok! */
+       return 1;
+}
+
 /* Is the given NLA-strip the first one to occur for the given AnimData block 
*/
 // TODO: make this an api method if necesary, but need to add prefix first
 short nlastrip_is_first (AnimData *adt, NlaStrip *strip)

Modified: 
branches/soc-2009-aligorith/source/blender/editors/animation/anim_channels.c
===================================================================
--- 
branches/soc-2009-aligorith/source/blender/editors/animation/anim_channels.c    
    2009-05-31 04:52:20 UTC (rev 20527)
+++ 
branches/soc-2009-aligorith/source/blender/editors/animation/anim_channels.c    
    2009-05-31 11:14:50 UTC (rev 20528)
@@ -87,32 +87,6 @@
 /* ************************************************************************** 
*/
 /* 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 */

Modified: 
branches/soc-2009-aligorith/source/blender/editors/include/ED_anim_api.h
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/include/ED_anim_api.h    
2009-05-31 04:52:20 UTC (rev 20527)
+++ branches/soc-2009-aligorith/source/blender/editors/include/ED_anim_api.h    
2009-05-31 11:14:50 UTC (rev 20528)
@@ -317,11 +317,36 @@
 /* Apply/Unapply NLA mapping to all keyframes in the nominated IPO block */
 void ANIM_nla_mapping_apply_fcurve(struct Object *ob, struct FCurve *fcu, 
short restore, short only_keys);
 
-/* ------------- xxx macros ----------------------- */
+/* ------------- Utility macros ----------------------- */
 
+/* checks if the given BezTriple is selected */
 #define BEZSELECTED(bezt) ((bezt->f2 & SELECT) || (bezt->f1 & SELECT) || 
(bezt->f3 & SELECT))
 
+/* 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); \
+       }
 
+
 /* --------- anim_deps.c, animation updates -------- */
 
        /* generic update flush, does tagged objects only, reads from Context 
screen (layers) and scene */

Modified: 
branches/soc-2009-aligorith/source/blender/editors/space_action/action_select.c
===================================================================
--- 
branches/soc-2009-aligorith/source/blender/editors/space_action/action_select.c 
    2009-05-31 04:52:20 UTC (rev 20527)
+++ 
branches/soc-2009-aligorith/source/blender/editors/space_action/action_select.c 
    2009-05-31 11:14:50 UTC (rev 20528)
@@ -174,7 +174,7 @@
                deselect_action_keys(&ac, 1, SELECT_ADD);
        
        /* set notifier that things have changed */
-       ED_area_tag_redraw(CTX_wm_area(C)); // FIXME... should be updating 
'keyframes' data context or so instead!
+       ANIM_animdata_send_notifiers(C, &ac, ANIM_CHANGED_BOTH);
        
        return OPERATOR_FINISHED;
 }
@@ -766,6 +766,7 @@
        if (ale == NULL) {
                /* channel not found */
                printf("Error: animation channel (index = %d) not found in 
mouse_action_keys() \n", channel_index);
+               BLI_freelistN(&anim_data);
                return;
        }
        else {

Modified: 
branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_channels.c
===================================================================
--- branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_channels.c 
2009-05-31 04:52:20 UTC (rev 20527)
+++ branches/soc-2009-aligorith/source/blender/editors/space_nla/nla_channels.c 
2009-05-31 11:14:50 UTC (rev 20528)
@@ -82,8 +82,116 @@
 /* *********************************************** */
 /* Operators for NLA channels-list which need to be different from the 
standard Animation Editor ones */
 
-// TODO: implemented borderselect too, since that also relies on ranges of 
buttons
+/* ******************** Borderselect Operator *********************** */
 
+static void borderselect_nla_channels (bAnimContext *ac, rcti *rect, short 
selectmode)
+{
+       ListBase anim_data = {NULL, NULL};
+       bAnimListElem *ale;
+       int filter;
+       
+       View2D *v2d= &ac->ar->v2d;
+       rctf rectf;
+       float ymin=(float)(-NLACHANNEL_HEIGHT), ymax=0;
+       
+       /* convert border-region to view coordinates */
+       UI_view2d_region_to_view(v2d, rect->xmin, rect->ymin+2, &rectf.xmin, 
&rectf.ymin);
+       UI_view2d_region_to_view(v2d, rect->xmax, rect->ymax-2, &rectf.xmax, 
&rectf.ymax);
+       
+       /* filter data */
+       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CHANNELS);
+       ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
+       
+       /* loop over data, doing border select */
+       for (ale= anim_data.first; ale; ale= ale->next) {
+               ymax= ymin + NLACHANNEL_STEP;
+               
+               /* if channel is within border-select region, alter it */
+               if (!((ymax < rectf.ymin) || (ymin > rectf.ymax))) {
+                       /* only the following types can be selected */
+                       switch (ale->type) {
+                               case ANIMTYPE_OBJECT: /* object */
+                               {
+                                       Base *base= (Base *)ale->data;
+                                       Object *ob= base->object;
+                                       
+                                       ACHANNEL_SET_FLAG(base, selectmode, 
SELECT);
+                                       ACHANNEL_SET_FLAG(ob, selectmode, 
SELECT);
+                               }
+                                       break;
+                               case ANIMTYPE_NLATRACK: /* nla-track */
+                               {
+                                       NlaTrack *nlt= (NlaTrack *)ale->data;
+                                       
+                                       ACHANNEL_SET_FLAG(nlt, selectmode, 
NLATRACK_SELECTED);
+                               }
+                                       break;
+                       }
+               }
+               
+               /* set maximum extent to be the minimum of the next channel */
+               ymin= ymax;
+       }
+       
+       /* cleanup */
+       BLI_freelistN(&anim_data);
+}
+
+/* ------------------- */
+
+static int nlachannels_borderselect_exec(bContext *C, wmOperator *op)
+{
+       bAnimContext ac;
+       rcti rect;
+       short selectmode=0;
+       int event;
+       
+       /* get editor data */
+       if (ANIM_animdata_get_context(C, &ac) == 0)
+               return OPERATOR_CANCELLED;
+       
+       /* get settings from operator */
+       rect.xmin= RNA_int_get(op->ptr, "xmin");
+       rect.ymin= RNA_int_get(op->ptr, "ymin");
+       rect.xmax= RNA_int_get(op->ptr, "xmax");
+       rect.ymax= RNA_int_get(op->ptr, "ymax");
+       
+       event= RNA_int_get(op->ptr, "event_type");
+       if (event == LEFTMOUSE) // FIXME... hardcoded
+               selectmode = ACHANNEL_SETFLAG_ADD;
+       else
+               selectmode = ACHANNEL_SETFLAG_CLEAR;
+       
+       /* apply borderselect animation channels */
+       borderselect_nla_channels(&ac, &rect, selectmode);
+       
+       return OPERATOR_FINISHED;
+} 
+
+void NLA_OT_channels_select_border(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Border Select";
+       ot->idname= "NLA_OT_channels_select_border";
+       
+       /* api callbacks */
+       ot->invoke= WM_border_select_invoke;
+       ot->exec= nlachannels_borderselect_exec;
+       ot->modal= WM_border_select_modal;
+       
+       ot->poll= ED_operator_areaactive;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* rna */
+       RNA_def_int(ot->srna, "event_type", 0, INT_MIN, INT_MAX, "Event Type", 
"", INT_MIN, INT_MAX);
+       RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", 
INT_MIN, INT_MAX);
+       RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", 
INT_MIN, INT_MAX);

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to