diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-04-30 16:21:04 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-04-30 16:23:04 +0300 |
commit | d9f395ac390d1e02aa9c3e97ebaee8bb834e3af4 (patch) | |
tree | 704df6a9d276f1daa3f8121e02aa8bc6317ba767 | |
parent | b5f5e6ce2981971783511d3bc9adeddc674e1715 (diff) |
UI: add vertex paint tools
Generalize logic to show the paintbrush as a tool so
different paint modes can use it.
-rw-r--r-- | release/scripts/startup/bl_ui/space_toolsystem_toolbar.py | 134 | ||||
-rw-r--r-- | release/scripts/startup/bl_ui/space_topbar.py | 12 | ||||
-rw-r--r-- | release/scripts/startup/bl_ui/space_view3d_toolbar.py | 4 |
3 files changed, 104 insertions, 46 deletions
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py index 1960fc4790e..db22b02b41b 100644 --- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py +++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py @@ -31,6 +31,52 @@ from .space_toolsystem_common import ( ToolDef, ) +def generate_from_brushes_ex( + context, *, + icon_prefix, + brush_test_attr, + brush_category_attr, + brush_category_layout, +): + # Categories + brush_categories = {} + for brush in context.blend_data.brushes: + if getattr(brush, brush_test_attr): + 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, + ) + ) + ) + + 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. + assert(len(brush_categories) == 0) + return tool_defs + + class _defs_view3d_generic: @ToolDef.from_fn def cursor(): @@ -504,51 +550,48 @@ class _defs_sculpt: @staticmethod def generate_from_brushes(context): - # Categories - brush_categories = {} - for brush in context.blend_data.brushes: - if brush.use_paint_sculpt: - sculpt_tool = brush.sculpt_tool - name = brush.name - brush_categories.setdefault(sculpt_tool, []).append( - ToolDef.from_dict( - dict( - text=name, - icon="brush.sculpt." + sculpt_tool.lower(), - data_block=name, - ) - ) - ) + return generate_from_brushes_ex( + context, + icon_prefix="brush.sculpt.", + brush_test_attr="use_paint_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',), + ) + ) - def tools_from_brush_group(*groups): - 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 = ( - *tools_from_brush_group("DRAW"), - *tools_from_brush_group("GRAB", "THUMB"), - *tools_from_brush_group("SNAKE_HOOK"), - *tools_from_brush_group("BLOB", "INFLATE"), - *tools_from_brush_group("SMOOTH", "SCRAPE" , "FLATTEN"), - *tools_from_brush_group("CREASE", "PINCH"), - *tools_from_brush_group("CLAY", "CLAY_STRIPS"), - *tools_from_brush_group("LAYER"), - *tools_from_brush_group("NUDGE", "ROTATE"), - *tools_from_brush_group("FILL"), - *tools_from_brush_group("SIMPLIFY"), - *tools_from_brush_group("MASK"), - ) - # Ensure we use all types. - assert(len(brush_categories) == 0) - return tool_defs +class _defs_vertexpaint: + + @staticmethod + def generate_from_brushes(context): + return generate_from_brushes_ex( + context, + icon_prefix="brush.vertexpaint.", + brush_test_attr="use_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', + ), + ) + ) class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel): @@ -691,6 +734,9 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel): 'SCULPT': [ _defs_sculpt.generate_from_brushes, ], + 'PAINT_VERTEX': [ + _defs_vertexpaint.generate_from_brushes, + ], } diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py index bb357269be4..7529a9dcd4a 100644 --- a/release/scripts/startup/bl_ui/space_topbar.py +++ b/release/scripts/startup/bl_ui/space_topbar.py @@ -148,6 +148,7 @@ class TOPBAR_HT_lower_bar(Header): layout.popover_group(space_type='VIEW_3D', region_type='TOOLS', context=".dummy", category="") elif mode == 'PAINT_VERTEX': layout.popover_group(space_type='VIEW_3D', region_type='TOOLS', context=".dummy", category="") + layout.popover_group(space_type='VIEW_3D', region_type='TOOLS', context=".vertexpaint", category="") elif mode == 'PAINT_WEIGHT': layout.popover_group(space_type='VIEW_3D', region_type='TOOLS', context="", category="") elif mode == 'PAINT_TEXTURE': @@ -191,6 +192,17 @@ class _draw_left_context_mode: UnifiedPaintPanel.prop_unified_strength(layout, context, brush, "strength", slider=True, text="Strength") layout.prop(brush, "direction", text="", expand=True) + def PAINT_VERTEX(context, layout): + brush = context.tool_settings.vertex_paint.brush + if brush is None: + return + + from .properties_paint_common import UnifiedPaintPanel + + layout.prop(brush, "color", text="") + UnifiedPaintPanel.prop_unified_size(layout, context, brush, "size", slider=True, text="Radius") + UnifiedPaintPanel.prop_unified_strength(layout, context, brush, "strength", slider=True, text="Strength") + class TOPBAR_PT_redo(Panel): bl_label = "Redo" bl_space_type = 'TOPBAR' diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py index 09fa7406dc5..577cd465ff1 100644 --- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py +++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py @@ -1094,7 +1094,7 @@ class VIEW3D_PT_tools_weightpaint_options(Panel, View3DPaintPanel): class VIEW3D_PT_tools_vertexpaint(Panel, View3DPaintPanel): bl_category = "Options" - bl_context = "vertexpaint" + bl_context = ".vertexpaint" # dot on purpose (access from topbar) bl_label = "Options" def draw(self, context): @@ -1110,7 +1110,7 @@ class VIEW3D_PT_tools_vertexpaint(Panel, View3DPaintPanel): class VIEW3D_PT_tools_vertexpaint_symmetry(Panel, View3DPaintPanel): bl_category = "Tools" - bl_context = "vertexpaint" + bl_context = ".vertexpaint" # dot on purpose (access from topbar) bl_options = {'DEFAULT_CLOSED'} bl_label = "Symmetry" |