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/makesrna
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/makesrna')
-rw-r--r--source/blender/makesrna/RNA_enum_types.h1
-rw-r--r--source/blender/makesrna/intern/rna_brush.c6
-rw-r--r--source/blender/makesrna/intern/rna_workspace_api.c19
3 files changed, 17 insertions, 9 deletions
diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h
index 935af5c8bbd..8376bdefbc4 100644
--- a/source/blender/makesrna/RNA_enum_types.h
+++ b/source/blender/makesrna/RNA_enum_types.h
@@ -120,6 +120,7 @@ extern const EnumPropertyItem rna_enum_operator_property_tags[];
extern const EnumPropertyItem rna_enum_brush_sculpt_tool_items[];
extern const EnumPropertyItem rna_enum_brush_vertex_tool_items[];
+extern const EnumPropertyItem rna_enum_brush_gpencil_types_items[];
extern const EnumPropertyItem rna_enum_brush_image_tool_items[];
extern const EnumPropertyItem rna_enum_particle_edit_hair_brush_items[];
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index 0bcb29fe860..ac41666a79f 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -124,14 +124,14 @@ const EnumPropertyItem rna_enum_brush_image_tool_items[] = {
{0, NULL, 0, NULL, NULL}
};
-#ifndef RNA_RUNTIME
-static EnumPropertyItem rna_enum_gpencil_brush_types_items[] = {
+const EnumPropertyItem rna_enum_brush_gpencil_types_items[] = {
{GPAINT_TOOL_DRAW, "DRAW", ICON_GP_STROKE, "Draw", "The brush is of type used for drawing strokes"},
{GPAINT_TOOL_FILL, "FILL", ICON_COLOR, "Fill", "The brush is of type used for filling areas"},
{GPAINT_TOOL_ERASE, "ERASE", ICON_PANEL_CLOSE, "Erase", "The brush is used for erasing strokes"},
{0, NULL, 0, NULL, NULL}
};
+#ifndef RNA_RUNTIME
static EnumPropertyItem rna_enum_gpencil_brush_eraser_modes_items[] = {
{ GP_BRUSH_ERASER_SOFT, "SOFT", 0, "Soft", "Use soft eraser" },
{ GP_BRUSH_ERASER_HARD, "HARD", 0, "Hard", "Use hard eraser" },
@@ -1360,7 +1360,7 @@ static void rna_def_brush(BlenderRNA *brna)
prop = RNA_def_property(srna, "gpencil_tool", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "gpencil_tool");
- RNA_def_property_enum_items(prop, rna_enum_gpencil_brush_types_items);
+ RNA_def_property_enum_items(prop, rna_enum_brush_gpencil_types_items);
RNA_def_property_ui_text(prop, "Type", "Category of the brush");
RNA_def_parameter_clear_flags(prop, PROP_ANIMATABLE, 0);
diff --git a/source/blender/makesrna/intern/rna_workspace_api.c b/source/blender/makesrna/intern/rna_workspace_api.c
index 83ee5195fd8..4cb74ac1479 100644
--- a/source/blender/makesrna/intern/rna_workspace_api.c
+++ b/source/blender/makesrna/intern/rna_workspace_api.c
@@ -116,13 +116,20 @@ static void rna_WorkspaceTool_refresh_from_context(
}
}
else {
- Paint *paint = BKE_paint_get_active(scene, view_layer);
- if (paint) {
+ const ePaintMode paint_mode = BKE_paintmode_get_from_tool(tref);
+ Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode);
+ const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode);
+ if (paint && paint->brush && items) {
const ID *brush = (ID *)paint->brush;
- if (brush) {
- if (!STREQ(tref_rt->data_block, brush->name + 2)) {
- STRNCPY(tref_rt->data_block, brush->name + 2);
- STRNCPY(tref->idname, brush->name + 2);
+ const char tool_type = *(char *)POINTER_OFFSET(brush, paint->runtime.tool_offset);
+ const int i = RNA_enum_from_value(items, tool_type);
+ /* Possible when loading files from the future. */
+ if (i != -1) {
+ const char *name = items[i].name;
+ const char *identifier = items[i].identifier;
+ if (!STREQ(tref_rt->data_block, identifier)) {
+ STRNCPY(tref_rt->data_block, identifier);
+ STRNCPY(tref->idname, name);
}
}
}