[Bf-blender-cvs] [ac8d7873278] blender2.8: Tool System: brushes are now categorized by tool

Campbell Barton noreply at git.blender.org
Fri Nov 2 09:44:03 CET 2018


Commit: ac8d7873278c47e8e282b7f83888108e2720a451
Author: Campbell Barton
Date:   Fri Nov 2 09:10:23 2018 +1100
Branches: blender2.8
https://developer.blender.org/rBac8d7873278c47e8e282b7f83888108e2720a451

Tool System: brushes are now categorized by tool

The toolbar now shows brush types, the brush selector now
only shows brushes matching the current tool type.

Details:

- Add's Paint.tool_slots (used by the toolbar).
- Removed custom grease pencil brush tool code.
- Bumped subversion.

See T57526 for details.

===================================================================

M	release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/BKE_blender_version.h
M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/brush.c
M	source/blender/blenkernel/intern/library_query.c
M	source/blender/blenkernel/intern/paint.c
A	source/blender/blenkernel/intern/paint_toolslots.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/gpencil/gpencil_ops.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/makesdna/DNA_brush_types.h
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_brush.c
M	source/blender/makesrna/intern/rna_sculpt_paint.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index 91892e010b7..363cc5f1797 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -341,10 +341,10 @@ class GreasePencilAppearancePanel:
 
             layout.prop(gp_settings, "use_cursor", text="Show Brush")
 
-            if gp_settings.tool == 'DRAW':
+            if brush.gpencil_tool == 'DRAW':
                 layout.prop(gp_settings, "show_lasso", text="Show fill color while drawing")
 
-            if gp_settings.tool == 'FILL':
+            if brush.gpencil_tool == 'FILL':
                 layout.prop(brush, "cursor_color_add", text="Color")
 
         elif ob.mode in {'GPENCIL_SCULPT', 'GPENCIL_WEIGHT'}:
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 04b64325771..caffcf829c5 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -38,65 +38,40 @@ from .properties_grease_pencil_common import (
     AnnotationDataPanel,
 )
 
-def generate_from_brushes_ex(
-        context, *,
+
+def generate_from_brushes_tool_slots_ex(
+        context, paint, *,
         icon_prefix,
-        brush_test_attr,
         brush_category_attr,
         brush_category_layout,
+        # Optional
+        icon_fn=None,
+        tooldef_keywords={},
 ):
     # Categories
     brush_categories = {}
-    if context.mode != 'GPENCIL_PAINT':
-        for brush in context.blend_data.brushes:
-            if getattr(brush, brush_test_attr) and brush.gpencil_settings is None:
-                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,
-                        )
-                    )
-                )
-    else:
-        def draw_settings(context, layout, tool):
-            _defs_gpencil_paint.draw_settings_common(context, layout, tool)
+    for paint_slot in paint.tool_slots:
+        brush = paint_slot.brush
+        if brush is None:
+            continue
+        category = getattr(brush, brush_category_attr)
+
+        if icon_fn is not None:
+            icon_id = icon_fn(brush)
+        else:
+            icon_id = category.lower()
 
-        for brush_type in brush_category_layout:
-            for brush in context.blend_data.brushes:
-                if brush.gpencil_settings and getattr(brush, brush_test_attr) and brush.gpencil_settings.gp_icon == brush_type[0]:
-                    category = brush_type[0]
-                    name = brush.name
-                    text = name
-
-                    # Define icon.
-                    icon_name = {
-                        'PENCIL': 'draw_pencil',
-                        'PEN': 'draw_pen',
-                        'INK': 'draw_ink',
-                        'INKNOISE': 'draw_noise',
-                        'BLOCK': 'draw_block',
-                        'MARKER': 'draw_marker',
-                        'FILL': 'draw_fill',
-                        'SOFT': 'draw.eraser_soft',
-                        'HARD': 'draw.eraser_hard',
-                        'STROKE': 'draw.eraser_stroke',
-                    }[category]
-                    brush_categories.setdefault(category, []).append(
-                        ToolDef.from_dict(
-                            dict(
-                                text=text,
-                                icon=icon_prefix + icon_name,
-                                data_block=name,
-                                widget=None,
-                                operator="gpencil.draw",
-                                draw_settings=draw_settings,
-                            )
-                        )
-                    )
+        name = brush.name
+        brush_categories.setdefault(category, []).append(
+            ToolDef.from_dict(
+                dict(
+                    text=name,
+                    icon=icon_prefix + icon_id,
+                    data_block=name,
+                    **tooldef_keywords,
+                )
+            )
+        )
 
     def tools_from_brush_group(groups):
         assert(type(groups) is tuple)
@@ -1052,10 +1027,9 @@ class _defs_sculpt:
 
     @staticmethod
     def generate_from_brushes(context):
-        return generate_from_brushes_ex(
-            context,
+        return generate_from_brushes_tool_slots_ex(
+            context, context.tool_settings.sculpt,
             icon_prefix="brush.sculpt.",
-            brush_test_attr="use_paint_sculpt",
             brush_category_attr="sculpt_tool",
             brush_category_layout=(
                 ('DRAW',),
@@ -1070,7 +1044,7 @@ class _defs_sculpt:
                 ('FILL',),
                 ('SIMPLIFY',),
                 ('MASK',),
-            )
+            ),
         )
 
     @ToolDef.from_fn
@@ -1108,10 +1082,9 @@ class _defs_vertex_paint:
 
     @staticmethod
     def generate_from_brushes(context):
-        return generate_from_brushes_ex(
-            context,
+        return generate_from_brushes_tool_slots_ex(
+            context, context.tool_settings.vertex_paint,
             icon_prefix="brush.paint_vertex.",
-            brush_test_attr="use_paint_vertex",
             brush_category_attr="vertex_tool",
             brush_category_layout=(
                 ('MIX',),
@@ -1123,7 +1096,7 @@ class _defs_vertex_paint:
                     'OVERLAY', 'SOFTLIGHT', 'EXCLUSION', 'LUMINOCITY',
                     'SATURATION', 'HUE', 'ERASE_ALPHA', 'ADD_ALPHA',
                 ),
-            )
+            ),
         )
 
 
@@ -1131,10 +1104,9 @@ class _defs_texture_paint:
 
     @staticmethod
     def generate_from_brushes(context):
-        return generate_from_brushes_ex(
-            context,
+        return generate_from_brushes_tool_slots_ex(
+            context, context.tool_settings.image_paint,
             icon_prefix="brush.paint_texture.",
-            brush_test_attr="use_paint_image",
             brush_category_attr="image_tool",
             brush_category_layout=(
                 ('DRAW',),
@@ -1143,7 +1115,7 @@ class _defs_texture_paint:
                 ('CLONE',),
                 ('FILL',),
                 ('MASK',),
-            )
+            ),
         )
 
 
@@ -1158,10 +1130,9 @@ class _defs_weight_paint:
 
     @staticmethod
     def generate_from_brushes(context):
-        return generate_from_brushes_ex(
-            context,
+        return generate_from_brushes_tool_slots_ex(
+            context, context.tool_settings.weight_paint,
             icon_prefix="brush.paint_weight.",
-            brush_test_attr="use_paint_weight",
             brush_category_attr="vertex_tool",
             brush_category_layout=(
                 ('MIX',),
@@ -1173,7 +1144,7 @@ class _defs_weight_paint:
                     'OVERLAY', 'SOFTLIGHT', 'EXCLUSION', 'LUMINOCITY',
                     'SATURATION', 'HUE',
                 ),
-            )
+            ),
         )
 
     @ToolDef.from_fn
@@ -1368,9 +1339,11 @@ class _defs_gpencil_paint:
         ob = context.active_object
         if ob and ob.mode == 'GPENCIL_PAINT':
             brush = context.active_gpencil_brush
+            if brush is None:
+                return
             gp_settings = brush.gpencil_settings
 
-            if gp_settings.tool == 'ERASE':
+            if brush.gpencil_tool == 'ERASE':
                 row = layout.row(align=True)
                 row.prop(brush, "size", text="Radius")
                 row.prop(gp_settings, "use_pressure", text="", icon='STYLUS_PRESSURE')
@@ -1378,7 +1351,7 @@ class _defs_gpencil_paint:
                     row = layout.row(align=True)
                     row.prop(gp_settings, "pen_strength", slider=True)
                     row.prop(gp_settings, "use_strength_pressure", text="", icon='STYLUS_PRESSURE')
-            elif gp_settings.tool == 'FILL':
+            elif brush.gpencil_tool == 'FILL':
                 row = layout.row()
                 row.prop(gp_settings, "fill_leak", text="Leak Size")
                 row.prop(brush, "size", text="Thickness")
@@ -1402,26 +1375,42 @@ class _defs_gpencil_paint:
 
     @staticmethod
     def generate_from_brushes(context):
-        return generate_from_brushes_ex(
-            context,
+
+        def draw_settings(context, layout, tool):
+            _defs_gpencil_paint.draw_settings_common(context, layout, tool)
+
+        def icon_fn(brush):
+            return {
+                'PENCIL': 'draw_pencil',
+                'PEN': 'draw_pen',
+                'INK': 'draw_ink',
+                'INKNOISE': 'draw_noise',
+                'BLOCK': 'draw_block',
+                'MARKER': 'draw_marker',
+                'FILL': 'draw_fill',
+                'SOFT': 'draw.eraser_soft',
+                'HARD': 'draw.eraser_hard',
+                'STROKE': 'draw.eraser_stroke',
+            }[brush.gpencil_settings.gp_icon]
+
+        return generate_from_brushes_tool_slots_ex(
+            context, context.tool_settings.gpencil_paint,
             icon_prefix="brush.gpencil.",
-            brush_test_attr="use_paint_grease_pencil",
-            brush_category_attr="grease_pencil_tool",
+            brush_category_attr="gpencil_tool",
             brush_category_layout=(
-                ('PENCIL',),
-                ('PEN',),
-                ('INK',),
-                ('INKNOISE',),
-                ('BLOCK',),
-                ('MARKER',),
+                ('DRAW',),
                 ('FILL',),
-                ('SOFT',),
-                ('HARD',),
-                ('STROKE',),
-            )
+                ('ERASE',),
+            ),
+            tooldef_keywords=dict(
+                operator="gpencil.draw",
+                draw_s

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list