[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44898] trunk/blender/source/blender/ makesrna/intern/rna_brush.c: Add RNA for brush capabilities ( sculpt-only for now.)

Nicholas Bishop nicholasbishop at gmail.com
Thu Mar 15 10:11:08 CET 2012


Revision: 44898
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44898
Author:   nicholasbishop
Date:     2012-03-15 09:10:54 +0000 (Thu, 15 Mar 2012)
Log Message:
-----------
Add RNA for brush capabilities (sculpt-only for now.)

Added a new RNA-only nested structure, Brush.SculptCapabilities. It
contains read-only properties that use the current sculpt tool (and
occasionally other brush properties) to determine whether some feature
is available.

For example, the grab and snake-hook brushes don't support the
strength property. Querying brush.sculpt_capabilities.has_strength
will return false only if one of these brushes is selected.

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/intern/rna_brush.c

Modified: trunk/blender/source/blender/makesrna/intern/rna_brush.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_brush.c	2012-03-15 06:51:09 UTC (rev 44897)
+++ trunk/blender/source/blender/makesrna/intern/rna_brush.c	2012-03-15 09:10:54 UTC (rev 44898)
@@ -100,6 +100,125 @@
 
 #include "WM_api.h"
 
+static int rna_SculptCapabilities_has_accumulate_get(PointerRNA *ptr)
+{
+	Brush *br = (Brush*)ptr->data;
+	return ELEM6(br->sculpt_tool,
+				 SCULPT_TOOL_BLOB, SCULPT_TOOL_CLAY, SCULPT_TOOL_CREASE,
+				 SCULPT_TOOL_DRAW, SCULPT_TOOL_INFLATE, SCULPT_TOOL_LAYER);
+}
+
+static int rna_SculptCapabilities_has_auto_smooth_get(PointerRNA *ptr)
+{
+	Brush *br = (Brush*)ptr->data;
+	return br->sculpt_tool != SCULPT_TOOL_SMOOTH;
+}
+
+static int rna_SculptCapabilities_has_height_get(PointerRNA *ptr)
+{
+	Brush *br = (Brush*)ptr->data;
+	return br->sculpt_tool == SCULPT_TOOL_LAYER;
+}
+
+static int rna_SculptCapabilities_has_jitter_get(PointerRNA *ptr)
+{
+	Brush *br = (Brush*)ptr->data;
+	return (!(br->flag & BRUSH_ANCHORED) &&
+			!(br->flag & BRUSH_RESTORE_MESH) &&
+			!ELEM4(br->sculpt_tool,
+				   SCULPT_TOOL_GRAB, SCULPT_TOOL_ROTATE,
+				   SCULPT_TOOL_SNAKE_HOOK, SCULPT_TOOL_THUMB));
+}
+
+static int rna_SculptCapabilities_has_normal_weight_get(PointerRNA *ptr)
+{
+	Brush *br = (Brush*)ptr->data;
+	return ELEM(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_SNAKE_HOOK);
+}
+
+static int rna_SculptCapabilities_has_persistence_get(PointerRNA *ptr)
+{
+	Brush *br = (Brush*)ptr->data;
+	return br->sculpt_tool == SCULPT_TOOL_LAYER;
+}
+
+static int rna_SculptCapabilities_has_pinch_factor_get(PointerRNA *ptr)
+{
+	Brush *br = (Brush*)ptr->data;
+	return ELEM(br->sculpt_tool, SCULPT_TOOL_BLOB, SCULPT_TOOL_CREASE);
+}
+
+static int rna_SculptCapabilities_has_plane_offset_get(PointerRNA *ptr)
+{
+	Brush *br = (Brush*)ptr->data;
+	return ELEM4(br->sculpt_tool, SCULPT_TOOL_CLAY, SCULPT_TOOL_FILL,
+				 SCULPT_TOOL_FLATTEN, SCULPT_TOOL_SCRAPE);
+}
+
+static int rna_SculptCapabilities_has_random_texture_angle_get(PointerRNA *ptr)
+{
+	Brush *br = (Brush*)ptr->data;
+	return ((br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) &&
+			!(br->flag & BRUSH_ANCHORED) &&
+			!ELEM4(br->sculpt_tool,
+				   SCULPT_TOOL_GRAB, SCULPT_TOOL_ROTATE,
+				   SCULPT_TOOL_SNAKE_HOOK, SCULPT_TOOL_THUMB));
+}
+
+static int rna_SculptCapabilities_has_sculpt_plane_get(PointerRNA *ptr)
+{
+	Brush *br = (Brush*)ptr->data;
+	return !ELEM3(br->sculpt_tool, SCULPT_TOOL_INFLATE, SCULPT_TOOL_PINCH,
+				  SCULPT_TOOL_SMOOTH);
+}
+
+static int rna_SculptCapabilities_has_secondary_color_get(PointerRNA *ptr)
+{
+	Brush *br = (Brush*)ptr->data;
+	return ELEM9(br->sculpt_tool,
+				 SCULPT_TOOL_BLOB, SCULPT_TOOL_CLAY, SCULPT_TOOL_CREASE,
+				 SCULPT_TOOL_DRAW, SCULPT_TOOL_FILL, SCULPT_TOOL_FLATTEN,
+				 SCULPT_TOOL_INFLATE, SCULPT_TOOL_PINCH, SCULPT_TOOL_SCRAPE);
+}
+
+static int rna_SculptCapabilities_has_smooth_stroke_get(PointerRNA *ptr)
+{
+	Brush *br = (Brush*)ptr->data;
+	return (!(br->flag & BRUSH_ANCHORED) &&
+			!(br->flag & BRUSH_RESTORE_MESH) &&
+			!ELEM4(br->sculpt_tool,
+				   SCULPT_TOOL_GRAB, SCULPT_TOOL_ROTATE,
+				   SCULPT_TOOL_SNAKE_HOOK, SCULPT_TOOL_THUMB));
+}
+
+static int rna_SculptCapabilities_has_space_attenuation_get(PointerRNA *ptr)
+{
+	Brush *br = (Brush*)ptr->data;
+	return ((br->flag & BRUSH_SPACE) &&
+			!ELEM4(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_ROTATE,
+			   SCULPT_TOOL_SMOOTH, SCULPT_TOOL_SNAKE_HOOK));
+}
+
+static int rna_SculptCapabilities_has_spacing_get(PointerRNA *ptr)
+{
+	Brush *br = (Brush*)ptr->data;
+	return (!(br->flag & BRUSH_ANCHORED) &&
+			!ELEM4(br->sculpt_tool,
+				   SCULPT_TOOL_GRAB, SCULPT_TOOL_ROTATE,
+				   SCULPT_TOOL_SNAKE_HOOK, SCULPT_TOOL_THUMB));
+}
+
+static int rna_SculptCapabilities_has_strength_get(PointerRNA *ptr)
+{
+	Brush *br = (Brush*)ptr->data;
+	return !ELEM(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_SNAKE_HOOK);
+}
+
+static PointerRNA rna_Brush_sculpt_capabilities_get(PointerRNA *ptr)
+{
+	return rna_pointer_inherit_refine(ptr, &RNA_SculptCapabilities, ptr->id.data);
+}
+
 static void rna_Brush_reset_icon(Brush *br, const char *UNUSED(type))
 {
 	ID *id = &br->id;
@@ -271,6 +390,45 @@
 	RNA_def_property_update(prop, 0, "rna_TextureSlot_update");
 }
 
+static void rna_def_sculpt_capabilities(BlenderRNA *brna)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+
+	srna = RNA_def_struct(brna, "SculptCapabilities", NULL);
+	RNA_def_struct_sdna(srna, "Brush");
+	RNA_def_struct_nested(brna, srna, "Brush");
+	RNA_def_struct_ui_text(srna, "Sculpt Capabilities",
+						   "Read-only indications of which brush operations "
+						   "are supported by the current sculpt tool");
+
+#define BRUSH_CAPABILITY(prop_name_, ui_name_)							\
+	prop = RNA_def_property(srna, #prop_name_,							\
+							PROP_BOOLEAN, PROP_NONE);					\
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);					\
+	RNA_def_property_boolean_funcs(prop, "rna_SculptCapabilities_"		\
+								   #prop_name_ "_get", NULL);			\
+	RNA_def_property_ui_text(prop, ui_name_, NULL)
+
+	BRUSH_CAPABILITY(has_accumulate, "Has Accumulate");
+	BRUSH_CAPABILITY(has_auto_smooth, "Has Auto Smooth");
+	BRUSH_CAPABILITY(has_height, "Has Height");
+	BRUSH_CAPABILITY(has_jitter, "Has Jitter");
+	BRUSH_CAPABILITY(has_normal_weight, "Has Crease/Pinch Factor");
+	BRUSH_CAPABILITY(has_persistence, "Has Persistence");
+	BRUSH_CAPABILITY(has_pinch_factor, "Has Pinch Factor");
+	BRUSH_CAPABILITY(has_plane_offset, "Has Plane Offset");
+	BRUSH_CAPABILITY(has_random_texture_angle, "Has Random Texture Angle");
+	BRUSH_CAPABILITY(has_sculpt_plane, "Has Sculpt Plane");
+	BRUSH_CAPABILITY(has_secondary_color, "Has Secondary Color");
+	BRUSH_CAPABILITY(has_smooth_stroke, "Has Smooth Stroke");
+	BRUSH_CAPABILITY(has_space_attenuation, "Has Space Attenuation");
+	BRUSH_CAPABILITY(has_spacing, "Has Spacing");
+	BRUSH_CAPABILITY(has_strength, "Has Strength");
+
+#undef SCULPT_CAPABILITY
+}
+
 static void rna_def_brush(BlenderRNA *brna)
 {
 	StructRNA *srna;
@@ -701,6 +859,13 @@
 	RNA_def_property_ui_text(prop, "Clone Offset", "");
 	RNA_def_property_ui_range(prop, -1.0f , 1.0f, 10.0f, 3);
 	RNA_def_property_update(prop, NC_SPACE|ND_SPACE_IMAGE, "rna_Brush_update");
+
+	/* brush capabilities (mode-dependent) */
+	prop = RNA_def_property(srna, "sculpt_capabilities", PROP_POINTER, PROP_NONE);
+	RNA_def_property_flag(prop, PROP_NEVER_NULL);
+	RNA_def_property_struct_type(prop, "SculptCapabilities");
+	RNA_def_property_pointer_funcs(prop, "rna_Brush_sculpt_capabilities_get", NULL, NULL, NULL);
+	RNA_def_property_ui_text(prop, "Sculpt Capabilities", "Brush's capabilities in sculpt mode");
 }
 
 
@@ -760,6 +925,7 @@
 void RNA_def_brush(BlenderRNA *brna)
 {
 	rna_def_brush(brna);
+	rna_def_sculpt_capabilities(brna);
 	rna_def_brush_texture_slot(brna);
 	rna_def_operator_stroke_element(brna);
 }




More information about the Bf-blender-cvs mailing list