[Bf-blender-cvs] [b26307991bd] greasepencil-object: WIP: Use a brush for filling

Antonio Vazquez noreply at git.blender.org
Wed Jan 3 17:46:51 CET 2018


Commit: b26307991bd0adab1b7561a3fb1973f36ca7747e
Author: Antonio Vazquez
Date:   Wed Jan 3 16:30:58 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rBb26307991bd0adab1b7561a3fb1973f36ca7747e

WIP: Use a brush for filling

Still need more work, but this commit adds the basic structure.

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

M	release/scripts/modules/bpy_extras/keyconfig_utils.py
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/editors/gpencil/gpencil_ops.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/screen/area.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/release/scripts/modules/bpy_extras/keyconfig_utils.py b/release/scripts/modules/bpy_extras/keyconfig_utils.py
index aae9726c3d4..dce91923e17 100644
--- a/release/scripts/modules/bpy_extras/keyconfig_utils.py
+++ b/release/scripts/modules/bpy_extras/keyconfig_utils.py
@@ -122,6 +122,8 @@ KM_HIERARCHY = [
 
     ('Grease Pencil', 'EMPTY', 'WINDOW', [  # grease pencil stuff (per region)
         ('Grease Pencil Stroke Edit Mode', 'EMPTY', 'WINDOW', []),
+        ('Grease Pencil Stroke Paint (Draw brush)', 'EMPTY', 'WINDOW', []),
+        ('Grease Pencil Stroke Paint (Fill)', 'EMPTY', 'WINDOW', []),
         ('Grease Pencil Stroke Paint Mode', 'EMPTY', 'WINDOW', []),
         ('Grease Pencil Stroke Sculpt Mode', 'EMPTY', 'WINDOW', []),
         ('Grease Pencil Stroke Weight Mode', 'EMPTY', 'WINDOW', []),
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 0c377bf6981..e4376cd5472 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -746,6 +746,15 @@ void BKE_gpencil_brush_init_presets(ToolSettings *ts)
 	brush->sublevel = 3;
 	brush->draw_random_sub = 0;
 	copy_v3_v3(brush->curcolor, curcolor);
+
+	/* Fill brush */
+	brush = BKE_gpencil_brush_addnew(ts, "Fill", false);
+	brush->thickness = 1.0f;
+	brush->flag |= GP_BRUSH_FILL_ONLY;
+	brush->draw_sensitivity = 1.0f;
+
+	brush->draw_strength = 1.0f;
+	copy_v3_v3(brush->curcolor, curcolor);
 }
 
 /* add a new gp-brush and make it the active */
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index c51a47c7ef6..82abc72700a 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -1361,6 +1361,10 @@ static int gp_brush_remove_exec(bContext *C, wmOperator *op)
 		return OPERATOR_CANCELLED;
 	}
 
+	if (brush->flag & GP_BRUSH_FILL_ONLY) {
+		BKE_report(op->reports, RPT_ERROR, "The fill brush cannot be deleted");
+		return OPERATOR_CANCELLED;
+	}
 
 	/* make the brush before this the new active brush
 	 * - use the one after if this is the first
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index 9d676baa75a..fa95e6e627c 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -35,6 +35,7 @@
 #include "BLI_sys_types.h"
 
 #include "BKE_context.h"
+#include "BKE_gpencil.h"
 
 #include "DNA_gpencil_types.h"
 #include "DNA_object_types.h"
@@ -76,7 +77,6 @@ static void ed_keymap_gpencil_general(wmKeyConfig *keyconf)
 	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", RIGHTMOUSE, KM_PRESS, KM_CTRL, DKEY);
 	RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW_POLY);
 	RNA_boolean_set(kmi->ptr, "wait_for_input", false);
-	
 	/* Viewport Tools ------------------------------- */
 	
 	/* Enter EditMode */
@@ -112,6 +112,26 @@ static int gp_stroke_paintmode_poll(bContext *C)
 	return (gpd && (gpd->flag & GP_DATA_STROKE_PAINTMODE));
 }
 
+/* Poll callback for stroke painting (draw brush) */
+static int gp_stroke_paintmode_draw_poll(bContext *C)
+{
+	/* TODO: limit this to mode, but review 2D editors */
+	bGPdata *gpd = CTX_data_gpencil_data(C);
+	ToolSettings *ts = CTX_data_tool_settings(C);
+	bGPDbrush *brush = BKE_gpencil_brush_getactive(ts);
+	return (gpd && (gpd->flag & GP_DATA_STROKE_PAINTMODE) && (brush) && ((brush->flag & GP_BRUSH_FILL_ONLY) == 0));
+}
+
+/* Poll callback for stroke painting (fill) */
+static int gp_stroke_paintmode_fill_poll(bContext *C)
+{
+	/* TODO: limit this to mode, but review 2D editors */
+	bGPdata *gpd = CTX_data_gpencil_data(C);
+	ToolSettings *ts = CTX_data_tool_settings(C);
+	bGPDbrush *brush = BKE_gpencil_brush_getactive(ts);
+	return (gpd && (gpd->flag & GP_DATA_STROKE_PAINTMODE) && (brush) && (brush->flag & GP_BRUSH_FILL_ONLY));
+}
+
 /* Poll callback for stroke sculpting mode */
 static int gp_stroke_sculptmode_poll(bContext *C)
 {
@@ -401,6 +421,41 @@ static void ed_keymap_gpencil_editing(wmKeyConfig *keyconf)
 	WM_keymap_add_menu(keymap, "GPENCIL_MT_gpencil_vertex_group", GKEY, KM_PRESS, KM_CTRL, 0);
 }
 
+/* keys for draw with a drawing brush (no fill) */
+static void ed_keymap_gpencil_painting_draw(wmKeyConfig *keyconf)
+{
+	wmKeyMap *keymap = WM_keymap_find(keyconf, "Grease Pencil Stroke Paint (Draw brush)", 0, 0);
+	wmKeyMapItem *kmi;
+
+	/* set poll callback */
+	keymap->poll = gp_stroke_paintmode_draw_poll;
+
+	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, 0, 0);
+	RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW);
+	RNA_boolean_set(kmi->ptr, "wait_for_input", false);
+
+	/* draw - straight lines */
+	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
+	RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW_STRAIGHT);
+	RNA_boolean_set(kmi->ptr, "wait_for_input", false);
+
+	/* draw - poly lines */
+	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
+	RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW_POLY);
+	RNA_boolean_set(kmi->ptr, "wait_for_input", false);
+}
+
+/* keys for draw with a fill brush */
+static void ed_keymap_gpencil_painting_fill(wmKeyConfig *keyconf)
+{
+	wmKeyMap *keymap = WM_keymap_find(keyconf, "Grease Pencil Stroke Paint (Fill)", 0, 0);
+
+	/* set poll callback */
+	keymap->poll = gp_stroke_paintmode_fill_poll;
+
+	WM_keymap_add_item(keymap, "GPENCIL_OT_fill", LEFTMOUSE, KM_PRESS, 0, 0);
+}
+
 /* Stroke Painting Keymap - Only when paintmode is enabled */
 static void ed_keymap_gpencil_painting(wmKeyConfig *keyconf)
 {
@@ -409,7 +464,7 @@ static void ed_keymap_gpencil_painting(wmKeyConfig *keyconf)
 
 	/* set poll callback - so that this keymap only gets enabled when stroke paintmode is enabled */
 	keymap->poll = gp_stroke_paintmode_poll;
-
+#if 0
 	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, 0, 0);
 	RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW);
 	RNA_boolean_set(kmi->ptr, "wait_for_input", false);
@@ -423,7 +478,7 @@ static void ed_keymap_gpencil_painting(wmKeyConfig *keyconf)
 	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
 	RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_DRAW_POLY);
 	RNA_boolean_set(kmi->ptr, "wait_for_input", false);
-
+#endif
 	/* erase */
 	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, KM_ALT, 0);
 	RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_ERASER);
@@ -493,9 +548,6 @@ static void ed_keymap_gpencil_painting(wmKeyConfig *keyconf)
 	/* menu draw specials (add two keys to make more easy for user) */
 	WM_keymap_add_menu(keymap, "GPENCIL_MT_gpencil_draw_specials", WKEY, KM_PRESS, 0, 0);
 	WM_keymap_add_menu(keymap, "GPENCIL_MT_gpencil_draw_specials", XKEY, KM_PRESS, 0, 0);
-
-	/* fill */
-	WM_keymap_add_item(keymap, "GPENCIL_OT_fill", PKEY, KM_PRESS, 0, 0);
 }
 
 /* Stroke Sculpting Keymap - Only when sculptmode is enabled */
@@ -606,6 +658,8 @@ void ED_keymap_gpencil(wmKeyConfig *keyconf)
 	ed_keymap_gpencil_general(keyconf);
 	ed_keymap_gpencil_editing(keyconf);
 	ed_keymap_gpencil_painting(keyconf);
+	ed_keymap_gpencil_painting_draw(keyconf);
+	ed_keymap_gpencil_painting_fill(keyconf);
 	ed_keymap_gpencil_sculpting(keyconf);
 	ed_keymap_gpencil_weightpainting(keyconf);
 }
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index ef9e89b7315..64190a33d73 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -949,7 +949,12 @@ const EnumPropertyItem *ED_gpencil_brushes_enum_itemf(
 		item_tmp.value = i;
 
 		if (brush->flag & GP_BRUSH_ACTIVE)
-			item_tmp.icon = ICON_BRUSH_DATA;
+			if (brush->flag & GP_BRUSH_FILL_ONLY) {
+				item_tmp.icon = ICON_GROUP_VCOL;
+			}
+			else {
+				item_tmp.icon = ICON_BRUSH_DATA;
+			}
 		else
 			item_tmp.icon = ICON_NONE;
 
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index a8abbf8c6fa..1555791861e 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -1531,6 +1531,12 @@ static void ed_default_handlers(wmWindowManager *wm, ScrArea *sa, ListBase *hand
 		wmKeyMap *keymap_paint = WM_keymap_find(wm->defaultconf, "Grease Pencil Stroke Paint Mode", 0, 0);
 		WM_event_add_keymap_handler(handlers, keymap_paint);
 
+		wmKeyMap *keymap_paint_draw = WM_keymap_find(wm->defaultconf, "Grease Pencil Stroke Paint (Draw brush)", 0, 0);
+		WM_event_add_keymap_handler(handlers, keymap_paint_draw);
+
+		wmKeyMap *keymap_paint_fill = WM_keymap_find(wm->defaultconf, "Grease Pencil Stroke Paint (Fill)", 0, 0);
+		WM_event_add_keymap_handler(handlers, keymap_paint_fill);
+
 		wmKeyMap *keymap_sculpt = WM_keymap_find(wm->defaultconf, "Grease Pencil Stroke Sculpt Mode", 0, 0);
 		WM_event_add_keymap_handler(handlers, keymap_sculpt);
 	}
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 45362e8861e..57250ec716d 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -141,7 +141,9 @@ typedef enum eGPDbrush_Flag {
 	/* brush use random for strength */
 	GP_BRUSH_USE_RANDOM_STRENGTH = (1 << 5),
 	/* enable screen cursor */
-	GP_BRUSH_ENABLE_CURSOR = (1 << 6)
+	GP_BRUSH_ENABLE_CURSOR = (1 << 6),
+	/* enable screen cursor */
+	GP_BRUSH_FILL_ONLY = (1 << 7)
 } eGPDbrush_Flag;
 
 /* ***************************************** */
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 1fd0ebb007b..a3427e4443c 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -644,7 +644,12 @@ static const EnumPropertyItem *rna_GPencilBrush_enum_itemf(
 		item_tmp.identifier = brush->info;
 		item_tmp.name = brush->info;
 		item_tmp.value = i;
-		item_tmp.icon = ICON_BRUSH_DATA;
+		if (brush->flag & GP_BRUSH_FILL_ONLY) {
+			item_tmp.icon = ICON_GROUP_VCOL;
+		}
+		else {
+			item_tmp.icon = ICON_BRUSH_DATA;
+		}
 
 		RNA_enum_item_add(&item, &totitem, &item_tmp);
 	}
@@ -2335,6 +2340,11 @@ stat

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list