[Bf-blender-cvs] [8032bd98d82] master: GPencil: Add Layer Mask ordering buttons

Antonio Vazquez noreply at git.blender.org
Mon Apr 19 17:45:34 CEST 2021


Commit: 8032bd98d820e4db549713e131fdf70dde6e89b2
Author: Antonio Vazquez
Date:   Mon Apr 19 17:37:10 2021 +0200
Branches: master
https://developer.blender.org/rB8032bd98d820e4db549713e131fdf70dde6e89b2

GPencil: Add Layer Mask ordering buttons

Now the list of masks can be ordered as is done in Layers.

This can be used to organize list and in the future refquired for new masking options.

===================================================================

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_ops.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index c1d60a127d2..3064b33c7f7 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -821,6 +821,12 @@ class GreasePencilLayerMasksPanel:
             col2.menu("GPENCIL_MT_layer_mask_menu", icon='ADD', text="")
             col2.operator("gpencil.layer_mask_remove", icon='REMOVE', text="")
 
+            col2.separator()
+
+            sub = col2.column(align=True)
+            sub.operator("gpencil.layer_mask_move", icon='TRIA_UP', text="").type = 'UP'
+            sub.operator("gpencil.layer_mask_move", icon='TRIA_DOWN', text="").type = 'DOWN'
+
 
 class GreasePencilLayerRelationsPanel:
 
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index b269fd84d5f..c93fcb9eb8c 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -3745,3 +3745,51 @@ void GPENCIL_OT_layer_mask_remove(wmOperatorType *ot)
   ot->exec = gpencil_layer_mask_remove_exec;
   ot->poll = gpencil_active_layer_poll;
 }
+
+static int gpencil_layer_mask_move_exec(bContext *C, wmOperator *op)
+{
+  bGPdata *gpd = ED_gpencil_data_get_active(C);
+  bGPDlayer *gpl = BKE_gpencil_layer_active_get(gpd);
+  const int direction = RNA_enum_get(op->ptr, "type");
+
+  /* sanity checks */
+  if (ELEM(NULL, gpd, gpl)) {
+    return OPERATOR_CANCELLED;
+  }
+  if (gpl->act_mask > 0) {
+    bGPDlayer_Mask *mask = BLI_findlink(&gpl->mask_layers, gpl->act_mask - 1);
+    if (mask != NULL) {
+      BLI_assert(ELEM(direction, -1, 0, 1)); /* we use value below */
+      if (BLI_listbase_link_move(&gpl->mask_layers, mask, direction)) {
+        gpl->act_mask += direction;
+        DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
+        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+      }
+    }
+  }
+
+  return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_layer_mask_move(wmOperatorType *ot)
+{
+  static const EnumPropertyItem slot_move[] = {
+      {GP_LAYER_MOVE_UP, "UP", 0, "Up", ""},
+      {GP_LAYER_MOVE_DOWN, "DOWN", 0, "Down", ""},
+      {0, NULL, 0, NULL, NULL},
+  };
+
+  /* identifiers */
+  ot->name = "Move Grease Pencil Layer Mask";
+  ot->idname = "GPENCIL_OT_layer_mask_move";
+  ot->description = "Move the active Grease Pencil mask layer up/down in the list";
+
+  /* api callbacks */
+  ot->exec = gpencil_layer_mask_move_exec;
+  ot->poll = gpencil_active_layer_poll;
+
+  /* flags */
+  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+  ot->prop = RNA_def_enum(ot->srna, "type", slot_move, 0, "Type", "");
+}
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index c6f74c39beb..09200125cb7 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -421,6 +421,7 @@ void GPENCIL_OT_layer_duplicate_object(struct wmOperatorType *ot);
 
 void GPENCIL_OT_layer_mask_add(struct wmOperatorType *ot);
 void GPENCIL_OT_layer_mask_remove(struct wmOperatorType *ot);
+void GPENCIL_OT_layer_mask_move(struct wmOperatorType *ot);
 
 void GPENCIL_OT_hide(struct wmOperatorType *ot);
 void GPENCIL_OT_reveal(struct wmOperatorType *ot);
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index 1a6cb5670c4..7d454eb3be1 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -601,6 +601,7 @@ void ED_operatortypes_gpencil(void)
 
   WM_operatortype_append(GPENCIL_OT_layer_mask_add);
   WM_operatortype_append(GPENCIL_OT_layer_mask_remove);
+  WM_operatortype_append(GPENCIL_OT_layer_mask_move);
 
   WM_operatortype_append(GPENCIL_OT_hide);
   WM_operatortype_append(GPENCIL_OT_reveal);



More information about the Bf-blender-cvs mailing list