[Bf-blender-cvs] [32c4bc3417a] greasepencil-object: WIP: New Eraser brush

Antonio Vazquez noreply at git.blender.org
Fri Mar 2 20:16:03 CET 2018


Commit: 32c4bc3417a247609ef8875c03c0b7153e224878
Author: Antonio Vazquez
Date:   Fri Mar 2 19:30:39 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rB32c4bc3417a247609ef8875c03c0b7153e224878

WIP: New Eraser brush

This new brush is equal to the old eraser, but it makes the interface more consistent.

Still need more work to adapt all eraser features, limit other actions not related to eraser and brush switching.

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

M	release/scripts/modules/bpy_extras/keyconfig_utils.py
M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/editors/gpencil/gpencil_ops.c
M	source/blender/editors/interface/interface_icons.c
M	source/blender/editors/screen/area.c
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 dce91923e17..24cc3ead595 100644
--- a/release/scripts/modules/bpy_extras/keyconfig_utils.py
+++ b/release/scripts/modules/bpy_extras/keyconfig_utils.py
@@ -124,6 +124,7 @@ KM_HIERARCHY = [
         ('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 (Erase)', '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/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index 0149a1922fe..aa18af2fc4f 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -304,29 +304,6 @@ class GreasePencilStrokeSculptPanel:
             layout.prop(brush, "affect_pressure")
 
 
-class GreasePencilEraserPanel:
-    bl_label = "Eraser"
-    bl_category = "Tools"
-    bl_region_type = 'TOOLS'
-    bl_options = {'DEFAULT_CLOSED'}
-
-    @classmethod
-    def poll(cls, context):
-        if context.gpencil_data is None:
-            return False
-        workspace = context.workspace
-        return context.active_object and workspace.object_mode == 'GPENCIL_PAINT'
-
-    @staticmethod
-    def draw(self, context):
-        layout = self.layout
-        layout.operator("gpencil.draw", icon='FORCE_CURVE', text="Erase").mode = 'ERASER'
-        
-        col = layout.column(align=True)
-        col.prop(context.user_preferences.edit, "grease_pencil_eraser_radius", text="Radius")
-        # TODO: Hard/Soft mode, sensitivity factors, etc.
-
-
 ###############################
 
 class GPENCIL_MT_pie_tool_palette(Menu):
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 92eb3dab30b..840f82ad3be 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -21,8 +21,7 @@ import bpy
 from bpy.types import Menu, Panel, UIList
 from .properties_grease_pencil_common import (
         GreasePencilStrokeEditPanel,
-        GreasePencilStrokeSculptPanel,
-        GreasePencilEraserPanel
+        GreasePencilStrokeSculptPanel
         )
 from .properties_paint_common import (
         UnifiedPaintPanel,
@@ -2122,8 +2121,14 @@ class VIEW3D_PT_tools_grease_pencil_brush(Panel):
                 sub.enabled = brush.fill_hide
                 sub.prop(brush, "fill_threshold", text="Threshold")
 
-            layout.separator()
-            layout.prop(context.tool_settings, "use_gpencil_draw_onback", text="Draw on Back")
+            if brush.type == 'ERASE':
+                col = layout.column(align=True)
+                col.prop(context.user_preferences.edit, "grease_pencil_eraser_radius", text="Radius")
+                # TODO: Hard/Soft mode, sensitivity factors, etc.
+
+            if brush.type != 'ERASE':
+                layout.separator()
+                layout.prop(context.tool_settings, "use_gpencil_draw_onback", text="Draw on Back")
 
 
 # Grease Pencil drawing brushes options
@@ -2502,11 +2507,6 @@ class VIEW3D_PT_tools_grease_pencil_appearance(Panel):
             row.prop(brush, "cursor_color_sub", text="Subtract")
 
 
-# Grease Pencil drawing brushes options
-class VIEW3D_PT_tools_grease_pencil_eraser(GreasePencilEraserPanel, Panel):
-    bl_space_type = 'VIEW_3D'
-
-
 # Note: moved here so that it's always in last position in 'Tools' panels!
 class VIEW3D_PT_tools_history(View3DPanel, Panel):
     bl_category = "Tools"
@@ -2589,7 +2589,6 @@ classes = (
     VIEW3D_PT_sculpt_symmetry,
     VIEW3D_PT_tools_brush_appearance,
     VIEW3D_PT_tools_grease_pencil_appearance,
-    VIEW3D_PT_tools_grease_pencil_eraser,
     VIEW3D_PT_tools_weightpaint,
     VIEW3D_PT_tools_weightpaint_symmetry,
     VIEW3D_PT_tools_weightpaint_options,
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 8b09c6a0a5d..b0f546debff 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -777,6 +777,29 @@ void BKE_gpencil_brush_init_presets(ToolSettings *ts)
 
 	brush->draw_strength = 1.0f;
 	copy_v3_v3(brush->curcolor, curcolor);
+
+	/* Eraser brush */
+	brush = BKE_gpencil_brush_addnew(ts, "Erase", false);
+	brush->thickness = 1.0f;
+	brush->flag |= GP_BRUSH_ENABLE_CURSOR;
+	brush->draw_sensitivity = 1.0f;
+	brush->fill_leak = 3;
+	brush->fill_threshold = 0.1f;
+	brush->fill_simplylvl = 1;
+	brush->icon = GPBRUSH_ERASE;
+	brush->type = GP_BRUSH_TYPE_ERASE;
+
+	brush->draw_smoothfac = 0.5f;
+	brush->draw_smoothlvl = 1;
+	brush->thick_smoothfac = 1.0f;
+	brush->thick_smoothlvl = 3;
+	brush->sublevel = 1;
+
+	brush->lazy_radius = LAZY_RADIUS;
+	brush->lazy_factor = LAZY_FACTOR;
+
+	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_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index b281d9bc20a..be8c0b77a08 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -122,6 +122,16 @@ static int gp_stroke_paintmode_draw_poll(bContext *C)
 	return (gpd && (gpd->flag & GP_DATA_STROKE_PAINTMODE) && (brush) && (brush->type == GP_BRUSH_TYPE_DRAW));
 }
 
+/* Poll callback for stroke painting (erase brush) */
+static int gp_stroke_paintmode_erase_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->type == GP_BRUSH_TYPE_ERASE));
+}
+
 /* Poll callback for stroke painting (fill) */
 static int gp_stroke_paintmode_fill_poll(bContext *C)
 {
@@ -482,6 +492,33 @@ static void ed_keymap_gpencil_painting_draw(wmKeyConfig *keyconf)
 	RNA_boolean_set(kmi->ptr, "deselect", false);
 }
 
+/* keys for draw with a eraser brush (erase) */
+static void ed_keymap_gpencil_painting_erase(wmKeyConfig *keyconf)
+{
+	wmKeyMap *keymap = WM_keymap_find(keyconf, "Grease Pencil Stroke Paint (Erase)", 0, 0);
+	wmKeyMapItem *kmi;
+
+	/* set poll callback */
+	keymap->poll = gp_stroke_paintmode_erase_poll;
+
+	/* erase */
+	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", LEFTMOUSE, KM_PRESS, 0, 0);
+	RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_ERASER);
+	RNA_boolean_set(kmi->ptr, "wait_for_input", false);
+
+	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", TABLET_ERASER, KM_PRESS, 0, 0);
+	RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_ERASER);
+	RNA_boolean_set(kmi->ptr, "wait_for_input", false);
+
+	/* Selection (used by eraser) */
+	/* border select */
+	WM_keymap_add_item(keymap, "GPENCIL_OT_select_border", BKEY, KM_PRESS, 0, 0);
+
+	/* lasso select */
+	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL | KM_ALT, 0);
+	RNA_boolean_set(kmi->ptr, "deselect", false);
+}
+
 /* keys for draw with a fill brush */
 static void ed_keymap_gpencil_painting_fill(wmKeyConfig *keyconf)
 {
@@ -684,6 +721,7 @@ void ED_keymap_gpencil(wmKeyConfig *keyconf)
 	ed_keymap_gpencil_editing(keyconf);
 	ed_keymap_gpencil_painting(keyconf);
 	ed_keymap_gpencil_painting_draw(keyconf);
+	ed_keymap_gpencil_painting_erase(keyconf);
 	ed_keymap_gpencil_painting_fill(keyconf);
 	ed_keymap_gpencil_sculpting(keyconf);
 	ed_keymap_gpencil_weightpainting(keyconf);
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 8dd89119b46..a6175a66535 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -440,7 +440,7 @@ static void init_brush_icons(void)
 	INIT_BRUSH_ICON(ICON_GPBRUSH_MARKER, gp_brush_marker);
 	INIT_BRUSH_ICON(ICON_GPBRUSH_CUSTOM, gp_brush_custom);
 	INIT_BRUSH_ICON(ICON_GPBRUSH_FILL, gp_brush_fill);
-	INIT_BRUSH_ICON(ICON_GPBRUSH_ERASE, gp_brush_fill);
+	INIT_BRUSH_ICON(ICON_GPBRUSH_ERASE, gp_brush_erase);
 
 #undef INIT_BRUSH_ICON
 }
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index ea29306b730..5bc7ad86f53 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -1498,6 +1498,9 @@ static void ed_default_handlers(wmWindowManager *wm, ScrArea *sa, ListBase *hand
 		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_erase = WM_keymap_find(wm->defaultconf, "Grease Pencil Stroke Paint (Erase)", 0, 0);
+		WM_event_add_keymap_handler(handlers, keymap_paint_erase);
+
 		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);
 
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index e4ddd4ae69b..40bebaaac30 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -454,7 +454,7 @@ static EnumPropertyItem rna_enum_gpencil_fill_draw_modes_items[] = {
 static EnumPropertyItem rna_enum_gpencil_brush_types_items[] = {
 	{ GP_BRUSH_TYPE_DRAW, "DRAW", 0, "Draw", "The brush is of type used for drawing strokes" },
 	{ GP_BRUSH_TYPE_FILL, "FILL", 0, "Fill", "The brush is of type used for filling areas" },
-	//{ GP_BRUSH_TYPE_ERASE, "ERASE", 0, "Erase", "The brush is used for erasing" },
+	{ GP_BRUSH_TYPE_ERASE, "ERASE", 0, "Erase", "The brush is used for erasing strokes" },
 	{ 0, NULL, 0, NULL, NULL }
 };
 
@@ -7

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list