diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-11-03 07:44:16 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-11-03 07:55:45 +0300 |
commit | 13c3c9b22fd8453d4418577efbc2ccb93209e92e (patch) | |
tree | cb332a7ed0e9022db2d189cd11bd983e33248468 /source/blender/blenkernel/intern | |
parent | a18927463c18eec24c74ce8c0b3c261ff5ace889 (diff) |
Cleanup: move brush query into utility function
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/paint.c | 52 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/paint_toolslots.c | 21 |
2 files changed, 56 insertions, 17 deletions
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 93b54fcb132..7838fb69f1a 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -302,6 +302,58 @@ void BKE_paint_brush_set(Paint *p, Brush *br) } } +bool BKE_paint_brush_tool_info( + const Scene *scene, const struct Paint *paint, + uint *r_tool_offset, eObjectMode *r_ob_mode) +{ + ToolSettings *ts = scene->toolsettings; + if (paint == &ts->imapaint.paint) { + if (r_tool_offset != NULL) { + *r_tool_offset = offsetof(Brush, imagepaint_tool); + } + if (r_ob_mode != NULL) { + *r_ob_mode = OB_MODE_TEXTURE_PAINT; + } + } + else if (paint == &ts->sculpt->paint) { + if (r_tool_offset != NULL) { + *r_tool_offset = offsetof(Brush, sculpt_tool); + } + if (r_ob_mode != NULL) { + *r_ob_mode = OB_MODE_SCULPT; + } + } + else if (paint == &ts->vpaint->paint) { + if (r_tool_offset != NULL) { + *r_tool_offset = offsetof(Brush, vertexpaint_tool); + } + if (r_ob_mode != NULL) { + *r_ob_mode = OB_MODE_VERTEX_PAINT; + } + } + else if (paint == &ts->wpaint->paint) { + if (r_tool_offset != NULL) { + *r_tool_offset = offsetof(Brush, vertexpaint_tool); + } + if (r_ob_mode != NULL) { + *r_ob_mode = OB_MODE_WEIGHT_PAINT; + } + } + else if (paint == &ts->gp_paint->paint) { + if (r_tool_offset != NULL) { + *r_tool_offset = offsetof(Brush, gpencil_tool); + } + if (r_ob_mode != NULL) { + *r_ob_mode = OB_MODE_GPENCIL_PAINT; + } + } + else { + return false; + } + return true; +} + + /** Free (or release) any data used by this paint curve (does not free the pcurve itself). */ void BKE_paint_curve_free(PaintCurve *pc) { diff --git a/source/blender/blenkernel/intern/paint_toolslots.c b/source/blender/blenkernel/intern/paint_toolslots.c index bdafe217276..19c461d1777 100644 --- a/source/blender/blenkernel/intern/paint_toolslots.c +++ b/source/blender/blenkernel/intern/paint_toolslots.c @@ -93,23 +93,10 @@ void BKE_paint_toolslots_init_from_main(struct Main *bmain) void BKE_paint_toolslots_brush_update_ex(Scene *scene, Paint *paint, Brush *brush) { - ToolSettings *ts = scene->toolsettings; - int slot_index; - if (paint == &ts->imapaint.paint) { - slot_index = brush->imagepaint_tool; - } - else if (paint == &ts->sculpt->paint) { - slot_index = brush->sculpt_tool; - } - else if (paint == &ts->vpaint->paint) { - slot_index = brush->vertexpaint_tool; - } - else if (paint == &ts->wpaint->paint) { - slot_index = brush->vertexpaint_tool; - } - else if (paint == &ts->gp_paint->paint) { - slot_index = brush->gpencil_tool; - } + uint tool_offset = 0; + bool ok = BKE_paint_brush_tool_info(scene, paint, &tool_offset, NULL); + BLI_assert(ok); + int slot_index = *(char *)POINTER_OFFSET(brush, tool_offset); BKE_paint_toolslots_len_ensure(paint, slot_index + 1); PaintToolSlot *tslot = &paint->tool_slots[slot_index]; id_us_plus(&brush->id); |