[Bf-blender-cvs] [986955a2d53] master: GPencil: Add Vertex Paint operators to Paint menu

Antonio Vazquez noreply at git.blender.org
Thu Dec 3 16:49:44 CET 2020


Commit: 986955a2d53a5fd94be38f22e0eb954333763aff
Author: Antonio Vazquez
Date:   Thu Dec 3 16:46:16 2020 +0100
Branches: master
https://developer.blender.org/rB986955a2d53a5fd94be38f22e0eb954333763aff

GPencil: Add Vertex Paint operators to Paint menu

These operators existed since 2.83, but the menu was hidden by error.

Also the operators have been cleanup and make multiframe compatible.

Reviewed By: mendio

Differential Revision: https://developer.blender.org/D9671

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

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_vertex_ops.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 5af88e15111..10c9f25b92a 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -1828,7 +1828,13 @@ class VIEW3D_MT_paint_gpencil(Menu):
     def draw(self, context):
         layout = self.layout
 
+        layout.operator("gpencil.vertex_color_set", text="Set Vertex Colors")
         layout.operator("gpencil.stroke_reset_vertex_color")
+        layout.separator()
+        layout.operator("gpencil.vertex_color_invert", text="Invert")
+        layout.operator("gpencil.vertex_color_levels", text="Levels")
+        layout.operator("gpencil.vertex_color_hsv", text="Hue Saturation Value")
+        layout.operator("gpencil.vertex_color_brightness_contrast", text="Bright/Contrast")
 
 
 class VIEW3D_MT_select_gpencil(Menu):
@@ -5044,22 +5050,6 @@ class VIEW3D_MT_weight_gpencil(Menu):
         layout.menu("VIEW3D_MT_gpencil_autoweights")
 
 
-class VIEW3D_MT_vertex_gpencil(Menu):
-    bl_label = "Paint"
-
-    def draw(self, _context):
-        layout = self.layout
-        layout.operator("gpencil.vertex_color_set", text="Set Vertex Colors")
-        layout.separator()
-        layout.operator("gpencil.vertex_color_invert", text="Invert")
-        layout.operator("gpencil.vertex_color_levels", text="Levels")
-        layout.operator("gpencil.vertex_color_hsv", text="Hue Saturation Value")
-        layout.operator("gpencil.vertex_color_brightness_contrast", text="Bright/Contrast")
-
-        layout.separator()
-        layout.menu("VIEW3D_MT_join_palette")
-
-
 class VIEW3D_MT_gpencil_animation(Menu):
     bl_label = "Animation"
 
@@ -7606,7 +7596,6 @@ classes = (
     VIEW3D_MT_edit_gpencil_delete,
     VIEW3D_MT_edit_gpencil_showhide,
     VIEW3D_MT_weight_gpencil,
-    VIEW3D_MT_vertex_gpencil,
     VIEW3D_MT_gpencil_animation,
     VIEW3D_MT_gpencil_simplify,
     VIEW3D_MT_gpencil_copy_layer,
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 15162f491d5..a183c34fd9d 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -5206,158 +5206,3 @@ void GPENCIL_OT_stroke_merge_by_distance(wmOperatorType *ot)
   RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 }
 /** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name Reset Stroke Vertex Color Operator
- * \{ */
-
-static void gpencil_reset_vertex(bGPDstroke *gps, eGp_Vertex_Mode mode)
-{
-  if (mode != GPPAINT_MODE_STROKE) {
-    zero_v4(gps->vert_color_fill);
-  }
-
-  if (mode != GPPAINT_MODE_FILL) {
-    bGPDspoint *pt;
-    for (int i = 0; i < gps->totpoints; i++) {
-      pt = &gps->points[i];
-      zero_v4(pt->vert_color);
-    }
-  }
-}
-
-static int gpencil_stroke_reset_vertex_color_exec(bContext *C, wmOperator *op)
-{
-  Object *obact = CTX_data_active_object(C);
-  bGPdata *gpd = (bGPdata *)obact->data;
-  const bool is_curve_edit = (bool)GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd);
-  const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
-  bGPDstroke *gps = NULL;
-
-  if (gpd == NULL) {
-    BKE_report(op->reports, RPT_ERROR, "No Grease Pencil data");
-    return OPERATOR_CANCELLED;
-  }
-  eGp_Vertex_Mode mode = RNA_enum_get(op->ptr, "mode");
-
-  /* First need to check if there are something selected. If not, apply to all strokes. */
-  bool all_strokes = true;
-  CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
-    bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
-    for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
-      if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
-        if (gpf == NULL) {
-          continue;
-        }
-        for (gps = gpf->strokes.first; gps; gps = gps->next) {
-          /* skip strokes that are invalid for current view */
-          if (ED_gpencil_stroke_can_use(C, gps) == false) {
-            continue;
-          }
-
-          if (is_curve_edit) {
-            if (gps->editcurve == NULL) {
-              continue;
-            }
-            bGPDcurve *gpc = gps->editcurve;
-            if (gpc->flag & GP_CURVE_SELECT) {
-              all_strokes = false;
-              break;
-            }
-          }
-          else {
-            if (gps->flag & GP_STROKE_SELECT) {
-              all_strokes = false;
-              break;
-            }
-          }
-        }
-        /* if not multiedit, exit loop*/
-        if (!is_multiedit) {
-          break;
-        }
-      }
-    }
-  }
-  CTX_DATA_END;
-
-  /* Reset Vertex colors. */
-  bool changed = false;
-  CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
-    bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
-
-    for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
-      if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
-        if (gpf == NULL) {
-          continue;
-        }
-
-        for (gps = gpf->strokes.first; gps; gps = gps->next) {
-          /* skip strokes that are invalid for current view */
-          if (ED_gpencil_stroke_can_use(C, gps) == false) {
-            continue;
-          }
-
-          if (is_curve_edit) {
-            if (gps->editcurve == NULL) {
-              continue;
-            }
-            bGPDcurve *gpc = gps->editcurve;
-            if ((all_strokes) || (gpc->flag & GP_CURVE_SELECT)) {
-              gpencil_reset_vertex(gps, mode);
-            }
-          }
-          else {
-            if ((all_strokes) || (gps->flag & GP_STROKE_SELECT)) {
-              gpencil_reset_vertex(gps, mode);
-            }
-          }
-
-          changed = true;
-        }
-        /* if not multiedit, exit loop*/
-        if (!is_multiedit) {
-          break;
-        }
-      }
-    }
-  }
-  CTX_DATA_END;
-
-  if (changed) {
-    /* updates */
-    DEG_id_tag_update(&gpd->id,
-                      ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
-    DEG_id_tag_update(&obact->id, ID_RECALC_COPY_ON_WRITE);
-    WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
-  }
-
-  return OPERATOR_FINISHED;
-}
-
-void GPENCIL_OT_stroke_reset_vertex_color(wmOperatorType *ot)
-{
-  static EnumPropertyItem mode_types_items[] = {
-      {GPPAINT_MODE_STROKE, "STROKE", 0, "Stroke", "Reset Vertex Color to Stroke only"},
-      {GPPAINT_MODE_FILL, "FILL", 0, "Fill", "Reset Vertex Color to Fill only"},
-      {GPPAINT_MODE_BOTH, "BOTH", 0, "Stroke and Fill", "Reset Vertex Color to Stroke and Fill"},
-      {0, NULL, 0, NULL, NULL},
-  };
-
-  /* identifiers */
-  ot->name = "Reset Vertex Color";
-  ot->idname = "GPENCIL_OT_stroke_reset_vertex_color";
-  ot->description = "Reset vertex color for all or selected strokes";
-
-  /* callbacks */
-  ot->exec = gpencil_stroke_reset_vertex_color_exec;
-  ot->poll = gpencil_stroke_edit_poll;
-
-  /* flags */
-  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
-  /* properties */
-  ot->prop = RNA_def_enum(ot->srna, "mode", mode_types_items, GPPAINT_MODE_BOTH, "Mode", "");
-}
-
-/** \} */
diff --git a/source/blender/editors/gpencil/gpencil_vertex_ops.c b/source/blender/editors/gpencil/gpencil_vertex_ops.c
index 69e50beb66e..c3fd8d10b64 100644
--- a/source/blender/editors/gpencil/gpencil_vertex_ops.c
+++ b/source/blender/editors/gpencil/gpencil_vertex_ops.c
@@ -60,23 +60,69 @@
 
 #include "gpencil_intern.h"
 
-enum {
-  GP_PAINT_VERTEX_STROKE = 0,
-  GP_PAINT_VERTEX_FILL = 1,
-  GP_PAINT_VERTEX_BOTH = 2,
-};
-
 static const EnumPropertyItem gpencil_modesEnumPropertyItem_mode[] = {
-    {GP_PAINT_VERTEX_STROKE, "STROKE", 0, "Stroke", ""},
-    {GP_PAINT_VERTEX_FILL, "FILL", 0, "Fill", ""},
-    {GP_PAINT_VERTEX_BOTH, "BOTH", 0, "Both", ""},
+    {GPPAINT_MODE_STROKE, "STROKE", 0, "Stroke", ""},
+    {GPPAINT_MODE_FILL, "FILL", 0, "Fill", ""},
+    {GPPAINT_MODE_BOTH, "BOTH", 0, "Stroke and Fill", ""},
     {0, NULL, 0, NULL, NULL},
 };
 
+/* Helper: Check if any stroke is selected. */
+static bool is_any_stroke_selected(bContext *C, const bool is_multiedit, const bool is_curve_edit)
+{
+  bool is_selected = false;
+
+  /* If not enabled any mask mode, the strokes are considered as not selected. */
+  ToolSettings *ts = CTX_data_tool_settings(C);
+  if (!GPENCIL_ANY_VERTEX_MASK(ts->gpencil_selectmode_vertex)) {
+    return false;
+  }
+
+  CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
+    bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
+    for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
+      if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && (is_multiedit))) {
+        if (gpf == NULL) {
+          continue;
+        }
+        LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
+          /* skip strokes that are invalid for current view */
+          if (ED_gpencil_stroke_can_use(C, gps) == false) {
+            continue;
+          }
+
+          if (is_curve_edit) {
+            if (gps->editcurve == NULL) {
+              continue;
+            }
+            bGPDcurve *gpc = gps->editcurve;
+            if (gpc->flag & GP_CURVE_SELECT) {
+              is_selected = true;
+              break;
+            }
+          }
+          else {
+            if (gps->flag & GP_STROKE_SELECT) {
+              is_selected = true;
+              break;
+            }
+          }
+        }
+        /* if not multiedit, exit loop*/
+        if (!is_multiedit) {
+          break;
+        }
+      }
+    }
+  }
+  CTX_DATA_END;
+
+  return is_selected;
+}
+
 /* Poll callback for stroke vertex paint operator. */
 static bool gpencil_vertexpaint_mode_poll(bContext *C)
 {
-  ToolSettings *ts = CTX_data_tool_settings(C);
   Object *ob = CTX_data_active_object(C);
   if ((ob == NULL) || (ob->type != OB_GPENCIL)) {
     return false;
@@ -84,10 +130,6 @@ static bool gpencil_vertexpaint_mode_poll(bContext *C)
 
   bGPdata *gpd = (bGPdata *)ob->data;
   if (GPENCIL_VERTEX_MODE(gpd)) {
-    if (!(GPENCIL_ANY_VERTEX_MASK(ts->gpencil_selectmode_vertex))) {
-      return false

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list