diff options
author | Nicholas Bishop <nicholasbishop@gmail.com> | 2012-05-11 00:32:31 +0400 |
---|---|---|
committer | Nicholas Bishop <nicholasbishop@gmail.com> | 2012-05-11 00:32:31 +0400 |
commit | 147b4b13ba3bacc02956d4678b14916ee5cdce53 (patch) | |
tree | 2c8a946ca4792446265145eda3412b1b81f29eff /source/blender/editors | |
parent | 26ce1018cdb082964fda8c81de271de4bdf818db (diff) |
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.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_ops.c | 87 |
1 files changed, 71 insertions, 16 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index c42f0e03d79..73c6d55d521 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -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 @@ static int brush_tool(const Brush *brush, size_t tool_offset) 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,11 +233,48 @@ static Brush *brush_tool_cycle(Main *bmain, Brush *brush_orig, const int tool, c 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); @@ -252,6 +295,9 @@ static int brush_select_exec(bContext *C, wmOperator *op) 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 @@ static int brush_select_exec(bContext *C, wmOperator *op) } } - 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 @@ static void PAINT_OT_brush_select(wmOperatorType *ot) 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, |