Operator to move mask layers up and down in the list
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 11 Jul 2012 10:37:38 +0000 (10:37 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 11 Jul 2012 10:37:38 +0000 (10:37 +0000)
release/scripts/startup/bl_ui/space_clip.py
source/blender/editors/mask/mask_edit.c
source/blender/editors/mask/mask_intern.h
source/blender/editors/mask/mask_ops.c

index 374588939e2fb61216cdfce403a7466f478300a2..a590a6cea94c8a6c43210d1f3aed7eae751751fc 100644 (file)
@@ -677,26 +677,36 @@ class CLIP_PT_mask_layers(Panel):
 
         sc = context.space_data
         mask = sc.mask
+        active_layer = mask.layers.active
+
+        rows = 5 if active_layer else 2
 
         row = layout.row()
         row.template_list(mask, "layers",
-                          mask, "active_layer_index", rows=3)
+                          mask, "active_layer_index", rows=rows)
 
         sub = row.column(align=True)
 
         sub.operator("mask.layer_new", icon='ZOOMIN', text="")
         sub.operator("mask.layer_remove", icon='ZOOMOUT', text="")
 
-        active = mask.layers.active
-        if active:
-            layout.prop(active, "name")
+        if active_layer:
+            sub.separator()
+
+            props = sub.operator("mask.layer_move", icon='TRIA_UP', text="")
+            props.direction = 'UP'
+
+            props = sub.operator("mask.layer_move", icon='TRIA_DOWN', text="")
+            props.direction = 'DOWN'
+
+            layout.prop(active_layer, "name")
 
             # blending
             row = layout.row(align=True)
-            row.prop(active, "alpha")
-            row.prop(active, "invert", text="", icon='IMAGE_ALPHA')
+            row.prop(active_layer, "alpha")
+            row.prop(active_layer, "invert", text="", icon='IMAGE_ALPHA')
 
-            layout.prop(active, "blend")
+            layout.prop(active_layer, "blend")
 
 
 class CLIP_PT_active_mask_spline(Panel):
index cce7e26115ec5e40e9054f0670fc03262383226c..b9522540e676acf533864d1f5a828e77f852bb5d 100644 (file)
@@ -238,6 +238,9 @@ void ED_operatortypes_mask(void)
        WM_operatortype_append(MASK_OT_shape_key_clear);
        WM_operatortype_append(MASK_OT_shape_key_feather_reset);
        WM_operatortype_append(MASK_OT_shape_key_rekey);
+
+       /* layers */
+       WM_operatortype_append(MASK_OT_layer_move);
 }
 
 void ED_keymap_mask(wmKeyConfig *keyconf)
index f1d72f5907800a504d2467c3e7fdd0375eb4f1ac..bad0a9c28a86318bd38e2529e7df2fb6394d67f0 100644 (file)
@@ -70,6 +70,8 @@ struct MaskSplinePoint *ED_mask_point_find_nearest(
         struct MaskLayer **masklay_r, struct MaskSpline **spline_r, int *is_handle_r,
         float *score);
 
+void MASK_OT_layer_move(struct wmOperatorType *ot);
+
 /* mask_relationships.c */
 void MASK_OT_parent_set(struct wmOperatorType *ot);
 void MASK_OT_parent_clear(struct wmOperatorType *ot);
index 91ba05c1ab2e02805d316dc9a10d64c20e11956a..902d065e87b2609d1f5b6f6829cf869340c79970 100644 (file)
@@ -1341,3 +1341,74 @@ void MASK_OT_feather_weight_clear(wmOperatorType *ot)
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
+
+/******************** move mask layer operator *********************/
+
+static int mask_layer_move_poll(bContext *C)
+{
+       if (ED_maskedit_mask_poll(C)) {
+               Mask *mask = CTX_data_edit_mask(C);
+
+               return mask->masklay_tot > 0;
+       }
+
+       return FALSE;
+}
+
+static int mask_layer_move_exec(bContext *C, wmOperator *op)
+{
+       Mask *mask = CTX_data_edit_mask(C);
+       MaskLayer *mask_layer = BLI_findlink(&mask->masklayers, mask->masklay_act);
+       MaskLayer *mask_layer_other;
+       int direction = RNA_enum_get(op->ptr, "direction");
+
+       if (!mask_layer)
+               return OPERATOR_CANCELLED;
+
+       if (direction == -1) {
+               mask_layer_other = mask_layer->prev;
+
+               if (!mask_layer_other)
+                       return OPERATOR_CANCELLED;
+
+               BLI_remlink(&mask->masklayers, mask_layer);
+               BLI_insertlinkbefore(&mask->masklayers, mask_layer_other, mask_layer);
+               mask->masklay_act--;
+       }
+       else if (direction == 1) {
+               mask_layer_other = mask_layer->next;
+
+               if (!mask_layer_other)
+                       return OPERATOR_CANCELLED;
+
+               BLI_remlink(&mask->masklayers, mask_layer);
+               BLI_insertlinkafter(&mask->masklayers, mask_layer_other, mask_layer);
+               mask->masklay_act++;
+       }
+
+       return OPERATOR_FINISHED;
+}
+
+void MASK_OT_layer_move(wmOperatorType *ot)
+{
+       static EnumPropertyItem direction_items[] = {
+               {-1, "UP", 0, "Up", ""},
+               {1, "DOWN", 0, "Down", ""},
+               {0, NULL, 0, NULL, NULL}
+       };
+
+       /* identifiers */
+       ot->name = "Move Layer";
+       ot->description = "Move the active layer up/down in the list";
+       ot->idname = "MASK_OT_layer_move";
+
+       /* api callbacks */
+       ot->exec = mask_layer_move_exec;
+       ot->poll = mask_layer_move_poll;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+       /* properties */
+       RNA_def_enum(ot->srna, "direction", direction_items, 0, "Direction", "Direction to move the active layer");
+}