[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43337] trunk/blender: Fix some RNA/ scene issuess with unified paint settings.

Nicholas Bishop nicholasbishop at gmail.com
Thu Jan 12 22:48:10 CET 2012


Revision: 43337
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43337
Author:   nicholasbishop
Date:     2012-01-12 21:48:08 +0000 (Thu, 12 Jan 2012)
Log Message:
-----------
Fix some RNA/scene issuess with unified paint settings.

Added RNA for the unified paint setting flags that matches the Brush
RNA. Fixed the getter/setter functions to avoid guessing which Scene's
UnifiedPaintSetting to use. The getter functions take a Scene pointer
now, the setter functions are removed in favor of a more explicit
approach through RNA:

Rather than RNA choosing whether a property's value is in the Brush or
in the UnifiedPaintSettings, there are now explicit properties for
both. The UI code has been modified accordingly to switch the toggle
buttons between affecting the Brush and the UnifiedPaintSettings.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    trunk/blender/source/blender/blenkernel/BKE_brush.h
    trunk/blender/source/blender/blenkernel/intern/brush.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c
    trunk/blender/source/blender/editors/sculpt_paint/sculpt.c
    trunk/blender/source/blender/makesrna/intern/rna_brush.c
    trunk/blender/source/blender/makesrna/intern/rna_scene.c

Modified: trunk/blender/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2012-01-12 21:47:14 UTC (rev 43336)
+++ trunk/blender/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2012-01-12 21:48:08 UTC (rev 43337)
@@ -475,7 +475,18 @@
         parent.prop(ups, "use_unified_size", text="Size")
         parent.prop(ups, "use_unified_strength", text="Strength")
 
+    @staticmethod
+    def prop_unified_size(parent, context, brush, prop_name, icon='NONE', text=""):
+        ups = context.tool_settings.unified_paint_settings
+        ptr = ups if ups.use_unified_size else brush
+        parent.prop(ptr, prop_name, icon=icon, text=text)
 
+    @staticmethod
+    def prop_unified_strength(parent, context, brush, prop_name, icon='NONE', text=""):
+        ups = context.tool_settings.unified_paint_settings
+        ptr = ups if ups.use_unified_strength else brush
+        parent.prop(ptr, prop_name, icon=icon, text=text)
+
 class VIEW3D_PT_tools_brush(PaintPanel, Panel):
     bl_label = "Brush"
 
@@ -530,14 +541,16 @@
 
             row = col.row(align=True)
 
-            if brush.use_locked_size:
-                row.prop(brush, "use_locked_size", toggle=True, text="", icon='LOCKED')
+            ups = context.tool_settings.unified_paint_settings
+            if ((ups.use_unified_size and ups.use_locked_size) or
+                ((not ups.use_unified_size) and brush.use_locked_size)):
+                self.prop_unified_size(row, context, brush, "use_locked_size", icon='LOCKED')
                 row.prop(brush, "unprojected_radius", text="Radius", slider=True)
             else:
-                row.prop(brush, "use_locked_size", toggle=True, text="", icon='UNLOCKED')
+                self.prop_unified_size(row, context, brush, "use_locked_size", icon='UNLOCKED')
                 row.prop(brush, "size", slider=True)
 
-            row.prop(brush, "use_pressure_size", toggle=True, text="")
+            self.prop_unified_size(row, context, brush, "use_pressure_size")
 
             if tool not in {'SNAKE_HOOK', 'GRAB', 'ROTATE'}:
                 col.separator()
@@ -551,12 +564,12 @@
                         row.prop(brush, "use_space_atten", toggle=True, text="", icon='UNLOCKED')
 
                 row.prop(brush, "strength", text="Strength", slider=True)
-                row.prop(brush, "use_pressure_strength", text="")
+                self.prop_unified_strength(row, context, brush, "use_pressure_strength")
 
             if tool == 'ROTATE':
                 row = col.row(align=True)
                 row.prop(brush, "strength", text="Strength", slider=True)
-                row.prop(brush, "use_pressure_strength", text="")
+                self.prop_unified_strength(row, context, brush, "use_pressure_strength")
 
             if tool != 'SMOOTH':
                 col.separator()
@@ -644,11 +657,11 @@
 
             row = col.row(align=True)
             row.prop(brush, "size", slider=True)
-            row.prop(brush, "use_pressure_size", toggle=True, text="")
+            self.prop_unified_size(row, context, brush, "use_pressure_size")
 
             row = col.row(align=True)
             row.prop(brush, "strength", text="Strength", slider=True)
-            row.prop(brush, "use_pressure_strength", toggle=True, text="")
+            self.prop_unified_strength(row, context, brush, "use_pressure_strength")
 
             row = col.row(align=True)
             row.prop(brush, "jitter", slider=True)
@@ -670,11 +683,11 @@
 
             row = col.row(align=True)
             row.prop(brush, "size", slider=True)
-            row.prop(brush, "use_pressure_size", toggle=True, text="")
+            self.prop_unified_size(row, context, brush, "use_pressure_size")
 
             row = col.row(align=True)
             row.prop(brush, "strength", text="Strength", slider=True)
-            row.prop(brush, "use_pressure_strength", toggle=True, text="")
+            self.prop_unified_strength(row, context, brush, "use_pressure_strength")
 
             row = col.row(align=True)
             row.prop(brush, "jitter", slider=True)
@@ -688,11 +701,11 @@
 
             row = col.row(align=True)
             row.prop(brush, "size", slider=True)
-            row.prop(brush, "use_pressure_size", toggle=True, text="")
+            self.prop_unified_size(row, context, brush, "use_pressure_size")
 
             row = col.row(align=True)
             row.prop(brush, "strength", text="Strength", slider=True)
-            row.prop(brush, "use_pressure_strength", toggle=True, text="")
+            self.prop_unified_strength(row, context, brush, "use_pressure_strength")
 
             # XXX - TODO
             #row = col.row(align=True)

Modified: trunk/blender/source/blender/blenkernel/BKE_brush.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_brush.h	2012-01-12 21:47:14 UTC (rev 43336)
+++ trunk/blender/source/blender/blenkernel/BKE_brush.h	2012-01-12 21:48:08 UTC (rev 43337)
@@ -76,7 +76,7 @@
 typedef struct BrushPainter BrushPainter;
 typedef int (*BrushFunc)(void *user, struct ImBuf *ibuf, float *lastpos, float *pos);
 
-BrushPainter *brush_painter_new(struct Brush *brush);
+BrushPainter *brush_painter_new(struct Scene *scene, struct Brush *brush);
 void brush_painter_require_imbuf(BrushPainter *painter, short flt,
 	short texonly, int size);
 int brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos,
@@ -95,15 +95,10 @@
 int  brush_size(struct Brush *brush);
 void brush_set_size(struct Brush *brush, int value);
 
-int  brush_use_locked_size(struct Brush *brush);
-void brush_set_use_locked_size(struct Brush *brush, int value);
+int  brush_use_locked_size(const struct Scene *scene, struct Brush *brush);
+int  brush_use_alpha_pressure(const struct Scene *scene, struct Brush *brush);
+int  brush_use_size_pressure(const struct Scene *scene, struct Brush *brush);
 
-int  brush_use_alpha_pressure(struct Brush *brush);
-void brush_set_use_alpha_pressure(struct Brush *brush, int value);
-
-int  brush_use_size_pressure(struct Brush *brush);
-void brush_set_use_size_pressure(struct Brush *brush, int value);
-
 float brush_unprojected_radius(struct Brush *brush);
 void  brush_set_unprojected_radius(struct Brush *brush, float value);
 

Modified: trunk/blender/source/blender/blenkernel/intern/brush.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/brush.c	2012-01-12 21:47:14 UTC (rev 43336)
+++ trunk/blender/source/blender/blenkernel/intern/brush.c	2012-01-12 21:48:08 UTC (rev 43337)
@@ -642,6 +642,7 @@
 } BrushPainterCache;
 
 struct BrushPainter {
+	Scene *scene;
 	Brush *brush;
 
 	float lastmousepos[2];	/* mouse position of last paint call */
@@ -665,11 +666,12 @@
 	BrushPainterCache cache;
 };
 
-BrushPainter *brush_painter_new(Brush *brush)
+BrushPainter *brush_painter_new(Scene *scene, Brush *brush)
 {
 	BrushPainter *painter= MEM_callocN(sizeof(BrushPainter), "BrushPainter");
 
 	painter->brush= brush;
+	painter->scene= scene;
 	painter->firsttouch= 1;
 	painter->cache.lastsize= -1; /* force ibuf create in refresh */
 
@@ -917,9 +919,9 @@
 
 static void brush_apply_pressure(BrushPainter *painter, Brush *brush, float pressure)
 {
-	if (brush_use_alpha_pressure(brush)) 
+	if (brush_use_alpha_pressure(painter->scene, brush)) 
 		brush_set_alpha(brush, MAX2(0.0f, painter->startalpha*pressure));
-	if (brush_use_size_pressure(brush))
+	if (brush_use_size_pressure(painter->scene, brush))
 		brush_set_size(brush, MAX2(1.0f, painter->startsize*pressure));
 	if (brush->flag & BRUSH_JITTER_PRESSURE)
 		brush->jitter = MAX2(0.0f, painter->startjitter*pressure);
@@ -1219,25 +1221,6 @@
 /* XXX, wouldnt it be better to only pass the active scene?
  * this can return any old scene! - campbell*/
 
-static void set_unified_settings(Brush *brush, short flag, int value)
-{
-	Scene *sce;
-	for (sce= G.main->scene.first; sce; sce= sce->id.next) {
-		if (sce->toolsettings && 
-			ELEM4(brush,
-			    paint_brush(&(sce->toolsettings->imapaint.paint)),
-			    paint_brush(&(sce->toolsettings->vpaint->paint)),
-			    paint_brush(&(sce->toolsettings->wpaint->paint)),
-			    paint_brush(&(sce->toolsettings->sculpt->paint))))
-		{
-			if (value)
-				sce->toolsettings->unified_paint_settings.flag |= flag;
-			else
-				sce->toolsettings->unified_paint_settings.flag &= ~flag;
-		}
-	}
-}
-
 static short unified_settings(Brush *brush)
 {
 	Scene *sce;
@@ -1389,79 +1372,28 @@
 	return (us_flag & UNIFIED_PAINT_SIZE) ? unified_size(brush) : brush->size;
 }
 
-void brush_set_use_locked_size(Brush *brush, int value)
+int brush_use_locked_size(const Scene *scene, Brush *brush)
 {
-	const short us_flag = unified_settings(brush);
+	const short us_flag = scene->toolsettings->unified_paint_settings.flag;
 
-	if (us_flag & UNIFIED_PAINT_SIZE) {
-		set_unified_settings(brush, UNIFIED_PAINT_BRUSH_LOCK_SIZE, value);
-	}
-	else {
-		if (value)
-			brush->flag |= BRUSH_LOCK_SIZE;
-		else
-			brush->flag &= ~BRUSH_LOCK_SIZE;
-	}
-
-	//WM_main_add_notifier(NC_BRUSH|NA_EDITED, brush);
-}
-
-int brush_use_locked_size(Brush *brush)
-{
-	const short us_flag = unified_settings(brush);
-
 	return (us_flag & UNIFIED_PAINT_SIZE) ?
 	        (us_flag & UNIFIED_PAINT_BRUSH_LOCK_SIZE) :
 	        (brush->flag & BRUSH_LOCK_SIZE);
 }
 
-void brush_set_use_size_pressure(Brush *brush, int value)
+int brush_use_size_pressure(const Scene *scene, Brush *brush)
 {
-	const short us_flag = unified_settings(brush);
+	const short us_flag = scene->toolsettings->unified_paint_settings.flag;
 
-	if (us_flag & UNIFIED_PAINT_SIZE) {
-		set_unified_settings(brush, UNIFIED_PAINT_BRUSH_SIZE_PRESSURE, value);
-	}
-	else {
-		if (value)
-			brush->flag |= BRUSH_SIZE_PRESSURE;
-		else
-			brush->flag &= ~BRUSH_SIZE_PRESSURE;
-	}
-
-	//WM_main_add_notifier(NC_BRUSH|NA_EDITED, brush);
-}
-
-int brush_use_size_pressure(Brush *brush)
-{
-	const short us_flag = unified_settings(brush);
-
 	return (us_flag & UNIFIED_PAINT_SIZE) ?
 	        (us_flag & UNIFIED_PAINT_BRUSH_SIZE_PRESSURE) :
 	        (brush->flag & BRUSH_SIZE_PRESSURE);
 }
 
-void brush_set_use_alpha_pressure(Brush *brush, int value)
+int brush_use_alpha_pressure(const Scene *scene, Brush *brush)
 {
-	const short us_flag = unified_settings(brush);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list