From e672cf11c3db51ad1e66f678e85bc5879ff714cb Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 9 Mar 2020 18:08:55 +0100 Subject: Cleanup: palette: Move to IDTypeInfo and remove unused BKE API. --- source/blender/blenkernel/intern/paint.c | 79 ++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 35 deletions(-) (limited to 'source/blender/blenkernel/intern/paint.c') diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index e6042b6ad4c..6afa498cf86 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -75,6 +75,50 @@ #include "bmesh.h" +static void palette_init_data(ID *id) +{ + Palette *palette = (Palette *)id; + + BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(palette, id)); + + /* Enable fake user by default. */ + id_fake_user_set(&palette->id); +} + +static void palette_copy_data(Main *UNUSED(bmain), + ID *id_dst, + const ID *id_src, + const int UNUSED(flag)) +{ + Palette *palette_dst = (Palette *)id_dst; + const Palette *palette_src = (const Palette *)id_src; + + BLI_duplicatelist(&palette_dst->colors, &palette_src->colors); +} + +static void palette_free_data(ID *id) +{ + Palette *palette = (Palette *)id; + + BLI_freelistN(&palette->colors); +} + +IDTypeInfo IDType_ID_PAL = { + .id_code = ID_PAL, + .id_filter = FILTER_ID_PAL, + .main_listbase_index = INDEX_ID_PAL, + .struct_size = sizeof(Palette), + .name = "Palette", + .name_plural = "palettes", + .translation_context = BLT_I18NCONTEXT_ID_PALETTE, + .flags = 0, + + .init_data = palette_init_data, + .copy_data = palette_copy_data, + .free_data = palette_free_data, + .make_local = NULL, +}; + static void paint_curve_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, @@ -642,24 +686,6 @@ Palette *BKE_palette_add(Main *bmain, const char *name) return palette; } -/** - * Only copy internal data of Palette ID from source - * to already allocated/initialized destination. - * You probably never want to use that directly, - * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. - * - * WARNING! This function will not handle ID user count! - * - * \param flag: Copying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more). - */ -void BKE_palette_copy_data(Main *UNUSED(bmain), - Palette *palette_dst, - const Palette *palette_src, - const int UNUSED(flag)) -{ - BLI_duplicatelist(&palette_dst->colors, &palette_src->colors); -} - Palette *BKE_palette_copy(Main *bmain, const Palette *palette) { Palette *palette_copy; @@ -667,23 +693,6 @@ Palette *BKE_palette_copy(Main *bmain, const Palette *palette) return palette_copy; } -void BKE_palette_make_local(Main *bmain, Palette *palette, const int flags) -{ - BKE_lib_id_make_local_generic(bmain, &palette->id, flags); -} - -void BKE_palette_init(Palette *palette) -{ - /* Enable fake user by default. */ - id_fake_user_set(&palette->id); -} - -/** Free (or release) any data used by this palette (does not free the palette itself). */ -void BKE_palette_free(Palette *palette) -{ - BLI_freelistN(&palette->colors); -} - PaletteColor *BKE_palette_color_add(Palette *palette) { PaletteColor *color = MEM_callocN(sizeof(*color), "Palette Color"); -- cgit v1.2.3