[Bf-blender-cvs] [bd82b77] temp-curve-draw: Add button in toolbar for the draw tool

Campbell Barton noreply at git.blender.org
Fri Apr 15 09:17:35 CEST 2016


Commit: bd82b7792d3806d41314c82e77bf1bd506d31b4d
Author: Campbell Barton
Date:   Fri Apr 15 17:11:54 2016 +1000
Branches: temp-curve-draw
https://developer.blender.org/rBbd82b7792d3806d41314c82e77bf1bd506d31b4d

Add button in toolbar for the draw tool

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

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/editors/curve/curve_ops.c
M	source/blender/editors/curve/editcurve_paint.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index a2770bd..ec15067 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -136,6 +136,7 @@ class VIEW3D_PT_tools_add_object(View3DPanel, Panel):
 
     @staticmethod
     def draw_add_curve(layout, label=False):
+
         if label:
             layout.label(text="Bezier:")
         layout.operator("curve.primitive_bezier_curve_add", text="Bezier", icon='CURVE_BEZCURVE')
@@ -149,6 +150,10 @@ class VIEW3D_PT_tools_add_object(View3DPanel, Panel):
         layout.operator("curve.primitive_nurbs_circle_add", text="Nurbs Circle", icon='CURVE_NCIRCLE')
         layout.operator("curve.primitive_nurbs_path_add", text="Path", icon='CURVE_PATH')
 
+        layout.separator()
+
+        layout.operator("curve.draw", icon='LINE_DATA')
+
     @staticmethod
     def draw_add_surface(layout):
         layout.operator("surface.primitive_nurbs_surface_curve_add", text="Nurbs Curve", icon='SURFACE_NCURVE')
diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c
index c8c037b..d1994c8 100644
--- a/source/blender/editors/curve/curve_ops.c
+++ b/source/blender/editors/curve/curve_ops.c
@@ -235,7 +235,8 @@ void ED_keymap_curve(wmKeyConfig *keyconf)
 
 	WM_keymap_add_item(keymap, "CURVE_OT_vertex_add", ACTIONMOUSE, KM_CLICK, KM_CTRL, 0);
 
-	WM_keymap_add_item(keymap, "CURVE_OT_draw", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0);
+	kmi = WM_keymap_add_item(keymap, "CURVE_OT_draw", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0);
+	RNA_boolean_set(kmi->ptr, "wait_for_input", false);
 
 	kmi = WM_keymap_add_item(keymap, "CURVE_OT_select_all", AKEY, KM_PRESS, 0, 0);
 	RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
diff --git a/source/blender/editors/curve/editcurve_paint.c b/source/blender/editors/curve/editcurve_paint.c
index 5966564..ae2d77c 100644
--- a/source/blender/editors/curve/editcurve_paint.c
+++ b/source/blender/editors/curve/editcurve_paint.c
@@ -210,6 +210,10 @@ struct CurveDrawData {
 
 	ViewContext vc;
 	bglMats mats;
+	enum {
+		CURVE_DRAW_IDLE = 0,
+		CURVE_DRAW_PAINTING = 1,
+	} state;
 
 	/* StrokeElem */
 	BLI_mempool *stroke_elem_pool;
@@ -540,6 +544,49 @@ static void curve_draw_event_add(wmOperator *op, const wmEvent *event)
 	ED_region_tag_redraw(cdd->vc.ar);
 }
 
+static void curve_draw_event_add_first(wmOperator *op, const wmEvent *event)
+{
+	struct CurveDrawData *cdd = op->customdata;
+	const CurvePaintSettings *cps = &cdd->vc.scene->toolsettings->curve_paint_settings;
+
+	/* add first point */
+	curve_draw_event_add(op, event);
+
+	if ((cps->depth_mode == CURVE_PAINT_PROJECT_SURFACE) && cdd->project.use_depth &&
+	    (cps->flag & CURVE_PAINT_FLAG_DEPTH_STROKE_ENDPOINTS))
+	{
+		RegionView3D *rv3d = cdd->vc.rv3d;
+
+		cdd->project.use_depth = false;
+		cdd->project.use_plane = true;
+
+		float normal[3] = {0.0f};
+		if (ELEM(cps->surface_plane,
+		         CURVE_PAINT_SURFACE_PLANE_NORMAL_VIEW,
+		         CURVE_PAINT_SURFACE_PLANE_NORMAL_SURFACE))
+		{
+			if (depth_read_normal(&cdd->vc, &cdd->mats, event->mval, normal)) {
+				if (cps->surface_plane == CURVE_PAINT_SURFACE_PLANE_NORMAL_VIEW) {
+					float cross_a[3], cross_b[3];
+					cross_v3_v3v3(cross_a, rv3d->viewinv[2], normal);
+					cross_v3_v3v3(cross_b, normal, cross_a);
+					copy_v3_v3(normal, cross_b);
+				}
+			}
+		}
+
+		/* CURVE_PAINT_SURFACE_PLANE_VIEW or fallback */
+		if (is_zero_v3(normal)) {
+			copy_v3_v3(normal, rv3d->viewinv[2]);
+		}
+
+		normalize_v3_v3(cdd->project.plane, normal);
+		cdd->project.plane[3] = -dot_v3v3(cdd->project.plane, cdd->prev.location_world_valid);
+	}
+
+	cdd->init_event_type = event->type;
+	cdd->state = CURVE_DRAW_PAINTING;
+}
 
 static void curve_draw_init(bContext *C, wmOperator *op, bool is_invoke)
 {
@@ -912,7 +959,7 @@ static int curve_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
 	const CurvePaintSettings *cps = &cdd->vc.scene->toolsettings->curve_paint_settings;
 
-	cdd->init_event_type = event->type;
+	const bool is_modal = RNA_boolean_get(op->ptr, "wait_for_input");
 
 	/* fallback (incase we can't find the depth on first test) */
 	{
@@ -985,45 +1032,13 @@ static int curve_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 		}
 	}
 
+	if (is_modal == false) {
+		curve_draw_event_add_first(op, event);
+	}
+
 	/* add temp handler */
 	WM_event_add_modal_handler(C, op);
 
-	/* add first point */
-	curve_draw_event_add(op, event);
-
-	if ((cps->depth_mode == CURVE_PAINT_PROJECT_SURFACE) && cdd->project.use_depth &&
-	    (cps->flag & CURVE_PAINT_FLAG_DEPTH_STROKE_ENDPOINTS))
-	{
-		RegionView3D *rv3d = cdd->vc.rv3d;
-
-		cdd->project.use_depth = false;
-		cdd->project.use_plane = true;
-
-		float normal[3] = {0.0f};
-		if (ELEM(cps->surface_plane,
-		         CURVE_PAINT_SURFACE_PLANE_NORMAL_VIEW,
-		         CURVE_PAINT_SURFACE_PLANE_NORMAL_SURFACE))
-		{
-			if (depth_read_normal(&cdd->vc, &cdd->mats, event->mval, normal)) {
-				if (cps->surface_plane == CURVE_PAINT_SURFACE_PLANE_NORMAL_VIEW) {
-					float cross_a[3], cross_b[3];
-					cross_v3_v3v3(cross_a, rv3d->viewinv[2], normal);
-					cross_v3_v3v3(cross_b, normal, cross_a);
-					copy_v3_v3(normal, cross_b);
-				}
-			}
-		}
-
-		/* CURVE_PAINT_SURFACE_PLANE_VIEW or fallback */
-		if (is_zero_v3(normal)) {
-			copy_v3_v3(normal, rv3d->viewinv[2]);
-		}
-
-		normalize_v3_v3(cdd->project.plane, normal);
-		cdd->project.plane[3] = -dot_v3v3(cdd->project.plane, cdd->prev.location_world_valid);
-
-	}
-
 	return OPERATOR_RUNNING_MODAL;
 }
 
@@ -1058,10 +1073,17 @@ static int curve_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
 		curve_draw_cancel(C, op);
 		return OPERATOR_CANCELLED;
 	}
+	else if (ELEM(event->type, LEFTMOUSE)) {
+		if (event->val == KM_PRESS) {
+			curve_draw_event_add_first(op, event);
+		}
+	}
 	else if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
-		const float mval_fl[2] = {UNPACK2(event->mval)};
-		if (len_squared_v2v2(mval_fl, cdd->prev.location_world) > SQUARE(STROKE_SAMPLE_DIST_MIN_PX)) {
-			curve_draw_event_add(op, event);
+		if (cdd->state == CURVE_DRAW_PAINTING) {
+			const float mval_fl[2] = {UNPACK2(event->mval)};
+			if (len_squared_v2v2(mval_fl, cdd->prev.location_world) > SQUARE(STROKE_SAMPLE_DIST_MIN_PX)) {
+				curve_draw_event_add(op, event);
+			}
 		}
 	}
 
@@ -1096,6 +1118,9 @@ void CURVE_OT_draw(wmOperatorType *ot)
 
 	prop = RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
 	RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+
+	prop = RNA_def_boolean(ot->srna, "wait_for_input", true, "Wait for Input", "");
+	RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
 }
 
 /** \} */
\ No newline at end of file




More information about the Bf-blender-cvs mailing list