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:
-rw-r--r--release/scripts/startup/bl_ui/space_toolsystem_toolbar.py2
-rw-r--r--source/blender/blenkernel/BKE_brush.h3
-rw-r--r--source/blender/blenkernel/intern/brush.c18
-rw-r--r--source/blender/makesdna/DNA_brush_types.h4
-rw-r--r--source/blender/makesrna/intern/rna_brush.c36
-rw-r--r--source/blender/makesrna/intern/rna_object.c18
6 files changed, 77 insertions, 4 deletions
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index af65ca35c52..4224ee02910 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -1127,6 +1127,8 @@ class _defs_gpencil_paint:
row.template_ID(gp_settings, "material", live_icon=True)
else:
row.template_greasepencil_color(gp_settings, "material", rows=3, cols=8, scale=0.8)
+ row.prop(gp_settings, "pin_material", text="")
+
@staticmethod
def draw_settings_common(context, layout, tool):
diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h
index 42399835b53..ebfe47c2f99 100644
--- a/source/blender/blenkernel/BKE_brush.h
+++ b/source/blender/blenkernel/BKE_brush.h
@@ -37,6 +37,8 @@ struct Main;
struct Scene;
struct ToolSettings;
struct UnifiedPaintSettings;
+struct Material;
+
// enum eCurveMappingPreset;
#include "DNA_object_enums.h"
@@ -58,6 +60,7 @@ void BKE_brush_free(struct Brush *brush);
void BKE_brush_sculpt_reset(struct Brush *brush);
void BKE_brush_gpencil_presets(struct bContext *C);
+void BKE_brush_update_material(struct Main *bmain, struct Material *ma, struct Brush *exclude_brush);
struct Brush *BKE_brush_getactive_gpencil(struct ToolSettings *ts);
struct Paint *BKE_brush_get_gpencil_paint(struct ToolSettings *ts);
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index e1cc3984601..1444cc6deaf 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -525,6 +525,24 @@ void BKE_brush_gpencil_presets(bContext *C)
}
+void BKE_brush_update_material(Main *bmain, Material *ma, Brush *exclude_brush)
+{
+ for (Brush *brush = bmain->brush.first; brush; brush = brush->id.next) {
+ if ((exclude_brush != NULL) && (brush == exclude_brush)) {
+ continue;
+ }
+
+ if (brush->gpencil_settings != NULL) {
+ BrushGpencilSettings *gpencil_settings = brush->gpencil_settings;
+ if (((gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) == 0) &&
+ (gpencil_settings->material != ma))
+ {
+ gpencil_settings->material = ma;
+ }
+ }
+ }
+}
+
/* get the active gp-brush for editing */
Brush *BKE_brush_getactive_gpencil(ToolSettings *ts)
{
diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h
index dcb7fbd344b..09d5ec92859 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -117,7 +117,9 @@ typedef enum eGPDbrush_Flag {
/* settings group */
GP_BRUSH_GROUP_SETTINGS = (1 << 11),
/* Random settings group */
- GP_BRUSH_GROUP_RANDOM = (1 << 12)
+ GP_BRUSH_GROUP_RANDOM = (1 << 12),
+ /* Keep material assigned to brush */
+ GP_BRUSH_MATERIAL_PINNED = (1 << 13)
} eGPDbrush_Flag;
/* BrushGpencilSettings->gp_fill_draw_mode */
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index 8ad77b88702..3df84a3a85b 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -171,6 +171,7 @@ static EnumPropertyItem rna_enum_gpencil_brush_icons_items[] = {
#include "BKE_colorband.h"
#include "BKE_brush.h"
#include "BKE_icons.h"
+#include "BKE_gpencil.h"
#include "BKE_paint.h"
#include "WM_api.h"
@@ -411,6 +412,31 @@ static void rna_Brush_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerR
/*WM_main_add_notifier(NC_SPACE|ND_SPACE_VIEW3D, NULL); */
}
+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);
+ }
+}
+
static void rna_Brush_main_tex_update(bContext *C, PointerRNA *ptr)
{
Main *bmain = CTX_data_main(C);
@@ -1202,10 +1228,10 @@ static void rna_def_gpencil_options(BlenderRNA *brna)
prop = RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Material");
RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_BrushGpencilSettings_material_poll");
- RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK | PROP_CONTEXT_UPDATE);
RNA_def_property_ui_text(prop, "Material", "Material used for strokes drawn using this brush");
RNA_def_parameter_clear_flags(prop, PROP_ANIMATABLE, 0);
- RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
+ RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_Brush_material_update");
prop = RNA_def_property(srna, "gpencil_fill_show_boundary", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_FILL_SHOW_HELPLINES);
@@ -1236,6 +1262,12 @@ static void rna_def_gpencil_options(BlenderRNA *brna)
RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_GROUP_RANDOM);
RNA_def_property_ui_text(prop, "Random Settings", "Enable random settings for brush");
RNA_def_parameter_clear_flags(prop, PROP_ANIMATABLE, 0);
+
+ prop = RNA_def_property(srna, "pin_material", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_MATERIAL_PINNED);
+ 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);
}
static void rna_def_brush(BlenderRNA *brna)
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 44e13437b9f..cf5b3aff571 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include "DNA_action_types.h"
+#include "DNA_brush_types.h"
#include "DNA_customdata_types.h"
#include "DNA_group_types.h"
#include "DNA_material_types.h"
@@ -193,6 +194,7 @@ const EnumPropertyItem rna_enum_object_axis_items[] = {
#include "DNA_node_types.h"
#include "BKE_armature.h"
+#include "BKE_brush.h"
#include "BKE_constraint.h"
#include "BKE_context.h"
#include "BKE_curve.h"
@@ -242,6 +244,20 @@ static void rna_Object_hide_update(Main *bmain, Scene *UNUSED(scene), PointerRNA
WM_main_add_notifier(NC_OBJECT | ND_DRAW, &ob->id);
}
+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);
+ }
+ }
+}
+
+
static void rna_Object_matrix_local_get(PointerRNA *ptr, float values[16])
{
Object *ob = ptr->id.data;
@@ -2215,7 +2231,7 @@ static void rna_def_object(BlenderRNA *brna)
RNA_def_property_int_funcs(prop, "rna_Object_active_material_index_get", "rna_Object_active_material_index_set",
"rna_Object_active_material_index_range");
RNA_def_property_ui_text(prop, "Active Material Index", "Index of active material slot");
- RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING_LINKS, NULL);
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING_LINKS, "rna_MaterialIndex_update");
/* transform */
prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION);