[Bf-blender-cvs] [c78fbccee80] greasepencil-object: GP: Set Cap mode as Enums

Antonioya noreply at git.blender.org
Sun Jan 6 16:41:13 CET 2019


Commit: c78fbccee804dc37e8db80eeb80875aee0972734
Author: Antonioya
Date:   Sun Jan 6 16:41:02 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rBc78fbccee804dc37e8db80eeb80875aee0972734

GP: Set Cap mode as Enums

Now the Cap mode is an enum ready for future modes.

Add the cap mode to material is not logic because the stroke start and end depends on the drawing direction. Maybe in the future we could add to material, but will need more work at stroke level.

The Toggle operator keeps equal in a circular switch mode. We can improve it also in the future.

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

M	source/blender/draw/engines/gpencil/gpencil_draw_utils.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index 73652ea02e6..52320f426c6 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -387,8 +387,8 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(
 		DRW_shgroup_uniform_int(grp, "color_type", &stl->shgroups[id].color_type, 1);
 		DRW_shgroup_uniform_float(grp, "pixfactor", &gpd->pixfactor, 1);
 
-		stl->shgroups[id].caps_mode[0] = ((gps) && (gps->flag & GP_STROKE_FLATCAPS_START)) ? 1 : 0;
-		stl->shgroups[id].caps_mode[1] = ((gps) && (gps->flag & GP_STROKE_FLATCAPS_END)) ? 1 : 0;
+		stl->shgroups[id].caps_mode[0] = gps->caps[0];
+		stl->shgroups[id].caps_mode[1] = gps->caps[1];
 		DRW_shgroup_uniform_int(grp, "caps_mode", &stl->shgroups[id].caps_mode[0], 2);
 	}
 	else {
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 1fcf6a1248d..4ca85ee6e77 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -2551,24 +2551,25 @@ static int gp_stroke_caps_set_exec(bContext *C, wmOperator *op)
 			if (!gp_style || (gp_style->flag & GP_STYLE_COLOR_HIDE) || (gp_style->flag & GP_STYLE_COLOR_LOCKED))
 				continue;
 
-			switch (type) {
-				case GP_STROKE_CAPS_TOGGLE_BOTH:
-					gps->flag ^= GP_STROKE_FLATCAPS_START;
-					gps->flag ^= GP_STROKE_FLATCAPS_END;
-					break;
-				case GP_STROKE_CAPS_TOGGLE_START:
-					gps->flag ^= GP_STROKE_FLATCAPS_START;
-					break;
-				case GP_STROKE_CAPS_TOGGLE_END:
-					gps->flag ^= GP_STROKE_FLATCAPS_END;
-					break;
-				case GP_STROKE_CAPS_TOGGLE_DEFAULT:
-					gps->flag &= ~GP_STROKE_FLATCAPS_START;
-					gps->flag &= ~GP_STROKE_FLATCAPS_END;
-					break;
-				default:
-					BLI_assert(0);
-					break;
+			if ((type == GP_STROKE_CAPS_TOGGLE_BOTH) ||
+				(type == GP_STROKE_CAPS_TOGGLE_START))
+			{
+				++gps->caps[0];
+				if (gps->caps[0] >= GP_STROKE_CAP_MAX) {
+					gps->caps[0] = GP_STROKE_CAP_ROUND;
+				}
+			}
+			if ((type == GP_STROKE_CAPS_TOGGLE_BOTH) ||
+				(type == GP_STROKE_CAPS_TOGGLE_END))
+			{
+				++gps->caps[1];
+				if (gps->caps[1] >= GP_STROKE_CAP_MAX) {
+					gps->caps[1] = GP_STROKE_CAP_ROUND;
+				}
+			}
+			if (type == GP_STROKE_CAPS_TOGGLE_DEFAULT) {
+				gps->caps[0] = GP_STROKE_CAP_ROUND;
+				gps->caps[1] = GP_STROKE_CAP_ROUND;
 			}
 		}
 	}
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 1ef0d281104..5a544691f88 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -178,7 +178,7 @@ typedef struct bGPDstroke {
 	char colorname[128] DNA_DEPRECATED;    /* color name */
 
 	int mat_nr;             /* material index */
-	char _pad1[4];
+	short caps[2];          /* caps mode for each extrem */
 
 	struct MDeformVert *dvert;    /* vertex weight data */
 
@@ -202,13 +202,19 @@ typedef enum eGPDstroke_Flag {
 	GP_STROKE_CYCLIC = (1 << 7),
 	/* Flag used to indicate that stroke is used for fill close and must use fill color for stroke and no fill area */
 	GP_STROKE_NOFILL = (1 << 8),
-	/* Flag used to indicate if the stroke has flat caps (by default rounded) */
-	GP_STROKE_FLATCAPS_START = (1 << 9),
-	GP_STROKE_FLATCAPS_END   = (1 << 10),
 	/* only for use with stroke-buffer (while drawing eraser) */
 	GP_STROKE_ERASER		= (1 << 15)
 } eGPDstroke_Flag;
 
+/* bGPDstroke->caps */
+typedef enum eGPDstroke_Caps {
+	/* type of extreme */
+	GP_STROKE_CAP_ROUND = 0,
+	GP_STROKE_CAP_FLAT  = 1,
+
+	GP_STROKE_CAP_MAX
+} GPDstroke_Caps;
+
 /* ***************************************** */
 /* GP Frame */
 
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 89d8e54e740..da322307454 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -87,6 +87,12 @@ static const EnumPropertyItem rna_enum_layer_blend_modes_items[] = {
 	{eGplBlendMode_Divide, "DIVIDE", 0, "Divide", "" },
 	{0, NULL, 0, NULL, NULL }
 };
+
+static EnumPropertyItem rna_enum_gpencil_caps_modes_items[] = {
+	{GP_STROKE_CAP_ROUND, "ROUND", 0, "Rounded", ""},
+	{GP_STROKE_CAP_FLAT, "FLAT", 0, "Flat", ""},
+	{0, NULL, 0, NULL, NULL}
+};
 #endif
 
 #ifdef RNA_RUNTIME
@@ -968,16 +974,18 @@ static void rna_def_gpencil_stroke(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Cyclic", "Enable cyclic drawing, closing the stroke");
 	RNA_def_property_update(prop, 0, "rna_GPencil_update");
 
-	/* Enable Flat Caps mode */
-	prop = RNA_def_property(srna, "is_start_flat_caps", PROP_BOOLEAN, PROP_NONE);
-	RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_STROKE_FLATCAPS_START);
-	RNA_def_property_ui_text(prop, "Flat", "Stroke caps are flat (rounded by default)");
-	RNA_def_property_update(prop, 0, "rna_GPencil_update");
+	/* Caps mode */
+	prop = RNA_def_property(srna, "start_cap_mode", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "caps[0]");
+	RNA_def_property_enum_items(prop, rna_enum_gpencil_caps_modes_items);
+	RNA_def_property_ui_text(prop, "Start Cap", "Stroke start extreme cap style");
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
 
-	prop = RNA_def_property(srna, "is_end_flat_caps", PROP_BOOLEAN, PROP_NONE);
-	RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_STROKE_FLATCAPS_END);
-	RNA_def_property_ui_text(prop, "Flat", "Stroke caps are flat (rounded by default)");
-	RNA_def_property_update(prop, 0, "rna_GPencil_update");
+	prop = RNA_def_property(srna, "end_cap_mode", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "caps[1]");
+	RNA_def_property_enum_items(prop, rna_enum_gpencil_caps_modes_items);
+	RNA_def_property_ui_text(prop, "End Cap", "Stroke end extreme cap style");
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
 
 	/* No fill: The stroke never must fill area and must use fill color as stroke color (this is a special flag for fill brush) */
 	prop = RNA_def_property(srna, "is_nofill_stroke", PROP_BOOLEAN, PROP_NONE);



More information about the Bf-blender-cvs mailing list