Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_edit.c
| Show First 20 Lines • Show All 1,185 Lines • ▼ Show 20 Lines | static int gp_strokes_copy_exec(bContext *C, wmOperator *op) | ||||
| CTX_DATA_END; | CTX_DATA_END; | ||||
| /* Build up hash of material colors used in these strokes */ | /* Build up hash of material colors used in these strokes */ | ||||
| if (gp_strokes_copypastebuf.first) { | if (gp_strokes_copypastebuf.first) { | ||||
| gp_strokes_copypastebuf_colors = BLI_ghash_int_new("GPencil CopyBuf Colors"); | gp_strokes_copypastebuf_colors = BLI_ghash_int_new("GPencil CopyBuf Colors"); | ||||
| GHash *ma_to_name = gp_strokes_copypastebuf_colors_material_to_name_create(bmain); | GHash *ma_to_name = gp_strokes_copypastebuf_colors_material_to_name_create(bmain); | ||||
| for (bGPDstroke *gps = gp_strokes_copypastebuf.first; gps; gps = gps->next) { | for (bGPDstroke *gps = gp_strokes_copypastebuf.first; gps; gps = gps->next) { | ||||
| if (ED_gpencil_stroke_can_use(C, gps)) { | if (ED_gpencil_stroke_can_use(C, gps)) { | ||||
| Material *ma = give_current_material(ob, gps->mat_nr + 1); | |||||
| /* Avoid default material. */ | |||||
| if (ma == NULL) { | |||||
| continue; | |||||
| } | |||||
| char **ma_name_val; | char **ma_name_val; | ||||
| if (!BLI_ghash_ensure_p( | if (!BLI_ghash_ensure_p( | ||||
| gp_strokes_copypastebuf_colors, &gps->mat_nr, (void ***)&ma_name_val)) { | gp_strokes_copypastebuf_colors, &gps->mat_nr, (void ***)&ma_name_val)) { | ||||
| Material *ma = give_current_material(ob, gps->mat_nr + 1); | |||||
| char *ma_name = BLI_ghash_lookup(ma_to_name, ma); | char *ma_name = BLI_ghash_lookup(ma_to_name, ma); | ||||
| *ma_name_val = MEM_dupallocN(ma_name); | *ma_name_val = MEM_dupallocN(ma_name); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| gp_strokes_copypastebuf_colors_material_to_name_free(ma_to_name); | gp_strokes_copypastebuf_colors_material_to_name_free(ma_to_name); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 2,857 Lines • ▼ Show 20 Lines | CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { | ||||
| /* add frame if not created before */ | /* add frame if not created before */ | ||||
| if (gpf_dst == NULL) { | if (gpf_dst == NULL) { | ||||
| gpf_dst = BKE_gpencil_layer_getframe(gpl_dst, gpf->framenum, GP_GETFRAME_ADD_NEW); | gpf_dst = BKE_gpencil_layer_getframe(gpl_dst, gpf->framenum, GP_GETFRAME_ADD_NEW); | ||||
| } | } | ||||
| /* add duplicate materials */ | /* add duplicate materials */ | ||||
| /* XXX same material can be in multiple slots. */ | /* XXX same material can be in multiple slots. */ | ||||
| ma = give_current_material(ob, gps->mat_nr + 1); | ma = BKE_material_gpencil_get(ob, gps->mat_nr + 1); | ||||
| idx = BKE_gpencil_object_material_ensure(bmain, ob_dst, ma); | idx = BKE_gpencil_object_material_ensure(bmain, ob_dst, ma); | ||||
| /* selected points mode */ | /* selected points mode */ | ||||
| if (mode == GP_SEPARATE_POINT) { | if (mode == GP_SEPARATE_POINT) { | ||||
| /* make copy of source stroke */ | /* make copy of source stroke */ | ||||
| bGPDstroke *gps_dst = BKE_gpencil_stroke_duplicate(gps); | bGPDstroke *gps_dst = BKE_gpencil_stroke_duplicate(gps); | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | if (gpl) { | ||||
| /* add duplicate materials */ | /* add duplicate materials */ | ||||
| for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { | for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { | ||||
| for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { | for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { | ||||
| /* skip strokes that are invalid for current view */ | /* skip strokes that are invalid for current view */ | ||||
| if (ED_gpencil_stroke_can_use(C, gps) == false) { | if (ED_gpencil_stroke_can_use(C, gps) == false) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| ma = give_current_material(ob, gps->mat_nr + 1); | ma = BKE_material_gpencil_get(ob, gps->mat_nr + 1); | ||||
| gps->mat_nr = BKE_gpencil_object_material_ensure(bmain, ob_dst, ma); | gps->mat_nr = BKE_gpencil_object_material_ensure(bmain, ob_dst, ma); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| DEG_id_tag_update(&gpd_src->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); | DEG_id_tag_update(&gpd_src->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); | ||||
| DEG_id_tag_update(&gpd_dst->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); | DEG_id_tag_update(&gpd_dst->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); | ||||
| ▲ Show 20 Lines • Show All 506 Lines • Show Last 20 Lines | |||||