Blender V4.5
gpencil_edit.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9
10#include <cstdlib>
11#include <cstring>
12
13#include "MEM_guardedalloc.h"
14
15#include "BLI_ghash.h"
16#include "BLI_listbase.h"
17#include "BLI_utildefines.h"
18
20#include "DNA_scene_types.h"
21#include "DNA_screen_types.h"
22
23#include "BKE_context.hh"
24#include "BKE_gpencil_legacy.h"
25#include "BKE_lib_id.hh"
26#include "BKE_paint.hh"
27#include "BKE_report.hh"
28#include "BKE_scene.hh"
29
30#include "UI_interface.hh"
31
32#include "WM_api.hh"
33#include "WM_message.hh"
34#include "WM_toolsystem.hh"
35#include "WM_types.hh"
36
37#include "RNA_access.hh"
38
39#include "UI_view2d.hh"
40
41#include "ED_gpencil_legacy.hh"
42#include "ED_image.hh"
43#include "ED_object.hh"
44#include "ED_outliner.hh"
45#include "ED_screen.hh"
46#include "ED_view3d.hh"
47
48#include "DEG_depsgraph.hh"
49
50#include "gpencil_intern.hh"
51
52/* -------------------------------------------------------------------- */
62
64
65/* Hash for hanging on to all the colors used by strokes in the buffer
66 *
67 * This is needed to prevent dangling and unsafe pointers when pasting across data-blocks,
68 * or after a color used by a stroke in the buffer gets deleted (via user action or undo).
69 */
71
73{
74 bGPDstroke *gps, *gpsn;
75
76 /* Free the colors buffer.
77 * NOTE: This is done before the strokes so that the pointers are still safe. */
81 }
82
83 /* Free the stroke buffer */
84 for (gps = static_cast<bGPDstroke *>(gpencil_strokes_copypastebuf.first); gps; gps = gpsn) {
85 gpsn = gps->next;
86
87 if (gps->points) {
88 MEM_freeN(gps->points);
89 }
90 if (gps->dvert) {
92 MEM_freeN(gps->dvert);
93 }
94
96
98 }
99
101}
102
104
105/* -------------------------------------------------------------------- */
108
110{
113
114 /* only if there's an active layer with an active frame */
115 return (gpl && gpl->actframe);
116}
117
118/* delete active frame - wrapper around API calls */
120{
123
124 Scene *scene = CTX_data_scene(C);
125
127
128 /* if there's no existing Grease-Pencil data there, add some */
129 if (gpd == nullptr) {
130 BKE_report(op->reports, RPT_ERROR, "No Grease Pencil data");
131 return OPERATOR_CANCELLED;
132 }
133 if (ELEM(nullptr, gpl, gpf)) {
134 BKE_report(op->reports, RPT_ERROR, "No active frame to delete");
135 return OPERATOR_CANCELLED;
136 }
137
138 /* delete it... */
140
141 /* notifiers */
144
145 return OPERATOR_FINISHED;
146}
147
149{
150 /* identifiers */
151 ot->name = "Delete Active Frame";
152 ot->idname = "GPENCIL_OT_annotation_active_frame_delete";
153 ot->description = "Delete the active frame for the active Annotation Layer";
154
156
157 /* callbacks */
160}
161
Scene * CTX_data_scene(const bContext *C)
void BKE_gpencil_free_stroke_weights(struct bGPDstroke *gps)
bool BKE_gpencil_layer_frame_delete(struct bGPDlayer *gpl, struct bGPDframe *gpf)
struct bGPDframe * BKE_gpencil_layer_frame_get(struct bGPDlayer *gpl, int cframe, eGP_GetFrame_Mode addnew)
struct bGPDlayer * BKE_gpencil_layer_active_get(struct bGPdata *gpd)
@ GP_GETFRAME_USE_PREV
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:126
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.cc:860
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:270
#define ELEM(...)
void DEG_id_tag_update(ID *id, unsigned int flags)
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:962
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:982
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
Read Guarded memory(de)allocation.
#define C
Definition RandGen.cpp:29
#define ND_DATA
Definition WM_types.hh:506
#define NA_EDITED
Definition WM_types.hh:581
#define NC_GPENCIL
Definition WM_types.hh:396
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
static wmOperatorStatus gpencil_actframe_delete_exec(bContext *C, wmOperator *op)
void ED_gpencil_strokes_copybuf_free()
static bool annotation_actframe_delete_poll(bContext *C)
static GHash * gpencil_strokes_copypastebuf_colors
void GPENCIL_OT_annotation_active_frame_delete(wmOperatorType *ot)
ListBase gpencil_strokes_copypastebuf
bGPdata * ED_annotation_data_get_active(const bContext *C)
#define MEM_SAFE_FREE(v)
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
struct RenderData r
bGPDtriangle * triangles
struct MDeformVert * dvert
struct bGPDstroke * next
struct ReportList * reports
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition wm_files.cc:4226