[Bf-blender-cvs] [6c835bb] soc-2013-paint: Cleanup: Get rid of polylines.

Antony Riakiotakis noreply at git.blender.org
Thu Apr 17 22:37:15 CEST 2014


Commit: 6c835bb336400a5b4c30c801deae5c9c440e1c2c
Author: Antony Riakiotakis
Date:   Thu Apr 17 23:37:04 2014 +0300
https://developer.blender.org/rB6c835bb336400a5b4c30c801deae5c9c440e1c2c

Cleanup: Get rid of polylines.

Before people start screaming, let's remind everyone that polylines are
curves with a vector handle. Changing handle types is not yet supported
in paint but it will follow soon.

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

M	release/scripts/startup/bl_ui/space_image.py
M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/editors/sculpt_paint/paint_stroke.c
M	source/blender/makesdna/DNA_brush_types.h
M	source/blender/makesrna/intern/rna_brush.c

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

diff --git a/release/scripts/startup/bl_ui/space_image.py b/release/scripts/startup/bl_ui/space_image.py
index e76270c..956f893 100644
--- a/release/scripts/startup/bl_ui/space_image.py
+++ b/release/scripts/startup/bl_ui/space_image.py
@@ -909,7 +909,7 @@ class IMAGE_PT_paint_stroke(BrushButtonsPanel, Panel):
             row.prop(brush, "spacing", text="Spacing")
             row.prop(brush, "use_pressure_spacing", toggle=True, text="")
             
-        if brush.use_line or brush.use_polyline or brush.use_curve:
+        if brush.use_line or brush.use_curve:
             col.separator()
             row = col.row(align=True)
             row.prop(brush, "spacing", text="Spacing")
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 43cdff8..ee92542 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1276,7 +1276,7 @@ class VIEW3D_PT_tools_brush_stroke(Panel, View3DPaintPanel):
             row.prop(brush, "spacing", text="Spacing")
             row.prop(brush, "use_pressure_spacing", toggle=True, text="")
 
-        if brush.use_line or brush.use_polyline or brush.use_curve:
+        if brush.use_line or brush.use_curve:
             col.separator()
             row = col.row(align=True)
             row.prop(brush, "spacing", text="Spacing")
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c
index 4e735d4..2544daa 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -73,20 +73,6 @@ typedef struct PaintSample {
 	float pressure;
 } PaintSample;
 
-typedef struct LinePoint {
-	struct LinePoint *next, *prev;
-	float pos[2];
-} LinePoint;
-
-/* stroke->curve_edited */
-enum {
-	CURVE_HANDLE_CENTER = 1,
-	CURVE_HANDLE_PREV = 2,
-	CURVE_HANDLE_NEXT = 3,
-	CURVE_HANDLE_PREV_CONSTRAINED = 4,
-	CURVE_HANDLE_NEXT_CONSTRAINED = 5
-};
-
 typedef struct PaintStroke {
 	void *mode_data;
 	void *stroke_cursor;
@@ -178,59 +164,31 @@ BLI_INLINE void draw_tri_point(float *co, float width)
 	glEnd();
 }
 
-static void paint_draw_line_cursor(bContext *C, int UNUSED(x), int UNUSED(y), void *customdata)
+static void paint_draw_line_cursor(bContext *C, int x, int y, void *customdata)
 {
 	Paint *paint = BKE_paint_get_active_from_context(C);
-	Brush *brush = BKE_paint_brush(paint);
 	PaintStroke *stroke = customdata;
 
-	if (stroke && brush) {
-		LinePoint *p = stroke->line.first;
-
-		glEnable(GL_LINE_SMOOTH);
-		glEnable(GL_BLEND);
-
-		while (p->next && p->next->next) {
-			glColor4ub(0, 0, 0, paint->paint_cursor_col[3]);
-			glLineWidth(3.0);
-			sdrawline((int)p->pos[0], (int)p->pos[1],
-			          (int)p->next->pos[0], (int)p->next->pos[1]);
-
-			glColor4ubv(paint->paint_cursor_col);
-			glLineWidth(1.0);
-			sdrawline((int)p->pos[0], (int)p->pos[1],
-			          (int)p->next->pos[0], (int)p->next->pos[1]);
+	glEnable(GL_LINE_SMOOTH);
+	glEnable(GL_BLEND);
 
-			draw_tri_point(p->pos, 10.0);
-			p = p->next;
-		}
-
-		if (p->next) {
-			if (brush->flag & BRUSH_POLYLINE)
-			{
-				glEnable(GL_LINE_STIPPLE);
-				glLineStipple(3, 0xAAAA);
-			}
-
-			glColor4ub(0, 0, 0, paint->paint_cursor_col[3]);
-			glLineWidth(3.0);
-			sdrawline((int)p->pos[0], (int)p->pos[1],
-			          (int)p->next->pos[0], (int)p->next->pos[1]);
+	glEnable(GL_LINE_STIPPLE);
+	glLineStipple(3, 0xAAAA);
 
-			glColor4ubv(paint->paint_cursor_col);
-			glLineWidth(1.0);
-			sdrawline((int)p->pos[0], (int)p->pos[1],
-			          (int)p->next->pos[0], (int)p->next->pos[1]);
+	glColor4ub(0, 0, 0, paint->paint_cursor_col[3]);
+	glLineWidth(3.0);
+	sdrawline((int)stroke->last_mouse_position[0], (int)stroke->last_mouse_position[1],
+	        x, y);
 
-			glDisable(GL_LINE_STIPPLE);
-			draw_tri_point(p->pos, 10.0);
-		}
+	glColor4ub(255, 255, 255, paint->paint_cursor_col[3]);
+	glLineWidth(1.0);
+	sdrawline((int)stroke->last_mouse_position[0], (int)stroke->last_mouse_position[1],
+	        x, y);
 
-		glLineWidth(1.0);
+	glDisable(GL_LINE_STIPPLE);
 
-		glDisable(GL_BLEND);
-		glDisable(GL_LINE_SMOOTH);
-	}
+	glDisable(GL_BLEND);
+	glDisable(GL_LINE_SMOOTH);
 }
 
 /* if this is a tablet event, return tablet pressure and set *pen_flip
@@ -666,7 +624,7 @@ PaintStroke *paint_stroke_new(bContext *C,
 	get_imapaint_zoom(C, &zoomx, &zoomy);
 	stroke->zoom_2d = max_ff(zoomx, zoomy);
 
-	if ((br->flag & (BRUSH_POLYLINE | BRUSH_CURVE))
+	if ((br->flag & BRUSH_CURVE)
 		&& RNA_struct_property_is_set(op->ptr, "mode")) {
 		RNA_enum_set(op->ptr, "mode", BRUSH_STROKE_NORMAL);
 	}
@@ -768,7 +726,7 @@ bool paint_supports_dynamic_size(Brush *br, PaintMode mode)
 bool paint_supports_smooth_stroke(Brush *br, PaintMode mode)
 {
 	if (!(br->flag & BRUSH_SMOOTH_STROKE) ||
-		 (br->flag & (BRUSH_ANCHORED | BRUSH_DRAG_DOT | BRUSH_LINE | BRUSH_POLYLINE)))
+		 (br->flag & (BRUSH_ANCHORED | BRUSH_DRAG_DOT | BRUSH_LINE)))
 	{
 		return false;
 	}
@@ -919,30 +877,14 @@ static void paint_line_strokes_spacing(bContext *C, wmOperator *op, PaintStroke
 }
 
 
-static void paint_stroke_polyline_end(bContext *C, wmOperator *op, PaintStroke *stroke)
+static void paint_stroke_line_end(bContext *C, wmOperator *op, PaintStroke *stroke, float mouse[2])
 {
 	Brush *br = stroke->brush;
-	if (stroke->stroke_started && (br->flag & (BRUSH_LINE | BRUSH_POLYLINE))) {
-		const Scene *scene = CTX_data_scene(C);
-		const float spacing = paint_space_stroke_spacing(scene, stroke, 1.0f, 1.0f);
-		LinePoint *p = stroke->line.first;
-		float length_residue = 0.0f;
-
-		/* last line point in polyline is dangling so remove */
-		if (br->flag & BRUSH_POLYLINE) {
-			LinePoint *plast = stroke->line.last;
-			BLI_remlink(&stroke->line, stroke->line.last);
-			MEM_freeN(plast);
-		}
-
+	if (stroke->stroke_started && (br->flag & BRUSH_LINE)) {
 		stroke->ups->overlap_factor = paint_stroke_integrate_overlap(br, 1.0);
 
-		if (p->next)
-			paint_brush_stroke_add_step(C, op, p->pos, 1.0);
-
-		for (p = p->next; p; p = p->next) {
-			paint_line_strokes_spacing(C, op, stroke, spacing, &length_residue, p->prev->pos, p->pos);
-		}
+		paint_brush_stroke_add_step(C, op, stroke->last_mouse_position, 1.0);
+		paint_space_stroke(C, op, mouse, 1.0);
 	}
 }
 
@@ -1014,7 +956,7 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
 	float pressure;
 
 	/* see if tablet affects event. Line, anchored and drag dot strokes do not support pressure */
-	pressure = (br->flag & (BRUSH_LINE | BRUSH_POLYLINE | BRUSH_ANCHORED | BRUSH_DRAG_DOT)) ? 1.0 : event_tablet_data(event, &stroke->pen_flip);
+	pressure = (br->flag & (BRUSH_LINE | BRUSH_ANCHORED | BRUSH_DRAG_DOT)) ? 1.0 : event_tablet_data(event, &stroke->pen_flip);
 
 	paint_stroke_add_sample(p, stroke, event->mval[0], event->mval[1], pressure);
 	paint_stroke_sample_average(stroke, &sample_average);
@@ -1050,17 +992,11 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
 			if (br->flag & BRUSH_AIRBRUSH)
 				stroke->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, stroke->brush->rate);
 
-			if (br->flag & (BRUSH_LINE | BRUSH_POLYLINE)) {
-				LinePoint *p = MEM_callocN(sizeof(*p), "line_stroke_point");
+			if (br->flag & BRUSH_LINE) {
 				stroke->stroke_cursor =
 					WM_paint_cursor_activate(CTX_wm_manager(C), paint_poll, paint_draw_line_cursor, stroke);
-
-				BLI_addtail(&stroke->line, p);
-				copy_v2_v2(p->pos, sample_average.mouse);
-				p = MEM_callocN(sizeof(*p), "line_stroke_point");
-				BLI_addtail(&stroke->line, p);
-				copy_v2_v2(p->pos, sample_average.mouse);
 			}
+
 			first_dab = true;
 		}
 	}
@@ -1077,33 +1013,20 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
 	}
 
 	if (event->type == stroke->event_type && !first_modal) {
-		if (br->flag & BRUSH_POLYLINE) {
-			if (event->val == KM_PRESS && stroke->stroke_started) {
-				/* Add new line here */
-				LinePoint *p = MEM_callocN(sizeof(*p), "line_stroke_point");
-				BLI_addtail(&stroke->line, p);
-				copy_v2_v2(p->pos, sample_average.mouse);
-				/* for rake to work well */
-				copy_v2_v2(stroke->last_mouse_position, sample_average.mouse);
-			}
-		}
-		else if (event->val == KM_RELEASE) {
-			paint_stroke_polyline_end (C, op, stroke);
+		if (event->val == KM_RELEASE) {
+			paint_stroke_line_end (C, op, stroke, sample_average.mouse);
 			stroke_done(C, op);
 			return OPERATOR_FINISHED;
 		}
 	}
 	else if (ELEM(event->type, RETKEY, SPACEKEY)) {
-		paint_stroke_polyline_end(C, op, stroke);
+		paint_stroke_line_end(C, op, stroke, sample_average.mouse);
 		stroke_done(C, op);
 		return OPERATOR_FINISHED;
 	}
-	else if ((br->flag & (BRUSH_LINE | BRUSH_POLYLINE)) && stroke->stroke_started &&
+	else if ((br->flag & BRUSH_LINE) && stroke->stroke_started &&
 			 (first_modal || (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE))))
 	{
-		LinePoint *p = stroke->line.last;
-		copy_v2_v2(p->pos, sample_average.mouse);
-
 		if (br->flag & BRUSH_RAKE) {
 			copy_v2_v2(stroke->ups->last_rake, stroke->last_mouse_position);
 			paint_calculate_rake_rotation(stroke->ups,  sample_average.mouse);
diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h
index 2e84e76..0cd2254 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -190,7 +190,7 @@ typedef enum BrushFlags {
 	BRUSH_SIZE_PRESSURE = (1 << 3),
 	BRUSH_JITTER_PRESSURE = (1 << 4),
 	BRUSH_SPACING_PRESSURE = (1 << 5),
-	BRUSH_POLYLINE = (1 << 6),
+	BRUSH_UNUSED = (1 << 6),
 	BRUSH_RAKE = (1 << 7),
 	BRUSH_ANCHORED = (1 << 8),
 	BRUSH_DIR_IN = (1 << 9),
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index 1fe6c9e..315d511 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -56,7 +56,6 @@ static EnumPropertyItem sculpt_stroke_method_items[] = {
 	{BRUSH_AIRBRUSH, "AIRBRUSH", 0, "Airbrush", "Keep applying paint effect while holding mouse (spray)"},
     {BRUSH_ANCHORED, "ANCHORED", 0, "Anchored", "Keep the brush anchor

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list