From a90bcdf93d82bf5d9964b12bb20af696ca66654e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 6 Nov 2018 12:08:39 +1100 Subject: Tool System: use tool type enum to access brushes Previously the brush names were used which had the limit that: - Brush names that were deleted wouldn't show up in the toolbar. - Naming collisions between user defined brushes and existing tools broke tool selection. Now brushes are created as needed when tools are selected. Note, vertex/weight paint combine tool and blend modes, this should be split out into a separate enum. --- source/blender/blenkernel/intern/paint.c | 50 ++++++++++++++++++++++ source/blender/blenkernel/intern/paint_toolslots.c | 13 ++++++ 2 files changed, 63 insertions(+) (limited to 'source/blender/blenkernel/intern') diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index f12e33344dc..6bc86f75d71 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -79,6 +79,8 @@ #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" +#include "RNA_enum_types.h" + #include "bmesh.h" const char PAINT_CURSOR_SCULPT[3] = {255, 100, 100}; @@ -172,6 +174,28 @@ Paint *BKE_paint_get_active_from_paintmode(Scene *sce, ePaintMode mode) return NULL; } +const EnumPropertyItem *BKE_paint_get_tool_enum_from_paintmode(ePaintMode mode) +{ + switch (mode) { + case ePaintSculpt: + return rna_enum_brush_sculpt_tool_items; + case ePaintVertex: + return rna_enum_brush_vertex_tool_items; + case ePaintWeight: + return rna_enum_brush_vertex_tool_items; + case ePaintTextureProjective: + case ePaintTexture2D: + return rna_enum_brush_image_tool_items; + case ePaintSculptUV: + return NULL; + case ePaintGpencil: + return rna_enum_brush_gpencil_types_items; + case ePaintInvalid: + break; + } + return NULL; +} + Paint *BKE_paint_get_active(Scene *sce, ViewLayer *view_layer) { if (sce && view_layer) { @@ -288,6 +312,32 @@ ePaintMode BKE_paintmode_get_active_from_context(const bContext *C) return ePaintInvalid; } +ePaintMode BKE_paintmode_get_from_tool(const struct bToolRef *tref) +{ + if (tref->space_type == SPACE_VIEW3D) { + switch (tref->mode) { + case CTX_MODE_SCULPT: + return ePaintSculpt; + case CTX_MODE_PAINT_VERTEX: + return ePaintVertex; + case CTX_MODE_PAINT_WEIGHT: + return ePaintWeight; + case CTX_MODE_GPENCIL_PAINT: + return ePaintGpencil; + case CTX_MODE_PAINT_TEXTURE: + return ePaintTextureProjective; + } + } + else if (tref->space_type == SPACE_IMAGE) { + switch (tref->mode) { + case SI_MODE_PAINT: + return ePaintTexture2D; + } + } + + return ePaintInvalid; +} + Brush *BKE_paint_brush(Paint *p) { return p ? p->brush : NULL; diff --git a/source/blender/blenkernel/intern/paint_toolslots.c b/source/blender/blenkernel/intern/paint_toolslots.c index 61e0f03ce9e..c0f26c1c9c1 100644 --- a/source/blender/blenkernel/intern/paint_toolslots.c +++ b/source/blender/blenkernel/intern/paint_toolslots.c @@ -22,6 +22,8 @@ * \ingroup bke */ +#include + #include "MEM_guardedalloc.h" #include "DNA_modifier_types.h" @@ -36,6 +38,8 @@ void BKE_paint_toolslots_len_ensure(Paint *paint, int len) { + /* Tool slots are 'uchar'. */ + BLI_assert(len <= UCHAR_MAX); if (paint->tool_slots_len < len) { paint->tool_slots = MEM_recallocN(paint->tool_slots, sizeof(*paint->tool_slots) * len); paint->tool_slots_len = len; @@ -122,3 +126,12 @@ void BKE_paint_toolslots_brush_validate(Main *bmain, Paint *paint) /* Fill slots from brushes. */ paint_toolslots_init(bmain, paint); } + +Brush *BKE_paint_toolslots_brush_get(Paint *paint, int slot_index) +{ + if (slot_index < paint->tool_slots_len) { + PaintToolSlot *tslot = &paint->tool_slots[slot_index]; + return tslot->brush; + } + return NULL; +} -- cgit v1.2.3