static bool view3d_ruler_to_gpencil(bContext *C, RulerInfo *ruler_info) { Scene *scene = CTX_data_scene(C); bGPDlayer *gpl; bGPDframe *gpf; bGPDstroke *gps; RulerItem *ruler_item; const char *ruler_name = RULER_ID; bool changed = false; if (scene->gpd == NULL) { scene->gpd = gpencil_data_addnew("GPencil"); } gpl = BLI_findstring(&scene->gpd->layers, ruler_name, offsetof(bGPDlayer, info)); if (gpl == NULL) { gpl = gpencil_layer_addnew(scene->gpd, ruler_name, false); gpl->thickness = 1; gpl->flag |= GP_LAYER_HIDE; } gpf = gpencil_layer_getframe(gpl, CFRA, true); free_gpencil_strokes(gpf); for (ruler_item = ruler_info->items.first; ruler_item; ruler_item = ruler_item->next) { bGPDspoint *pt; int j; /* allocate memory for a new stroke */ gps = MEM_callocN(sizeof(bGPDstroke), "gp_stroke"); if (ruler_item->flag & RULERITEM_USE_ANGLE) { gps->totpoints = 3; pt = gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points"); for (j = 0; j < 3; j++) { copy_v3_v3(&pt->x, ruler_item->co[j]); pt->pressure = 1.0f; pt++; } } else { gps->totpoints = 2; pt = gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points"); for (j = 0; j < 3; j += 2) { copy_v3_v3(&pt->x, ruler_item->co[j]); pt->pressure = 1.0f; pt++; } } gps->flag = GP_STROKE_3DSPACE; BLI_addtail(&gpf->strokes, gps); changed = true; } return changed; }
/* delete the given frame from a layer */ void gpencil_layer_delframe(bGPDlayer *gpl, bGPDframe *gpf) { /* error checking */ if (ELEM(NULL, gpl, gpf)) return; /* free the frame and its data */ free_gpencil_strokes(gpf); BLI_freelinkN(&gpl->frames, gpf); gpl->actframe = NULL; }
/* delete the given frame from a layer */ bool gpencil_layer_delframe(bGPDlayer *gpl, bGPDframe *gpf) { bool changed = false; /* error checking */ if (ELEM(NULL, gpl, gpf)) return false; /* free the frame and its data */ changed = free_gpencil_strokes(gpf); BLI_freelinkN(&gpl->frames, gpf); gpl->actframe = NULL; return changed; }
/* Free all of a gp-layer's frames */ void free_gpencil_frames(bGPDlayer *gpl) { bGPDframe *gpf, *gpfn; /* error checking */ if (gpl == NULL) return; /* free frames */ for (gpf = gpl->frames.first; gpf; gpf = gpfn) { gpfn = gpf->next; /* free strokes and their associated memory */ free_gpencil_strokes(gpf); BLI_freelinkN(&gpl->frames, gpf); } gpl->actframe = NULL; }
/* delete the given frame from a layer */ bool gpencil_layer_delframe(bGPDlayer *gpl, bGPDframe *gpf) { bool changed = false; /* error checking */ if (ELEM(NULL, gpl, gpf)) return false; /* if this frame was active, make the previous frame active instead * since it's tricky to set active frame otherwise */ if (gpl->actframe == gpf) gpl->actframe = gpf->prev; else gpl->actframe = NULL; /* free the frame and its data */ changed = free_gpencil_strokes(gpf); BLI_freelinkN(&gpl->frames, gpf); return changed; }
static void rna_GPencil_frame_clear(bGPDframe *frame) { free_gpencil_strokes(frame); WM_main_add_notifier(NC_GPENCIL | ND_DATA | NA_EDITED, NULL); }