[Bf-blender-cvs] [a87f9f8081f] temp-T96709-painting-target: Connect python panel to use `ED_paint_tool_use_canvas` logic.

Jeroen Bakker noreply at git.blender.org
Tue Mar 29 10:54:51 CEST 2022


Commit: a87f9f8081f6932c3b9c2646becde6bf57d57a64
Author: Jeroen Bakker
Date:   Tue Mar 29 10:53:18 2022 +0200
Branches: temp-T96709-painting-target
https://developer.blender.org/rBa87f9f8081f6932c3b9c2646becde6bf57d57a64

Connect python panel to use `ED_paint_tool_use_canvas` logic.

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

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/editors/sculpt_paint/paint_canvas.cc
M	source/blender/makesrna/intern/rna_internal.h
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/makesrna/intern/rna_space_api.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index a956ecbefdd..0109ef0fdd2 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -2227,20 +2227,9 @@ class VIEW3D_PT_tools_paint_canvas(View3DPanel, Panel):
     def poll(cls, context):
         if not context.preferences.experimental.use_sculpt_vertex_colors:
             return False
-
-        if context.active_object is None:
-            return False
-
-        # TODO: connect to ED_paint_tool_use_canvas.
-        from bl_ui.space_toolsystem_common import ToolSelectPanelHelper
-        tool_context = ToolSelectPanelHelper.tool_active_from_context(context)
-        if not tool_context:
+        if context.space_data is None:
             return False
-            
-        return tool_context.idname in [
-            "builtin_brush.Paint",
-            "builtin.color_filter",
-        ]
+        return context.space_data.uses_paint_canvas()
 
     def draw(self, context):
         layout = self.layout
diff --git a/source/blender/editors/sculpt_paint/paint_canvas.cc b/source/blender/editors/sculpt_paint/paint_canvas.cc
index 9a1a0040a85..829b5a39559 100644
--- a/source/blender/editors/sculpt_paint/paint_canvas.cc
+++ b/source/blender/editors/sculpt_paint/paint_canvas.cc
@@ -514,7 +514,7 @@ int ED_paint_canvas_uvmap_layer_index_get(const struct PaintModeSettings *settin
 bool ED_paint_tool_use_canvas(struct bContext *C, struct Object *ob)
 {
   /* Quick exit, only sculpt tools can use canvas. */
-  if (ob->sculpt == nullptr) {
+  if (ob == nullptr || ob->sculpt == nullptr) {
     return false;
   }
 
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index 84f083cb37a..ccd720eeab4 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -446,6 +446,7 @@ void RNA_api_wm(struct StructRNA *srna);
 void RNA_api_space_node(struct StructRNA *srna);
 void RNA_api_space_text(struct StructRNA *srna);
 void RNA_api_space_filebrowser(struct StructRNA *srna);
+void RNA_api_space_view3d(struct StructRNA *srna);
 void RNA_api_region_view3d(struct StructRNA *srna);
 void RNA_api_texture(struct StructRNA *srna);
 void RNA_api_sequences(BlenderRNA *brna, PropertyRNA *cprop, bool metastrip);
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 2344aa42838..90cf852ca64 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -5015,6 +5015,8 @@ static void rna_def_space_view3d(BlenderRNA *brna)
     RNA_def_property_ui_text(prop, "Visibility Icon", "");
   }
 
+  RNA_api_space_view3d(srna);
+
   /* Nested Structs */
   prop = RNA_def_property(srna, "shading", PROP_POINTER, PROP_NONE);
   RNA_def_property_flag(prop, PROP_NEVER_NULL);
diff --git a/source/blender/makesrna/intern/rna_space_api.c b/source/blender/makesrna/intern/rna_space_api.c
index 06bb2207b0a..b3879dedbee 100644
--- a/source/blender/makesrna/intern/rna_space_api.c
+++ b/source/blender/makesrna/intern/rna_space_api.c
@@ -14,6 +14,7 @@
 #  include "BKE_global.h"
 
 #  include "ED_fileselect.h"
+#  include "ED_paint.h"
 #  include "ED_screen.h"
 #  include "ED_text.h"
 
@@ -57,6 +58,12 @@ static void rna_SpaceTextEditor_region_location_from_cursor(
   }
 }
 
+static void rna_SpaceView3D_uses_paint_canvas(View3D *UNUSED(v3d), bContext *C, bool *r_result)
+{
+  Object *ob = CTX_data_active_object(C);
+  *r_result = ED_paint_tool_use_canvas(C, ob);
+}
+
 #else
 
 void RNA_api_region_view3d(StructRNA *srna)
@@ -68,6 +75,20 @@ void RNA_api_region_view3d(StructRNA *srna)
   RNA_def_function_ui_description(func, "Recalculate the view matrices");
 }
 
+void RNA_api_space_view3d(StructRNA *srna)
+{
+  FunctionRNA *func;
+  PropertyRNA *parm;
+
+  func = RNA_def_function(srna, "uses_paint_canvas", "rna_SpaceView3D_uses_paint_canvas");
+  RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+  RNA_def_function_ui_description(func, "Does this view have a canvas active for painting");
+  parm = RNA_def_boolean(
+      func, "result", false, "Use Paint Canvas", "Is there an active painting canvas");
+  RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+  RNA_def_function_output(func, parm);
+}
+
 void RNA_api_space_node(StructRNA *srna)
 {
   FunctionRNA *func;



More information about the Bf-blender-cvs mailing list