GP: Select color in Brush or in Properties

After some artist feedback the material selection was not clear.

Now, the material can be selected in the top bar or in the properties panel.

1) If the material is selected in properties panel, all Brushes except pinned will be assigned to this material.

2) If the material is selected in the brush, the properties panel is updated to set the active material.

Added a new Pin icon to keep locked the material to one brush
This commit is contained in:
Antonioya 2018-08-24 23:59:56 +02:00
parent 6901712734
commit 1a7837596c
6 changed files with 77 additions and 4 deletions

View File

@ -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):

View File

@ -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);

View File

@ -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)
{

View File

@ -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 */

View File

@ -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)

View File

@ -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);