Revision: 18237
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18237
Author:   aligorith
Date:     2009-01-02 02:28:05 +0100 (Fri, 02 Jan 2009)

Log Message:
-----------
2.5 Animation Channels - Borderselect Tool 

Added BorderSelect operator for animation channels.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/animation/anim_channels.c
    
branches/blender2.5/blender/source/blender/editors/space_action/action_select.c

Modified: 
branches/blender2.5/blender/source/blender/editors/animation/anim_channels.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/animation/anim_channels.c    
    2009-01-02 01:28:02 UTC (rev 18236)
+++ 
branches/blender2.5/blender/source/blender/editors/animation/anim_channels.c    
    2009-01-02 01:28:05 UTC (rev 18237)
@@ -104,8 +104,6 @@
 
 /* -------------------------- Exposed API ----------------------------------- 
*/
 
-
-
 /* Deselect all animation channels 
  *     - data: pointer to datatype, as contained in bAnimContext
  *     - datatype: the type of data that 'data' represents (eAnim_ChannelType)
@@ -258,6 +256,159 @@
        RNA_def_property(ot->srna, "invert", PROP_BOOLEAN, PROP_NONE);
 }
 
+/* ******************** Borderselect Operator *********************** */
+
+// XXX do we need to set some extra thingsfor each channel selected?
+static void borderselect_anim_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=0, ymax=(float)(-ACHANNEL_HEIGHT);
+       
+       /* 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(&anim_data, filter, ac->data, ac->datatype);
+       
+       /* loop over data, doing border select */
+       for (ale= anim_data.first; ale; ale= ale->next) {
+               ymin= ymax - ACHANNEL_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_GROUP: /* action group */
+                               {
+                                       bActionGroup *agrp= (bActionGroup 
*)ale->data;
+                                       
+                                       ACHANNEL_SET_FLAG(agrp, selectmode, 
AGRP_SELECTED);
+                               }
+                                       break;
+                               case ANIMTYPE_ACHAN: /* action channel */
+                               case ANIMTYPE_FILLIPO: /* expand ipo curves = 
action channel */
+                               case ANIMTYPE_FILLCON: /* expand constraint 
channels = action channel */
+                               {
+                                       bActionChannel *achan= (bActionChannel 
*)ale->data;
+                                       
+                                       ACHANNEL_SET_FLAG(achan, selectmode, 
ACHAN_SELECTED);
+                                       
+                                       /* messy... set active bone */
+                                       
//select_poseelement_by_name(achan->name, selectmode);
+                               }
+                                       break;
+                               case ANIMTYPE_CONCHAN: /* constraint channel */
+                               {
+                                       bConstraintChannel *conchan = 
(bConstraintChannel *)ale->data;
+                                       
+                                       ACHANNEL_SET_FLAG(conchan, selectmode, 
CONSTRAINT_CHANNEL_SELECT);
+                               }
+                                       break;
+                               case ANIMTYPE_ICU: /* ipo-curve channel */
+                               {
+                                       IpoCurve *icu = (IpoCurve *)ale->data;
+                                       
+                                       ACHANNEL_SET_FLAG(icu, selectmode, 
IPO_SELECT);
+                               }
+                                       break;
+                               case ANIMTYPE_GPLAYER: /* grease-pencil layer */
+                               {
+                                       bGPDlayer *gpl = (bGPDlayer *)ale->data;
+                                       
+                                       ACHANNEL_SET_FLAG(gpl, selectmode, 
GP_LAYER_SELECT);
+                               }
+                                       break;
+                       }
+                       
+                       /* select action-channel 'owner' */
+                       if ((ale->owner) && (ale->ownertype == ANIMTYPE_ACHAN)) 
{
+                               //bActionChannel *achano= (bActionChannel 
*)ale->owner;
+                               
+                               /* messy... set active bone */
+                               //select_poseelement_by_name(achano->name, 
selectmode);
+                       }
+               }
+               
+               /* set minimum extent to be the maximum of the next channel */
+               ymax= ymin;
+       }
+       
+       /* cleanup */
+       BLI_freelistN(&anim_data);
+}
+
+/* ------------------- */
+
+static int animchannels_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_anim_channels(&ac, &rect, selectmode);
+       
+       return OPERATOR_FINISHED;
+} 
+
+void ANIM_OT_channels_borderselect(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Border Select";
+       ot->idname= "ANIM_OT_channels_borderselect";
+       
+       /* api callbacks */
+       ot->invoke= WM_border_select_invoke;
+       ot->exec= animchannels_borderselect_exec;
+       ot->modal= WM_border_select_modal;
+       
+       ot->poll= ED_operator_areaactive;
+       
+       /* flags */
+       // XXX er...
+       ot->flag= OPTYPE_REGISTER/*|OPTYPE_UNDO*/;
+       
+       /* rna */
+       RNA_def_property(ot->srna, "event_type", PROP_INT, PROP_NONE);
+       RNA_def_property(ot->srna, "xmin", PROP_INT, PROP_NONE);
+       RNA_def_property(ot->srna, "xmax", PROP_INT, PROP_NONE);
+       RNA_def_property(ot->srna, "ymin", PROP_INT, PROP_NONE);
+       RNA_def_property(ot->srna, "ymax", PROP_INT, PROP_NONE);
+}
+
 /* ******************** Mouse-Click Operator *********************** */
 /* Depending on the channel that was clicked on, the mouse click will activate 
whichever
  * part of the channel is relevant.
@@ -650,6 +801,7 @@
 void ED_operatortypes_animchannels(void)
 {
        WM_operatortype_append(ANIM_OT_channels_deselectall);
+       WM_operatortype_append(ANIM_OT_channels_borderselect);
        WM_operatortype_append(ANIM_OT_channels_mouseclick);
 }
 
@@ -657,14 +809,18 @@
 {
        ListBase *keymap = WM_keymap_listbase(wm, "Animation_Channels", 0, 0);
        
-       /* click-select */
+       /* selection */
+               /* click-select */
                // XXX for now, only leftmouse.... 
        WM_keymap_add_item(keymap, "ANIM_OT_channels_mouseclick", LEFTMOUSE, 
KM_PRESS, 0, 0);
        RNA_boolean_set(WM_keymap_add_item(keymap, 
"ANIM_OT_channels_mouseclick", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, 
"extend_select", 1);
        
-       /* deselect all */
+               /* deselect all */
        WM_keymap_add_item(keymap, "ANIM_OT_channels_deselectall", AKEY, 
KM_PRESS, 0, 0);
        RNA_boolean_set(WM_keymap_add_item(keymap, 
"ANIM_OT_channels_deselectall", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1);
+       
+               /* borderselect */
+       WM_keymap_add_item(keymap, "ANIM_OT_channels_borderselect", BKEY, 
KM_PRESS, 0, 0);
 }
 
 /* ************************************************************************** 
*/

Modified: 
branches/blender2.5/blender/source/blender/editors/space_action/action_select.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/space_action/action_select.c 
    2009-01-02 01:28:02 UTC (rev 18236)
+++ 
branches/blender2.5/blender/source/blender/editors/space_action/action_select.c 
    2009-01-02 01:28:05 UTC (rev 18237)
@@ -852,7 +852,7 @@
                deselect_action_keys(ac, 0, 0);
                
                if (ELEM(ac->datatype, ANIMCONT_ACTION, ANIMCONT_DOPESHEET)) {
-                       //deselect_action_channels(0);
+                       ANIM_deselect_anim_channels(ac->data, ac->datatype, 0, 
ACHANNEL_SETFLAG_CLEAR);
                        
                        /* Highlight either an Action-Channel or Action-Group */
                        if (achan) {
@@ -866,7 +866,7 @@
                        }
                }
                else if (ac->datatype == ANIMCONT_GPENCIL) {
-                       //deselect_action_channels(0);
+                       ANIM_deselect_anim_channels(ac->data, ac->datatype, 0, 
ACHANNEL_SETFLAG_CLEAR);
                        
                        /* Highlight gpencil layer */
                        gpl->flag |= GP_LAYER_SELECT;


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

Reply via email to