[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58928] branches/soc-2013-paint: Changes to the fill/gradient tools:

Antony Riakiotakis kalast at gmail.com
Mon Aug 5 14:44:43 CEST 2013


Revision: 58928
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58928
Author:   psy-fi
Date:     2013-08-05 12:44:42 +0000 (Mon, 05 Aug 2013)
Log Message:
-----------
Changes to the fill/gradient tools:

Fill is now a paint tool, this is done to get correct cursor drawing for
gradient fill. It also allows to unify the gradient and fill tools to
one and use the appropriate depending on whether gradient is checked or
not.

Gradient fill and strokes are still inactive in this commmit, but I
added another goodie, drag'n'drop of colors in the image editor main
window while paint mode is active will do bucket filling.

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/include/UI_interface.h
    branches/soc-2013-paint/source/blender/editors/interface/interface_intern.h
    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
    branches/soc-2013-paint/source/blender/editors/space_image/space_image.c
    branches/soc-2013-paint/source/blender/makesdna/DNA_brush_types.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 12:02:43 UTC (rev 58927)
+++ branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py	2013-08-05 12:44:42 UTC (rev 58928)
@@ -707,7 +707,7 @@
 
             col = layout.column()
 
-            if brush.image_tool == 'DRAW' and brush.blend not in ('ERASE_ALPHA', 'ADD_ALPHA'):
+            if brush.image_tool in ('DRAW', 'FILL') and brush.blend not in ('ERASE_ALPHA', 'ADD_ALPHA'):
                 if not brush.use_gradient:
                     col.template_color_picker(brush, "color", value_slider=True)
                 col.prop(brush, "use_gradient")
@@ -717,11 +717,12 @@
                 else:
                     col = layout.column(align=True)            
                     col.prop(brush, "color", text="")
-                col.prop(brush, "secondary_color", text="")
+                if brush.image_tool != 'FILL':
+                    col.prop(brush, "secondary_color", text="")
                 col = layout.column()
                 col.template_ID(toolsettings, "palette", new="palette.new")
                 if toolsettings.palette:
-                    col.template_palette(toolsettings, "palette", color=True)
+                    col.template_palette(toolsettings, "palette", color=True)      
 
             row = col.row(align=True)
             self.prop_unified_size(row, context, brush, "size", slider=True, text="Radius")
@@ -962,19 +963,7 @@
         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")
-        col.operator("paint.gradient_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-08-05 12:02:43 UTC (rev 58927)
+++ branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-08-05 12:44:42 UTC (rev 58928)
@@ -684,7 +684,7 @@
 
             col = layout.column()
 
-            if brush.image_tool == 'DRAW' and brush.blend not in ('ERASE_ALPHA', 'ADD_ALPHA'):
+            if brush.image_tool in ('DRAW', 'FILL') and brush.blend not in ('ERASE_ALPHA', 'ADD_ALPHA'):
                 if not brush.use_gradient:
                     col.template_color_picker(brush, "color", value_slider=True)
                 col.prop(brush, "use_gradient")
@@ -694,7 +694,8 @@
                 else:
                     col = layout.column(align=True)            
                     col.prop(brush, "color", text="")
-                col.prop(brush, "secondary_color", text="")
+                if brush.image_tool != 'FILL':
+                    col.prop(brush, "secondary_color", text="")
                 col = layout.column()
                 col.template_ID(settings, "palette", new="palette.new")
                 if settings.palette:
@@ -1270,18 +1271,6 @@
         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")
-        col.operator("paint.gradient_fill")
-
-
 class VIEW3D_PT_imagepaint_options(View3DPaintPanel):
     bl_label = "Options"
     bl_options = {'DEFAULT_CLOSED'}

Modified: branches/soc-2013-paint/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/soc-2013-paint/source/blender/editors/include/UI_interface.h	2013-08-05 12:02:43 UTC (rev 58927)
+++ branches/soc-2013-paint/source/blender/editors/include/UI_interface.h	2013-08-05 12:44:42 UTC (rev 58928)
@@ -896,6 +896,11 @@
 void uiItemMenuEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, const char *name, int icon);
 
 /* UI Operators */
+typedef struct uiDragColorHandle {
+	float color[3];
+	bool gamma_corrected;
+} uiDragColorHandle;
+
 void UI_buttons_operatortypes(void);
 void UI_drop_color_copy(struct wmDrag *drag, struct wmDropBox *drop);
 int UI_drop_color_poll(struct bContext *C, struct wmDrag *drag, const struct wmEvent *event);

Modified: branches/soc-2013-paint/source/blender/editors/interface/interface_intern.h
===================================================================
--- branches/soc-2013-paint/source/blender/editors/interface/interface_intern.h	2013-08-05 12:02:43 UTC (rev 58927)
+++ branches/soc-2013-paint/source/blender/editors/interface/interface_intern.h	2013-08-05 12:44:42 UTC (rev 58928)
@@ -583,10 +583,4 @@
 int ui_but_anim_expression_set(uiBut *but, const char *str);
 int ui_but_anim_expression_create(uiBut *but, const char *str);
 void ui_but_anim_autokey(struct bContext *C, uiBut *but, struct Scene *scene, float cfra);
-
-typedef struct uiDragColorHandle {
-	float color[3];
-	bool gamma_corrected;
-} uiDragColorHandle;
-
 #endif

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 12:02:43 UTC (rev 58927)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c	2013-08-05 12:44:42 UTC (rev 58928)
@@ -547,8 +547,10 @@
 	void *custom_paint;
 
 	float prevmouse[2];
+	float startmouse[2];
 	double starttime;
 
+	void *cursor;
 	ViewContext vc;
 } PaintOperation;
 
@@ -577,22 +579,42 @@
 	}
 }
 
+static void gradient_draw_line(bContext *UNUSED(C), int x, int y, void *customdata) {
+	PaintOperation *pop = (PaintOperation *)customdata;
 
+	if (pop) {
+		glEnable(GL_LINE_SMOOTH);
+		glEnable(GL_BLEND);
+
+		glColor4ub(0, 0, 0, 255);
+		sdrawline(x, y, pop->startmouse[0], pop->startmouse[1]);
+
+		glDisable(GL_BLEND);
+		glDisable(GL_LINE_SMOOTH);
+	}
+}
+
+
 static PaintOperation *texture_paint_init(bContext *C, wmOperator *op, float mouse[2])
 {
 	Scene *scene = CTX_data_scene(C);
-	ToolSettings *settings = scene->toolsettings;
+	ToolSettings *toolsettings = scene->toolsettings;
 	PaintOperation *pop = MEM_callocN(sizeof(PaintOperation), "PaintOperation"); /* caller frees */
+	Brush *brush = BKE_paint_brush(&toolsettings->imapaint.paint);
 	int mode = RNA_enum_get(op->ptr, "mode");
 	view3d_set_viewcontext(C, &pop->vc);
 
-	pop->prevmouse[0] = mouse[0];
-	pop->prevmouse[1] = mouse[1];
+	copy_v2_v2(pop->prevmouse, mouse);
+	copy_v2_v2(pop->startmouse, mouse);
 
+	if ((brush->imagepaint_tool == PAINT_TOOL_FILL) && (brush->flag & BRUSH_USE_GRADIENT)) {
+		pop->cursor = WM_paint_cursor_activate(CTX_wm_manager(C), image_paint_poll, gradient_draw_line, pop);
+	}
+
 	/* initialize from context */
 	if (CTX_wm_region_view3d(C)) {
 		pop->mode = PAINT_MODE_3D_PROJECT;
-		pop->custom_paint = paint_proj_new_stroke(C, OBACT, pop->prevmouse, mode);
+		pop->custom_paint = paint_proj_new_stroke(C, OBACT, mouse, mode);
 	}
 	else {
 		pop->mode = PAINT_MODE_2D;
@@ -604,7 +626,7 @@
 		return NULL;
 	}
 
-	settings->imapaint.flag |= IMAGEPAINT_DRAWING;
+	toolsettings->imapaint.flag |= IMAGEPAINT_DRAWING;
 	undo_paint_push_begin(UNDO_PAINT_IMAGE, op->type->name,
 	                      image_undo_restore, image_undo_free);
 
@@ -638,6 +660,13 @@
 	float size;
 	int eraser;
 
+	/* stroking with fill tool only acts on stroke end */
+	if (brush->imagepaint_tool == PAINT_TOOL_FILL) {
+		pop->prevmouse[0] = mouse[0];
+		pop->prevmouse[1] = mouse[1];
+		return;
+	}
+
 	RNA_float_get_array(itemptr, "mouse", mouse);
 	pressure = RNA_float_get(itemptr, "pressure");
 	eraser = RNA_boolean_get(itemptr, "pen_flip");
@@ -684,11 +713,26 @@
 static void paint_stroke_done(const bContext *C, struct PaintStroke *stroke)
 {
 	Scene *scene = CTX_data_scene(C);
-	ToolSettings *settings = scene->toolsettings;
+	ToolSettings *toolsettings = scene->toolsettings;
 	PaintOperation *pop = paint_stroke_mode_data(stroke);
+	Brush *brush = BKE_paint_brush(&toolsettings->imapaint.paint);
 
-	settings->imapaint.flag &= ~IMAGEPAINT_DRAWING;
+	toolsettings->imapaint.flag &= ~IMAGEPAINT_DRAWING;
 
+	if (brush->imagepaint_tool == PAINT_TOOL_FILL) {
+		if (brush->flag & BRUSH_USE_GRADIENT) {
+
+		}
+		else {
+			float color[3];
+
+			srgb_to_linearrgb_v3_v3(color, brush->rgb);
+
+			if (pop->mode == PAINT_MODE_2D) {
+				paint_2d_bucket_fill(C, color);
+			}
+		}
+	}
 	if (pop->mode == PAINT_MODE_3D_PROJECT) {
 		paint_proj_stroke_done(pop->custom_paint);
 	}
@@ -696,6 +740,10 @@
 		paint_2d_stroke_done(pop->custom_paint);
 	}
 
+	if (pop->cursor) {
+		WM_paint_cursor_end(CTX_wm_manager(C), pop->cursor);
+	}
+
 	image_undo_end();
 
 	/* duplicate warning, see texpaint_init */
@@ -1287,34 +1335,23 @@
 
 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);
+	else {		
+		Brush *br = image_paint_brush(C);
 
 		srgb_to_linearrgb_v3_v3(color, br->rgb);
 	}
 
-	mode = BKE_paintmode_get_active_from_context(C);
-
 	undo_paint_push_begin(UNDO_PAINT_IMAGE, op->type->name,
 	                      image_undo_restore, image_undo_free);
-	switch(mode) {
-		case PAINT_TEXTURE_2D:
-			paint_2d_bucket_fill(C, color);
-			break;
-		case PAINT_TEXTURE_PROJECTIVE:
-			break;
-		default:
-			break;
-	}
 
+	paint_2d_bucket_fill(C, color);
+
 	undo_paint_push_end(UNDO_PAINT_IMAGE);
 
 	RNA_float_set_array(op->ptr, "color", color);
@@ -1340,82 +1377,7 @@
 	RNA_def_float_color(ot->srna, "color", 3, NULL, 0.0, 1.0, "Color", "Color for bucket fill", 0.0, 1.0);
 }
 
-typedef struct GradientFillData {
-	int mouse_init[2];
-//	int x_init, y_init;
-	bool started;
-	void *cursor;
-} GradientFillData;
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list