code cleanup: use const events for modal and invoke operators.
[blender.git] / source / blender / editors / space_action / action_select.c
index 539a32161e5a3bf0377049261925f4c5ce40cdba..c814c0b4d8cb1571b1ee2e402e5a5fa3cfa42517 100644 (file)
@@ -184,6 +184,7 @@ void ACTION_OT_select_all_toggle(wmOperatorType *ot)
        
        /* props */
        ot->prop = RNA_def_boolean(ot->srna, "invert", 0, "Invert", "");
+       RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE);
 }
 
 /* ******************** Border Select Operator **************************** */
@@ -254,16 +255,39 @@ static void borderselect_action(bAnimContext *ac, rcti rect, short mode, short s
                }
                
                /* perform vertical suitability check (if applicable) */
-               if ( (mode == ACTKEYS_BORDERSEL_FRAMERANGE) || 
-                    !((ymax < rectf.ymin) || (ymin > rectf.ymax)) )
+               if ((mode == ACTKEYS_BORDERSEL_FRAMERANGE) ||
+                   !((ymax < rectf.ymin) || (ymin > rectf.ymax)))
                {
                        /* loop over data selecting */
-                       if (ale->type == ANIMTYPE_GPLAYER)
-                               ED_gplayer_frames_select_border(ale->data, rectf.xmin, rectf.xmax, selectmode);
-                       else if (ale->type == ANIMTYPE_MASKLAYER)
-                               ED_masklayer_frames_select_border(ale->data, rectf.xmin, rectf.xmax, selectmode);
-                       else
-                               ANIM_animchannel_keyframes_loop(&ked, ac->ads, ale, ok_cb, select_cb, NULL);
+                       switch (ale->type) {
+                               case ANIMTYPE_GPDATABLOCK:
+                               {
+                                       bGPdata *gpd = ale->data;
+                                       bGPDlayer *gpl;
+                                       for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+                                               ED_gplayer_frames_select_border(gpl, rectf.xmin, rectf.xmax, selectmode);
+                                       }
+                                       break;
+                               }
+                               case ANIMTYPE_GPLAYER:
+                                       ED_gplayer_frames_select_border(ale->data, rectf.xmin, rectf.xmax, selectmode);
+                                       break;
+                               case ANIMTYPE_MASKDATABLOCK:
+                               {
+                                       Mask *mask = ale->data;
+                                       MaskLayer *masklay;
+                                       for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
+                                               ED_masklayer_frames_select_border(ale->data, rectf.xmin, rectf.xmax, selectmode);
+                                       }
+                                       break;
+                               }
+                               case ANIMTYPE_MASKLAYER:
+                                       ED_masklayer_frames_select_border(ale->data, rectf.xmin, rectf.xmax, selectmode);
+                                       break;
+                               default:
+                                       ANIM_animchannel_keyframes_loop(&ked, ac->ads, ale, ok_cb, select_cb, NULL);
+                                       break;
+                       }
                }
                
                /* set minimum extent to be the maximum of the next channel */
@@ -293,10 +317,7 @@ static int actkeys_borderselect_exec(bContext *C, wmOperator *op)
                deselect_action_keys(&ac, 1, SELECT_SUBTRACT);
        
        /* 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");
+       WM_operator_properties_border_to_rcti(op, &rect);
                
        gesture_mode = RNA_int_get(op->ptr, "gesture_mode");
        if (gesture_mode == GESTURE_MODAL_SELECT)
@@ -311,7 +332,7 @@ static int actkeys_borderselect_exec(bContext *C, wmOperator *op)
                 *      - the frame-range select option is favored over the channel one (x over y), as frame-range one is often
                 *        used for tweaking timing when "blocking", while channels is not that useful...
                 */
-               if ((rect.xmax - rect.xmin) >= (rect.ymax - rect.ymin))
+               if (BLI_rcti_size_x(&rect) >= BLI_rcti_size_y(&rect))
                        mode = ACTKEYS_BORDERSEL_FRAMERANGE;
                else
                        mode = ACTKEYS_BORDERSEL_CHANNELS;
@@ -765,7 +786,7 @@ static void actkeys_select_leftright(bAnimContext *ac, short leftright, short se
        if (leftright == ACTKEYS_LRSEL_LEFT) {
                ked.f1 = MINAFRAMEF;
                ked.f2 = (float)(CFRA + 0.1f);
-       } 
+       }
        else {
                ked.f1 = (float)(CFRA - 0.1f);
                ked.f2 = MAXFRAMEF;
@@ -787,7 +808,7 @@ static void actkeys_select_leftright(bAnimContext *ac, short leftright, short se
                        ANIM_fcurve_keyframes_loop(&ked, ale->key_data, ok_cb, select_cb, NULL);
                        ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 1);
                }
-               else if (ale->type == ANIMTYPE_GPLAYER) 
+               else if (ale->type == ANIMTYPE_GPLAYER)
                        ED_gplayer_frames_select_border(ale->data, ked.f1, ked.f2, select_mode);
                else if (ale->type == ANIMTYPE_MASKLAYER)
                        ED_masklayer_frames_select_border(ale->data, ked.f1, ked.f2, select_mode);
@@ -804,8 +825,8 @@ static void actkeys_select_leftright(bAnimContext *ac, short leftright, short se
                        TimeMarker *marker;
                        
                        for (marker = markers->first; marker; marker = marker->next) {
-                               if ( ((leftright == ACTKEYS_LRSEL_LEFT) && (marker->frame < CFRA)) ||
-                                    ((leftright == ACTKEYS_LRSEL_RIGHT) && (marker->frame >= CFRA)) )
+                               if (((leftright == ACTKEYS_LRSEL_LEFT)  && (marker->frame <  CFRA)) ||
+                                   ((leftright == ACTKEYS_LRSEL_RIGHT) && (marker->frame >= CFRA)))
                                {
                                        marker->flag |= SELECT;
                                }
@@ -851,7 +872,7 @@ static int actkeys_select_leftright_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-static int actkeys_select_leftright_invoke(bContext *C, wmOperator *op, wmEvent *event)
+static int actkeys_select_leftright_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
        bAnimContext ac;
        short leftright = RNA_enum_get(op->ptr, "mode");
@@ -871,7 +892,7 @@ static int actkeys_select_leftright_invoke(bContext *C, wmOperator *op, wmEvent
                UI_view2d_region_to_view(v2d, event->mval[0], event->mval[1], &x, NULL);
                if (x < CFRA)
                        RNA_enum_set(op->ptr, "mode", ACTKEYS_LRSEL_LEFT);
-               else    
+               else
                        RNA_enum_set(op->ptr, "mode", ACTKEYS_LRSEL_RIGHT);
        }
        
@@ -881,6 +902,8 @@ static int actkeys_select_leftright_invoke(bContext *C, wmOperator *op, wmEvent
 
 void ACTION_OT_select_leftright(wmOperatorType *ot)
 {
+       PropertyRNA *prop;
+       
        /* identifiers */
        ot->name = "Select Left/Right";
        ot->idname = "ACTION_OT_select_leftright";
@@ -894,9 +917,12 @@ void ACTION_OT_select_leftright(wmOperatorType *ot)
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
-       /* id-props */
+       /* properties */
        ot->prop = RNA_def_enum(ot->srna, "mode", prop_actkeys_leftright_select_types, ACTKEYS_LRSEL_TEST, "Mode", "");
-       RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", "");
+       RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE);
+       
+       prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", "");
+       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 }
 
 /* ******************** Mouse-Click Select Operator *********************** */
@@ -909,9 +935,6 @@ void ACTION_OT_select_leftright(wmOperatorType *ot)
  * selection mode between replacing the selection (without) and inverting the selection (with).
  */
 
-/* sensitivity factor for frame-selections */
-#define FRAME_CLICK_THRESH      0.1f
-
 /* ------------------- */
  
 /* option 1) select keyframe directly under mouse */
@@ -930,8 +953,26 @@ static void actkeys_mselect_single(bAnimContext *ac, bAnimListElem *ale, short s
                ED_gpencil_select_frame(ale->data, selx, select_mode);
        else if (ale->type == ANIMTYPE_MASKLAYER)
                ED_mask_select_frame(ale->data, selx, select_mode);
-       else
-               ANIM_animchannel_keyframes_loop(&ked, ac->ads, ale, ok_cb, select_cb, NULL);
+       else {
+               if (ELEM(ac->datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK) &&
+                   (ale->type == ANIMTYPE_SUMMARY) && (ale->datatype == ALE_ALL))
+               {
+                       ListBase anim_data = {NULL, NULL};
+                       int filter;
+                       filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE /*| ANIMFILTER_CURVESONLY */ | ANIMFILTER_NODUPLIS);
+                       ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
+                       for (ale = anim_data.first; ale; ale = ale->next) {
+                               if (ale->type == ANIMTYPE_GPLAYER)
+                                       ED_gpencil_select_frame(ale->data, selx, select_mode);
+                               else if (ale->type == ANIMTYPE_MASKLAYER)
+                                       ED_mask_select_frame(ale->data, selx, select_mode);
+                       }
+                       BLI_freelistN(&anim_data);
+               }
+               else {
+                       ANIM_animchannel_keyframes_loop(&ked, ac->ads, ale, ok_cb, select_cb, NULL);
+               }
+       }
 }
 
 /* Option 2) Selects all the keyframes on either side of the current frame (depends on which side the mouse is on) */
@@ -1064,7 +1105,7 @@ static void mouse_action_keys(bAnimContext *ac, const int mval[2], short select_
                        /* dopesheet summary covers everything */
                        summary_to_keylist(ac, &anim_keys, NULL);
                }
-               else if (ale->type == ANIMTYPE_GROUP) { 
+               else if (ale->type == ANIMTYPE_GROUP) {
                        // TODO: why don't we just give groups key_data too?
                        bActionGroup *agrp = (bActionGroup *)ale->data;
                        agroup_to_keylist(adt, agrp, &anim_keys, NULL);
@@ -1127,7 +1168,7 @@ static void mouse_action_keys(bAnimContext *ac, const int mval[2], short select_
                                        
                                        agrp->flag |= AGRP_SELECTED;
                                        ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, agrp, ANIMTYPE_GROUP);
-                               }       
+                               }
                                else if (ale->type == ANIMTYPE_FCURVE) {
                                        FCurve *fcu = ale->data;
                                        
@@ -1182,7 +1223,7 @@ static void mouse_action_keys(bAnimContext *ac, const int mval[2], short select_
 }
 
 /* handle clicking */
-static int actkeys_clickselect_invoke(bContext *C, wmOperator *op, wmEvent *event)
+static int actkeys_clickselect_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
        bAnimContext ac;
        /* ARegion *ar; */ /* UNUSED */
@@ -1193,7 +1234,7 @@ static int actkeys_clickselect_invoke(bContext *C, wmOperator *op, wmEvent *even
                return OPERATOR_CANCELLED;
                
        /* get useful pointers from animation context data */
-       /* ar= ac.ar; */ /* UNUSED */
+       /* ar = ac.ar; */ /* UNUSED */
 
        /* select mode is either replace (deselect all, then add) or add/extend */
        if (RNA_boolean_get(op->ptr, "extend"))
@@ -1216,6 +1257,8 @@ static int actkeys_clickselect_invoke(bContext *C, wmOperator *op, wmEvent *even
  
 void ACTION_OT_clickselect(wmOperatorType *ot)
 {
+       PropertyRNA *prop;
+       
        /* identifiers */
        ot->name = "Mouse Select Keys";
        ot->idname = "ACTION_OT_clickselect";
@@ -1228,9 +1271,11 @@ void ACTION_OT_clickselect(wmOperatorType *ot)
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
-       /* id-props */
-       RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); // SHIFTKEY
-       RNA_def_boolean(ot->srna, "column", 0, "Column Select", ""); // ALTKEY
+       /* properties */
+       prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); // SHIFTKEY
+       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+       prop = RNA_def_boolean(ot->srna, "column", 0, "Column Select", ""); // ALTKEY
+       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 }
 
 /* ************************************************************************** */