Tool System: hide paint options for non brush tools
authorCampbell Barton <ideasman42@gmail.com>
Wed, 29 Aug 2018 13:58:44 +0000 (23:58 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 29 Aug 2018 13:58:44 +0000 (23:58 +1000)
release/scripts/startup/bl_ui/space_toolsystem_common.py
release/scripts/startup/bl_ui/space_topbar.py
source/blender/makesrna/intern/rna_workspace.c

index 727b0fd..e03b3eb 100644 (file)
@@ -526,6 +526,7 @@ class ToolSelectPanelHelper:
         draw_settings = item.draw_settings
         if draw_settings is not None:
             draw_settings(context, layout, tool)
+        return tool
 
 
 # The purpose of this menu is to be a generic popup to select between tools
index 5003f6c..cc3d925 100644 (file)
@@ -96,7 +96,7 @@ class TOPBAR_HT_lower_bar(Header):
         # Active Tool
         # -----------
         from .space_toolsystem_common import ToolSelectPanelHelper
-        ToolSelectPanelHelper.draw_active_tool_header(context, layout)
+        tool = ToolSelectPanelHelper.draw_active_tool_header(context, layout)
 
         # Object Mode Options
         # -------------------
@@ -107,17 +107,21 @@ class TOPBAR_HT_lower_bar(Header):
         # (obviously separated for from the users POV)
         draw_fn = getattr(_draw_left_context_mode, mode, None)
         if draw_fn is not None:
-            draw_fn(context, layout)
+            draw_fn(context, layout, tool)
 
         # Note: general mode options should be added to 'draw_right'.
         if mode == 'SCULPT':
-            layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
+            if tool.has_datablock:
+                layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
         elif mode == 'PAINT_VERTEX':
-            layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
+            if tool.has_datablock:
+                layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
         elif mode == 'PAINT_WEIGHT':
-            layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
+            if tool.has_datablock:
+                layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
         elif mode == 'PAINT_TEXTURE':
-            layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
+            if tool.has_datablock:
+                layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
         elif mode == 'EDIT_ARMATURE':
             pass
         elif mode == 'EDIT_CURVE':
@@ -128,7 +132,8 @@ class TOPBAR_HT_lower_bar(Header):
             pass
         elif mode == 'PARTICLE':
             # Disable, only shows "Brush" panel, which is already in the top-bar.
-            # layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
+            # if tool.has_datablock:
+            #     layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".paint_common", category="")
             pass
         elif mode == 'GPENCIL_PAINT':
             layout.popover_group(space_type='PROPERTIES', region_type='WINDOW', context=".greasepencil_paint", category="")
@@ -182,7 +187,9 @@ class TOPBAR_HT_lower_bar(Header):
 
 class _draw_left_context_mode:
     @staticmethod
-    def SCULPT(context, layout):
+    def SCULPT(context, layout, tool):
+        if not tool.has_datablock:
+            return
         brush = context.tool_settings.sculpt.brush
         if brush is None:
             return
@@ -193,7 +200,9 @@ 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_TEXTURE(context, layout):
+    def PAINT_TEXTURE(context, layout, tool):
+        if not tool.has_datablock:
+            return
         brush = context.tool_settings.vertex_paint.brush
         if brush is None:
             return
@@ -204,7 +213,9 @@ class _draw_left_context_mode:
         UnifiedPaintPanel.prop_unified_size(layout, context, brush, "size", slider=True, text="Radius")
         UnifiedPaintPanel.prop_unified_strength(layout, context, brush, "strength", slider=True, text="Strength")
 
-    def PAINT_VERTEX(context, layout):
+    def PAINT_VERTEX(context, layout, tool):
+        if not tool.has_datablock:
+            return
         brush = context.tool_settings.vertex_paint.brush
         if brush is None:
             return
@@ -215,7 +226,9 @@ class _draw_left_context_mode:
         UnifiedPaintPanel.prop_unified_size(layout, context, brush, "size", slider=True, text="Radius")
         UnifiedPaintPanel.prop_unified_strength(layout, context, brush, "strength", slider=True, text="Strength")
 
-    def PAINT_WEIGHT(context, layout):
+    def PAINT_WEIGHT(context, layout, tool):
+        if not tool.has_datablock:
+            return
         brush = context.tool_settings.weight_paint.brush
         if brush is None:
             return
@@ -226,7 +239,7 @@ class _draw_left_context_mode:
         UnifiedPaintPanel.prop_unified_size(layout, context, brush, "size", slider=True, text="Radius")
         UnifiedPaintPanel.prop_unified_strength(layout, context, brush, "strength", slider=True, text="Strength")
 
-    def PARTICLE(context, layout):
+    def PARTICLE(context, layout, tool):
         # See: 'VIEW3D_PT_tools_brush', basically a duplicate
         settings = context.tool_settings.particle_edit
         brush = settings.brush
index 88b79e8..db6a58f 100644 (file)
@@ -152,6 +152,12 @@ static int rna_WorkspaceTool_index_get(PointerRNA *ptr)
        return (tref->runtime) ? tref->runtime->index : 0;
 }
 
+static int rna_WorkspaceTool_has_datablock_get(PointerRNA *ptr)
+{
+       bToolRef *tref = ptr->data;
+       return (tref->runtime) ? (tref->runtime->data_block[0] != '\0') : false;
+}
+
 #else /* RNA_RUNTIME */
 
 static void rna_def_workspace_owner(BlenderRNA *brna)
@@ -230,6 +236,13 @@ static void rna_def_workspace_tool(BlenderRNA *brna)
        RNA_def_property_enum_items(prop, rna_enum_space_type_items);
        RNA_def_property_ui_text(prop, "Space Type", "");
 
+       RNA_define_verify_sdna(0);
+       prop = RNA_def_property(srna, "has_datablock", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Has Datablock", "");
+       RNA_def_property_boolean_funcs(prop, "rna_WorkspaceTool_has_datablock_get", NULL);
+       RNA_define_verify_sdna(1);
+
        RNA_api_workspace_tool(srna);
 }