diff options
Diffstat (limited to 'source/blender/editors/mask')
-rw-r--r-- | source/blender/editors/mask/mask_edit.c | 3 | ||||
-rw-r--r-- | source/blender/editors/mask/mask_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/mask/mask_ops.c | 71 |
3 files changed, 76 insertions, 0 deletions
diff --git a/source/blender/editors/mask/mask_edit.c b/source/blender/editors/mask/mask_edit.c index cce7e26115e..b9522540e67 100644 --- a/source/blender/editors/mask/mask_edit.c +++ b/source/blender/editors/mask/mask_edit.c @@ -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) diff --git a/source/blender/editors/mask/mask_intern.h b/source/blender/editors/mask/mask_intern.h index f1d72f59078..bad0a9c28a8 100644 --- a/source/blender/editors/mask/mask_intern.h +++ b/source/blender/editors/mask/mask_intern.h @@ -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); diff --git a/source/blender/editors/mask/mask_ops.c b/source/blender/editors/mask/mask_ops.c index 91ba05c1ab2..902d065e87b 100644 --- a/source/blender/editors/mask/mask_ops.c +++ b/source/blender/editors/mask/mask_ops.c @@ -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"); +} |