Operator to move mask layers up and down in the list

This commit is contained in:
Sergey Sharybin 2012-07-11 10:37:38 +00:00
parent 35b6f41f46
commit 6e6dd576a8
4 changed files with 93 additions and 7 deletions

@ -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):

@ -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)

@ -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);

@ -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");
}