[Bf-blender-cvs] [2878a75e822] temp-T96709-painting-target: Change RNA API.

Jeroen Bakker noreply at git.blender.org
Tue Apr 5 15:20:35 CEST 2022


Commit: 2878a75e82261bdb68c97fadfd52c68f62256203
Author: Jeroen Bakker
Date:   Tue Apr 5 15:20:30 2022 +0200
Branches: temp-T96709-painting-target
https://developer.blender.org/rB2878a75e82261bdb68c97fadfd52c68f62256203

Change RNA API.

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

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/editors/include/ED_paint.h
M	source/blender/editors/sculpt_paint/paint_canvas.cc
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_internal.h
M	source/blender/makesrna/intern/rna_material.c
M	source/blender/makesrna/intern/rna_sculpt_paint.c
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/makesrna/intern/rna_space_api.c
M	source/blender/makesrna/intern/rna_workspace.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index dd6521cfdf4..5b446bdfdbf 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -458,6 +458,10 @@ class VIEW3D_MT_tools_projectpaint_uvlayer(Menu):
 
 class SelectPaintSlotHelper:
     bl_category = "Tool"
+
+    canvas_source_attr_name = "canvas_source"
+    canvas_image_attr_name = "canvas_image"
+
     def draw(self, context):
         layout = self.layout
         layout.use_property_split = True
@@ -468,12 +472,12 @@ class SelectPaintSlotHelper:
 
         ob = context.active_object
 
-        layout.prop(mode_settings, "mode", text="Mode")
+        layout.prop(mode_settings, self.canvas_source_attr_name, text="Mode")
         layout.separator()
 
         have_image = False
 
-        match mode_settings.mode:
+        match getattr(mode_settings, self.canvas_source_attr_name):
             case 'MATERIAL':
                 if len(ob.material_slots) > 1:
                     layout.template_list("MATERIAL_UL_matslots", "layers",
@@ -504,12 +508,12 @@ class SelectPaintSlotHelper:
             case 'IMAGE':
                 mesh = ob.data
                 uv_text = mesh.uv_layers.active.name if mesh.uv_layers.active else ""
-                layout.template_ID(mode_settings, "canvas", new="image.new", open="image.open")
+                layout.template_ID(mode_settings, self.canvas_image_attr_name, new="image.new", open="image.open")
                 if settings.missing_uvs:
                     layout.operator("paint.add_simple_uvs", icon='ADD', text="Add UVs")
                 else:
                     layout.menu("VIEW3D_MT_tools_projectpaint_uvlayer", text=uv_text, translate=False)
-                have_image = settings.canvas is not None
+                have_image = getattr(settings, self.canvas_image_attr_name) is not None
                 
                 self.draw_image_interpolation(layout=layout, mode_settings=mode_settings)
 
@@ -533,6 +537,9 @@ class VIEW3D_PT_slots_projectpaint(SelectPaintSlotHelper, View3DPanel, Panel):
     bl_context = ".imagepaint"  # dot on purpose (access from topbar)
     bl_label = "Texture Slots"
 
+    canvas_source_attr_name = "mode"
+    canvas_image_attr_name = "canvas"
+
     @classmethod
     def poll(cls, context):
         brush = context.tool_settings.image_paint.brush
@@ -555,9 +562,11 @@ class VIEW3D_PT_slots_paint_canvas(SelectPaintSlotHelper, View3DPanel, Panel):
     def poll(cls, context):
         if not context.preferences.experimental.use_sculpt_vertex_colors:
             return False
-        if context.space_data is None:
+        from bl_ui.space_toolsystem_common import ToolSelectPanelHelper
+        tool = ToolSelectPanelHelper.tool_active_from_context(context)
+        if tool is None:
             return False
-        return context.space_data.uses_paint_canvas()
+        return tool.use_paint_canvas
 
     def get_mode_settings(self, context):
         return context.tool_settings.paint_mode
diff --git a/source/blender/editors/include/ED_paint.h b/source/blender/editors/include/ED_paint.h
index 105f08a30bd..e222750499a 100644
--- a/source/blender/editors/include/ED_paint.h
+++ b/source/blender/editors/include/ED_paint.h
@@ -126,8 +126,12 @@ eV3DShadingColorType ED_paint_shading_color_override(struct bContext *C,
                                                      struct Object *ob,
                                                      eV3DShadingColorType orig_color_type);
 
-/** Does the active tool uses a paint canvas for the given object. */
-bool ED_paint_tool_use_canvas(struct bContext *C, struct Object *ob);
+/**
+ * Does the given tool use a paint canvas.
+ * 
+ * When #tref isn't given the active tool from the context is used.
+ */
+bool ED_paint_tool_use_canvas(struct bContext *C, struct bToolRef *tref);
 
 /* Store the last used tool in the sculpt session. */
 void ED_paint_tool_update_sticky_shading_color(struct bContext *C, struct Object *ob);
diff --git a/source/blender/editors/sculpt_paint/paint_canvas.cc b/source/blender/editors/sculpt_paint/paint_canvas.cc
index 0cdc34bc00a..ac934ee179d 100644
--- a/source/blender/editors/sculpt_paint/paint_canvas.cc
+++ b/source/blender/editors/sculpt_paint/paint_canvas.cc
@@ -89,19 +89,16 @@ static bool paint_tool_shading_color_follows_last_used_tool(struct bContext *C,
   return paint_tool_shading_color_follows_last_used(tref->idname);
 }
 
-bool ED_paint_tool_use_canvas(struct bContext *C, struct Object *ob)
+bool ED_paint_tool_use_canvas(struct bContext *C, bToolRef *tref)
 {
-  /* Quick exit, only sculpt tools can use canvas. */
-  if (ob == nullptr || ob->sculpt == nullptr) {
-    return false;
+  if (tref == nullptr) {
+    tref = WM_toolsystem_ref_from_context(C);
   }
-
-  bToolRef *tref = WM_toolsystem_ref_from_context(C);
-  if (tref != nullptr) {
-    return paint_tool_uses_canvas(tref->idname);
+  if (tref == nullptr) {
+    return false;
   }
 
-  return false;
+  return paint_tool_uses_canvas(tref->idname);
 }
 
 eV3DShadingColorType ED_paint_shading_color_override(bContext *C,
@@ -113,7 +110,7 @@ eV3DShadingColorType ED_paint_shading_color_override(bContext *C,
    * For better integration with the vertex paint in sculpt mode we sticky
    * with the last stoke when using tools like masking.
    */
-  if (!ED_paint_tool_use_canvas(C, ob) &&
+  if (!ED_paint_tool_use_canvas(C, nullptr) &&
       !(paint_tool_shading_color_follows_last_used_tool(C, ob) &&
         ob->sculpt->sticky_shading_color)) {
     return orig_color_type;
@@ -161,7 +158,7 @@ Image *ED_paint_canvas_image_get(const struct PaintModeSettings *settings, struc
     case PAINT_CANVAS_SOURCE_COLOR_ATTRIBUTE:
       return nullptr;
     case PAINT_CANVAS_SOURCE_IMAGE:
-      return settings->image;
+      return settings->canvas_image;
     case PAINT_CANVAS_SOURCE_MATERIAL: {
       TexPaintSlot *slot = get_active_slot(ob);
       if (slot == nullptr) {
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index 29f0bcc9055..9cc4d5ed55b 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -938,7 +938,7 @@ typedef struct PaintModeSettings {
   char _pad[7];
 
   /** Selected image when canvas_source=PAINT_CANVAS_SOURCE_IMAGE. */
-  Image *image;
+  Image *canvas_image;
 
 } PaintModeSettings;
 
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index 2bd6f1a6a8d..0df0be07fee 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -450,7 +450,6 @@ 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_material.c b/source/blender/makesrna/intern/rna_material.c
index 67434e14faf..7cedf71b7e2 100644
--- a/source/blender/makesrna/intern/rna_material.c
+++ b/source/blender/makesrna/intern/rna_material.c
@@ -1030,7 +1030,6 @@ static void rna_def_tex_slot(BlenderRNA *brna)
       srna, "Texture Paint Slot", "Slot that contains information about texture painting");
 
   prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
-  RNA_def_property_string_maxlength(prop, 64); /* else it uses the pointer size! */
   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
   RNA_def_property_string_funcs(
       prop, "rna_TexPaintSlot_name_get", "rna_TexPaintSlot_name_length", NULL);
diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c
index 620e8e753f0..fdbfd249ba8 100644
--- a/source/blender/makesrna/intern/rna_sculpt_paint.c
+++ b/source/blender/makesrna/intern/rna_sculpt_paint.c
@@ -552,7 +552,7 @@ static void rna_ImaPaint_canvas_update(bContext *C, PointerRNA *UNUSED(ptr))
 /** \name Paint mode settings
  * \{ */
 
-static bool rna_PaintModeSettings_image_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
+static bool rna_PaintModeSettings_canvas_image_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
 {
   Image *image = (Image *)value.owner_id;
   return !ELEM(image->type, IMA_TYPE_COMPOSITE, IMA_TYPE_R_RESULT);
@@ -1042,9 +1042,7 @@ static void rna_def_paint_mode(BlenderRNA *brna)
   RNA_def_struct_path_func(srna, "rna_PaintModeSettings_path");
   RNA_def_struct_ui_text(srna, "Paint Mode", "Properties of paint mode");
 
-  /* Property mode, sync API name with TexPaintSettings.mode */
-  prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
-  RNA_def_property_enum_sdna(prop, NULL, "canvas_source");
+  prop = RNA_def_property(srna, "canvas_source", PROP_ENUM, PROP_NONE);
   RNA_def_property_enum_items(prop, rna_enum_canvas_source_items);
   RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
   RNA_def_property_enum_funcs(prop,
@@ -1054,10 +1052,9 @@ static void rna_def_paint_mode(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "Source", "Source to select canvas from");
   RNA_def_property_update(prop, 0, "rna_PaintModeSettings_canvas_source_update");
 
-  /* Property canvas, sync API name with TexPaintSettings.canvas */
-  prop = RNA_def_property(srna, "canvas", PROP_POINTER, PROP_NONE);
-  RNA_def_property_pointer_sdna(prop, NULL, "image");
-  RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_PaintModeSettings_image_poll");
+  prop = RNA_def_property(srna, "canvas_image", PROP_POINTER, PROP_NONE);
+  RNA_def_property_pointer_funcs(
+      prop, NULL, NULL, NULL, "rna_PaintModeSettings_canvas_image_poll");
   RNA_def_property_flag(prop, PROP_EDITABLE | PROP_CONTEXT_UPDATE);
   RNA_def_property_ui_text(prop, "Texture", "Image used as as painting target");
 }
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_sp

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list