[Bf-blender-cvs] [7becd283cc2] master: GPencil: New Brush predefined mode

Antonio Vazquez noreply at git.blender.org
Wed Jul 29 15:41:07 CEST 2020


Commit: 7becd283cc27c520a38e98a3802e7cb1edf515d9
Author: Antonio Vazquez
Date:   Wed Jul 29 15:34:54 2020 +0200
Branches: master
https://developer.blender.org/rB7becd283cc27c520a38e98a3802e7cb1edf515d9

GPencil: New Brush predefined mode

it's good to have an option to ' pin' a mode to the brush, to use that mode always, independent of the current viewport selected mode.

{F8723224}

Reviewed By: pepeland

Differential Revision: https://developer.blender.org/D8399
81a002

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

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/makesdna/DNA_brush_types.h
M	source/blender/makesrna/intern/rna_brush.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 6e31808d27d..25dc4663500 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1393,6 +1393,9 @@ class VIEW3D_PT_tools_grease_pencil_brush_advanced(View3DPanel, Panel):
 
         col = layout.column(align=True)
         if brush is not None:
+            col.prop(gp_settings, "brush_draw_mode")
+            col.separator()
+
             if brush.gpencil_tool != 'FILL':
                 col.prop(gp_settings, "input_samples")
                 col.separator()
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index f206f5c832a..fb0d94f2307 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -695,7 +695,6 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
   bool is_depth = (bool)(*align_flag & (GP_PROJECT_DEPTH_VIEW | GP_PROJECT_DEPTH_STROKE));
   const bool is_camera = (bool)(ts->gp_sculpt.lock_axis == 0) &&
                          (tgpi->rv3d->persp == RV3D_CAMOB) && (!is_depth);
-  const bool is_vertex_stroke = GPENCIL_USE_VERTEX_COLOR_STROKE(ts, brush);
 
   if (tgpi->type == GP_STROKE_BOX) {
     gps->totpoints = (tgpi->tot_edges * 4 + tgpi->tot_stored_edges);
@@ -1020,12 +1019,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
     pt->time = 0.0f;
     pt->flag = 0;
     pt->uv_fac = tpt->uv_fac;
-    if (is_vertex_stroke) {
-      copy_v4_v4(pt->vert_color, tpt->vert_color);
-    }
-    else {
-      zero_v4(pt->vert_color);
-    }
+    ED_gpencil_point_vertex_color_set(ts, brush, pt, tpt);
 
     if (gps->dvert != NULL) {
       MDeformVert *dvert = &gps->dvert[i];
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index f77bb394567..d412c13aea2 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -2688,7 +2688,11 @@ void ED_gpencil_tag_scene_gpencil(Scene *scene)
 
 void ED_gpencil_fill_vertex_color_set(ToolSettings *ts, Brush *brush, bGPDstroke *gps)
 {
-  if (GPENCIL_USE_VERTEX_COLOR_FILL(ts, brush)) {
+  const bool is_vertex = (GPENCIL_USE_VERTEX_COLOR_FILL(ts, brush) &&
+                          (brush->gpencil_settings->brush_draw_mode != GP_BRUSH_MODE_MATERIAL)) ||
+                         (!GPENCIL_USE_VERTEX_COLOR_FILL(ts, brush) &&
+                          (brush->gpencil_settings->brush_draw_mode == GP_BRUSH_MODE_VERTEXCOLOR));
+  if (is_vertex) {
     copy_v3_v3(gps->vert_color_fill, brush->rgb);
     gps->vert_color_fill[3] = brush->gpencil_settings->vertex_factor;
     srgb_to_linearrgb_v4(gps->vert_color_fill, gps->vert_color_fill);
@@ -2703,7 +2707,12 @@ void ED_gpencil_point_vertex_color_set(ToolSettings *ts,
                                        bGPDspoint *pt,
                                        tGPspoint *tpt)
 {
-  if (GPENCIL_USE_VERTEX_COLOR_STROKE(ts, brush)) {
+  const bool is_vertex = (GPENCIL_USE_VERTEX_COLOR_STROKE(ts, brush) &&
+                          (brush->gpencil_settings->brush_draw_mode != GP_BRUSH_MODE_MATERIAL)) ||
+                         (!GPENCIL_USE_VERTEX_COLOR_STROKE(ts, brush) &&
+                          (brush->gpencil_settings->brush_draw_mode == GP_BRUSH_MODE_VERTEXCOLOR));
+
+  if (is_vertex) {
     if (tpt == NULL) {
       copy_v3_v3(pt->vert_color, brush->rgb);
       pt->vert_color[3] = brush->gpencil_settings->vertex_factor;
@@ -2859,6 +2868,18 @@ void ED_gpencil_sbuffer_vertex_color_set(Depsgraph *depsgraph,
   bGPdata *gpd_eval = (bGPdata *)ob_eval->data;
   MaterialGPencilStyle *gp_style = material->gp_style;
 
+  const bool is_vertex_fill =
+      (GPENCIL_USE_VERTEX_COLOR_FILL(ts, brush) &&
+       (brush->gpencil_settings->brush_draw_mode != GP_BRUSH_MODE_MATERIAL)) ||
+      (!GPENCIL_USE_VERTEX_COLOR_FILL(ts, brush) &&
+       (brush->gpencil_settings->brush_draw_mode == GP_BRUSH_MODE_VERTEXCOLOR));
+
+  const bool is_vertex_stroke =
+      (GPENCIL_USE_VERTEX_COLOR_STROKE(ts, brush) &&
+       (brush->gpencil_settings->brush_draw_mode != GP_BRUSH_MODE_MATERIAL)) ||
+      (!GPENCIL_USE_VERTEX_COLOR_STROKE(ts, brush) &&
+       (brush->gpencil_settings->brush_draw_mode == GP_BRUSH_MODE_VERTEXCOLOR));
+
   int idx = gpd->runtime.sbuffer_used;
   tGPspoint *tpt = (tGPspoint *)gpd->runtime.sbuffer + idx;
 
@@ -2868,14 +2889,14 @@ void ED_gpencil_sbuffer_vertex_color_set(Depsgraph *depsgraph,
   srgb_to_linearrgb_v4(vertex_color, vertex_color);
 
   /* Copy fill vertex color. */
-  if (GPENCIL_USE_VERTEX_COLOR_FILL(ts, brush)) {
+  if (is_vertex_fill) {
     copy_v4_v4(gpd->runtime.vert_color_fill, vertex_color);
   }
   else {
     copy_v4_v4(gpd->runtime.vert_color_fill, gp_style->fill_rgba);
   }
   /* Copy stroke vertex color. */
-  if (GPENCIL_USE_VERTEX_COLOR_STROKE(ts, brush)) {
+  if (is_vertex_stroke) {
     copy_v4_v4(tpt->vert_color, vertex_color);
   }
   else {
diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h
index e2102abb285..ac1a257a4c6 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -118,7 +118,8 @@ typedef struct BrushGpencilSettings {
   int sculpt_mode_flag;
   /** Preset type (used to reset brushes - internal). */
   short preset_type;
-  char _pad3[2];
+  /** Brush preselected mode (Active/Material/Vertexcolor). */
+  short brush_draw_mode;
 
   /** Randomness for Hue. */
   float random_hue;
@@ -258,6 +259,13 @@ typedef enum eGP_BrushEraserMode {
   GP_BRUSH_ERASER_STROKE = 2,
 } eGP_BrushEraserMode;
 
+/* BrushGpencilSettings->brush_draw_mode */
+typedef enum eGP_BrushMode {
+  GP_BRUSH_MODE_ACTIVE = 0,
+  GP_BRUSH_MODE_MATERIAL = 1,
+  GP_BRUSH_MODE_VERTEXCOLOR = 2,
+} eGP_BrushMode;
+
 /* BrushGpencilSettings default brush icons */
 typedef enum eGP_BrushIcons {
   GP_BRUSH_ICON_PENCIL = 1,
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index 71922eb86b5..452564fbe48 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -243,6 +243,12 @@ static EnumPropertyItem rna_enum_gpencil_fill_draw_modes_items[] = {
     {GP_FILL_DMODE_CONTROL, "CONTROL", 0, "Edit Lines", "Use edit lines as fill boundary limits"},
     {0, NULL, 0, NULL, NULL}};
 
+static EnumPropertyItem rna_enum_gpencil_brush_modes_items[] = {
+    {GP_BRUSH_MODE_ACTIVE, "ACTIVE", 0, "Active", "Use current mode"},
+    {GP_BRUSH_MODE_MATERIAL, "MATERIAL", 0, "Material", "Use always material mode"},
+    {GP_BRUSH_MODE_VERTEXCOLOR, "VERTEXCOLOR", 0, "Vertex Color", "Use always Vertex Color mode"},
+    {0, NULL, 0, NULL, NULL}};
+
 static EnumPropertyItem rna_enum_gpencil_brush_paint_icons_items[] = {
     {GP_BRUSH_ICON_PENCIL, "PENCIL", ICON_GPBRUSH_PENCIL, "Pencil", ""},
     {GP_BRUSH_ICON_PEN, "PEN", ICON_GPBRUSH_PEN, "Pen", ""},
@@ -1640,6 +1646,12 @@ static void rna_def_gpencil_options(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "Mode", "Mode to draw boundary limits");
   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
 
+  prop = RNA_def_property(srna, "brush_draw_mode", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_sdna(prop, NULL, "brush_draw_mode");
+  RNA_def_property_enum_items(prop, rna_enum_gpencil_brush_modes_items);
+  RNA_def_property_ui_text(prop, "Mode", "Preselected mode when using this brush");
+  RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+
   prop = RNA_def_property(srna, "trim", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_TRIM_STROKE);
   RNA_def_property_boolean_default(prop, false);



More information about the Bf-blender-cvs mailing list