[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58935] branches/soc-2013-paint: Gradient fill functional in 2d paint.

Antony Riakiotakis kalast at gmail.com
Mon Aug 5 17:51:50 CEST 2013


Revision: 58935
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58935
Author:   psy-fi
Date:     2013-08-05 15:51:50 +0000 (Mon, 05 Aug 2013)
Log Message:
-----------
Gradient fill functional in 2d paint. To use select the fill tool and
tick use gradient. Then drag on the canvas to define the gradient line.

Modified Paths:
--------------
    branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py
    branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h
    branches/soc-2013-paint/source/blender/makesrna/intern/rna_brush.c

Modified: branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py
===================================================================
--- branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py	2013-08-05 15:49:25 UTC (rev 58934)
+++ branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py	2013-08-05 15:51:50 UTC (rev 58935)
@@ -712,7 +712,8 @@
                     col.template_color_picker(brush, "color", value_slider=True)
                 col.prop(brush, "use_gradient")
                 if brush.use_gradient:
-                    col.prop(brush, "gradient_source")
+                    if brush.image_tool == 'DRAW':
+                        col.prop(brush, "gradient_source")
                     col.template_color_ramp(brush, "gradient", expand=True)
                 else:
                     col = layout.column(align=True)            

Modified: branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-08-05 15:49:25 UTC (rev 58934)
+++ branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-08-05 15:51:50 UTC (rev 58935)
@@ -689,7 +689,8 @@
                     col.template_color_picker(brush, "color", value_slider=True)
                 col.prop(brush, "use_gradient")
                 if brush.use_gradient:
-                    col.prop(brush, "gradient_source")
+                    if brush.image_tool == 'DRAW':
+                        col.prop(brush, "gradient_source")
                     col.template_color_ramp(brush, "gradient", expand=True)
                 else:
                     col = layout.column(align=True)            

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-08-05 15:49:25 UTC (rev 58934)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-08-05 15:51:50 UTC (rev 58935)
@@ -586,8 +586,13 @@
 		glEnable(GL_LINE_SMOOTH);
 		glEnable(GL_BLEND);
 
+		glLineWidth(4.0);
 		glColor4ub(0, 0, 0, 255);
 		sdrawline(x, y, pop->startmouse[0], pop->startmouse[1]);
+		glLineWidth(2.0);
+		glColor4ub(255, 255, 255, 255);
+		sdrawline(x, y, pop->startmouse[0], pop->startmouse[1]);
+		glLineWidth(1.0);
 
 		glDisable(GL_BLEND);
 		glDisable(GL_LINE_SMOOTH);
@@ -660,6 +665,11 @@
 	float size;
 	int eraser;
 
+	RNA_float_get_array(itemptr, "mouse", mouse);
+	pressure = RNA_float_get(itemptr, "pressure");
+	eraser = RNA_boolean_get(itemptr, "pen_flip");
+	size = RNA_float_get(itemptr, "size");
+
 	/* stroking with fill tool only acts on stroke end */
 	if (brush->imagepaint_tool == PAINT_TOOL_FILL) {
 		pop->prevmouse[0] = mouse[0];
@@ -667,11 +677,6 @@
 		return;
 	}
 
-	RNA_float_get_array(itemptr, "mouse", mouse);
-	pressure = RNA_float_get(itemptr, "pressure");
-	eraser = RNA_boolean_get(itemptr, "pen_flip");
-	size = RNA_float_get(itemptr, "size");
-
 	if (BKE_brush_use_alpha_pressure(scene, brush))
 		BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * pressure * alphafac));
 	else
@@ -721,7 +726,9 @@
 
 	if (brush->imagepaint_tool == PAINT_TOOL_FILL) {
 		if (brush->flag & BRUSH_USE_GRADIENT) {
-
+			if (pop->mode == PAINT_MODE_2D) {
+				paint_2d_gradient_fill(C, brush, pop->startmouse, pop->prevmouse, pop->custom_paint);
+			}
 		}
 		else {
 			float color[3];

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-08-05 15:49:25 UTC (rev 58934)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-08-05 15:51:50 UTC (rev 58935)
@@ -47,6 +47,7 @@
 #include "BKE_image.h"
 #include "BKE_paint.h"
 #include "BKE_report.h"
+#include "BKE_texture.h"
 
 #include "ED_screen.h"
 
@@ -1272,3 +1273,78 @@
 
 	WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
 }
+
+void paint_2d_gradient_fill (const bContext *C, Brush *br, float mouse_init[2], float mouse_final[2], void *ps)
+{
+	SpaceImage *sima = CTX_wm_space_image(C);
+	Image *ima = sima->image;
+	ImagePaintState *s = ps;
+
+	ImBuf *ibuf;
+	unsigned short i = 0, j = 0;
+	unsigned int color_b;
+	float color_f[4];
+	float image_init[2], image_final[2];
+	float tangent[2];
+	float line_len_sq_inv;
+
+	bool do_float;
+
+	if (!ima)
+		return;
+
+	ibuf = BKE_image_acquire_ibuf(ima, &sima->iuser, NULL);
+
+	if (!ibuf)
+		return;
+
+	UI_view2d_region_to_view(s->v2d, mouse_final[0], mouse_final[1], &image_final[0], &image_final[1]);
+	UI_view2d_region_to_view(s->v2d, mouse_init[0], mouse_init[1], &image_init[0], &image_init[1]);
+
+	image_final[0] *= ibuf->x;
+	image_final[1] *= ibuf->y;
+
+	image_init[0] *= ibuf->x;
+	image_init[1] *= ibuf->y;
+
+	/* some math to get needed gradient variables */
+	sub_v2_v2v2(tangent, image_final, image_init);
+	line_len_sq_inv = 1.0/len_squared_v2(tangent);
+
+	do_float = (ibuf->rect_float != NULL);
+
+	/* this will be substituted by something else when selection is available */
+	imapaint_dirty_region(ima, ibuf, 0, 0, ibuf->x, ibuf->y);
+
+	if (do_float) {
+		for (; i < ibuf->x; i++) {
+			for (j = 0; j < ibuf->y; j++) {
+				float p[2] = {i - image_init[0], j - image_init[1]};
+				float f = dot_v2v2(p, tangent)*line_len_sq_inv;
+
+				do_colorband(br->gradient, f, color_f);
+				copy_v4_v4(ibuf->rect_float + 4 * (j * ibuf->x + i), color_f);
+			}
+		}
+	}
+	else {
+		for (; i < ibuf->x; i++) {
+			for (j = 0; j < ibuf->y; j++) {
+				float p[2] = {i - image_init[0], j - image_init[1]};
+				float f = dot_v2v2(p, tangent)*line_len_sq_inv;
+
+				do_colorband(br->gradient, f, color_f);
+				rgba_float_to_uchar((unsigned char *)&color_b, color_f);
+
+				*(ibuf->rect + j * ibuf->x + i) =  color_b;
+			}
+		}
+	}
+
+	imapaint_image_update(sima, ima, ibuf, false);
+	imapaint_clear_partial_redraw();
+
+	BKE_image_release_ibuf(ima, ibuf, NULL);
+
+	WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
+}

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h	2013-08-05 15:49:25 UTC (rev 58934)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h	2013-08-05 15:51:50 UTC (rev 58935)
@@ -159,6 +159,7 @@
 void paint_2d_stroke_done(void *ps);
 void paint_2d_stroke(void *ps, const float prev_mval[2], const float mval[2], int eraser);
 void paint_2d_bucket_fill(const struct bContext *C, float color[3]);
+void paint_2d_gradient_fill (const struct bContext *C, struct Brush *br, float mouse_init[2], float mouse_final[2], void *ps);
 void *paint_proj_new_stroke(struct bContext *C, struct Object *ob, const float mouse[2], int mode);
 void paint_proj_stroke(struct bContext *C, void *ps, const float prevmval_i[2], const float mval_i[2]);
 void paint_proj_redraw(const bContext *C, void *pps, bool final);

Modified: branches/soc-2013-paint/source/blender/makesrna/intern/rna_brush.c
===================================================================
--- branches/soc-2013-paint/source/blender/makesrna/intern/rna_brush.c	2013-08-05 15:49:25 UTC (rev 58934)
+++ branches/soc-2013-paint/source/blender/makesrna/intern/rna_brush.c	2013-08-05 15:51:50 UTC (rev 58935)
@@ -410,7 +410,7 @@
 	else br->flag &= ~BRUSH_USE_GRADIENT;
 
 	if ((br->flag & BRUSH_USE_GRADIENT) && br->gradient == NULL)
-		br->gradient = add_colorband(false);
+		br->gradient = add_colorband(true);
 }
 
 static void rna_Brush_set_unprojected_radius(PointerRNA *ptr, float value)




More information about the Bf-blender-cvs mailing list