From 9e8c037375b42f7e2376549e55958cb98c4eea4e Mon Sep 17 00:00:00 2001 From: Sean Kim Date: Mon, 6 Jan 2025 18:52:01 +0100 Subject: [PATCH] Python API: Make `paint.brush` and `paint.eraser_brush` read-only With the brush asset project, the `Paint` `brush` and `eraser_brush` properties were effectively turned into a convenient cache of the active brush. A related operator, `paint.brush_set` was also removed in favor of `brush.asset_activate` While this is technically a breaking change to the API, it currently seems better to align this property with expected usage & other recent changes rather than allow users to set a property that may not behave as expected. There are two currently known side effects that setting this property via the Python API has that the equivalent call to brush.asset_activate does not: * Changing this property via the console or script, peforming a stroke and then undoing the stroke causes the active brush to change - this directly contrasts with the normal experience of using the asset shelf where brush changes are not affected by undo * The asset shelf itself does not update the currently active brush until a subsequent mouseover Pull Request: https://projects.blender.org/blender/blender/pulls/131991 --- .../makesrna/intern/rna_sculpt_paint.cc | 29 ++++--------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.cc b/source/blender/makesrna/intern/rna_sculpt_paint.cc index dd370cf6741..46b7b113cd0 100644 --- a/source/blender/makesrna/intern/rna_sculpt_paint.cc +++ b/source/blender/makesrna/intern/rna_sculpt_paint.cc @@ -275,14 +275,6 @@ static PointerRNA rna_Paint_brush_get(PointerRNA *ptr) return RNA_id_pointer_create(&brush->id); } -static void rna_Paint_brush_set(PointerRNA *ptr, PointerRNA value, ReportList * /*reports*/) -{ - Paint *paint = static_cast(ptr->data); - Brush *brush = static_cast(value.data); - BKE_paint_brush_set(paint, brush); - BKE_paint_invalidate_overlay_all(); -} - static bool rna_Paint_brush_poll(PointerRNA *ptr, PointerRNA value) { const Paint *paint = static_cast(ptr->data); @@ -301,14 +293,6 @@ static PointerRNA rna_Paint_eraser_brush_get(PointerRNA *ptr) return RNA_id_pointer_create(&brush->id); } -static void rna_Paint_eraser_brush_set(PointerRNA *ptr, PointerRNA value, ReportList * /*reports*/) -{ - Paint *paint = static_cast(ptr->data); - Brush *brush = static_cast(value.data); - BKE_paint_eraser_brush_set(paint, brush); - BKE_paint_invalidate_overlay_all(); -} - static bool rna_Paint_eraser_brush_poll(PointerRNA *ptr, PointerRNA value) { const Paint *paint = static_cast(ptr->data); @@ -547,10 +531,10 @@ static void rna_def_paint(BlenderRNA *brna) /* Global Settings */ prop = RNA_def_property(srna, "brush", PROP_POINTER, PROP_NONE); - RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_struct_type(prop, "Brush"); RNA_def_property_pointer_funcs( - prop, "rna_Paint_brush_get", "rna_Paint_brush_set", nullptr, "rna_Paint_brush_poll"); + prop, "rna_Paint_brush_get", nullptr, nullptr, "rna_Paint_brush_poll"); RNA_def_property_ui_text(prop, "Brush", "Active brush"); RNA_def_property_update(prop, NC_BRUSH | NA_SELECTED, nullptr); @@ -562,13 +546,10 @@ static void rna_def_paint(BlenderRNA *brna) "the last used brush on file load"); prop = RNA_def_property(srna, "eraser_brush", PROP_POINTER, PROP_NONE); - RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_struct_type(prop, "Brush"); - RNA_def_property_pointer_funcs(prop, - "rna_Paint_eraser_brush_get", - "rna_Paint_eraser_brush_set", - nullptr, - "rna_Paint_eraser_brush_poll"); + RNA_def_property_pointer_funcs( + prop, "rna_Paint_eraser_brush_get", nullptr, nullptr, "rna_Paint_eraser_brush_poll"); RNA_def_property_ui_text(prop, "Default Eraser Brush", "Default eraser brush for quickly alternating with the main brush");