[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46512] trunk/blender/source/blender: Add new options to PAINT_OT_brush_select, toggle and create_missing.

Nicholas Bishop nicholasbishop at gmail.com
Thu May 10 22:32:31 CEST 2012


Revision: 46512
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46512
Author:   nicholasbishop
Date:     2012-05-10 20:32:31 +0000 (Thu, 10 May 2012)
Log Message:
-----------
Add new options to PAINT_OT_brush_select, toggle and create_missing.

The toggle option, if enabled, will toggle back and forth between two
brushes. (The first brush of the desired tool type will be toggled to,
running the toggle again switches back to the previously selected
brush.)

If no brush of the desired type is found, and the create_missing
option is enabled, a new brush of that type will be created and set.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c
    trunk/blender/source/blender/makesdna/DNA_brush_types.h

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c	2012-05-10 20:32:21 UTC (rev 46511)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c	2012-05-10 20:32:31 UTC (rev 46512)
@@ -25,6 +25,7 @@
 #include "MEM_guardedalloc.h"
 
 #include <stdlib.h>
+#include "BLI_listbase.h"
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
 
@@ -204,6 +205,11 @@
 	return *(((char *)brush) + tool_offset);
 }
 
+static void brush_tool_set(const Brush *brush, size_t tool_offset, int tool)
+{
+	*(((char *)brush) + tool_offset) = tool;
+}
+
 /* 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)
 {
@@ -227,12 +233,49 @@
 	return NULL;
 }
 
-static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool, const size_t tool_offset, const int ob_mode)
+static Brush *brush_tool_toggle(Main *bmain, Brush *brush_orig, const int tool, const size_t tool_offset, const int ob_mode)
 {
+	if(!brush_orig || brush_tool(brush_orig, tool_offset) != tool) {
+		Brush *br;
+		/* if the current brush is not using the desired tool, look
+		   for one that is */
+		br= brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);
+		/* store the previously-selected brush */
+		if(br)
+			br->toggle_brush= brush_orig;
+		
+		return br;
+	}
+	else if(brush_orig->toggle_brush &&
+			BLI_findindex(bmain->brush.first, brush_orig->toggle_brush) != -1) {
+		/* if current brush is using the desired tool, try to toggle
+		   back to the previously selected brush (if it was set, and
+		   if it still exists) */
+		return brush_orig->toggle_brush;
+	}
+	else
+		return NULL;
+}
+
+static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool,
+								  const size_t tool_offset, const int ob_mode,
+								  const char *tool_name, int create_missing,
+								  int toggle)
+{
 	struct Brush *brush, *brush_orig = paint_brush(paint);
 
-	brush = brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);
+	if(toggle)
+		brush = brush_tool_toggle(bmain, brush_orig, tool, tool_offset, ob_mode);
+	else
+		brush = brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);
 
+	if(!brush && brush_tool(brush_orig, tool_offset) != tool && create_missing) {
+		brush = BKE_brush_add(tool_name);
+		brush_tool_set(brush, tool_offset, tool);
+		brush->ob_mode= ob_mode;
+		brush->toggle_brush= brush_orig;
+	}
+
 	if (brush) {
 		paint_brush_set(paint, brush);
 		WM_main_add_notifier(NC_BRUSH | NA_EDITED, brush);
@@ -252,6 +295,9 @@
 	ToolSettings *toolsettings = CTX_data_tool_settings(C);
 	Paint *paint = NULL;
 	int tool, paint_mode = RNA_enum_get(op->ptr, "paint_mode");
+	int create_missing = RNA_boolean_get(op->ptr, "create_missing");
+	int toggle = RNA_boolean_get(op->ptr, "toggle");
+	const char *tool_name = "Brush";
 	size_t tool_offset;
 
 	if (paint_mode == OB_MODE_ACTIVE) {
@@ -269,34 +315,40 @@
 		}
 	}
 
-	switch (paint_mode) {
+	switch(paint_mode) {
 		case OB_MODE_SCULPT:
-			paint = &toolsettings->sculpt->paint;
-			tool_offset = offsetof(Brush, sculpt_tool);
-			tool = RNA_enum_get(op->ptr, "sculpt_tool");
+			paint= &toolsettings->sculpt->paint;
+			tool_offset= offsetof(Brush, sculpt_tool);
+			tool= RNA_enum_get(op->ptr, "sculpt_tool");
+			RNA_enum_name_from_value(brush_sculpt_tool_items, tool, &tool_name);
 			break;
 		case OB_MODE_VERTEX_PAINT:
-			paint = &toolsettings->vpaint->paint;
-			tool_offset = offsetof(Brush, vertexpaint_tool);
-			tool = RNA_enum_get(op->ptr, "vertex_paint_tool");
+			paint= &toolsettings->vpaint->paint;
+			tool_offset= offsetof(Brush, vertexpaint_tool);
+			tool= RNA_enum_get(op->ptr, "vertex_paint_tool");
+			RNA_enum_name_from_value(brush_vertex_tool_items, tool, &tool_name);
 			break;
 		case OB_MODE_WEIGHT_PAINT:
-			paint = &toolsettings->wpaint->paint;
+			paint= &toolsettings->wpaint->paint;
 			/* vertexpaint_tool is used for weight paint mode */
-			tool_offset = offsetof(Brush, vertexpaint_tool);
-			tool = RNA_enum_get(op->ptr, "weight_paint_tool");
+			tool_offset= offsetof(Brush, vertexpaint_tool);
+			tool= RNA_enum_get(op->ptr, "weight_paint_tool");
+			RNA_enum_name_from_value(brush_vertex_tool_items, tool, &tool_name);
 			break;
 		case OB_MODE_TEXTURE_PAINT:
-			paint = &toolsettings->imapaint.paint;
-			tool_offset = offsetof(Brush, imagepaint_tool);
-			tool = RNA_enum_get(op->ptr, "texture_paint_tool");
+			paint= &toolsettings->imapaint.paint;
+			tool_offset= offsetof(Brush, imagepaint_tool);
+			tool= RNA_enum_get(op->ptr, "texture_paint_tool");
+			RNA_enum_name_from_value(brush_image_tool_items, tool, &tool_name);
 			break;
 		default:
 			/* invalid paint mode */
 			return OPERATOR_CANCELLED;
 	}
 
-	return brush_generic_tool_set(bmain, paint, tool, tool_offset, paint_mode);
+	return brush_generic_tool_set(bmain, paint, tool, tool_offset,
+								  paint_mode, tool_name, create_missing,
+								  toggle);
 }
 
 static void PAINT_OT_brush_select(wmOperatorType *ot)
@@ -327,6 +379,9 @@
 	RNA_def_enum(ot->srna, "vertex_paint_tool", brush_vertex_tool_items, 0, "Vertex Paint Tool", "");
 	RNA_def_enum(ot->srna, "weight_paint_tool", brush_vertex_tool_items, 0, "Weight Paint Tool", "");
 	RNA_def_enum(ot->srna, "texture_paint_tool", brush_image_tool_items, 0, "Texture Paint Tool", "");
+
+	RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "Toggle between two brushes rather than cycling");
+	RNA_def_boolean(ot->srna, "create_missing", 0, "Create Missing", "If the requested brush type does not exist, create a new brush");
 }
 
 static wmKeyMapItem *keymap_brush_select(wmKeyMap *keymap, int paint_mode,

Modified: trunk/blender/source/blender/makesdna/DNA_brush_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_brush_types.h	2012-05-10 20:32:21 UTC (rev 46511)
+++ trunk/blender/source/blender/makesdna/DNA_brush_types.h	2012-05-10 20:32:31 UTC (rev 46512)
@@ -57,6 +57,8 @@
 	struct CurveMapping *curve;	/* falloff curve */
 	struct MTex mtex;
 
+	struct Brush *toggle_brush;
+
 	struct ImBuf *icon_imbuf;
 	PreviewImage *preview;
 	char icon_filepath[1024]; /* 1024 = FILE_MAX */




More information about the Bf-blender-cvs mailing list