[Bf-blender-cvs] [8746575d093] master: GP: Add Shift+F to define strength for primitives

Antonioya noreply at git.blender.org
Sun Dec 23 16:45:47 CET 2018


Commit: 8746575d09394b7aec1e322fbd5af70b45399b58
Author: Antonioya
Date:   Sun Dec 23 16:45:36 2018 +0100
Branches: master
https://developer.blender.org/rB8746575d09394b7aec1e322fbd5af70b45399b58

GP: Add Shift+F to define strength for primitives

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

M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_primitive.c

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

diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 3fb2464aaf3..71d293d5244 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -158,6 +158,7 @@ typedef struct tGPDprimitive {
 	int orign_type;                   /* original type of primitive */
 	bool curve;                       /* type of primitive is a curve */
 	int brush_size;                   /* brush size */
+	float brush_strength;             /* brush strength */
 	short flip;                       /* flip option */
 	tGPspoint *points;                /* array of data-points for stroke */
 	int point_count;                  /* number of edges allocated */
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index f015c01a8e6..310f47f25cb 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -97,6 +97,7 @@
 #define IN_CURVE_EDIT 2
 #define IN_MOVE 3
 #define IN_BRUSH_SIZE 4
+#define IN_BRUSH_STRENGTH 5
 
 #define SELECT_NONE 0
 #define SELECT_START 1
@@ -1329,10 +1330,34 @@ static void gpencil_primitive_edit_event_handling(bContext *C, wmOperator *op, w
 	}
 }
 
+/* brush strength */
+static void gpencil_primitive_strength(tGPDprimitive *tgpi, bool reset)
+{
+	Brush *brush = tgpi->brush;
+	if (brush) {
+		if (reset) {
+			brush->gpencil_settings->draw_strength = tgpi->brush_strength;
+			tgpi->brush_strength = 0.0f;
+		}
+		else {
+			if (tgpi->brush_strength == 0.0f) {
+				tgpi->brush_strength = brush->gpencil_settings->draw_strength;
+			}
+			float move[2];
+			sub_v2_v2v2(move, tgpi->mval, tgpi->mvalo);
+			float adjust = (move[1] > 0.0f) ? 0.01f : -0.01f;
+			brush->gpencil_settings->draw_strength += adjust * fabsf(len_manhattan_v2(move));
+		}
+
+		/* limit low limit because below 0.2f the stroke is invisible */
+		CLAMP(brush->gpencil_settings->draw_strength, 0.2f, 1.0f);
+	}
+}
+
 /* brush size */
 static void gpencil_primitive_size(tGPDprimitive *tgpi, bool reset)
 {
-	Brush * brush = tgpi->brush;
+	Brush *brush = tgpi->brush;
 	if (brush) {
 		if (reset) {
 			brush->size = tgpi->brush_size;
@@ -1415,23 +1440,46 @@ static int gpencil_primitive_modal(bContext *C, wmOperator *op, const wmEvent *e
 	}
 	else if (tgpi->flag == IN_BRUSH_SIZE) {
 		switch (event->type) {
-		case MOUSEMOVE:
-			gpencil_primitive_size(tgpi, false);
-			gpencil_primitive_update(C, op, tgpi);
-			break;
-		case ESCKEY:
-		case MIDDLEMOUSE:
-		case LEFTMOUSE:
-			tgpi->brush_size = 0;
-			tgpi->flag = IN_CURVE_EDIT;
-			break;
-		case RIGHTMOUSE:
-			if (event->val == KM_RELEASE) {
+			case MOUSEMOVE:
+				gpencil_primitive_size(tgpi, false);
+				gpencil_primitive_update(C, op, tgpi);
+				break;
+			case ESCKEY:
+			case MIDDLEMOUSE:
+			case LEFTMOUSE:
+				tgpi->brush_size = 0;
 				tgpi->flag = IN_CURVE_EDIT;
-				gpencil_primitive_size(tgpi, true);
+				break;
+			case RIGHTMOUSE:
+				if (event->val == KM_RELEASE) {
+					tgpi->flag = IN_CURVE_EDIT;
+					gpencil_primitive_size(tgpi, true);
+					gpencil_primitive_update(C, op, tgpi);
+				}
+				break;
+		}
+		copy_v2_v2(tgpi->mvalo, tgpi->mval);
+		return OPERATOR_RUNNING_MODAL;
+	}
+	else if (tgpi->flag == IN_BRUSH_STRENGTH) {
+		switch (event->type) {
+			case MOUSEMOVE:
+				gpencil_primitive_strength(tgpi, false);
 				gpencil_primitive_update(C, op, tgpi);
-			}
-			break;
+				break;
+			case ESCKEY:
+			case MIDDLEMOUSE:
+			case LEFTMOUSE:
+				tgpi->brush_strength = 0.0f;
+				tgpi->flag = IN_CURVE_EDIT;
+				break;
+			case RIGHTMOUSE:
+				if (event->val == KM_RELEASE) {
+					tgpi->flag = IN_CURVE_EDIT;
+					gpencil_primitive_strength(tgpi, true);
+					gpencil_primitive_update(C, op, tgpi);
+				}
+				break;
 		}
 		copy_v2_v2(tgpi->mvalo, tgpi->mval);
 		return OPERATOR_RUNNING_MODAL;
@@ -1528,10 +1576,15 @@ static int gpencil_primitive_modal(bContext *C, wmOperator *op, const wmEvent *e
 			}
 			break;
 		}
-		case FKEY: /* brush thickness */
+		case FKEY: /* brush thickness/ brush strength */
 		{
 			if ((event->val == KM_PRESS)) {
-				tgpi->flag = IN_BRUSH_SIZE;
+				if (event->shift) {
+					tgpi->flag = IN_BRUSH_STRENGTH;
+				}
+				else {
+					tgpi->flag = IN_BRUSH_SIZE;
+				}
 				WM_cursor_modal_set(win, BC_NS_SCROLLCURSOR);
 			}
 			break;



More information about the Bf-blender-cvs mailing list