Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonioya <blendergit@gmail.com>2019-03-25 19:02:42 +0300
committerAntonioya <blendergit@gmail.com>2019-03-25 19:06:07 +0300
commit7021bd527380b4d87cf48057f0039509326b03dd (patch)
tree55126437da17d736a789d236c8a98d199a1e6260 /source/blender/makesrna
parent84240ebb3ebde58f6bfba256e49d37697fb6bc9f (diff)
GPencil: Only brushes with pinned materials have materials
Using GP_BRUSH_MATERIAL_PINNED to switch between active material and brush material, instead of updating all brushes on active material changes. This will allow brushes to have no material and therefore to not inflate the user count. This fix T62465. Patch contributed by @matc Reviewers: @brecht @antoniov @billreynish @mendio
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r--source/blender/makesrna/intern/rna_brush.c44
-rw-r--r--source/blender/makesrna/intern/rna_object.c13
2 files changed, 30 insertions, 27 deletions
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index 7e4482790af..1a35fd8d0fb 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -159,6 +159,7 @@ static EnumPropertyItem rna_enum_gpencil_brush_icons_items[] = {
#include "BKE_icons.h"
#include "BKE_gpencil.h"
#include "BKE_paint.h"
+#include "BKE_material.h"
#include "WM_api.h"
@@ -444,27 +445,8 @@ static void rna_Brush_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerR
static void rna_Brush_material_update(bContext *C, PointerRNA *ptr)
{
- Main *bmain = CTX_data_main(C);
- ViewLayer *view_layer = CTX_data_view_layer(C);
- Object *ob = OBACT(view_layer);
- Brush *br = (Brush *)ptr->id.data;
- int index;
-
- /* set material slot to same material */
- if ((ob) && (ob->type == OB_GPENCIL) && (br->gpencil_settings != NULL)) {
- BrushGpencilSettings *gpencil_settings = br->gpencil_settings;
- if (gpencil_settings->material != NULL) {
-
- index = BKE_gpencil_get_material_index(ob, gpencil_settings->material);
- if ((index > 0) && (ob->actcol != index)) {
- ob->actcol = index;
- /* update other brushes to keep all synchro */
- BKE_brush_update_material(bmain, gpencil_settings->material, br);
- }
-
- }
- WM_main_add_notifier(NC_SPACE | ND_SPACE_PROPERTIES, NULL);
- }
+ /* number of material users changed */
+ WM_main_add_notifier(NC_SPACE | ND_SPACE_PROPERTIES, NULL);
}
static void rna_Brush_main_tex_update(bContext *C, PointerRNA *ptr)
@@ -723,6 +705,24 @@ static void rna_BrushGpencilSettings_default_eraser_update(Main *bmain, Scene *s
}
}
+static void rna_BrushGpencilSettings_use_material_pin_update(bContext *C, PointerRNA *ptr)
+{
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
+ Brush *brush = ptr->id.data;
+
+ if (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) {
+ Material *material = give_current_material(ob, ob->actcol);
+ BKE_gpencil_brush_set_material(brush, material);
+ }
+ else {
+ BKE_gpencil_brush_set_material(brush, NULL);
+ }
+
+ /* number of material users changed */
+ WM_event_add_notifier(C, NC_SPACE | ND_SPACE_PROPERTIES, NULL);
+}
+
static void rna_BrushGpencilSettings_eraser_mode_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
{
ToolSettings *ts = scene->toolsettings;
@@ -1337,9 +1337,11 @@ static void rna_def_gpencil_options(BlenderRNA *brna)
prop = RNA_def_property(srna, "use_material_pin", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_MATERIAL_PINNED);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_ui_icon(prop, ICON_UNPINNED, 1);
RNA_def_property_ui_text(prop, "Pin Material", "Keep material assigned to brush");
RNA_def_parameter_clear_flags(prop, PROP_ANIMATABLE, 0);
+ RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_BrushGpencilSettings_use_material_pin_update");
prop = RNA_def_property(srna, "show_lasso", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GP_BRUSH_DISSABLE_LASSO);
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 53bcb7e0bca..0eaddf0c44e 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -277,14 +277,10 @@ static void rna_Object_hide_update(Main *bmain, Scene *UNUSED(scene), PointerRNA
static void rna_MaterialIndex_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
{
- /* update the material of all brushes not pinned */
Object *ob = (Object *)ptr->id.data;
if (ob && ob->type == OB_GPENCIL) {
- Material *ma = give_current_material(ob, ob->actcol);
- if (ma != NULL) {
- BKE_brush_update_material(bmain, ma, NULL);
- WM_main_add_notifier(NC_SPACE | ND_SPACE_VIEW3D, NULL);
- }
+ /* notifying material property in topbar */
+ WM_main_add_notifier(NC_SPACE | ND_SPACE_VIEW3D, NULL);
}
}
@@ -821,6 +817,11 @@ static void rna_Object_active_material_set(PointerRNA *ptr, PointerRNA value)
BLI_assert(BKE_id_is_in_global_main(&ob->id));
BLI_assert(BKE_id_is_in_global_main(value.data));
assign_material(G_MAIN, ob, value.data, ob->actcol, BKE_MAT_ASSIGN_EXISTING);
+
+ if (ob && ob->type == OB_GPENCIL) {
+ /* notifying material property in topbar */
+ WM_main_add_notifier(NC_SPACE | ND_SPACE_VIEW3D, NULL);
+ }
}
static int rna_Object_active_material_editable(PointerRNA *ptr, const char **UNUSED(r_info))