[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58748] branches/soc-2013-paint: Bucket fill for 2d painting.

Antony Riakiotakis kalast at gmail.com
Tue Jul 30 22:33:18 CEST 2013


Revision: 58748
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58748
Author:   psy-fi
Date:     2013-07-30 20:33:17 +0000 (Tue, 30 Jul 2013)
Log Message:
-----------
Bucket fill for 2d painting. Warning, no undo supported yet. And
changing the operator color on properties panel is problematic
unfortunately since it the context is not set up correctly when changing
tool options in 3d viewport toolbar. For now I have disabled it. This is
quite a headache I must say :/ Also some minor code for gradients is
included

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/editors/sculpt_paint/paint_ops.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-07-30 19:05:29 UTC (rev 58747)
+++ branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py	2013-07-30 20:33:17 UTC (rev 58748)
@@ -956,7 +956,18 @@
         if brush.use_custom_icon:
             col.prop(brush, "icon_filepath", text="")
 
+class IMAGE_PT_tools_imagepaint(BrushButtonsPanel, Panel):
+    bl_context = "imagepaint"
+    bl_label = "Image Tools"
 
+    def draw(self, context):
+        layout = self.layout
+
+        col = layout.column()
+        col.operator("paint.bucket_fill")
+
+
+
 class IMAGE_UV_sculpt_curve(Panel):
     bl_space_type = 'IMAGE_EDITOR'
     bl_region_type = 'UI'

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-07-30 19:05:29 UTC (rev 58747)
+++ branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-07-30 20:33:17 UTC (rev 58748)
@@ -1264,6 +1264,17 @@
         col.operator("image.save_dirty", text="Save All Edited")
 
 
+class VIEW3D_PT_tools_imagepaint(View3DPanel, Panel):
+    bl_context = "imagepaint"
+    bl_label = "Image Tools"
+
+    def draw(self, context):
+        layout = self.layout
+
+        col = layout.column()
+        col.operator("paint.bucket_fill")
+
+
 class VIEW3D_PT_imagepaint_options(View3DPaintPanel):
     bl_label = "Options"
     bl_options = {'DEFAULT_CLOSED'}

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-07-30 19:05:29 UTC (rev 58747)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-07-30 20:33:17 UTC (rev 58748)
@@ -1283,6 +1283,81 @@
 }
 
 
+static int bucket_fill_exec(bContext *C, wmOperator *op)
+{
+	PaintMode mode;
+	float color[3];
+
+	/* get from rna property only if set */
+	if (RNA_struct_property_is_set(op->ptr, "color")) {
+		RNA_float_get_array(op->ptr, "color", color);
+	}
+	else {
+		Paint *p = BKE_paint_get_active(CTX_data_scene(C));
+		Brush *br = BKE_paint_brush(p);
+
+		copy_v3_v3(color, br->rgb);
+	}
+
+	mode = BKE_paintmode_get_active_from_context(C);
+
+	switch(mode) {
+		case PAINT_TEXTURE_2D:
+			paint_2d_bucket_fill(C, color);
+			break;
+		case PAINT_TEXTURE_PROJECTIVE:
+			break;
+		default:
+			break;
+	}
+
+	RNA_float_set_array(op->ptr, "color", color);
+
+	return OPERATOR_FINISHED;
+}
+
+
+void PAINT_OT_bucket_fill(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Bucket Fill";
+	ot->idname = "PAINT_OT_bucket_fill";
+	ot->description = "Fill canvas with brush color";
+
+	/* api callbacks */
+	ot->exec = bucket_fill_exec;
+	ot->poll = image_paint_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER;
+
+	RNA_def_float_color(ot->srna, "color", 3, NULL, 0.0, 1.0, "Color", "Color for bucket fill", 0.0, 1.0);
+}
+
+static int gradient_fill_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	PaintMode mode = BKE_paintmode_get_active_from_context(C);
+
+	return OPERATOR_FINISHED;
+}
+
+
+void PAINT_OT_gradient_fill(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Gradient Fill";
+	ot->idname = "PAINT_OT_gradient_fill";
+	ot->description = "Fill canvas with a gradient";
+
+	/* api callbacks */
+	ot->exec = gradient_fill_exec;
+	ot->poll = image_paint_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+
 static int texture_paint_poll(bContext *C)
 {
 	if (texture_paint_toggle_poll(C))

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-07-30 19:05:29 UTC (rev 58747)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-07-30 20:33:17 UTC (rev 58748)
@@ -1212,3 +1212,58 @@
 
 	MEM_freeN(s);
 }
+
+
+/* this function expects linear space color values */
+void paint_2d_bucket_fill (bContext *C, float color[3])
+{
+	SpaceImage *sima = CTX_wm_space_image(C);
+	Image *ima = sima->image;
+
+	ImBuf *ibuf;
+	unsigned short i = 0, j = 0;
+	unsigned int color_b;
+	float color_f[4];
+
+	bool do_float;
+
+	if (!ima)
+		return;
+
+	ibuf = BKE_image_acquire_ibuf(ima, &sima->iuser, NULL);
+
+	do_float = (ibuf->rect_float != NULL);
+	/* first check if our image is float. If it is not we should correct the colour to
+	 * be in gamma space */
+
+	if (!do_float) {
+		linearrgb_to_srgb_uchar3((unsigned char *)&color_b, color);
+		*(((char *)&color_b) + 3) = 255;
+	} else {
+		copy_v3_v3(color_f, color);
+		color_f[3] = 1.0;
+	}
+
+	if (do_float) {
+		for (; i < ibuf->x; i++) {
+			for (j = 0; j < ibuf->y; j++) {
+				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++) {
+				*(ibuf->rect + j * ibuf->x + i) =  color_b;
+			}
+		}
+	}
+
+	ibuf->userflags |= IB_BITMAPDIRTY;
+
+	BKE_image_release_ibuf(ima, ibuf, NULL);
+
+	GPU_free_image(ima);
+
+	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-07-30 19:05:29 UTC (rev 58747)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_intern.h	2013-07-30 20:33:17 UTC (rev 58748)
@@ -158,6 +158,7 @@
 void paint_2d_redraw(const bContext *C, void *ps, bool final);
 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(struct bContext *C, float color[3]);
 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);
@@ -171,6 +172,8 @@
 void PAINT_OT_texture_paint_toggle(struct wmOperatorType *ot);
 void PAINT_OT_project_image(struct wmOperatorType *ot);
 void PAINT_OT_image_from_view(struct wmOperatorType *ot);
+void PAINT_OT_bucket_fill(struct wmOperatorType *ot);
+void PAINT_OT_gradient_fill(struct wmOperatorType *ot);
 
 /* new texture painting */
 void PAINT_OT_image_paint(struct wmOperatorType *ot);

Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_ops.c	2013-07-30 19:05:29 UTC (rev 58747)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_ops.c	2013-07-30 20:33:17 UTC (rev 58748)
@@ -1030,6 +1030,8 @@
 	WM_operatortype_append(PAINT_OT_project_image);
 	WM_operatortype_append(PAINT_OT_image_from_view);
 	WM_operatortype_append(PAINT_OT_texture_colors_flip);
+	WM_operatortype_append(PAINT_OT_bucket_fill);
+	WM_operatortype_append(PAINT_OT_gradient_fill);
 
 	/* weight */
 	WM_operatortype_append(PAINT_OT_weight_paint_toggle);




More information about the Bf-blender-cvs mailing list