Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_edit.c
| Show First 20 Lines • Show All 1,235 Lines • ▼ Show 20 Lines | static bool gp_strokes_paste_poll(bContext *C) | ||||
| * but that should prompt a warning instead. | * but that should prompt a warning instead. | ||||
| * 2) Copy buffer must at least have something (though it may be the wrong sort...). | * 2) Copy buffer must at least have something (though it may be the wrong sort...). | ||||
| */ | */ | ||||
| return (ED_gpencil_data_get_active(C) != NULL) && | return (ED_gpencil_data_get_active(C) != NULL) && | ||||
| (!BLI_listbase_is_empty(&gp_strokes_copypastebuf)); | (!BLI_listbase_is_empty(&gp_strokes_copypastebuf)); | ||||
| } | } | ||||
| typedef enum eGP_PasteMode { | typedef enum eGP_PasteMode { | ||||
| GP_COPY_ONLY = -1, | GP_COPY_BY_LAYER = -1, | ||||
| GP_COPY_MERGE = 1, | GP_COPY_TO_ACTIVE = 1, | ||||
| } eGP_PasteMode; | } eGP_PasteMode; | ||||
| static int gp_strokes_paste_exec(bContext *C, wmOperator *op) | static int gp_strokes_paste_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| bGPdata *gpd = ED_gpencil_data_get_active(C); | bGPdata *gpd = ED_gpencil_data_get_active(C); | ||||
| bGPDlayer *gpl = CTX_data_active_gpencil_layer(C); /* only use active for copy merge */ | bGPDlayer *gpl = CTX_data_active_gpencil_layer(C); /* only use active for copy merge */ | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Show All 16 Lines | BKE_report(op->reports, | ||||
| RPT_ERROR, | RPT_ERROR, | ||||
| "No strokes to paste, select and copy some points before trying again"); | "No strokes to paste, select and copy some points before trying again"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| else if (gpl == NULL) { | else if (gpl == NULL) { | ||||
| /* no active layer - let's just create one */ | /* no active layer - let's just create one */ | ||||
| gpl = BKE_gpencil_layer_addnew(gpd, DATA_("GP_Layer"), true); | gpl = BKE_gpencil_layer_addnew(gpd, DATA_("GP_Layer"), true); | ||||
| } | } | ||||
| else if ((gpencil_layer_is_editable(gpl) == false) && (type == GP_COPY_MERGE)) { | else if ((gpencil_layer_is_editable(gpl) == false) && (type == GP_COPY_TO_ACTIVE)) { | ||||
| BKE_report( | BKE_report( | ||||
| op->reports, RPT_ERROR, "Can not paste strokes when active layer is hidden or locked"); | op->reports, RPT_ERROR, "Can not paste strokes when active layer is hidden or locked"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| else { | else { | ||||
| /* Check that some of the strokes in the buffer can be used */ | /* Check that some of the strokes in the buffer can be used */ | ||||
| bGPDstroke *gps; | bGPDstroke *gps; | ||||
| bool ok = false; | bool ok = false; | ||||
| Show All 36 Lines | static int gp_strokes_paste_exec(bContext *C, wmOperator *op) | ||||
| /* Ensure that all the necessary colors exist */ | /* Ensure that all the necessary colors exist */ | ||||
| new_colors = gp_copybuf_validate_colormap(C); | new_colors = gp_copybuf_validate_colormap(C); | ||||
| /* Copy over the strokes from the buffer (and adjust the colors) */ | /* Copy over the strokes from the buffer (and adjust the colors) */ | ||||
| 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)) { | ||||
| /* Need to verify if layer exists */ | /* Need to verify if layer exists */ | ||||
| if (type != GP_COPY_MERGE) { | if (type != GP_COPY_TO_ACTIVE) { | ||||
| gpl = BLI_findstring(&gpd->layers, gps->runtime.tmp_layerinfo, offsetof(bGPDlayer, info)); | gpl = BLI_findstring(&gpd->layers, gps->runtime.tmp_layerinfo, offsetof(bGPDlayer, info)); | ||||
| if (gpl == NULL) { | if (gpl == NULL) { | ||||
| /* no layer - use active (only if layer deleted before paste) */ | /* no layer - use active (only if layer deleted before paste) */ | ||||
| gpl = CTX_data_active_gpencil_layer(C); | gpl = CTX_data_active_gpencil_layer(C); | ||||
| } | } | ||||
| } | } | ||||
| /* Ensure we have a frame to draw into | /* Ensure we have a frame to draw into | ||||
| Show All 34 Lines | static int gp_strokes_paste_exec(bContext *C, wmOperator *op) | ||||
| WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); | WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void GPENCIL_OT_paste(wmOperatorType *ot) | void GPENCIL_OT_paste(wmOperatorType *ot) | ||||
| { | { | ||||
| static const EnumPropertyItem copy_type[] = { | static const EnumPropertyItem copy_type[] = { | ||||
| {GP_COPY_ONLY, "COPY", 0, "Copy", ""}, | {GP_COPY_TO_ACTIVE, "ACTIVE", 0, "Paste to Active", ""}, | ||||
| {GP_COPY_MERGE, "MERGE", 0, "Merge", ""}, | {GP_COPY_BY_LAYER, "LAYER", 0, "Paste by Layer", ""}, | ||||
| {0, NULL, 0, NULL, NULL}, | {0, NULL, 0, NULL, NULL}, | ||||
| }; | }; | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Paste Strokes"; | ot->name = "Paste Strokes"; | ||||
| ot->idname = "GPENCIL_OT_paste"; | ot->idname = "GPENCIL_OT_paste"; | ||||
| ot->description = "Paste previously copied strokes or copy and merge in active layer"; | ot->description = "Paste previously copied strokes to active layer or to original layer"; | ||||
| /* callbacks */ | /* callbacks */ | ||||
| ot->exec = gp_strokes_paste_exec; | ot->exec = gp_strokes_paste_exec; | ||||
| ot->poll = gp_strokes_paste_poll; | ot->poll = gp_strokes_paste_poll; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| /* properties */ | /* properties */ | ||||
| ot->prop = RNA_def_enum(ot->srna, "type", copy_type, 0, "Type", ""); | ot->prop = RNA_def_enum(ot->srna, "type", copy_type, GP_COPY_TO_ACTIVE, "Type", ""); | ||||
| } | } | ||||
| /* ******************* Move To Layer ****************************** */ | /* ******************* Move To Layer ****************************** */ | ||||
| static int gp_move_to_layer_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(evt)) | static int gp_move_to_layer_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(evt)) | ||||
| { | { | ||||
| uiPopupMenu *pup; | uiPopupMenu *pup; | ||||
| uiLayout *layout; | uiLayout *layout; | ||||
| ▲ Show 20 Lines • Show All 3,274 Lines • Show Last 20 Lines | |||||