/* poll callback for adding data/layers - special */ static int gp_data_unlink_poll(bContext *C) { bGPdata **gpd_ptr = gpencil_data_get_pointers(C, NULL); /* if we have access to some active data, make sure there's a datablock before enabling this */ return (gpd_ptr && *gpd_ptr); }
/* Standard panel to be included whereever Grease Pencil is used... */ void gpencil_panel_standard(const bContext *C, Panel *pa) { bGPdata **gpd_ptr = NULL; PointerRNA ptr; //if (v3d->flag2 & V3D_DISPGP)... etc. /* get pointer to Grease Pencil Data */ gpd_ptr= gpencil_data_get_pointers((bContext *)C, &ptr); if (gpd_ptr) draw_gpencil_panel((bContext *)C, pa->layout, *gpd_ptr, &ptr); }
int ED_undo_gpencil_step(bContext *C, int step, const char *name) { bGPdata **gpd_ptr = NULL, *new_gpd = NULL; gpd_ptr = gpencil_data_get_pointers(C, NULL); if (step == 1) { /* undo */ //printf("\t\tGP - undo step\n"); if (cur_node->prev) { if (!name || strcmp(cur_node->name, name) == 0) { cur_node = cur_node->prev; new_gpd = cur_node->gpd; } } } else if (step == -1) { //printf("\t\tGP - redo step\n"); if (cur_node->next) { if (!name || strcmp(cur_node->name, name) == 0) { cur_node = cur_node->next; new_gpd = cur_node->gpd; } } } if (new_gpd) { if (gpd_ptr) { if (*gpd_ptr) { bGPdata *gpd = *gpd_ptr; bGPDlayer *gpl, *gpld; free_gpencil_layers(&gpd->layers); /* copy layers */ gpd->layers.first = gpd->layers.last = NULL; for (gpl = new_gpd->layers.first; gpl; gpl = gpl->next) { /* make a copy of source layer and its data */ gpld = gpencil_layer_duplicate(gpl); BLI_addtail(&gpd->layers, gpld); } } } } WM_event_add_notifier(C, NC_SCREEN | ND_GPENCIL | NA_EDITED, NULL); return OPERATOR_FINISHED; }
/* add new layer - wrapper around API */ static int gp_layer_add_exec(bContext *C, wmOperator *op) { bGPdata **gpd_ptr = gpencil_data_get_pointers(C, NULL); /* if there's no existing Grease-Pencil data there, add some */ if (gpd_ptr == NULL) { BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go"); return OPERATOR_CANCELLED; } if (*gpd_ptr == NULL) *gpd_ptr = gpencil_data_addnew(DATA_("GPencil")); /* add new layer now */ gpencil_layer_addnew(*gpd_ptr, DATA_("GP_Layer"), 1); /* notifiers */ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); return OPERATOR_FINISHED; }
/* unlink datablock - wrapper around API */ static int gp_data_unlink_exec(bContext *C, wmOperator *op) { bGPdata **gpd_ptr = gpencil_data_get_pointers(C, NULL); if (gpd_ptr == NULL) { BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go"); return OPERATOR_CANCELLED; } else { /* just unlink datablock now, decreasing its user count */ bGPdata *gpd = (*gpd_ptr); id_us_min(&gpd->id); *gpd_ptr = NULL; } /* notifiers */ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); return OPERATOR_FINISHED; }
/* add new datablock - wrapper around API */ static int gp_data_add_exec(bContext *C, wmOperator *op) { bGPdata **gpd_ptr = gpencil_data_get_pointers(C, NULL); if (gpd_ptr == NULL) { BKE_report(op->reports, RPT_ERROR, "Nowhere for Grease Pencil data to go"); return OPERATOR_CANCELLED; } else { /* decrement user count and add new datablock */ bGPdata *gpd = (*gpd_ptr); id_us_min(&gpd->id); *gpd_ptr = gpencil_data_addnew("GPencil"); } /* notifiers */ WM_event_add_notifier(C, NC_SCREEN | ND_GPENCIL | NA_EDITED, NULL); // XXX need a nicer one that will work return OPERATOR_FINISHED; }
/* poll callback for adding data/layers - special */ static int gp_add_poll(bContext *C) { /* the base line we have is that we have somewhere to add Grease Pencil data */ return gpencil_data_get_pointers(C, NULL) != NULL; }
/* Get the active Grease Pencil datablock */ bGPdata *gpencil_data_get_active(const bContext *C) { bGPdata **gpd_ptr = gpencil_data_get_pointers(C, NULL); return (gpd_ptr) ? *(gpd_ptr) : NULL; }