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
This commit is contained in:
Sean Kim
2025-01-06 18:52:01 +01:00
committed by Sean Kim
parent 1b82ef37be
commit 9e8c037375

View File

@@ -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<Paint *>(ptr->data);
Brush *brush = static_cast<Brush *>(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<Paint *>(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<Paint *>(ptr->data);
Brush *brush = static_cast<Brush *>(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<Paint *>(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");