Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/gpencil.c
| Show First 20 Lines • Show All 747 Lines • ▼ Show 20 Lines | for (gpf_src = gpl_src->frames.first; gpf_src; gpf_src = gpf_src->next) { | ||||
| if (gpf_src == gpl_dst->actframe) | if (gpf_src == gpl_dst->actframe) | ||||
| gpl_dst->actframe = gpf_dst; | gpl_dst->actframe = gpf_dst; | ||||
| } | } | ||||
| /* return new layer */ | /* return new layer */ | ||||
| return gpl_dst; | return gpl_dst; | ||||
| } | } | ||||
| /** | |||||
| * Only copy internal data of GreasePencil ID from source to already allocated/initialized destination. | |||||
| * You probably nerver want to use that directly, use 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_library.h's LIB_ID_COPY_... flags for more). | |||||
| */ | |||||
| void BKE_gpencil_copy_data(Main *UNUSED(bmain), bGPdata *gpd_dst, const bGPdata *gpd_src, const int UNUSED(flag)) | |||||
| { | |||||
| /* copy layers */ | |||||
| BLI_listbase_clear(&gpd_dst->layers); | |||||
| for (const bGPDlayer *gpl_src = gpd_src->layers.first; gpl_src; gpl_src = gpl_src->next) { | |||||
| /* make a copy of source layer and its data */ | |||||
| bGPDlayer *gpl_dst = BKE_gpencil_layer_duplicate(gpl_src); /* TODO here too could add unused flags... */ | |||||
| BLI_addtail(&gpd_dst->layers, gpl_dst); | |||||
| } | |||||
| /* copy palettes */ | |||||
| BLI_listbase_clear(&gpd_dst->palettes); | |||||
| for (const bGPDpalette *palette_src = gpd_src->palettes.first; palette_src; palette_src = palette_src->next) { | |||||
| bGPDpalette *palette_dst = BKE_gpencil_palette_duplicate(palette_src); /* TODO here too could add unused flags... */ | |||||
| BLI_addtail(&gpd_dst->palettes, palette_dst); | |||||
| } | |||||
| } | |||||
| /* make a copy of a given gpencil datablock */ | /* make a copy of a given gpencil datablock */ | ||||
| bGPdata *BKE_gpencil_data_duplicate(Main *bmain, const bGPdata *gpd_src, bool internal_copy) | bGPdata *BKE_gpencil_data_duplicate(Main *bmain, const bGPdata *gpd_src, bool internal_copy) | ||||
| { | { | ||||
| /* Yuck and super-uber-hyper yuck!!! | |||||
| * Should be replaceable with a no-main copy (LIB_ID_COPY_NO_MAIN etc.), but not sure about it, | |||||
| * so for now keep old code for that one. */ | |||||
| if (internal_copy) { | |||||
| const bGPDlayer *gpl_src; | const bGPDlayer *gpl_src; | ||||
| bGPDlayer *gpl_dst; | bGPDlayer *gpl_dst; | ||||
| bGPdata *gpd_dst; | bGPdata *gpd_dst; | ||||
| /* error checking */ | |||||
| if (gpd_src == NULL) { | |||||
| return NULL; | |||||
| } | |||||
| /* make a copy of the base-data */ | |||||
| if (internal_copy) { | |||||
| /* make a straight copy for undo buffers used during stroke drawing */ | /* make a straight copy for undo buffers used during stroke drawing */ | ||||
| gpd_dst = MEM_dupallocN(gpd_src); | gpd_dst = MEM_dupallocN(gpd_src); | ||||
| } | |||||
| else { | |||||
| /* make a copy when others use this */ | |||||
| gpd_dst = BKE_libblock_copy(bmain, &gpd_src->id); | |||||
| } | |||||
| /* copy layers */ | /* copy layers */ | ||||
| BLI_listbase_clear(&gpd_dst->layers); | BLI_listbase_clear(&gpd_dst->layers); | ||||
| for (gpl_src = gpd_src->layers.first; gpl_src; gpl_src = gpl_src->next) { | for (gpl_src = gpd_src->layers.first; gpl_src; gpl_src = gpl_src->next) { | ||||
| /* make a copy of source layer and its data */ | /* make a copy of source layer and its data */ | ||||
| gpl_dst = BKE_gpencil_layer_duplicate(gpl_src); | gpl_dst = BKE_gpencil_layer_duplicate(gpl_src); | ||||
| BLI_addtail(&gpd_dst->layers, gpl_dst); | BLI_addtail(&gpd_dst->layers, gpl_dst); | ||||
| } | } | ||||
| if (!internal_copy) { | |||||
| /* copy palettes */ | |||||
| bGPDpalette *palette_src, *palette_dst; | |||||
| BLI_listbase_clear(&gpd_dst->palettes); | |||||
| for (palette_src = gpd_src->palettes.first; palette_src; palette_src = palette_src->next) { | |||||
| palette_dst = BKE_gpencil_palette_duplicate(palette_src); | |||||
| BLI_addtail(&gpd_dst->palettes, palette_dst); | |||||
| } | |||||
| } | |||||
| /* return new */ | /* return new */ | ||||
| return gpd_dst; | return gpd_dst; | ||||
| } | } | ||||
| else { | |||||
| bGPdata *gpd_copy; | |||||
| BKE_id_copy_ex(bmain, &gpd_src->id, (ID **)&gpd_copy, 0, false); | |||||
| return gpd_copy; | |||||
| } | |||||
| } | |||||
| void BKE_gpencil_make_local(Main *bmain, bGPdata *gpd, const bool lib_local) | void BKE_gpencil_make_local(Main *bmain, bGPdata *gpd, const bool lib_local) | ||||
| { | { | ||||
| BKE_id_make_local_generic(bmain, &gpd->id, true, lib_local); | BKE_id_make_local_generic(bmain, &gpd->id, true, lib_local); | ||||
| } | } | ||||
| /* -------- GP-Stroke API --------- */ | /* -------- GP-Stroke API --------- */ | ||||
| ▲ Show 20 Lines • Show All 536 Lines • Show Last 20 Lines | |||||