Commit: 338903f5f5f976a5ebf0c91ebb73cab3e3a041e7 Author: Antonio Vazquez Date: Tue Mar 13 12:59:19 2018 +0100 Branches: greasepencil-object https://developer.blender.org/rB338903f5f5f976a5ebf0c91ebb73cab3e3a041e7
New default color for Brush If the brush defines a default Palette and Color, when draw the color used is this and not the current context default color. Still there is problem when change drawing mode from Line to Dots. =================================================================== M release/scripts/startup/bl_ui/space_view3d_toolbar.py M source/blender/blenkernel/BKE_gpencil.h M source/blender/blenkernel/intern/gpencil.c M source/blender/blenloader/intern/readfile.c M source/blender/editors/gpencil/gpencil_paint.c M source/blender/makesdna/DNA_brush_types.h M source/blender/makesrna/intern/rna_brush.c =================================================================== diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py index 64868af2b6e..ba320173a4f 100644 --- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py +++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py @@ -2156,6 +2156,14 @@ class VIEW3D_PT_tools_grease_pencil_brush_option(Panel): col.prop(brush, "active_smooth_factor") col.separator() + col.label("Color Settings:") + col.template_ID(brush, "palette") + if brush.palette: + col.separator() + subcol = col.column() + subcol.prop_search(brush, "colorname", brush.palette, "colors", text="Color", icon="LAYER_ACTIVE") + col.separator() + if brush.gpencil_brush_type == 'DRAW': col.prop(brush, "use_stabilizer", text="Stabilizer") if brush.use_stabilizer: diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h index 5e3a9865824..3b781e8f0a4 100644 --- a/source/blender/blenkernel/BKE_gpencil.h +++ b/source/blender/blenkernel/BKE_gpencil.h @@ -47,6 +47,7 @@ struct bGPDpalettecolor; struct Main; struct PaletteColor; struct BoundBox; +struct Brush; struct Object; struct bDeformGroup; struct GpencilSimplifyModifierData; @@ -149,6 +150,7 @@ void BKE_gpencil_paletteslot_set_palette(struct bGPdata *gpd, struct bGPDpalette struct bGPDpaletteref *BKE_gpencil_paletteslot_add(struct bGPdata *gpd, struct Palette *palette); struct bGPDpaletteref *BKE_gpencil_paletteslot_addnew(struct Main *bmain, struct bGPdata *gpd, const char name[]); struct bGPDpaletteref *BKE_gpencil_paletteslot_validate(struct Main *bmain, struct bGPdata *gpd); +struct PaletteColor *BKE_gpencil_get_color_from_brush(struct bGPdata *gpd, struct Brush *brush); /* Palettes - Deprecated (2.78-2.79) */ void BKE_gpencil_free_palettes(struct ListBase *list); diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index a337b3b4143..cac976f0b85 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -1281,6 +1281,32 @@ bGPDpaletteref *BKE_gpencil_paletteslot_addnew(Main *bmain, bGPdata *gpd, const return BKE_gpencil_paletteslot_add(gpd, palette); } +PaletteColor *BKE_gpencil_get_color_from_brush(bGPdata *gpd, Brush *brush) +{ + bGPDpaletteref *palslot = NULL; + PaletteColor *palcolor = NULL; + + if ((brush->palette) && (brush->colorname)) { + + /* verify paletteslots has this palette */ + for (bGPDpaletteref *slot = gpd->palette_slots.first; slot; slot = slot->next) { + if (slot->palette == brush->palette) { + palslot = slot; + break; + } + } + /* add slot */ + if (palslot == NULL) { + palslot = BKE_gpencil_paletteslot_add(gpd, NULL); + palslot->palette = brush->palette; + } + + palcolor = BKE_palette_color_getbyname(brush->palette, brush->colorname); + } + + return palcolor; +} + /* Get active palette slot, and add all default settings if we don't find anything */ bGPDpaletteref *BKE_gpencil_paletteslot_validate(Main *bmain, bGPdata *gpd) { diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 81ca27e43cd..04970a54133 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2331,6 +2331,9 @@ static void lib_link_brush(FileData *fd, Main *main) brush->toggle_brush = newlibadr(fd, brush->id.lib, brush->toggle_brush); brush->paint_curve = newlibadr_us(fd, brush->id.lib, brush->paint_curve); + /* link default grease pencil palette */ + brush->palette = newlibadr(fd, brush->id.lib, brush->palette); + brush->id.tag &= ~LIB_TAG_NEED_LINK; } } @@ -8972,8 +8975,8 @@ static void lib_link_all(FileData *fd, Main *main) lib_link_action(fd, main); lib_link_vfont(fd, main); lib_link_nodetree(fd, main); /* has to be done after scene/materials, this will verify group nodes */ - lib_link_brush(fd, main); lib_link_palette(fd, main); + lib_link_brush(fd, main); lib_link_paint_curve(fd, main); lib_link_particlesettings(fd, main); lib_link_movieclip(fd, main); diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 603168fcdb4..d39d4fb2a89 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -1563,18 +1563,26 @@ static void gp_init_drawing_brush(bContext *C, tGPsdata *p) static void gp_init_palette(tGPsdata *p) { bGPdata *gpd = p->gpd; - - bGPDpaletteref *palslot; + Brush *brush = p->brush; + + bGPDpaletteref *palslot = NULL; Palette *palette = NULL; PaletteColor *palcolor = NULL; - /* get palette and color info + /* if the brush has a palette and color defined, use these and not current defaults */ + palcolor = BKE_gpencil_get_color_from_brush(gpd, brush); + + /* if no brush defaults, get palette and color info * NOTE: _validate() ensures that everything we need will exist... */ - palslot = BKE_gpencil_paletteslot_validate(p->bmain, gpd); - palette = palslot->palette; - palcolor = BKE_palette_color_get_active(palette); - + if (palcolor != NULL) { + palette = brush->palette; + } + else { + palslot = BKE_gpencil_paletteslot_validate(p->bmain, gpd); + palette = palslot->palette; + palcolor = BKE_palette_color_get_active(palette); + } /* assign color to temp tGPsdata */ if (palcolor) { p->palette = palette; diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h index 989c6bfdac0..f08e492c434 100644 --- a/source/blender/makesdna/DNA_brush_types.h +++ b/source/blender/makesdna/DNA_brush_types.h @@ -179,6 +179,10 @@ typedef struct Brush { int gp_eraser_mode; /* soft, hard or stroke */ float gp_active_smooth; /* smooth while drawing factor */ char pad_[4]; + + /* optional link of palette and color to replace default color in context */ + struct Palette *palette; /* palette linked */ + char colorname[64]; /* color name */ } Brush; /* Brush->gp_flag */ diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c index 63a04ef591c..ad96b5f20f1 100644 --- a/source/blender/makesrna/intern/rna_brush.c +++ b/source/blender/makesrna/intern/rna_brush.c @@ -689,6 +689,27 @@ static void rna_brush_gpencil_eraser_mode(Main *bmain, Scene *scene, PointerRNA } +static void rna_BrushPalette_colorname_reset(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) +{ + /* reset colorname */ + Brush *brush = ptr->data; + brush->colorname[0] = '\0'; +} + +/* check the current color is valid */ +static int rna_Brush_color_valid(PointerRNA *ptr) +{ + Brush *brush = ptr->data; + Palette *palette = brush->palette; + PaletteColor *palcolor = BKE_palette_color_getbyname(palette, brush->colorname); + + if (palcolor) { + return true; + } + + return false; +} + #else static void rna_def_brush_texture_slot(BlenderRNA *brna) @@ -1784,6 +1805,25 @@ static void rna_def_brush(BlenderRNA *brna) RNA_def_property_enum_items(prop, rna_enum_gpencil_fill_draw_modes_items); RNA_def_property_ui_text(prop, "Mode", "Mode to draw boundary limits"); + /* Palette */ + prop = RNA_def_property(srna, "palette", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "Palette"); + RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK); + RNA_def_property_ui_text(prop, "Palette", "Palette used when enable this brush"); + RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_BrushPalette_colorname_reset"); + + /* Color Name */ + prop = RNA_def_property(srna, "colorname", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, NULL, "colorname"); + RNA_def_property_ui_text(prop, "Color", "Name of the color used when enable this brush"); + RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL); + + prop = RNA_def_property(srna, "is_color_valid", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_funcs(prop, "rna_Brush_color_valid", NULL); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Color valid", "Flag to check if color name exist in current palette"); + RNA_def_property_update(prop, NC_GPENCIL | ND_DATA | NA_SELECTED, NULL); + prop = RNA_def_property(srna, "gpencil_fill_show_boundary", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "gp_flag", GP_BRUSH_FILL_SHOW_HELPLINES); RNA_def_property_boolean_default(prop, true); _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs