[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47392] trunk/blender/source/blender: Fix #31093: Brush's "Paint curve presets" in Image paint in UV\Image Editor doesn' t work if weight paint mode is active

Sergey Sharybin sergey.vfx at gmail.com
Mon Jun 4 09:29:53 CEST 2012


Revision: 47392
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47392
Author:   nazgul
Date:     2012-06-04 07:29:45 +0000 (Mon, 04 Jun 2012)
Log Message:
-----------
Fix #31093: Brush's "Paint curve presets" in Image paint in UV\Image Editor doesn't work if weight paint mode is active

Some operators like curve presets, color sample and some more were using object's
mode to distinguish in which mode user is currently painting. Such approach fails
in cases when there's paint mode active in 3D viewport and Image Editor.

Changed logic here to use some context's state like active space which helps
distinguishing current paint mode more accurate.

Ported all areas which uses paint_get_active() to new paint_get_active_from_context().
There're still some calls to paint_get_active(), but that shouldn't be harmful due
to that places indeed have object's mode as priority when getting paint mode.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_paint.h
    trunk/blender/source/blender/blenkernel/intern/paint.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h
    trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_utils.c
    trunk/blender/source/blender/editors/space_buttons/buttons_texture.c
    trunk/blender/source/blender/editors/space_view3d/view3d_edit.c

Modified: trunk/blender/source/blender/blenkernel/BKE_paint.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_paint.h	2012-06-04 07:24:19 UTC (rev 47391)
+++ trunk/blender/source/blender/blenkernel/BKE_paint.h	2012-06-04 07:29:45 UTC (rev 47392)
@@ -32,6 +32,7 @@
  *  \ingroup bke
  */
 
+struct bContext;
 struct Brush;
 struct MDisps;
 struct MeshElemMap;
@@ -55,6 +56,7 @@
 void copy_paint(struct Paint *src, struct Paint *tar);
 
 struct Paint *paint_get_active(struct Scene *sce);
+struct Paint *paint_get_active_from_context(const struct bContext *C);
 struct Brush *paint_brush(struct Paint *paint);
 void paint_brush_set(struct Paint *paint, struct Brush *br);
 

Modified: trunk/blender/source/blender/blenkernel/intern/paint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/paint.c	2012-06-04 07:24:19 UTC (rev 47391)
+++ trunk/blender/source/blender/blenkernel/intern/paint.c	2012-06-04 07:29:45 UTC (rev 47392)
@@ -41,6 +41,7 @@
 #include "BLI_utildefines.h"
 
 #include "BKE_brush.h"
+#include "BKE_context.h"
 #include "BKE_library.h"
 #include "BKE_paint.h"
 #include "BKE_subsurf.h"
@@ -83,6 +84,53 @@
 	return NULL;
 }
 
+Paint *paint_get_active_from_context(const bContext *C)
+{
+	Scene *sce = CTX_data_scene(C);
+
+	if (sce) {
+		ToolSettings *ts = sce->toolsettings;
+		Object *obact = NULL;
+
+		if (sce->basact && sce->basact->object)
+			obact = sce->basact->object;
+
+		if (CTX_wm_space_image(C) != NULL) {
+			if (obact->mode == OB_MODE_EDIT) {
+				if (ts->use_uv_sculpt)
+					return &ts->uvsculpt->paint;
+				else
+					return &ts->imapaint.paint;
+			}
+			else {
+				return &ts->imapaint.paint;
+			}
+		}
+		else {
+			switch (obact->mode) {
+				case OB_MODE_SCULPT:
+					return &ts->sculpt->paint;
+				case OB_MODE_VERTEX_PAINT:
+					return &ts->vpaint->paint;
+				case OB_MODE_WEIGHT_PAINT:
+					return &ts->wpaint->paint;
+				case OB_MODE_TEXTURE_PAINT:
+					return &ts->imapaint.paint;
+				case OB_MODE_EDIT:
+					if (ts->use_uv_sculpt)
+						return &ts->uvsculpt->paint;
+					else
+						return &ts->imapaint.paint;
+			}
+
+			/* default to image paint */
+			return &ts->imapaint.paint;
+		}
+	}
+
+	return NULL;
+}
+
 Brush *paint_brush(Paint *p)
 {
 	return p ? p->brush : NULL;

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c	2012-06-04 07:24:19 UTC (rev 47391)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c	2012-06-04 07:29:45 UTC (rev 47392)
@@ -333,7 +333,7 @@
                                      float location[3])
 {
 	Scene *scene = CTX_data_scene(C);
-	Paint *paint = paint_get_active(scene);
+	Paint *paint = paint_get_active_from_context(C);
 	Brush *brush = paint_brush(paint);
 	float window[2];
 	int hit;
@@ -503,7 +503,7 @@
 static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
 {
 	Scene *scene = CTX_data_scene(C);
-	Paint *paint = paint_get_active(scene);
+	Paint *paint = paint_get_active_from_context(C);
 	Brush *brush = paint_brush(paint);
 	ViewContext vc;
 	float final_radius;
@@ -605,7 +605,7 @@
 
 void paint_cursor_start(bContext *C, int (*poll)(bContext *C))
 {
-	Paint *p = paint_get_active(CTX_data_scene(C));
+	Paint *p = paint_get_active_from_context(C);
 
 	if (p && !p->paint_cursor)
 		p->paint_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), poll, paint_draw_cursor, NULL);

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2012-06-04 07:24:19 UTC (rev 47391)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2012-06-04 07:29:45 UTC (rev 47392)
@@ -5215,7 +5215,7 @@
 
 	Scene *scene = CTX_data_scene(C);
 	//Brush *brush= image_paint_brush(C);
-	Paint *paint = paint_get_active(scene);
+	Paint *paint = paint_get_active_from_context(C);
 	Brush *brush = paint_brush(paint);
 
 	if (paint && brush && paint->flags & PAINT_SHOW_BRUSH) {
@@ -5420,13 +5420,12 @@
 
 static int sample_color_exec(bContext *C, wmOperator *op)
 {
-	Scene *scene = CTX_data_scene(C);
 	Brush *brush = image_paint_brush(C);
 	ARegion *ar = CTX_wm_region(C);
 	int location[2];
 
 	RNA_int_get_array(op->ptr, "location", location);
-	paint_sample_color(scene, ar, location[0], location[1]);
+	paint_sample_color(C, ar, location[0], location[1]);
 
 	WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
 	

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h	2012-06-04 07:24:19 UTC (rev 47391)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h	2012-06-04 07:29:45 UTC (rev 47392)
@@ -137,7 +137,7 @@
 int imapaint_pick_face(struct ViewContext *vc, const int mval[2], unsigned int *index, unsigned int totface);
 void imapaint_pick_uv(struct Scene *scene, struct Object *ob, unsigned int faceindex, const int xy[2], float uv[2]);
 
-void paint_sample_color(struct Scene *scene, struct ARegion *ar, int x, int y);
+void paint_sample_color(const struct bContext *C, struct ARegion *ar, int x, int y);
 void BRUSH_OT_curve_preset(struct wmOperatorType *ot);
 
 void PAINT_OT_face_select_linked(struct wmOperatorType *ot);

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c	2012-06-04 07:24:19 UTC (rev 47391)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c	2012-06-04 07:29:45 UTC (rev 47392)
@@ -60,7 +60,7 @@
 static int brush_add_exec(bContext *C, wmOperator *UNUSED(op))
 {
 	/*int type = RNA_enum_get(op->ptr, "type");*/
-	Paint *paint = paint_get_active(CTX_data_scene(C));
+	Paint *paint = paint_get_active_from_context(C);
 	struct Brush *br = paint_brush(paint);
 
 	if (br)
@@ -68,7 +68,7 @@
 	else
 		br = BKE_brush_add("Brush");
 
-	paint_brush_set(paint_get_active(CTX_data_scene(C)), br);
+	paint_brush_set(paint, br);
 
 	return OPERATOR_FINISHED;
 }
@@ -91,7 +91,7 @@
 static int brush_scale_size_exec(bContext *C, wmOperator *op)
 {
 	Scene *scene = CTX_data_scene(C);
-	Paint  *paint =  paint_get_active(scene);
+	Paint  *paint =  paint_get_active_from_context(C);
 	struct Brush  *brush =  paint_brush(paint);
 	// Object *ob=     CTX_data_active_object(C);
 	float scalar = RNA_float_get(op->ptr, "scalar");
@@ -173,7 +173,7 @@
 
 static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op))
 {
-	Paint *paint = paint_get_active(CTX_data_scene(C));
+	Paint *paint = paint_get_active_from_context(C);
 	struct Brush *brush = paint_brush(paint);
 	Object *ob = CTX_data_active_object(C);
 

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c	2012-06-04 07:24:19 UTC (rev 47391)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c	2012-06-04 07:29:45 UTC (rev 47392)
@@ -100,10 +100,11 @@
 /*** Cursor ***/
 static void paint_draw_smooth_stroke(bContext *C, int x, int y, void *customdata) 
 {
-	Brush *brush = paint_brush(paint_get_active(CTX_data_scene(C)));
+	Paint *paint = paint_get_active_from_context(C);
+	Brush *brush = paint_brush(paint);
 	PaintStroke *stroke = customdata;
 
-	glColor4ubv(paint_get_active(CTX_data_scene(C))->paint_cursor_col);
+	glColor4ubv(paint->paint_cursor_col);
 	glEnable(GL_LINE_SMOOTH);
 	glEnable(GL_BLEND);
 
@@ -141,7 +142,7 @@
 static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *event, float mouse_in[2])
 {
 	Scene *scene = CTX_data_scene(C);
-	Paint *paint = paint_get_active(scene);
+	Paint *paint = paint_get_active_from_context(C);
 	Brush *brush = paint_brush(paint);
 	PaintStroke *stroke = op->customdata;
 	float mouse[3];
@@ -281,7 +282,7 @@
 {
 	PaintStroke *stroke = MEM_callocN(sizeof(PaintStroke), "PaintStroke");
 
-	stroke->brush = paint_brush(paint_get_active(CTX_data_scene(C)));
+	stroke->brush = paint_brush(paint_get_active_from_context(C));
 	view3d_set_viewcontext(C, &stroke->vc);
 	view3d_get_transformation(stroke->vc.ar, stroke->vc.rv3d, stroke->vc.obact, &stroke->mats);
 
@@ -394,7 +395,7 @@
 
 int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event)
 {
-	Paint *p = paint_get_active(CTX_data_scene(C));
+	Paint *p = paint_get_active_from_context(C);
 	PaintStroke *stroke = op->customdata;
 	PaintSample sample_average;
 	float mouse[2];
@@ -518,7 +519,7 @@
 
 int paint_poll(bContext *C)
 {
-	Paint *p = paint_get_active(CTX_data_scene(C));
+	Paint *p = paint_get_active_from_context(C);
 	Object *ob = CTX_data_active_object(C);
 
 	return p && ob && paint_brush(p) &&

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_utils.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_utils.c	2012-06-04 07:24:19 UTC (rev 47391)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_utils.c	2012-06-04 07:29:45 UTC (rev 47392)
@@ -333,9 +333,9 @@
 }
 
 /* used for both 3d view and image window */
-void paint_sample_color(Scene *scene, ARegion *ar, int x, int y)    /* frontbuf */
+void paint_sample_color(const bContext *C, ARegion *ar, int x, int y)    /* frontbuf */
 {
-	Brush *br = paint_brush(paint_get_active(scene));
+	Brush *br = paint_brush(paint_get_active_from_context(C));
 	unsigned int col;
 	char *cp;
 
@@ -357,7 +357,7 @@
 
 static int brush_curve_preset_exec(bContext *C, wmOperator *op)
 {
-	Brush *br = paint_brush(paint_get_active(CTX_data_scene(C)));
+	Brush *br = paint_brush(paint_get_active_from_context(C));
 	BKE_brush_curve_preset(br, RNA_enum_get(op->ptr, "shape"));
 
 	return OPERATOR_FINISHED;
@@ -365,7 +365,7 @@
 
 static int brush_curve_preset_poll(bContext *C)
 {
-	Brush *br = paint_brush(paint_get_active(CTX_data_scene(C)));
+	Brush *br = paint_brush(paint_get_active_from_context(C));
 
 	return br && br->curve;
 }

Modified: trunk/blender/source/blender/editors/space_buttons/buttons_texture.c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list