Blender V5.3
rna_annotations.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10#include "DNA_scene_types.h"
11
12#include "RNA_define.hh"
13#include "RNA_enum_types.hh"
14#include "RNA_path.hh"
15
16#include "rna_internal.hh"
17
18#include "WM_types.hh"
19
20#ifdef RNA_RUNTIME
21
22# include <fmt/format.h>
23
24# include "BLT_translation.hh"
25
26# include "BLI_listbase.hh"
27# include "BLI_math_base_c.hh"
28# include "BLI_memory_utils.hh"
29# include "BLI_string.hh"
30# include "BLI_string_utf8.hh"
31# include "BLI_string_utils.hh"
32
33# include "BKE_animsys.hh"
34# include "BKE_annotations.h"
35# include "BKE_global.hh"
36# include "BKE_icons.hh"
37# include "BKE_report.hh"
38
39# include "DEG_depsgraph.hh"
40
41# include "WM_api.hh"
42
43namespace blender {
44
45static bGPdata *rna_annotations(const PointerRNA *ptr)
46{
47 return reinterpret_cast<bGPdata *>(ptr->owner_id);
48}
49
50static void rna_annotation_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
51{
54}
55
56/* Poll Callback to filter legacy GP Datablocks to only show those for Annotations */
58{
59 bGPdata *gpd = static_cast<bGPdata *>(value.data);
60 return (gpd->flag & GP_DATA_ANNOTATIONS) != 0;
61}
62
63static bGPDframe *rna_annotation_frame_new(bGPDlayer *layer,
64 ReportList *reports,
65 int frame_number,
66 bool active)
67{
68 bGPDframe *frame;
69
70 if (BKE_annotations_layer_frame_find(layer, frame_number)) {
71 BKE_reportf(reports, RPT_ERROR, "Frame already exists on this frame number %d", frame_number);
72 return nullptr;
73 }
74
75 frame = BKE_annotations_frame_addnew(layer, frame_number);
76 if (active) {
78 }
80
81 return frame;
82}
83
84static void rna_annotation_frame_remove(bGPDlayer *layer,
85 ReportList *reports,
86 PointerRNA *frame_ptr)
87{
88 bGPDframe *frame = static_cast<bGPDframe *>(frame_ptr->data);
89 if (BLI_findindex(&layer->frames, frame) == -1) {
90 BKE_report(reports, RPT_ERROR, "Frame not found in annotation layer");
91 return;
92 }
93
95 frame_ptr->invalidate();
96
98}
99
100static bGPDframe *rna_annotation_frame_copy(bGPDlayer *layer, bGPDframe *src)
101{
102 bGPDframe *frame = BKE_annotations_frame_duplicate(src, true);
103
104 while (BKE_annotations_layer_frame_find(layer, frame->framenum)) {
105 frame->framenum++;
106 }
107
108 BLI_addtail(&layer->frames, frame);
109
111
112 return frame;
113}
114
115static bGPDlayer *rna_annotation_layer_new(bGPdata *gpd, const char *name, bool setactive)
116{
117 bGPDlayer *gpl = BKE_annotations_layer_addnew(gpd, name, setactive != 0, false);
118
120
121 return gpl;
122}
123
124static void rna_annotation_layer_remove(bGPdata *gpd, ReportList *reports, PointerRNA *layer_ptr)
125{
126 bGPDlayer *layer = static_cast<bGPDlayer *>(layer_ptr->data);
127 if (BLI_findindex(&gpd->layers, layer) == -1) {
128 BKE_report(reports, RPT_ERROR, "Layer not found in annotation data");
129 return;
130 }
131
133 layer_ptr->invalidate();
134
136}
137
138static std::optional<std::string> rna_annotation_layer_path(const PointerRNA *ptr)
139{
140 bGPDlayer *gpl = static_cast<bGPDlayer *>(ptr->data);
141 char name_esc[sizeof(gpl->info) * 2];
142
143 BLI_str_escape(name_esc, gpl->info, sizeof(name_esc));
144
145 return fmt::format("layers[\"{}\"]", name_esc);
146}
147
148static int rna_annotation_layer_active_frame_editable(const PointerRNA *ptr,
149 const char ** /*r_info*/)
150{
151 bGPDlayer *gpl = static_cast<bGPDlayer *>(ptr->data);
152
153 /* surely there must be other criteria too... */
154 if (gpl->flag & GP_LAYER_LOCKED) {
155 return 0;
156 }
157 return PROP_EDITABLE;
158}
159
160static void rna_annotation_layer_info_set(PointerRNA *ptr, const char *value)
161{
162 bGPdata *gpd = rna_annotations(ptr);
163 bGPDlayer *gpl = static_cast<bGPDlayer *>(ptr->data);
164
165 char oldname[sizeof(gpl->info)] = "";
166 STRNCPY_UTF8(oldname, gpl->info);
167
168 /* copy the new name into the name slot */
169 STRNCPY_UTF8(gpl->info, value);
170
172 &gpd->layers, gpl, DATA_("GP_Layer"), '.', offsetof(bGPDlayer, info), sizeof(gpl->info));
173
174 /* now fix animation paths */
175 if (ptr->owner_id) {
176 BKE_animdata_fix_paths(*ptr->owner_id,
177 "layers",
178 RNA_path_name_to_infix(oldname),
179 RNA_path_name_to_infix(gpl->info),
180 /*verify_paths=*/true,
181 *G_MAIN);
182 }
183
184 /* Fix mask layers. */
185 for (bGPDlayer &gpl_ : gpd->layers) {
186 for (bGPDlayer_Mask &mask : gpl_.mask_layers) {
187 if (STREQ(mask.name, oldname)) {
188 STRNCPY(mask.name, gpl->info);
189 }
190 }
191 }
192}
193
194static int rna_annotation_active_layer_index_get(PointerRNA *ptr)
195{
196 bGPdata *gpd = rna_annotations(ptr);
198
199 return BLI_findindex(&gpd->layers, gpl);
200}
201
202static void rna_annotation_active_layer_index_set(PointerRNA *ptr, int value)
203{
204 bGPdata *gpd = rna_annotations(ptr);
205 bGPDlayer *gpl = static_cast<bGPDlayer *>(BLI_findlink(&gpd->layers, value));
206
208
209 /* Now do standard updates... */
212}
213
214static void rna_annotation_active_layer_index_range(
215 PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax)
216{
217 bGPdata *gpd = rna_annotations(ptr);
218
219 *min = 0;
220 *max = max_ii(0, gpd->layers.count() - 1);
221
222 *softmin = *min;
223 *softmax = *max;
224}
225
226static const EnumPropertyItem *rna_annotation_active_layer_itemf(bContext *C,
227 PointerRNA *ptr,
228 PropertyRNA * /*prop*/,
229 bool *r_free)
230{
231 bGPdata *gpd = rna_annotations(ptr);
232 bGPDlayer *gpl;
233 EnumPropertyItem *item = nullptr, item_tmp = {0};
234 int totitem = 0;
235 int i = 0;
236
237 if (ELEM(nullptr, C, gpd)) {
239 }
240
241 /* Existing layers */
242 for (gpl = gpd->layers.first(), i = 0; gpl; gpl = gpl->next, i++) {
243 item_tmp.identifier = gpl->info;
244 item_tmp.name = gpl->info;
245 item_tmp.value = i;
246
247 item_tmp.icon = (gpd->flag & GP_DATA_ANNOTATIONS) ? BKE_icon_gplayer_color_ensure(gpl) :
248 ICON_GREASEPENCIL;
249
250 RNA_enum_item_add(&item, &totitem, &item_tmp);
251 }
252
253 RNA_enum_item_end(&item, &totitem);
254 *r_free = true;
255
256 return item;
257}
258
259static bGPDstroke *rna_annotation_stroke_new(bGPDframe *frame)
260{
261 /* Use MEM_new<T> for struct allocation. */
262 bGPDstroke *stroke = MEM_new<bGPDstroke>("gp_stroke");
263 if (stroke == nullptr) {
264 return nullptr;
265 }
266
267 /* Set some default values. */
268 stroke->thickness = 1;
269 stroke->fill_opacity_fac = 1.0f;
270 stroke->hardness = 1.0f;
271 stroke->uv_scale = 1.0f;
272 stroke->flag = GP_STROKE_3DSPACE;
273 stroke->mat_nr = 0;
274 stroke->caps[0] = GP_STROKE_CAP_ROUND;
275 stroke->caps[1] = GP_STROKE_CAP_ROUND;
276
277 BLI_addtail(&frame->strokes, stroke);
279 return stroke;
280}
281
282static void rna_annotation_stroke_remove(bGPDframe *frame,
283 ReportList *reports,
284 PointerRNA *stroke_ptr)
285{
286 bGPDstroke *stroke = static_cast<bGPDstroke *>(stroke_ptr->data);
287
288 if (BLI_findindex(&frame->strokes, stroke) == -1) {
289 BKE_reportf(reports, RPT_ERROR, "Stroke not found in frame");
290 return;
291 }
292
293 BLI_remlink(&frame->strokes, stroke);
295
296 /* Clear ptrs. */
297 stroke_ptr->data = nullptr;
298 stroke_ptr->type = nullptr;
299
301}
302
303static void rna_annotation_stroke_point_add(bGPDstroke *stroke,
304 const int count,
305 const float pressure,
306 const float strength)
307{
308 /* Count is always >=1(RNA min set to 1). */
309 if (count <= 0) {
310 return;
311 }
312
313 const int old_count = stroke->totpoints;
314 const int new_count = old_count + count;
315
316 bGPDspoint *old_points = stroke->points;
317 stroke->points = MEM_new_array<bGPDspoint>(new_count, "gp_stroke_points");
318
319 /* Copy existing points using assignment (void* cast to avoid -Wclass-memaccess). */
320 if (old_points && old_count > 0) {
321 uninitialized_move_n(old_points, old_count, stroke->points);
322 }
323
324 for (int i = old_count; i < new_count; i++) {
325 bGPDspoint *pt = &stroke->points[i];
326 pt->pressure = pressure;
327 pt->strength = strength;
328 pt->time = 0.0f;
329 pt->x = 0.0f;
330 pt->y = 0.0f;
331 pt->z = 0.0f;
332 }
333
334 if (old_points) {
335 MEM_delete(old_points);
336 }
337
338 stroke->totpoints = new_count;
339
341}
342
343static void rna_annotation_stroke_point_remove(bGPDstroke *stroke,
344 ReportList *reports,
345 const int index)
346{
347 if (stroke->totpoints <= 0) {
348 BKE_report(reports, RPT_ERROR, "Stroke has no points");
349 return;
350 }
351
352 if (index < 0 || index >= stroke->totpoints) {
353 BKE_reportf(reports, RPT_ERROR, "Index %d out of range [0, %d]", index, stroke->totpoints - 1);
354 return;
355 }
356
357 if (stroke->totpoints == 1) {
358 BKE_report(reports, RPT_ERROR, "Cannot remove last point from stroke");
359 return;
360 }
361
362 const int new_count = stroke->totpoints - 1;
363
364 bGPDspoint *old_points = stroke->points;
365 stroke->points = MEM_new_array<bGPDspoint>(new_count, "gp_stroke_points");
366
367 /* Copy points before removed index. */
368 if (index > 0) {
369 uninitialized_move_n(old_points, index, stroke->points);
370 }
371
372 /* Copy points after removed index. */
373 if (index < new_count) {
374 uninitialized_move_n(&old_points[index + 1], new_count - index, &stroke->points[index]);
375 }
376
377 MEM_delete(old_points);
378
379 stroke->totpoints = new_count;
380
382}
383
384} // namespace blender
385
386#else
387
388namespace blender {
389
391{
392 StructRNA *srna;
393 PropertyRNA *parm;
394 FunctionRNA *func;
395
396 RNA_def_property_srna(cprop, "AnnotationStrokes");
397 srna = RNA_def_struct(brna, "AnnotationStrokes", nullptr);
398 RNA_def_struct_sdna(srna, "bGPDframe");
399 RNA_def_struct_ui_text(srna, "Annotation Strokes", "Collection of annotation strokes");
400
401 func = RNA_def_function(srna, "new", "rna_annotation_stroke_new");
402 RNA_def_function_ui_description(func, "Add a new annotation stroke");
403 parm = RNA_def_pointer(func, "stroke", "AnnotationStroke", "", "The newly created stroke");
405 RNA_def_function_return(func, parm);
406
407 func = RNA_def_function(srna, "remove", "rna_annotation_stroke_remove");
408 RNA_def_function_ui_description(func, "Remove an annotation stroke");
410 parm = RNA_def_pointer(func, "stroke", "AnnotationStroke", "", "The stroke to remove");
413}
414
416{
417 StructRNA *srna;
418 PropertyRNA *parm;
419 FunctionRNA *func;
420
421 RNA_def_property_srna(cprop, "AnnotationStrokePoints");
422 srna = RNA_def_struct(brna, "AnnotationStrokePoints", nullptr);
423 RNA_def_struct_sdna(srna, "bGPDstroke");
425 srna, "Annotation Stroke Points", "Collection of annotation stroke points");
426
427 func = RNA_def_function(srna, "add", "rna_annotation_stroke_point_add");
428 RNA_def_function_ui_description(func, "Add point(s) to the stroke");
429 parm = RNA_def_int(func, "count", 1, 1, INT_MAX, "Count", "Number of points to add", 1, 100);
431 RNA_def_float(func,
432 "pressure",
433 1.0f,
434 0.0f,
435 FLT_MAX,
436 "Pressure",
437 "Pressure/radius for new points",
438 0.0f,
439 10.0f);
440 RNA_def_float(func,
441 "strength",
442 1.0f,
443 0.0f,
444 1.0f,
445 "Strength",
446 "Color strength/opacity for new points",
447 0.0f,
448 1.0f);
449
450 func = RNA_def_function(srna, "remove", "rna_annotation_stroke_point_remove");
451 RNA_def_function_ui_description(func, "Remove a point from the stroke");
453 parm = RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Index of point to remove", 0, 10000);
455}
456
458{
459 StructRNA *srna;
460 PropertyRNA *prop;
461
462 srna = RNA_def_struct(brna, "AnnotationStrokePoint", nullptr);
463 RNA_def_struct_sdna(srna, "bGPDspoint");
464 RNA_def_struct_ui_text(srna, "Annotation Stroke Point", "Data point for freehand stroke curve");
465
466 prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_XYZ);
467 RNA_def_property_float_sdna(prop, nullptr, "x");
468 RNA_def_property_array(prop, 3);
469 RNA_def_property_ui_text(prop, "Coordinates", "");
470 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_annotation_update");
471}
472
474{
475 StructRNA *srna;
476 PropertyRNA *prop;
477
478 srna = RNA_def_struct(brna, "AnnotationStroke", nullptr);
479 RNA_def_struct_sdna(srna, "bGPDstroke");
480 RNA_def_struct_ui_text(srna, "Annotation Stroke", "Freehand curve defining part of a sketch");
481
482 /* Points */
483 prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE);
484 RNA_def_property_collection_sdna(prop, nullptr, "points", "totpoints");
485 RNA_def_property_struct_type(prop, "AnnotationStrokePoint");
486 RNA_def_property_ui_text(prop, "Stroke Points", "Stroke data points");
488
489 /* Display Mode. */
490 static const EnumPropertyItem stroke_display_mode_items[] = {
491 {GP_STROKE_3DSPACE, "3DSPACE", 0, "3D Space", "Stroke is in 3D space"},
493 "2DSPACE",
494 0,
495 "2D Space",
496 "Stroke is in 2D space, locked to the camera view"},
497 {GP_STROKE_2DIMAGE, "2DIMAGE", 0, "2D Image", "Stroke is in 2D image/UV space"},
498 {0, nullptr, 0, nullptr, nullptr},
499 };
500
501 prop = RNA_def_property(srna, "display_mode", PROP_ENUM, PROP_NONE);
502 RNA_def_property_enum_bitflag_sdna(prop, nullptr, "flag");
503 RNA_def_property_enum_items(prop, stroke_display_mode_items);
504 RNA_def_property_ui_text(prop, "Display Mode", "Coordinate space that stroke is in");
506}
507
509{
510 StructRNA *srna;
511 PropertyRNA *prop;
512
513 srna = RNA_def_struct(brna, "AnnotationFrame", nullptr);
514 RNA_def_struct_sdna(srna, "bGPDframe");
516 srna, "Annotation Frame", "Collection of related sketches on a particular frame");
517
518 /* Strokes */
519 prop = RNA_def_property(srna, "strokes", PROP_COLLECTION, PROP_NONE);
520 RNA_def_property_collection_sdna(prop, nullptr, "strokes", nullptr);
521 RNA_def_property_struct_type(prop, "AnnotationStroke");
522 RNA_def_property_ui_text(prop, "Strokes", "Freehand curves defining the sketch on this frame");
524
525 /* Frame Number */
526 prop = RNA_def_property(srna, "frame_number", PROP_INT, PROP_NONE);
527 RNA_def_property_int_sdna(prop, nullptr, "framenum");
528 /* XXX NOTE: this cannot occur on the same frame as another sketch. */
530 RNA_def_property_ui_text(prop, "Frame Number", "The frame on which this sketch appears");
531 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_annotation_update");
532
533 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
534 RNA_def_property_boolean_sdna(prop, nullptr, "flag", GP_FRAME_SELECT);
535 RNA_def_property_ui_text(prop, "Select", "Frame is selected for editing in the Dope Sheet");
536 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_annotation_update");
537}
538
540{
541 StructRNA *srna;
542
543 FunctionRNA *func;
544 PropertyRNA *parm;
545
546 RNA_def_property_srna(cprop, "AnnotationFrames");
547 srna = RNA_def_struct(brna, "AnnotationFrames", nullptr);
548 RNA_def_struct_sdna(srna, "bGPDlayer");
549 RNA_def_struct_ui_text(srna, "Annotation Frames", "Collection of annotation frames");
550
551 func = RNA_def_function(srna, "new", "rna_annotation_frame_new");
552 RNA_def_function_ui_description(func, "Add a new annotation frame");
554 parm = RNA_def_int(func,
555 "frame_number",
556 1,
557 MINAFRAME,
558 MAXFRAME,
559 "Frame Number",
560 "The frame on which this sketch appears",
561 MINAFRAME,
562 MAXFRAME);
564 RNA_def_boolean(func, "active", false, "Active", "");
565 parm = RNA_def_pointer(func, "frame", "AnnotationFrame", "", "The newly created frame");
567 RNA_def_function_return(func, parm);
568
569 func = RNA_def_function(srna, "remove", "rna_annotation_frame_remove");
570 RNA_def_function_ui_description(func, "Remove an annotation frame");
572 parm = RNA_def_pointer(func, "frame", "AnnotationFrame", "Frame", "The frame to remove");
575
576 func = RNA_def_function(srna, "copy", "rna_annotation_frame_copy");
577 RNA_def_function_ui_description(func, "Copy an annotation frame");
578 parm = RNA_def_pointer(func, "source", "AnnotationFrame", "Source", "The source frame");
580 parm = RNA_def_pointer(func, "copy", "AnnotationFrame", "", "The newly copied frame");
582 RNA_def_function_return(func, parm);
583}
584
586{
587 StructRNA *srna;
588 PropertyRNA *prop;
589
590 srna = RNA_def_struct(brna, "AnnotationLayer", nullptr);
591 RNA_def_struct_sdna(srna, "bGPDlayer");
592 RNA_def_struct_ui_text(srna, "Annotation Layer", "Collection of related sketches");
593 RNA_def_struct_path_func(srna, "rna_annotation_layer_path");
594
595 /* Name */
596 prop = RNA_def_property(srna, "info", PROP_STRING, PROP_NONE);
597 RNA_def_property_ui_text(prop, "Info", "Layer name");
598 RNA_def_property_string_funcs(prop, nullptr, nullptr, "rna_annotation_layer_info_set");
600 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA | NA_RENAME, "rna_annotation_update");
601
602 /* Frames */
603 prop = RNA_def_property(srna, "frames", PROP_COLLECTION, PROP_NONE);
604 RNA_def_property_collection_sdna(prop, nullptr, "frames", nullptr);
605 RNA_def_property_struct_type(prop, "AnnotationFrame");
606 RNA_def_property_ui_text(prop, "Frames", "Sketches for this layer on different frames");
608
609 /* Active Frame */
610 prop = RNA_def_property(srna, "active_frame", PROP_POINTER, PROP_NONE);
611 RNA_def_property_pointer_sdna(prop, nullptr, "actframe");
612 RNA_def_property_ui_text(prop, "Active Frame", "Frame currently being displayed for this layer");
613 RNA_def_property_editable_func(prop, "rna_annotation_layer_active_frame_editable");
615
616 /* Layer Opacity (Annotations). */
617 prop = RNA_def_property(srna, "annotation_opacity", PROP_FLOAT, PROP_NONE);
618 RNA_def_property_float_sdna(prop, nullptr, "opacity");
619 RNA_def_property_range(prop, 0.0, 1.0f);
621 RNA_def_property_ui_text(prop, "Opacity", "Annotation Layer Opacity");
622 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_annotation_update");
623
624 /* Stroke Drawing Color (Annotations) */
625 prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR_GAMMA);
626 RNA_def_property_array(prop, 3);
627 RNA_def_property_range(prop, 0.0f, 1.0f);
629 RNA_def_property_ui_text(prop, "Color", "Color for all strokes in this layer");
630 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_annotation_update");
631
632 /* Line Thickness (Annotations) */
633 prop = RNA_def_property(srna, "thickness", PROP_INT, PROP_PIXEL);
634 RNA_def_property_int_sdna(prop, nullptr, "thickness");
635 RNA_def_property_range(prop, 1, 10);
637 RNA_def_property_ui_text(prop, "Thickness", "Thickness of annotation strokes");
638 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_annotation_update");
639
640 /* Onion-Skinning */
641 prop = RNA_def_property(srna, "use_annotation_onion_skinning", PROP_BOOLEAN, PROP_NONE);
642 RNA_def_property_boolean_sdna(prop, nullptr, "onion_flag", GP_LAYER_ONIONSKIN);
645 prop, "Onion Skinning", "Display annotation onion skins before and after the current frame");
646 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_annotation_update");
647
648 prop = RNA_def_property(srna, "annotation_onion_before_range", PROP_INT, PROP_NONE);
649 RNA_def_property_int_sdna(prop, nullptr, "gstep");
650 RNA_def_property_range(prop, -1, 120);
653 prop, "Frames Before", "Maximum number of frames to show before current frame");
654 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_annotation_update");
655
656 prop = RNA_def_property(srna, "annotation_onion_after_range", PROP_INT, PROP_NONE);
657 RNA_def_property_int_sdna(prop, nullptr, "gstep_next");
658 RNA_def_property_range(prop, -1, 120);
661 prop, "Frames After", "Maximum number of frames to show after current frame");
662 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_annotation_update");
663
664 prop = RNA_def_property(srna, "annotation_onion_before_color", PROP_FLOAT, PROP_COLOR_GAMMA);
665 RNA_def_property_float_sdna(prop, nullptr, "gcolor_prev");
666 RNA_def_property_array(prop, 3);
667 RNA_def_property_range(prop, 0.0f, 1.0f);
669 RNA_def_property_ui_text(prop, "Before Color", "Base color for ghosts before the active frame");
670 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_annotation_update");
671
672 prop = RNA_def_property(srna, "annotation_onion_after_color", PROP_FLOAT, PROP_COLOR_GAMMA);
673 RNA_def_property_float_sdna(prop, nullptr, "gcolor_next");
674 RNA_def_property_array(prop, 3);
675 RNA_def_property_range(prop, 0.0f, 1.0f);
677 RNA_def_property_ui_text(prop, "After Color", "Base color for ghosts after the active frame");
678 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_annotation_update");
679
680 prop = RNA_def_property(srna, "annotation_onion_use_custom_color", PROP_BOOLEAN, PROP_NONE);
684 "Custom Onion Skin Colors",
685 "Use custom colors for onion skinning instead of the theme");
686 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_annotation_update");
687
688 prop = RNA_def_property(srna, "annotation_hide", PROP_BOOLEAN, PROP_NONE);
689 RNA_def_property_boolean_sdna(prop, nullptr, "flag", GP_LAYER_HIDE);
690 RNA_def_property_ui_icon(prop, ICON_HIDE_OFF, -1);
692 RNA_def_property_ui_text(prop, "Hide", "Set annotation Visibility");
693 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_annotation_update");
694
695 prop = RNA_def_property(srna, "lock", PROP_BOOLEAN, PROP_NONE);
696 RNA_def_property_boolean_sdna(prop, nullptr, "flag", GP_LAYER_LOCKED);
697 RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
699 prop, "Locked", "Protect layer from further editing and/or frame changes");
700 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_annotation_update");
701
702 prop = RNA_def_property(srna, "lock_frame", PROP_BOOLEAN, PROP_NONE);
704 RNA_def_property_ui_icon(prop, ICON_UNLOCKED, 1);
706 RNA_def_property_ui_text(prop, "Frame Locked", "Lock current frame displayed by layer");
707 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_annotation_update");
708
709 prop = RNA_def_property(srna, "is_ruler", PROP_BOOLEAN, PROP_NONE);
710 RNA_def_property_boolean_sdna(prop, nullptr, "flag", GP_LAYER_IS_RULER);
711 RNA_def_property_ui_text(prop, "Ruler", "This is a special ruler layer");
713
714 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
715 RNA_def_property_boolean_sdna(prop, nullptr, "flag", GP_LAYER_SELECT);
716 RNA_def_property_ui_text(prop, "Select", "Layer is selected for editing in the Dope Sheet");
717 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA | NA_SELECTED, "rna_annotation_update");
718
719 /* In Front */
720 prop = RNA_def_property(srna, "show_in_front", PROP_BOOLEAN, PROP_NONE);
722 RNA_def_property_ui_text(prop, "In Front", "Make the layer display in front of objects");
723 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_annotation_update");
724}
725
727{
728 StructRNA *srna;
729 PropertyRNA *prop;
730 FunctionRNA *func;
731 PropertyRNA *parm;
732
733 RNA_def_property_srna(cprop, "AnnotationLayers");
734 srna = RNA_def_struct(brna, "AnnotationLayers", nullptr);
735 RNA_def_struct_sdna(srna, "bGPdata");
736 RNA_def_struct_ui_text(srna, "Annotation Layers", "Collection of annotation layers");
737
738 func = RNA_def_function(srna, "new", "rna_annotation_layer_new");
739 RNA_def_function_ui_description(func, "Add a new annotation layer");
740 parm = RNA_def_string(func, "name", "Layer", MAX_NAME, "Name", "Name of the layer");
743 func, "set_active", true, "Set Active", "Set the newly created layer to the active layer");
744 parm = RNA_def_pointer(func, "layer", "AnnotationLayer", "", "The newly created layer");
746 RNA_def_function_return(func, parm);
747
748 func = RNA_def_function(srna, "remove", "rna_annotation_layer_remove");
749 RNA_def_function_ui_description(func, "Remove a annotation layer");
751 parm = RNA_def_pointer(func, "layer", "AnnotationLayer", "", "The layer to remove");
754
755 prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
757 "rna_annotation_active_layer_index_get",
758 "rna_annotation_active_layer_index_set",
759 "rna_annotation_active_layer_index_range");
760 RNA_def_property_ui_text(prop, "Active Layer Index", "Index of active annotation layer");
762
763 /* Active Layer - As an enum (for selecting active layer for annotations) */
764 prop = RNA_def_property(srna, "active_note", PROP_ENUM, PROP_NONE);
766 "rna_annotation_active_layer_index_get",
767 "rna_annotation_active_layer_index_set",
768 "rna_annotation_active_layer_itemf");
770 prop, rna_enum_dummy_DEFAULT_items); /* purely dynamic, as it maps to user-data */
771 RNA_def_property_ui_text(prop, "Active Note", "Note/Layer to add annotation strokes to");
772 RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_annotation_update");
773}
774
776{
777 StructRNA *srna;
778 PropertyRNA *prop;
779
780 /* NOTE: This used to be the legacy Grease Pencil ID type. */
781 srna = RNA_def_struct(brna, "Annotation", "ID");
782 RNA_def_struct_sdna(srna, "bGPdata");
783 RNA_def_struct_ui_text(srna, "Annotation", "Freehand annotation sketchbook");
784 RNA_def_struct_ui_icon(srna, ICON_OUTLINER_DATA_GREASEPENCIL);
785
786 /* Layers */
787 prop = RNA_def_property(srna, "layers", PROP_COLLECTION, PROP_NONE);
788 RNA_def_property_collection_sdna(prop, nullptr, "layers", nullptr);
789 RNA_def_property_struct_type(prop, "AnnotationLayer");
790 RNA_def_property_ui_text(prop, "Layers", "");
791
793
794 /* Animation Data */
796}
797
806
807} // namespace blender
808
809#endif
#define G_MAIN
#define STRNCPY_UTF8(dst, src)
#define DATA_(msgid)
#define MAX_NAME
Definition DNA_defs.h:63
#define MINAFRAME
#define MAXFRAME
#define C
Definition RandGen.cpp:29
#define ND_DATA
Definition WM_types.hh:552
#define ND_SPACE_PROPERTIES
Definition WM_types.hh:572
#define NA_EDITED
Definition WM_types.hh:634
#define NC_GPENCIL
Definition WM_types.hh:412
#define NA_RENAME
Definition WM_types.hh:638
#define NA_SELECTED
Definition WM_types.hh:639
#define ELEM(...)
#define STREQ(a, b)
btScalar max
#define offsetof(t, d)
#define FLT_MAX
#define INT_MAX
#define layer
BMesh Iterators.
struct bGPDframe * BKE_annotations_frame_addnew(struct bGPDlayer *gpl, int cframe)
void WM_main_add_notifier(uint type, void *reference)
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
static void rna_def_annotation_strokes_api(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable)
void BKE_annotations_layer_active_set(struct bGPdata *gpd, struct bGPDlayer *active)
static void rna_def_annotation_frames_api(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
char * STRNCPY(char(&dst)[N], const char *src)
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_def_property_boolean_negative_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
static void rna_def_annotation_stroke(BlenderRNA *brna)
struct bGPDframe * BKE_annotations_layer_frame_get(struct bGPDlayer *gpl, int cframe, eGP_GetFrame_Mode addnew)
static void rna_def_annotation_data(BlenderRNA *brna)
void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
struct bGPDlayer * BKE_annotations_layer_addnew(struct bGPdata *gpd, const char *name, bool setactive, bool add_to_header)
std::string RNA_path_name_to_infix(const StringRefNull string)
Definition rna_path.cc:1419
@ FUNC_USE_REPORTS
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
static void rna_def_annotation_stroke_point(BlenderRNA *brna)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
MINLINE int max_ii(int a, int b)
void BKE_annotations_free_stroke(struct bGPDstroke *gps)
void RNA_def_annotations(BlenderRNA *brna)
void RNA_def_property_enum_bitflag_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
struct bGPDframe * BKE_annotations_layer_frame_find(struct bGPDlayer *gpl, int cframe)
void rna_def_animdata_common(StructRNA *srna)
void BKE_animdata_fix_paths(ID &id, StringRef prefix, StringRef old_infix, StringRef new_infix, bool verify_paths, const DriverMap &driver_map)
void BKE_annotations_layer_delete(struct bGPdata *gpd, struct bGPDlayer *gpl)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
void BLI_uniquename(const ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t name_maxncpy) ATTR_NONNULL(1
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
static void rna_def_annotation_layer(BlenderRNA *brna)
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_POINTER
Definition RNA_types.hh:215
@ PROP_STRING
Definition RNA_types.hh:213
@ PROP_COLLECTION
Definition RNA_types.hh:216
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
static void rna_def_annotation_frame(BlenderRNA *brna)
bool rna_GPencil_datablocks_annotations_poll(PointerRNA *ptr, const PointerRNA value)
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
char char size_t BLI_str_escape(char *__restrict dst, StringRef src, size_t dst_maxncpy) ATTR_NONNULL(1)
void RNA_def_struct_path_func(StructRNA *srna, const char *path)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
const EnumPropertyItem rna_enum_dummy_DEFAULT_items[]
Definition rna_rna.cc:34
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier_c_str, const char *call)
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:28
struct bGPDlayer * BKE_annotations_layer_active_get(struct bGPdata *gpd)
static void rna_def_annotation_stroke_points_api(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
static void rna_def_annotation_layers_api(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_function_flag(FunctionRNA *func, FunctionFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ PROP_EDITABLE
Definition RNA_types.hh:376
@ PROP_THICK_WRAP
Definition RNA_types.hh:493
@ PROP_NEVER_NULL
Definition RNA_types.hh:447
@ PROP_ANIMATABLE
Definition RNA_types.hh:389
void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
bool BKE_annotations_layer_frame_delete(struct bGPDlayer *gpl, struct bGPDframe *gpf)
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
int BKE_icon_gplayer_color_ensure(bGPDlayer *gpl)
Definition icons.cc:324
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
@ PROP_COLOR_GAMMA
Definition RNA_types.hh:329
@ PROP_UNSIGNED
Definition RNA_types.hh:306
@ PARM_REQUIRED
Definition RNA_types.hh:631
@ PARM_RNAPTR
Definition RNA_types.hh:633
void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop, const bool allow_replace)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void RNA_def_property_array(PropertyRNA *prop, int length)
void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive)
void uninitialized_move_n(T *src, int64_t n, T *dst)
struct bGPDframe * BKE_annotations_frame_duplicate(const struct bGPDframe *gpf_src, bool dup_strokes)
#define min(a, b)
Definition sort.cc:38