Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-11-06 04:08:39 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-11-06 04:39:51 +0300
commita90bcdf93d82bf5d9964b12bb20af696ca66654e (patch)
treee57a15e78d957955db370ad8a8591d024de57b8f /source/blender/blenkernel
parent29dfe9a61456dba8c8e4cdae0a90cfa3eef1cd2a (diff)
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.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_paint.h5
-rw-r--r--source/blender/blenkernel/intern/paint.c50
-rw-r--r--source/blender/blenkernel/intern/paint_toolslots.c13
3 files changed, 68 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 6dcd3a7c446..dc05642fb69 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -33,10 +33,12 @@
*/
struct bContext;
+struct bToolRef;
struct BMesh;
struct BMFace;
struct Brush;
struct CurveMapping;
+struct EnumPropertyItem;
struct MeshElemMap;
struct GridPaintMask;
struct Main;
@@ -136,9 +138,11 @@ void BKE_paint_cavity_curve_preset(struct Paint *p, int preset);
eObjectMode BKE_paint_object_mode_from_paint_mode(ePaintMode mode);
struct Paint *BKE_paint_get_active_from_paintmode(struct Scene *sce, ePaintMode mode);
+const struct EnumPropertyItem *BKE_paint_get_tool_enum_from_paintmode(ePaintMode mode);
struct Paint *BKE_paint_get_active(struct Scene *sce, struct ViewLayer *view_layer);
struct Paint *BKE_paint_get_active_from_context(const struct bContext *C);
ePaintMode BKE_paintmode_get_active_from_context(const struct bContext *C);
+ePaintMode BKE_paintmode_get_from_tool(const struct bToolRef *tref);
struct Brush *BKE_paint_brush(struct Paint *paint);
void BKE_paint_brush_set(struct Paint *paint, struct Brush *br);
struct Palette *BKE_paint_palette(struct Paint *paint);
@@ -179,6 +183,7 @@ void BKE_paint_toolslots_len_ensure(struct Paint *paint, int len);
void BKE_paint_toolslots_brush_update_ex(struct Paint *paint, struct Brush *brush);
void BKE_paint_toolslots_brush_update(struct Paint *paint);
void BKE_paint_toolslots_brush_validate(struct Main *bmain, struct Paint *paint);
+struct Brush *BKE_paint_toolslots_brush_get(struct Paint *paint, int slot_index);
/* Used for both vertex color and weight paint */
struct SculptVertexPaintGeomMap {
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 <limits.h>
+
#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;
+}