[Bf-blender-cvs] [6726379] GPencil_Editing_Stage3: GPencil Tablet Support: Eraser now works during Continuous Drawing

Joshua Leung noreply at git.blender.org
Sun Aug 9 14:38:45 CEST 2015


Commit: 6726379ce3bc38050c4b15964379043ee43ebb33
Author: Joshua Leung
Date:   Mon Aug 10 00:19:27 2015 +1200
Branches: GPencil_Editing_Stage3
https://developer.blender.org/rB6726379ce3bc38050c4b15964379043ee43ebb33

GPencil Tablet Support: Eraser now works during Continuous Drawing

When continuous drawing is enabled, the eraser-end of the pen can be used to
erase strokes (as an alternative to RMB).

The keymap system still doesn't let us add such tablet events to the keymap
as actual events though, so we cannot just have a D+Eraser = Erase keymapping.

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

M	source/blender/editors/gpencil/gpencil_ops.c
M	source/blender/editors/gpencil/gpencil_paint.c

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

diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index eafa801..2a72795 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -75,6 +75,7 @@ static void ed_keymap_gpencil_general(wmKeyConfig *keyconf)
 	RNA_boolean_set(kmi->ptr, "wait_for_input", false);
 	
 	/* erase */
+	/* TODO: it would be nice to be able to catch tablet events for this... */
 	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_draw", RIGHTMOUSE, KM_PRESS, 0, DKEY);
 	RNA_enum_set(kmi->ptr, "mode", GP_PAINTMODE_ERASER);
 	RNA_boolean_set(kmi->ptr, "wait_for_input", false);
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index cccb958..bd56def 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -1417,6 +1417,17 @@ static void gpencil_draw_toggle_eraser_cursor(bContext *C, tGPsdata *p, short en
 	}
 }
 
+/* Check if tablet eraser is being used (when processing events) */
+static bool gpencil_is_tablet_eraser_active(const wmEvent *event)
+{
+	if (event->tablet_data) {
+		const wmTabletData *wmtab = event->tablet_data;
+		return (wmtab->Active == EVT_TABLET_ERASER);
+	}
+	
+	return false;
+}
+
 /* ------------------------------- */
 
 
@@ -1622,9 +1633,6 @@ static void gpencil_draw_apply_event(wmOperator *op, const wmEvent *event)
 		
 		tablet = (wmtab->Active != EVT_TABLET_NONE);
 		p->pressure = wmtab->Pressure;
-		
-		/* if (wmtab->Active == EVT_TABLET_ERASER) */
-		/* TODO... this should get caught by the keymaps which call drawing in the first place */
 	}
 	else
 		p->pressure = 1.0f;
@@ -1819,7 +1827,6 @@ static tGPsdata *gpencil_stroke_begin(bContext *C, wmOperator *op)
 	/* we may need to set up paint env again if we're resuming */
 	/* XXX: watch it with the paintmode! in future,
 	 *      it'd be nice to allow changing paint-mode when in sketching-sessions */
-	/* XXX: with tablet events, we may event want to check for eraser here, for nicer tablet support */
 	
 	if (gp_session_initdata(C, p))
 		gp_paint_initstroke(p, p->paintmode);
@@ -2008,14 +2015,14 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
 				/* Switch paintmode (temporarily if need be) based on which button was used
 				 * NOTE: This is to make it more convenient to erase strokes when using drawing sessions
 				 */
-				if (event->type == LEFTMOUSE) {
-					/* restore drawmode to default */
-					p->paintmode = RNA_enum_get(op->ptr, "mode");
-				}
-				else if (event->type == RIGHTMOUSE) {
+				if ((event->type == RIGHTMOUSE) || gpencil_is_tablet_eraser_active(event)) {
 					/* turn on eraser */
 					p->paintmode = GP_PAINTMODE_ERASER;
 				}
+				else if (event->type == LEFTMOUSE) {
+					/* restore drawmode to default */
+					p->paintmode = RNA_enum_get(op->ptr, "mode");
+				}
 				
 				gpencil_draw_toggle_eraser_cursor(C, p, p->paintmode == GP_PAINTMODE_ERASER);




More information about the Bf-blender-cvs mailing list