[Bf-blender-cvs] [763bc0c] GPencil_Editing_Stage3: GP Sculpt: Experimenting to make sculpt operator non-modal

Joshua Leung noreply at git.blender.org
Mon Sep 28 15:36:52 CEST 2015


Commit: 763bc0c9052cac64ee312d916e228fd0c85dfd91
Author: Joshua Leung
Date:   Tue Sep 29 02:15:40 2015 +1300
Branches: GPencil_Editing_Stage3
https://developer.blender.org/rB763bc0c9052cac64ee312d916e228fd0c85dfd91

GP Sculpt: Experimenting to make sculpt operator non-modal

Sometimes the modal nature of this operator made it cumbersome to operate.
This commit tries to make this better by making changes to the operator + keymap
so that:

* EKEY + LMB-drag (just like for drawing) = Do a single sculpt stroke
  (i.e. it starts immediately, and ends as soon as the stroke ends)

* CTRL + EKEY = Enter Sculpt Mode (as before). Can do multiple strokes this way
  without holding down any keys.

* DKEY + EKEY -> Sculpt = Enter Sculpt Mode (as before)


I'm still on the fence about the Ctrl+EKEY one. Perhaps it's too much of a hassle,
and we just drop this one?

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

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

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

diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index 02f5c91..afd1f61 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -1218,6 +1218,7 @@ static int gpsculpt_brush_exec(bContext *C, wmOperator *op)
 static int gpsculpt_brush_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
 	tGP_BrushEditData *gso = NULL;
+	const bool is_modal = RNA_boolean_get(op->ptr, "wait_for_input");
 	bool needs_timer = false;
 	float brush_rate = 0.0f;
 	
@@ -1262,6 +1263,18 @@ static int gpsculpt_brush_invoke(bContext *C, wmOperator *op, const wmEvent *eve
 	/* register modal handler */
 	WM_event_add_modal_handler(C, op);
 	
+	/* start drawing immediately? */
+	if (is_modal == false) {
+		ARegion *ar = CTX_wm_region(C);
+		
+		/* apply first dab... */
+		gso->is_painting = true;
+		gpsculpt_brush_apply_event(C, op, event);
+		
+		/* redraw view with feedback */
+		ED_region_tag_redraw(ar);
+	}
+	
 	return OPERATOR_RUNNING_MODAL;
 }
 
@@ -1269,6 +1282,7 @@ static int gpsculpt_brush_invoke(bContext *C, wmOperator *op, const wmEvent *eve
 static int gpsculpt_brush_modal(bContext *C, wmOperator *op, const wmEvent *event)
 {
 	tGP_BrushEditData *gso = op->customdata;
+	const bool is_modal = RNA_boolean_get(op->ptr, "wait_for_input");
 	bool redraw_region = false;
 	
 	/* The operator can be in 2 states: Painting and Idling */
@@ -1297,7 +1311,17 @@ static int gpsculpt_brush_modal(bContext *C, wmOperator *op, const wmEvent *even
 			/* Painting mbut release = Stop painting (back to idle) */
 			case LEFTMOUSE:
 				//BLI_assert(event->val == KM_RELEASE);
-				gso->is_painting = false;
+				if (is_modal) {
+					/* go back to idling... */
+					gso->is_painting = false;
+				}
+				else {
+					/* end sculpt session, since we're not modal */
+					gso->is_painting = false;
+					
+					gpsculpt_brush_exit(C, op);
+					return OPERATOR_FINISHED;
+				}
 				break;
 				
 			/* Abort painting if any of the usual things are tried */
@@ -1311,6 +1335,8 @@ static int gpsculpt_brush_modal(bContext *C, wmOperator *op, const wmEvent *even
 	}
 	else {
 		/* Idling */
+		BLI_assert(is_modal == true);
+		
 		switch (event->type) {
 			/* Painting mbut press = Start painting (switch to painting state) */
 			case LEFTMOUSE:
@@ -1417,6 +1443,9 @@ void GPENCIL_OT_brush_paint(wmOperatorType *ot)
 
 	/* properties */
 	RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
+	
+	RNA_def_boolean(ot->srna, "wait_for_input", true, "Wait for Input",
+	                "Enter a mini 'sculpt-mode' if enabled, otherwise, exit after drawing a single stroke");
 }
 
 /* ************************************************ */
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index 14288a0..4fd155c 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -214,7 +214,12 @@ static void ed_keymap_gpencil_editing(wmKeyConfig *keyconf)
 	
 	
 	/* Brush-Based Editing */
-	WM_keymap_add_item(keymap, "GPENCIL_OT_brush_paint", EKEY, KM_PRESS, 0, 0);
+	/* 1) EKEY + LMB = Single stroke, draw immediately */
+	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_brush_paint", LEFTMOUSE, KM_PRESS, 0, EKEY);
+	RNA_boolean_set(kmi->ptr, "wait_for_input", false);
+	/* 2) EKEY + CTRL = Enter sculpt mode */
+	kmi = WM_keymap_add_item(keymap, "GPENCIL_OT_brush_paint", EKEY, KM_PRESS, KM_CTRL, 0);
+	RNA_boolean_set(kmi->ptr, "wait_for_input", true);
 	
 	/* Shift-FKEY = Sculpt Strength */
 	kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0);




More information about the Bf-blender-cvs mailing list