[Bf-blender-cvs] [432bd312767] greasepencil-object: Fix compile error after merge
Joshua Leung
noreply at git.blender.org
Wed Oct 4 14:17:32 CEST 2017
Commit: 432bd3127675570cf782fe7b9d07701957236cb4
Author: Joshua Leung
Date: Thu Oct 5 01:16:24 2017 +1300
Branches: greasepencil-object
https://developer.blender.org/rB432bd3127675570cf782fe7b9d07701957236cb4
Fix compile error after merge
(Also added convenience API to make it easier to add new palettes to GP
datablock without having to worry about manually fixing usercount)
===================================================================
M source/blender/blenkernel/BKE_gpencil.h
M source/blender/blenkernel/intern/gpencil.c
M source/blender/editors/gpencil/gpencil_add_monkey.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 17fe3f82e23..f7719e1e6b0 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -159,6 +159,7 @@ void BKE_gpencil_paletteslot_set_active_palette(struct bGPdata *gpd, const struc
void BKE_gpencil_paletteslot_set_palette(struct bGPdata *gpd, struct bGPDpaletteref *palslot, struct Palette *palette);
struct bGPDpaletteref *BKE_gpencil_paletteslot_add(struct bGPdata *gpd, struct Palette *palette);
+struct bGPDpaletteref *BKE_gpencil_paletteslot_addnew(struct Main *bmain, struct bGPdata *gpd, char name[MAX_ID_NAME - 2]);
struct bGPDpaletteref *BKE_gpencil_paletteslot_validate(struct Main *bmain, struct bGPdata *gpd);
/* Palettes - Deprecated (2.78-2.79) */
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index b80c392d03e..87e3f0934e2 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -855,11 +855,16 @@ bGPDframe *BKE_gpencil_frame_duplicate(const bGPDframe *gpf_src)
/* fix any null value in palettes (this must be removed in the future) */
static void gpencil_fix_null_palette(const bContext *C, bGPDstroke *gps_src)
{
+ bGPdata *gpd = CTX_data_gpencil_data(C);
Palette *tmp_palette = NULL;
tmp_palette = BKE_palette_get_active_from_context(C);
if (!tmp_palette) {
- tmp_palette = BKE_palette_add_gpencil(C);
+ bGPDpaletteref *palslot;
+
+ palslot = BKE_gpencil_paletteslot_addnew(CTX_data_main(C), gpd,
+ "Auto-Generated Palette");
+ tmp_palette = palslot->palette;
}
gps_src->palette = tmp_palette;
@@ -1547,6 +1552,21 @@ bGPDpaletteref *BKE_gpencil_paletteslot_add(bGPdata *gpd, Palette *palette)
return palslot;
}
+/* Wrapper for BKE_gpencil_paletteslot_add() to add a new Palette + slot,
+ * and set all the usercounts correctly
+ */
+bGPDpaletteref *BKE_gpencil_paletteslot_addnew(Main *bmain, bGPdata *gpd, char name[MAX_ID_NAME - 2])
+{
+ /* create the palette first */
+ Palette *palette = BKE_palette_add(bmain, name);
+
+ /* lower the usercount, as assigning to the slot will add its own instead */
+ id_us_min(&palette->id);
+
+ /* create and return the new slot */
+ return BKE_gpencil_paletteslot_add(gpd, palette);
+}
+
/* 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/editors/gpencil/gpencil_add_monkey.c b/source/blender/editors/gpencil/gpencil_add_monkey.c
index 8f0c9f9a1ba..2ba22d0a12a 100644
--- a/source/blender/editors/gpencil/gpencil_add_monkey.c
+++ b/source/blender/editors/gpencil/gpencil_add_monkey.c
@@ -1354,12 +1354,8 @@ void ED_gpencil_create_monkey(bContext *C, bGPdata *gpd)
bGPDstroke *gps;
/* create palette and colors */
- Palette *palette = BKE_palette_add(bmain, "Monkey");
- bGPDpaletteref *palslot = BKE_gpencil_paletteslot_add(gpd, palette);
-
- /* palette already had users when created, but assigning to palslot added an extra one... */
- id_us_min(&palette->id);
-
+ bGPDpaletteref *palslot = BKE_gpencil_paletteslot_addnew(bmain, gpd, "Monkey");
+ Palette *palette = palslot->palette;
PaletteColor *color_Black = BKE_palette_color_add_name(palette, "Black");
ARRAY_SET_ITEMS(color_Black->rgb, 0.0f, 0.0f, 0.0f, 1.0f);
More information about the Bf-blender-cvs
mailing list