[Bf-blender-cvs] [a90bcdf93d8] blender2.8: Tool System: use tool type enum to access brushes
Campbell Barton
noreply at git.blender.org
Tue Nov 6 02:40:44 CET 2018
Commit: a90bcdf93d82bf5d9964b12bb20af696ca66654e
Author: Campbell Barton
Date: Tue Nov 6 12:08:39 2018 +1100
Branches: blender2.8
https://developer.blender.org/rBa90bcdf93d82bf5d9964b12bb20af696ca66654e
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.
===================================================================
M release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M source/blender/blenkernel/BKE_paint.h
M source/blender/blenkernel/intern/paint.c
M source/blender/blenkernel/intern/paint_toolslots.c
M source/blender/makesrna/RNA_enum_types.h
M source/blender/makesrna/intern/rna_brush.c
M source/blender/makesrna/intern/rna_workspace_api.c
M source/blender/windowmanager/intern/wm_toolsystem.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index c494aae03cd..bd64e7e3834 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -39,64 +39,12 @@ from .properties_grease_pencil_common import (
)
-def generate_from_brushes_tool_slots_ex(
- context, paint, *,
- icon_prefix,
- brush_category_attr,
- brush_category_layout,
- # Optional
- tooldef_keywords={},
-):
- # Categories
- brush_categories = {}
- for paint_slot in paint.tool_slots:
- brush = paint_slot.brush
- if brush is None:
- continue
- category = getattr(brush, brush_category_attr)
- name = brush.name
- brush_categories.setdefault(category, []).append(
- ToolDef.from_dict(
- dict(
- text=name,
- icon=icon_prefix + category.lower(),
- data_block=name,
- **tooldef_keywords,
- )
- )
- )
-
- def tools_from_brush_group(groups):
- assert(type(groups) is tuple)
- if len(groups) == 1:
- tool_defs = tuple(brush_categories.pop(groups[0], ()))
- else:
- tool_defs = tuple(item for g in groups for item in brush_categories.pop(g, ()))
-
- if len(tool_defs) > 1:
- return (tool_defs,)
- else:
- return tool_defs
-
- # Each item below is a single toolbar entry:
- # Grouped for multiple or none if no brushes are found.
- tool_defs = tuple(
- tool_def
- for category in brush_category_layout
- for tool_def in tools_from_brush_group(category)
- )
- # Ensure we use all types.
- if brush_categories:
- print(brush_categories)
- assert(len(brush_categories) == 0)
- return tool_defs
-
-
def generate_from_enum_ex(
context, *,
icon_prefix,
type,
attr,
+ tooldef_keywords={},
):
tool_defs = []
for enum in type.bl_rna.properties[attr].enum_items_static:
@@ -108,6 +56,7 @@ def generate_from_enum_ex(
text=name,
icon=icon_prefix + identifier.lower(),
data_block=identifier,
+ **tooldef_keywords,
)
)
)
@@ -1015,26 +964,11 @@ class _defs_sculpt:
@staticmethod
def generate_from_brushes(context):
- return generate_from_brushes_tool_slots_ex(
- context, context.tool_settings.sculpt,
+ return generate_from_enum_ex(
+ context,
icon_prefix="brush.sculpt.",
- brush_category_attr="sculpt_tool",
- brush_category_layout=(
- ('DRAW',),
- ('GRAB', 'THUMB'),
- ('SNAKE_HOOK',),
- ('BLOB', 'INFLATE'),
- ('SMOOTH',),
- ('SCRAPE',),
- ('FLATTEN',),
- ('CREASE', 'PINCH'),
- ('CLAY', 'CLAY_STRIPS'),
- ('LAYER',),
- ('NUDGE', 'ROTATE'),
- ('FILL',),
- ('SIMPLIFY',),
- ('MASK',),
- ),
+ type=bpy.types.Brush,
+ attr="sculpt_tool",
)
@ToolDef.from_fn
@@ -1072,40 +1006,22 @@ class _defs_vertex_paint:
@staticmethod
def generate_from_brushes(context):
- return generate_from_brushes_tool_slots_ex(
- context, context.tool_settings.vertex_paint,
+ return generate_from_enum_ex(
+ context,
icon_prefix="brush.paint_vertex.",
- brush_category_attr="vertex_tool",
- brush_category_layout=(
- ('MIX',),
- ('BLUR', 'AVERAGE'),
- ('SMEAR',),
- (
- 'ADD', 'SUB', 'MUL', 'LIGHTEN', 'DARKEN',
- 'COLORDODGE', 'DIFFERENCE', 'SCREEN', 'HARDLIGHT',
- 'OVERLAY', 'SOFTLIGHT', 'EXCLUSION', 'LUMINOCITY',
- 'SATURATION', 'HUE', 'ERASE_ALPHA', 'ADD_ALPHA',
- ),
- ),
+ type=bpy.types.Brush,
+ attr="vertex_tool",
)
-
class _defs_texture_paint:
@staticmethod
def generate_from_brushes(context):
- return generate_from_brushes_tool_slots_ex(
- context, context.tool_settings.image_paint,
+ return generate_from_enum_ex(
+ context,
icon_prefix="brush.paint_texture.",
- brush_category_attr="image_tool",
- brush_category_layout=(
- ('DRAW',),
- ('SOFTEN',),
- ('SMEAR',),
- ('CLONE',),
- ('FILL',),
- ('MASK',),
- ),
+ type=bpy.types.Brush,
+ attr="image_tool",
)
@@ -1120,21 +1036,11 @@ class _defs_weight_paint:
@staticmethod
def generate_from_brushes(context):
- return generate_from_brushes_tool_slots_ex(
- context, context.tool_settings.weight_paint,
+ return generate_from_enum_ex(
+ context,
icon_prefix="brush.paint_weight.",
- brush_category_attr="vertex_tool",
- brush_category_layout=(
- ('MIX',),
- ('BLUR', 'AVERAGE'),
- ('SMEAR',),
- (
- 'ADD', 'SUB', 'MUL', 'LIGHTEN', 'DARKEN',
- 'COLORDODGE', 'DIFFERENCE', 'SCREEN', 'HARDLIGHT',
- 'OVERLAY', 'SOFTLIGHT', 'EXCLUSION', 'LUMINOCITY',
- 'SATURATION', 'HUE',
- ),
- ),
+ type=bpy.types.Brush,
+ attr="vertex_tool",
)
@ToolDef.from_fn
@@ -1299,16 +1205,11 @@ class _defs_gpencil_paint:
@staticmethod
def generate_from_brushes(context):
-
- return generate_from_brushes_tool_slots_ex(
- context, context.tool_settings.gpencil_paint,
+ return generate_from_enum_ex(
+ context,
icon_prefix="brush.gpencil_draw.",
- brush_category_attr="gpencil_tool",
- brush_category_layout=(
- ('DRAW',),
- ('FILL',),
- ('ERASE',),
- ),
+ type=bpy.types.Brush,
+ attr="gpencil_tool",
tooldef_keywords=dict(
operator="gpencil.draw",
),
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:
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list