[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [35930] trunk/blender: Add back sculpt mode brush keys.

Campbell Barton ideasman42 at gmail.com
Fri Apr 1 08:14:40 CEST 2011


Revision: 35930
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35930
Author:   campbellbarton
Date:     2011-04-01 06:14:39 +0000 (Fri, 01 Apr 2011)
Log Message:
-----------
Add back sculpt mode brush keys.
Operator for switching brushes based on type, cycling through brushes when multiple exist.

This has the advantages over the old method that it doenst rely on hard coded brush names and if there are multiple brushes of the same type it cycles between them.

also fix error in previous commit which broke number buttons changing brushes.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_operators/wm.py
    trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c

Modified: trunk/blender/release/scripts/startup/bl_operators/wm.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_operators/wm.py	2011-04-01 04:22:30 UTC (rev 35929)
+++ trunk/blender/release/scripts/startup/bl_operators/wm.py	2011-04-01 06:14:39 UTC (rev 35930)
@@ -95,7 +95,7 @@
             return {'CANCELLED'}
 
         for i, brush in enumerate((cur for cur in bpy.data.brushes if getattr(cur, attr))):
-            if i == self.number:
+            if i == self.index:
                 getattr(context.tool_settings, self.mode).brush = brush
                 return {'FINISHED'}
 

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c	2011-04-01 04:22:30 UTC (rev 35929)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c	2011-04-01 06:14:39 UTC (rev 35930)
@@ -28,10 +28,12 @@
 
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_brush_types.h"
 
 #include "BKE_brush.h"
 #include "BKE_context.h"
 #include "BKE_paint.h"
+#include "BKE_main.h"
 
 #include "ED_sculpt.h"
 #include "ED_screen.h"
@@ -42,12 +44,14 @@
 
 #include "RNA_access.h"
 #include "RNA_define.h"
+#include "RNA_enum_types.h"
 
 #include "paint_intern.h"
 #include "sculpt_intern.h"
 
 #include <string.h>
 //#include <stdio.h>
+#include <stddef.h>
 
 /* Brush operators */
 static int brush_add_exec(bContext *C, wmOperator *UNUSED(op))
@@ -191,6 +195,148 @@
 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+/* generic functions for setting the active brush based on the tool */
+static Brush *brush_tool_cycle(Main *bmain, Brush *brush_orig, const int tool, const size_t tool_offset, const int ob_mode)
+{
+	struct Brush *brush;
+
+	if(!brush_orig && !(brush_orig= bmain->brush.first)) {
+		return NULL;
+	}
+
+	/* get the next brush with the active tool */
+	for(	brush= brush_orig->id.next ? brush_orig->id.next : bmain->brush.first;
+			brush != brush_orig;
+			brush= brush->id.next ? brush->id.next : bmain->brush.first)
+	{
+		if(	(brush->ob_mode & ob_mode) &&
+			(*(((char *)brush) + tool_offset) == tool)
+		) {
+			return brush;
+		}
+	}
+
+	return NULL;
+
+}
+
+static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool, const size_t tool_offset, const int ob_mode)
+{
+	struct Brush *brush, *brush_orig= paint_brush(paint);
+
+	brush= brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);
+
+	if(brush) {
+		paint_brush_set(paint, brush);
+		WM_main_add_notifier(NC_BRUSH|NA_EDITED, brush);
+		return OPERATOR_FINISHED;
+	}
+	else {
+		return OPERATOR_CANCELLED;
+	}
+}
+
+static int brush_sculpt_tool_set_exec(bContext *C, wmOperator *op)
+{
+	Main *bmain= CTX_data_main(C);
+	Scene *scene= CTX_data_scene(C);
+
+	return brush_generic_tool_set(bmain, &scene->toolsettings->sculpt->paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, sculpt_tool), OB_MODE_SCULPT);
+}
+
+static void BRUSH_OT_sculpt_tool_set(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Sculpt Tool Set";
+	ot->description= "Set the sculpt tool";
+	ot->idname= "BRUSH_OT_sculpt_tool_set";
+
+	/* api callbacks */
+	ot->exec= brush_sculpt_tool_set_exec;
+
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+	/* props */
+	ot->prop= RNA_def_enum(ot->srna, "tool", brush_sculpt_tool_items, 0, "Tool", "");
+}
+
+static int brush_vertex_tool_set_exec(bContext *C, wmOperator *op)
+{
+	Main *bmain= CTX_data_main(C);
+	Scene *scene= CTX_data_scene(C);
+
+	return brush_generic_tool_set(bmain, &scene->toolsettings->vpaint->paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, vertexpaint_tool), OB_MODE_VERTEX_PAINT);
+}
+
+static void BRUSH_OT_vertex_tool_set(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Vertex Paint Tool Set";
+	ot->description= "Set the vertex paint tool";
+	ot->idname= "BRUSH_OT_vertex_tool_set";
+
+	/* api callbacks */
+	ot->exec= brush_vertex_tool_set_exec;
+
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+	/* props */
+	ot->prop= RNA_def_enum(ot->srna, "tool", brush_vertex_tool_items, 0, "Tool", "");
+}
+
+static int brush_weight_tool_set_exec(bContext *C, wmOperator *op)
+{
+	Main *bmain= CTX_data_main(C);
+	Scene *scene= CTX_data_scene(C);
+	/* vertexpaint_tool is used for weight paint mode */
+	return brush_generic_tool_set(bmain, &scene->toolsettings->wpaint->paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, vertexpaint_tool), OB_MODE_WEIGHT_PAINT);
+}
+
+static void BRUSH_OT_weight_tool_set(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Weight Paint Tool Set";
+	ot->description= "Set the weight paint tool";
+	ot->idname= "BRUSH_OT_weight_tool_set";
+
+	/* api callbacks */
+	ot->exec= brush_weight_tool_set_exec;
+
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+	/* props */
+	ot->prop= RNA_def_enum(ot->srna, "tool", brush_vertex_tool_items, 0, "Tool", "");
+}
+
+static int brush_image_tool_set_exec(bContext *C, wmOperator *op)
+{
+	Main *bmain= CTX_data_main(C);
+	Scene *scene= CTX_data_scene(C);
+
+	return brush_generic_tool_set(bmain, &scene->toolsettings->imapaint.paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, imagepaint_tool), OB_MODE_TEXTURE_PAINT);
+}
+
+static void BRUSH_OT_image_tool_set(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Image Paint Tool Set";
+	ot->description= "Set the image tool";
+	ot->idname= "BRUSH_OT_image_tool_set";
+
+	/* api callbacks */
+	ot->exec= brush_image_tool_set_exec;
+
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+	/* props */
+	ot->prop= RNA_def_enum(ot->srna, "tool", brush_image_tool_items, 0, "Tool", "");
+}
+
+
 /**************************** registration **********************************/
 
 void ED_operatortypes_paint(void)
@@ -201,6 +347,12 @@
 	WM_operatortype_append(BRUSH_OT_curve_preset);
 	WM_operatortype_append(BRUSH_OT_reset);
 
+	/* note, particle uses a different system, can be added with existing operators in wm.py */
+	WM_operatortype_append(BRUSH_OT_sculpt_tool_set);
+	WM_operatortype_append(BRUSH_OT_vertex_tool_set);
+	WM_operatortype_append(BRUSH_OT_weight_tool_set);
+	WM_operatortype_append(BRUSH_OT_image_tool_set);
+
 	/* image */
 	WM_operatortype_append(PAINT_OT_texture_paint_toggle);
 	WM_operatortype_append(PAINT_OT_texture_paint_radial_control);
@@ -345,6 +497,16 @@
 	ed_keymap_paint_brush_switch(keymap, "sculpt");
 	ed_keymap_paint_brush_size(keymap, "tool_settings.sculpt.brush.size");
 
+	RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", DKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_DRAW);
+	RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", SKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_SMOOTH);
+	RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", PKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_PINCH);
+	RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", IKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_INFLATE);
+	RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", GKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_GRAB);
+	RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", LKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_LAYER);
+	RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", TKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "tool", SCULPT_TOOL_FLATTEN); /* was just TKEY in 2.4x */
+	RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", CKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_CLAY);
+	RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", CKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "tool", SCULPT_TOOL_CREASE);
+
 	/* */
 	kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", AKEY, KM_PRESS, 0, 0);
 	RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.stroke_method");




More information about the Bf-blender-cvs mailing list