diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-11-02 01:10:23 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-11-02 11:40:39 +0300 |
commit | ac8d7873278c47e8e282b7f83888108e2720a451 (patch) | |
tree | 902a404882e4ab22b8d7a153fbfc2e306747b083 /source/blender/makesrna/intern/rna_sculpt_paint.c | |
parent | 5bd3f3e64b7eba34e6c1676b82eec5b3c7d49d97 (diff) |
Tool System: brushes are now categorized by tool
The toolbar now shows brush types, the brush selector now
only shows brushes matching the current tool type.
Details:
- Add's Paint.tool_slots (used by the toolbar).
- Removed custom grease pencil brush tool code.
- Bumped subversion.
See T57526 for details.
Diffstat (limited to 'source/blender/makesrna/intern/rna_sculpt_paint.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_sculpt_paint.c | 113 |
1 files changed, 108 insertions, 5 deletions
diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c index 9efb4fb4d97..dcddf77b963 100644 --- a/source/blender/makesrna/intern/rna_sculpt_paint.c +++ b/source/blender/makesrna/intern/rna_sculpt_paint.c @@ -273,23 +273,102 @@ static char *rna_ParticleEdit_path(PointerRNA *UNUSED(ptr)) static bool rna_Brush_mode_poll(PointerRNA *ptr, PointerRNA value) { Scene *scene = (Scene *)ptr->id.data; + const Paint *paint = ptr->data; ToolSettings *ts = scene->toolsettings; Brush *brush = value.id.data; int mode = 0; + uint brush_tool_offset = 0; /* check the origin of the Paint struct to see which paint * mode to select from */ - if (ptr->data == &ts->imapaint) + if (paint == &ts->imapaint.paint) { mode = OB_MODE_TEXTURE_PAINT; - else if (ptr->data == ts->sculpt) + brush_tool_offset = offsetof(Brush, imagepaint_tool); + } + else if (paint == &ts->sculpt->paint) { mode = OB_MODE_SCULPT; - else if (ptr->data == ts->vpaint) + brush_tool_offset = offsetof(Brush, sculpt_tool); + } + else if (paint == &ts->vpaint->paint) { mode = OB_MODE_VERTEX_PAINT; - else if (ptr->data == ts->wpaint) + brush_tool_offset = offsetof(Brush, vertexpaint_tool); + } + else if (paint == &ts->wpaint->paint) { mode = OB_MODE_WEIGHT_PAINT; - else if (ptr->data == ts->gp_paint) + brush_tool_offset = offsetof(Brush, vertexpaint_tool); + } + else if (paint == &ts->gp_paint->paint) { mode = OB_MODE_GPENCIL_PAINT; + brush_tool_offset = offsetof(Brush, gpencil_tool); + } + + if (brush->ob_mode & mode) { + if (paint->brush) { + const char *tool_a = (const char *)POINTER_OFFSET(paint->brush, brush_tool_offset); + const char *tool_b = (const char *)POINTER_OFFSET(brush, brush_tool_offset); + if (*tool_a == *tool_b) { + return true; + } + } + else { + return true; + } + } + + return false; +} + +static bool paint_contains_brush_slot(const Paint *paint, const PaintToolSlot *tslot, int *r_index) +{ + if ((tslot >= paint->tool_slots) && + (tslot < (paint->tool_slots + paint->tool_slots_len))) + { + *r_index = (int)(tslot - paint->tool_slots); + return true; + } + return false; +} + +static bool rna_Brush_mode_with_tool_poll(PointerRNA *ptr, PointerRNA value) +{ + Scene *scene = (Scene *)ptr->id.data; + const PaintToolSlot *tslot = ptr->data; + ToolSettings *ts = scene->toolsettings; + Brush *brush = value.id.data; + int mode = 0; + int slot_index = 0; + + if (paint_contains_brush_slot(&ts->imapaint.paint, tslot, &slot_index)) { + if (slot_index != brush->imagepaint_tool) { + return false; + } + mode = OB_MODE_TEXTURE_PAINT; + } + else if (paint_contains_brush_slot(&ts->sculpt->paint, tslot, &slot_index)) { + if (slot_index != brush->sculpt_tool) { + return false; + } + mode = OB_MODE_SCULPT; + } + else if (paint_contains_brush_slot(&ts->vpaint->paint, tslot, &slot_index)) { + if (slot_index != brush->vertexpaint_tool) { + return false; + } + mode = OB_MODE_VERTEX_PAINT; + } + else if (paint_contains_brush_slot(&ts->wpaint->paint, tslot, &slot_index)) { + if (slot_index != brush->vertexpaint_tool) { + return false; + } + mode = OB_MODE_WEIGHT_PAINT; + } + else if (paint_contains_brush_slot(&ts->gp_paint->paint, tslot, &slot_index)) { + if (slot_index != brush->gpencil_tool) { + return false; + } + mode = OB_MODE_GPENCIL_PAINT; + } return brush->ob_mode & mode; } @@ -383,9 +462,11 @@ static char *rna_ParticleBrush_path(PointerRNA *UNUSED(ptr)) static void rna_Paint_brush_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { + Scene *scene = (Scene *)ptr->id.data; Paint *paint = ptr->data; Brush *br = paint->brush; BKE_paint_invalidate_overlay_all(); + BKE_paint_toolslots_brush_update(scene, paint); WM_main_add_notifier(NC_BRUSH | NA_SELECTED, br); } @@ -498,6 +579,19 @@ static void rna_def_paint_curve(BlenderRNA *brna) RNA_def_struct_ui_icon(srna, ICON_CURVE_BEZCURVE); } +static void rna_def_paint_tool_slot(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna = RNA_def_struct(brna, "PaintToolSlot", NULL); + RNA_def_struct_ui_text(srna, "Paint Tool Slot", ""); + + prop = RNA_def_property(srna, "brush", PROP_POINTER, PROP_NONE); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_Brush_mode_with_tool_poll"); + RNA_def_property_ui_text(prop, "Brush", ""); +} static void rna_def_paint(BlenderRNA *brna) { @@ -514,6 +608,14 @@ static void rna_def_paint(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Brush", "Active Brush"); RNA_def_property_update(prop, 0, "rna_Paint_brush_update"); + /* paint_tool_slots */ + prop = RNA_def_property(srna, "tool_slots", PROP_COLLECTION, PROP_NONE); + RNA_def_property_collection_sdna(prop, NULL, "tool_slots", "tool_slots_len"); + RNA_def_property_struct_type(prop, "PaintToolSlot"); + /* don't dereference pointer! */ + RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, "rna_iterator_array_get", NULL, NULL, NULL, NULL); + RNA_def_property_ui_text(prop, "Paint Tool Slots", ""); + prop = RNA_def_property(srna, "palette", PROP_POINTER, PROP_NONE); RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, NULL); @@ -1276,6 +1378,7 @@ void RNA_def_sculpt_paint(BlenderRNA *brna) /* *** Non-Animated *** */ RNA_define_animate_sdna(false); rna_def_paint_curve(brna); + rna_def_paint_tool_slot(brna); rna_def_paint(brna); rna_def_sculpt(brna); rna_def_uv_sculpt(brna); |