Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Vazquez <blendergit@gmail.com>2020-01-07 13:29:42 +0300
committerAntonio Vazquez <blendergit@gmail.com>2020-01-07 13:34:20 +0300
commitfa3a0697b846bd0ed3766fcabd1bf6f260aa425a (patch)
tree19a1bc85b29fb1cced92246270864bb8d1b41c35 /source/blender/editors/gpencil
parente237b78b91b9e88da8e3c4a5fb360101238c39e4 (diff)
Annotations: Split annotation operators and pointer functions
This allows to have annotation panels and grease pencil object panel at the same time. Differential Revision: https://developer.blender.org/D6467
Diffstat (limited to 'source/blender/editors/gpencil')
-rw-r--r--source/blender/editors/gpencil/annotate_draw.c4
-rw-r--r--source/blender/editors/gpencil/annotate_paint.c39
-rw-r--r--source/blender/editors/gpencil/gpencil_data.c215
-rw-r--r--source/blender/editors/gpencil/gpencil_edit.c38
-rw-r--r--source/blender/editors/gpencil/gpencil_intern.h6
-rw-r--r--source/blender/editors/gpencil/gpencil_ops.c6
-rw-r--r--source/blender/editors/gpencil/gpencil_utils.c135
7 files changed, 269 insertions, 174 deletions
diff --git a/source/blender/editors/gpencil/annotate_draw.c b/source/blender/editors/gpencil/annotate_draw.c
index 67bf64a2903..6e91be862a9 100644
--- a/source/blender/editors/gpencil/annotate_draw.c
+++ b/source/blender/editors/gpencil/annotate_draw.c
@@ -1056,7 +1056,7 @@ void ED_annotation_draw_2dimage(const bContext *C)
int offsx, offsy, sizex, sizey;
int dflag = GP_DRAWDATA_NOSTATUS;
- bGPdata *gpd = ED_gpencil_data_get_active(C); // XXX
+ bGPdata *gpd = ED_annotation_data_get_active(C);
if (gpd == NULL) {
return;
}
@@ -1132,7 +1132,7 @@ void ED_annotation_draw_view2d(const bContext *C, bool onlyv2d)
if (sa == NULL) {
return;
}
- bGPdata *gpd = ED_gpencil_data_get_active(C); // XXX
+ bGPdata *gpd = ED_annotation_data_get_active(C);
if (gpd == NULL) {
return;
}
diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c
index 7a10547f35c..04b5d8f6d40 100644
--- a/source/blender/editors/gpencil/annotate_paint.c
+++ b/source/blender/editors/gpencil/annotate_paint.c
@@ -218,19 +218,9 @@ static void gp_session_validatebuffer(tGPsdata *p);
/* check if context is suitable for drawing */
static bool gpencil_draw_poll(bContext *C)
{
- /* if is inside grease pencil draw mode cannot use annotations */
- Object *obact = CTX_data_active_object(C);
- ScrArea *sa = CTX_wm_area(C);
- if ((sa) && (sa->spacetype == SPACE_VIEW3D)) {
- if ((obact) && (obact->type == OB_GPENCIL) && (obact->mode == OB_MODE_PAINT_GPENCIL)) {
- CTX_wm_operator_poll_msg_set(C, "Annotation cannot be used in grease pencil draw mode");
- return false;
- }
- }
-
if (ED_operator_regionactive(C)) {
/* check if current context can support GPencil data */
- if (ED_gpencil_data_get_pointers(C, NULL) != NULL) {
+ if (ED_annotation_data_get_pointers(C, NULL) != NULL) {
/* check if Grease Pencil isn't already running */
if (ED_gpencil_session_active() == 0) {
return true;
@@ -240,7 +230,7 @@ static bool gpencil_draw_poll(bContext *C)
}
}
else {
- CTX_wm_operator_poll_msg_set(C, "Failed to find Grease Pencil data to draw into");
+ CTX_wm_operator_poll_msg_set(C, "Failed to find Annotation data to draw into");
}
}
else {
@@ -1115,7 +1105,7 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
}
/* get gp-data */
- gpd_ptr = ED_gpencil_data_get_pointers(C, &p->ownerPtr);
+ gpd_ptr = ED_annotation_data_get_pointers(C, &p->ownerPtr);
if ((gpd_ptr == NULL) || !ED_gpencil_data_owner_is_annotation(&p->ownerPtr)) {
p->status = GP_STATUS_ERROR;
if (G.debug & G_DEBUG) {
@@ -1886,9 +1876,6 @@ static int gpencil_draw_exec(bContext *C, wmOperator *op)
/* start of interactive drawing part of operator */
static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- Object *ob = CTX_data_active_object(C);
- ScrArea *sa = CTX_wm_area(C);
- Scene *scene = CTX_data_scene(C);
tGPsdata *p = NULL;
/* support for tablets eraser pen */
@@ -1896,26 +1883,6 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event
RNA_enum_set(op->ptr, "mode", GP_PAINTMODE_ERASER);
}
- /* if try to do annotations with a gp object selected, first
- * unselect the object to avoid conflicts.
- * The solution is not perfect but we can keep running the annotations while
- * found a better solution.
- */
- if (sa && sa->spacetype == SPACE_VIEW3D) {
- if ((ob != NULL) && (ob->type == OB_GPENCIL)) {
- ob->mode = OB_MODE_OBJECT;
- bGPdata *gpd = (bGPdata *)ob->data;
- ED_gpencil_setup_modes(C, gpd, 0);
- DEG_id_tag_update(&gpd->id, ID_RECALC_COPY_ON_WRITE);
-
- ViewLayer *view_layer = CTX_data_view_layer(C);
- BKE_view_layer_base_deselect_all(view_layer);
- view_layer->basact = NULL;
- DEG_id_tag_update(&scene->id, ID_RECALC_SELECT);
- WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
- }
- }
-
if (G.debug & G_DEBUG) {
printf("GPencil - Starting Drawing\n");
}
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 1331cc92d96..fa23dd5e059 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -91,64 +91,43 @@
/* ******************* Add New Data ************************ */
static bool gp_data_add_poll(bContext *C)
{
- Object *obact = CTX_data_active_object(C);
- if (obact && obact->type == OB_GPENCIL) {
- if (obact->mode != OB_MODE_OBJECT) {
- return false;
- }
- }
/* the base line we have is that we have somewhere to add Grease Pencil data */
- return ED_gpencil_data_get_pointers(C, NULL) != NULL;
+ return ED_annotation_data_get_pointers(C, NULL) != NULL;
}
/* add new datablock - wrapper around API */
static int gp_data_add_exec(bContext *C, wmOperator *op)
{
PointerRNA gpd_owner = {NULL};
- bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, &gpd_owner);
- bool is_annotation = ED_gpencil_data_owner_is_annotation(&gpd_owner);
+ bGPdata **gpd_ptr = ED_annotation_data_get_pointers(C, &gpd_owner);
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 */
- /* TODO: if a datablock exists,
- * we should make a copy of it instead of starting fresh (as in other areas) */
- Main *bmain = CTX_data_main(C);
-
- /* decrement user count of old GP datablock */
- if (*gpd_ptr) {
- bGPdata *gpd = (*gpd_ptr);
- id_us_min(&gpd->id);
- }
- /* Add new datablock, with a single layer ready to use
- * (so users don't have to perform an extra step). */
- if (is_annotation) {
- bGPdata *gpd = BKE_gpencil_data_addnew(bmain, DATA_("Annotations"));
- *gpd_ptr = gpd;
+ /* decrement user count and add new datablock */
+ /* TODO: if a datablock exists,
+ * we should make a copy of it instead of starting fresh (as in other areas) */
+ Main *bmain = CTX_data_main(C);
- /* tag for annotations */
- gpd->flag |= GP_DATA_ANNOTATIONS;
+ /* decrement user count of old GP datablock */
+ if (*gpd_ptr) {
+ bGPdata *gpd = (*gpd_ptr);
+ id_us_min(&gpd->id);
+ }
- /* add new layer (i.e. a "note") */
- BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("Note"), true);
- }
- else {
- /* GP Object Case - This shouldn't happen! */
- *gpd_ptr = BKE_gpencil_data_addnew(bmain, DATA_("GPencil"));
+ /* Add new datablock, with a single layer ready to use
+ * (so users don't have to perform an extra step). */
+ bGPdata *gpd = BKE_gpencil_data_addnew(bmain, DATA_("Annotations"));
+ *gpd_ptr = gpd;
- /* add default sets of colors and brushes */
- Object *ob = CTX_data_active_object(C);
- ED_gpencil_add_defaults(C, ob);
+ /* tag for annotations */
+ gpd->flag |= GP_DATA_ANNOTATIONS;
- /* add new layer */
- BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("GP_Layer"), true);
- }
- }
+ /* add new layer (i.e. a "note") */
+ BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("Note"), true);
/* notifiers */
WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
@@ -156,12 +135,12 @@ static int gp_data_add_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
-void GPENCIL_OT_data_add(wmOperatorType *ot)
+void GPENCIL_OT_annotation_add(wmOperatorType *ot)
{
/* identifiers */
- ot->name = "Grease Pencil Add New";
- ot->idname = "GPENCIL_OT_data_add";
- ot->description = "Add new Grease Pencil data-block";
+ ot->name = "Annotation Add New";
+ ot->idname = "GPENCIL_OT_annotation_add";
+ ot->description = "Add new Annotation data-block";
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* callbacks */
@@ -174,7 +153,7 @@ void GPENCIL_OT_data_add(wmOperatorType *ot)
/* poll callback for adding data/layers - special */
static bool gp_data_unlink_poll(bContext *C)
{
- bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
+ bGPdata **gpd_ptr = ED_annotation_data_get_pointers(C, NULL);
/* only unlink annotation datablocks */
if ((gpd_ptr != NULL) && (*gpd_ptr != NULL)) {
@@ -190,7 +169,7 @@ static bool gp_data_unlink_poll(bContext *C)
/* unlink datablock - wrapper around API */
static int gp_data_unlink_exec(bContext *C, wmOperator *op)
{
- bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
+ bGPdata **gpd_ptr = ED_annotation_data_get_pointers(C, NULL);
if (gpd_ptr == NULL) {
BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go");
@@ -231,47 +210,43 @@ void GPENCIL_OT_data_unlink(wmOperatorType *ot)
/* add new layer - wrapper around API */
static int gp_layer_add_exec(bContext *C, wmOperator *op)
{
- PointerRNA gpd_owner = {NULL};
- bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, &gpd_owner);
- bool is_annotation = ED_gpencil_data_owner_is_annotation(&gpd_owner);
+ const bool is_annotation = STREQ(op->idname, "GPENCIL_OT_layer_annotation_add");
- /* 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) {
- Main *bmain = CTX_data_main(C);
- if (is_annotation) {
- /* Annotations */
- *gpd_ptr = BKE_gpencil_data_addnew(bmain, DATA_("Annotations"));
+ PointerRNA gpd_owner = {NULL};
+ Main *bmain = CTX_data_main(C);
+ bGPdata *gpd = NULL;
- /* mark as annotation */
- (*gpd_ptr)->flag |= GP_DATA_ANNOTATIONS;
+ if (is_annotation) {
+ bGPdata **gpd_ptr = ED_annotation_data_get_pointers(C, &gpd_owner);
+ /* 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;
}
- else {
- /* GP Object */
- /* NOTE: This shouldn't actually happen in practice */
- *gpd_ptr = BKE_gpencil_data_addnew(bmain, DATA_("GPencil"));
-
- /* add default sets of colors and brushes */
- Object *ob = CTX_data_active_object(C);
- ED_gpencil_add_defaults(C, ob);
+ /* Annotations */
+ if (*gpd_ptr == NULL) {
+ *gpd_ptr = BKE_gpencil_data_addnew(bmain, DATA_("Annotations"));
}
- }
- /* add new layer now */
- if (is_annotation) {
+ /* mark as annotation */
+ (*gpd_ptr)->flag |= GP_DATA_ANNOTATIONS;
BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("Note"), true);
+ gpd = *gpd_ptr;
}
else {
- BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("GP_Layer"), true);
+ /* GP Object */
+ Object *ob = CTX_data_active_object(C);
+ if ((ob != NULL) && (ob->type == OB_GPENCIL)) {
+ gpd = (bGPdata *)ob->data;
+ BKE_gpencil_layer_addnew(gpd, DATA_("GP_Layer"), true);
+ }
}
/* notifiers */
- bGPdata *gpd = *gpd_ptr;
- DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
+ if (gpd) {
+ DEG_id_tag_update(&gpd->id,
+ ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_COPY_ON_WRITE);
+ }
WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
return OPERATOR_FINISHED;
@@ -291,11 +266,32 @@ void GPENCIL_OT_layer_add(wmOperatorType *ot)
ot->poll = gp_add_poll;
}
+static bool gp_add_annotation_poll(bContext *C)
+{
+ return ED_annotation_data_get_pointers(C, NULL) != NULL;
+}
+
+void GPENCIL_OT_layer_annotation_add(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Add New Annotation Layer";
+ ot->idname = "GPENCIL_OT_layer_annotation_add";
+ ot->description = "Add new Annotation layer or note for the active data-block";
+
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* callbacks */
+ ot->exec = gp_layer_add_exec;
+ ot->poll = gp_add_annotation_poll;
+}
/* ******************* Remove Active Layer ************************* */
static int gp_layer_remove_exec(bContext *C, wmOperator *op)
{
- bGPdata *gpd = ED_gpencil_data_get_active(C);
+ const bool is_annotation = STREQ(op->idname, "GPENCIL_OT_layer_annotation_remove");
+
+ bGPdata *gpd = (!is_annotation) ? ED_gpencil_data_get_active(C) :
+ ED_annotation_data_get_active(C);
bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
/* sanity checks */
@@ -343,6 +339,27 @@ void GPENCIL_OT_layer_remove(wmOperatorType *ot)
ot->poll = gp_active_layer_poll;
}
+static bool gp_active_layer_annotation_poll(bContext *C)
+{
+ bGPdata *gpd = ED_annotation_data_get_active(C);
+ bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
+
+ return (gpl != NULL);
+}
+
+void GPENCIL_OT_layer_annotation_remove(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Remove Annotation Layer";
+ ot->idname = "GPENCIL_OT_layer_annotation_remove";
+ ot->description = "Remove active Annotation layer";
+
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* callbacks */
+ ot->exec = gp_layer_remove_exec;
+ ot->poll = gp_active_layer_annotation_poll;
+}
/* ******************* Move Layer Up/Down ************************** */
enum {
@@ -352,7 +369,10 @@ enum {
static int gp_layer_move_exec(bContext *C, wmOperator *op)
{
- bGPdata *gpd = ED_gpencil_data_get_active(C);
+ const bool is_annotation = STREQ(op->idname, "GPENCIL_OT_layer_annotation_move");
+
+ bGPdata *gpd = (!is_annotation) ? ED_gpencil_data_get_active(C) :
+ ED_annotation_data_get_active(C);
bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
const int direction = RNA_enum_get(op->ptr, "type") * -1;
@@ -394,6 +414,28 @@ void GPENCIL_OT_layer_move(wmOperatorType *ot)
ot->prop = RNA_def_enum(ot->srna, "type", slot_move, 0, "Type", "");
}
+void GPENCIL_OT_layer_annotation_move(wmOperatorType *ot)
+{
+ static const EnumPropertyItem slot_move[] = {
+ {GP_LAYER_MOVE_UP, "UP", 0, "Up", ""},
+ {GP_LAYER_MOVE_DOWN, "DOWN", 0, "Down", ""},
+ {0, NULL, 0, NULL, NULL},
+ };
+
+ /* identifiers */
+ ot->name = "Move Annotation Layer";
+ ot->idname = "GPENCIL_OT_layer_annotation_move";
+ ot->description = "Move the active Annotation layer up/down in the list";
+
+ /* api callbacks */
+ ot->exec = gp_layer_move_exec;
+ ot->poll = gp_active_layer_annotation_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ ot->prop = RNA_def_enum(ot->srna, "type", slot_move, 0, "Type", "");
+}
/* ********************* Duplicate Layer ************************** */
static int gp_layer_copy_exec(bContext *C, wmOperator *UNUSED(op))
@@ -995,7 +1037,7 @@ void GPENCIL_OT_lock_all(wmOperatorType *ot)
/* callbacks */
ot->exec = gp_lock_all_exec;
- ot->poll = gp_reveal_poll; /* XXX: could use dedicated poll later */
+ ot->poll = gp_reveal_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -1034,7 +1076,7 @@ void GPENCIL_OT_unlock_all(wmOperatorType *ot)
/* callbacks */
ot->exec = gp_unlock_all_exec;
- ot->poll = gp_reveal_poll; /* XXX: could use dedicated poll later */
+ ot->poll = gp_reveal_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -2176,22 +2218,22 @@ static void joined_gpencil_fix_animdata_cb(ID *id, FCurve *fcu, void *user_data)
if (fcu->driver) {
/* Fix driver references to invalid ID's */
for (DriverVar *dvar = fcu->driver->variables.first; dvar; dvar = dvar->next) {
- /* only change the used targets, since the others will need fixing manually anyway */
+ /* Only change the used targets, since the others will need fixing manually anyway. */
DRIVER_TARGETS_USED_LOOPER_BEGIN (dvar) {
- /* change the ID's used... */
+ /* Change the ID's used. */
if (dtar->id == src_id) {
dtar->id = dst_id;
- /* also check on the subtarget...
- * XXX: We duplicate the logic from drivers_path_rename_fix() here, with our own
- * little twists so that we know that it isn't going to clobber the wrong data
+ /* Also check on the subtarget...
+ * We duplicate the logic from drivers_path_rename_fix() here, with our own
+ * little twists so that we know that it isn't going to clobber the wrong data
*/
if (dtar->rna_path && strstr(dtar->rna_path, "layers[")) {
GHASH_ITER (gh_iter, afd->names_map) {
const char *old_name = BLI_ghashIterator_getKey(&gh_iter);
const char *new_name = BLI_ghashIterator_getValue(&gh_iter);
- /* only remap if changed */
+ /* Only remap if changed. */
if (!STREQ(old_name, new_name)) {
if ((dtar->rna_path) && strstr(dtar->rna_path, old_name)) {
/* Fix up path */
@@ -2230,7 +2272,6 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op)
}
/* Ensure all rotations are applied before */
- // XXX: Why don't we apply them here instead of warning?
CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) {
if (ob_iter->type == OB_GPENCIL) {
if ((ob_iter->rot[0] != 0) || (ob_iter->rot[1] != 0) || (ob_iter->rot[2] != 0)) {
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index a87db4543e4..d47db0a3ce8 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -1650,10 +1650,23 @@ static bool gp_actframe_delete_poll(bContext *C)
return (gpl && gpl->actframe);
}
+static bool gp_annotation_actframe_delete_poll(bContext *C)
+{
+ bGPdata *gpd = ED_annotation_data_get_active(C);
+ bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
+
+ /* only if there's an active layer with an active frame */
+ return (gpl && gpl->actframe);
+}
+
/* delete active frame - wrapper around API calls */
static int gp_actframe_delete_exec(bContext *C, wmOperator *op)
{
- bGPdata *gpd = ED_gpencil_data_get_active(C);
+ const int is_annotation = RNA_boolean_get(op->ptr, "is_annotation");
+
+ bGPdata *gpd = (!is_annotation) ? ED_gpencil_data_get_active(C) :
+ ED_annotation_data_get_active(C);
+
bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
Scene *scene = CTX_data_scene(C);
@@ -1682,6 +1695,8 @@ static int gp_actframe_delete_exec(bContext *C, wmOperator *op)
void GPENCIL_OT_active_frame_delete(wmOperatorType *ot)
{
+ PropertyRNA *prop;
+
/* identifiers */
ot->name = "Delete Active Frame";
ot->idname = "GPENCIL_OT_active_frame_delete";
@@ -1692,8 +1707,29 @@ void GPENCIL_OT_active_frame_delete(wmOperatorType *ot)
/* callbacks */
ot->exec = gp_actframe_delete_exec;
ot->poll = gp_actframe_delete_poll;
+
+ prop = RNA_def_boolean(ot->srna, "is_annotation", false, "Annotation", "");
+ RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
+void GPENCIL_OT_annotation_active_frame_delete(wmOperatorType *ot)
+{
+ PropertyRNA *prop;
+
+ /* identifiers */
+ ot->name = "Delete Active Frame";
+ ot->idname = "GPENCIL_OT_annotation_active_frame_delete";
+ ot->description = "Delete the active frame for the active Annotation Layer";
+
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* callbacks */
+ ot->exec = gp_actframe_delete_exec;
+ ot->poll = gp_annotation_actframe_delete_poll;
+
+ prop = RNA_def_boolean(ot->srna, "is_annotation", true, "Annotation", "");
+ RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
+}
/* **************** Delete All Active Frames ****************** */
static bool gp_actframe_delete_all_poll(bContext *C)
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 1af641e5c84..69ec11685fb 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -428,12 +428,15 @@ void GPENCIL_OT_sculpt_paint(struct wmOperatorType *ot);
/* buttons editing --- */
-void GPENCIL_OT_data_add(struct wmOperatorType *ot);
+void GPENCIL_OT_annotation_add(struct wmOperatorType *ot);
void GPENCIL_OT_data_unlink(struct wmOperatorType *ot);
void GPENCIL_OT_layer_add(struct wmOperatorType *ot);
void GPENCIL_OT_layer_remove(struct wmOperatorType *ot);
void GPENCIL_OT_layer_move(struct wmOperatorType *ot);
+void GPENCIL_OT_layer_annotation_add(struct wmOperatorType *ot);
+void GPENCIL_OT_layer_annotation_remove(struct wmOperatorType *ot);
+void GPENCIL_OT_layer_annotation_move(struct wmOperatorType *ot);
void GPENCIL_OT_layer_duplicate(struct wmOperatorType *ot);
void GPENCIL_OT_layer_duplicate_object(struct wmOperatorType *ot);
@@ -449,6 +452,7 @@ void GPENCIL_OT_layer_merge(struct wmOperatorType *ot);
void GPENCIL_OT_blank_frame_add(struct wmOperatorType *ot);
void GPENCIL_OT_active_frame_delete(struct wmOperatorType *ot);
+void GPENCIL_OT_annotation_active_frame_delete(struct wmOperatorType *ot);
void GPENCIL_OT_active_frames_delete_all(struct wmOperatorType *ot);
void GPENCIL_OT_frame_duplicate(struct wmOperatorType *ot);
void GPENCIL_OT_frame_clean_fill(struct wmOperatorType *ot);
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index ce410f3e52d..7a541cd8f03 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -276,12 +276,15 @@ void ED_operatortypes_gpencil(void)
/* Editing (Buttons) ------------ */
- WM_operatortype_append(GPENCIL_OT_data_add);
+ WM_operatortype_append(GPENCIL_OT_annotation_add);
WM_operatortype_append(GPENCIL_OT_data_unlink);
WM_operatortype_append(GPENCIL_OT_layer_add);
WM_operatortype_append(GPENCIL_OT_layer_remove);
WM_operatortype_append(GPENCIL_OT_layer_move);
+ WM_operatortype_append(GPENCIL_OT_layer_annotation_add);
+ WM_operatortype_append(GPENCIL_OT_layer_annotation_remove);
+ WM_operatortype_append(GPENCIL_OT_layer_annotation_move);
WM_operatortype_append(GPENCIL_OT_layer_duplicate);
WM_operatortype_append(GPENCIL_OT_layer_duplicate_object);
@@ -295,6 +298,7 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_blank_frame_add);
WM_operatortype_append(GPENCIL_OT_active_frame_delete);
+ WM_operatortype_append(GPENCIL_OT_annotation_active_frame_delete);
WM_operatortype_append(GPENCIL_OT_active_frames_delete_all);
WM_operatortype_append(GPENCIL_OT_frame_duplicate);
WM_operatortype_append(GPENCIL_OT_frame_clean_fill);
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 300d7d9e925..9de3c32e05e 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -92,23 +92,20 @@
* and an RNA-pointer to trace back to whatever owns it,
* when context info is not available.
*/
-bGPdata **ED_gpencil_data_get_pointers_direct(
- ID *screen_id, ScrArea *sa, Scene *scene, Object *ob, PointerRNA *r_ptr)
+bGPdata **ED_gpencil_data_get_pointers_direct(ScrArea *sa, Object *ob, PointerRNA *r_ptr)
{
/* if there's an active area, check if the particular editor may
* have defined any special Grease Pencil context for editing...
*/
if (sa) {
- SpaceLink *sl = sa->spacedata.first;
-
switch (sa->spacetype) {
- /* XXX: Should we reduce reliance on context.gpencil_data for these cases? */
case SPACE_PROPERTIES: /* properties */
- case SPACE_INFO: /* header info (needed after workspaces merge) */
- case SPACE_ACTION: /* Dopesheet header. */
+ case SPACE_INFO: /* header info */
+ case SPACE_TOPBAR: /* Topbar */
+ case SPACE_VIEW3D: /* 3D-View */
{
if (ob && (ob->type == OB_GPENCIL)) {
- /* GP Object */
+ /* GP Object. */
if (r_ptr) {
RNA_id_pointer_create(&ob->id, r_ptr);
}
@@ -120,25 +117,44 @@ bGPdata **ED_gpencil_data_get_pointers_direct(
break;
}
+ default: /* Unsupported space. */
+ return NULL;
+ }
+ }
+
+ return NULL;
+}
+
+/**
+ * Get pointer to active Grease Pencil datablock for annotations,
+ * and an RNA-pointer to trace back to whatever owns it,
+ * when context info is not available.
+ */
+bGPdata **ED_annotation_data_get_pointers_direct(ID *screen_id,
+ ScrArea *sa,
+ Scene *scene,
+ PointerRNA *r_ptr)
+{
+ /* If there's an active area, check if the particular editor may
+ * have defined any special Grease Pencil context for editing. */
+ if (sa) {
+ SpaceLink *sl = sa->spacedata.first;
+
+ switch (sa->spacetype) {
+ case SPACE_PROPERTIES: /* properties */
+ case SPACE_INFO: /* header info */
+ {
+ return NULL;
+ break;
+ }
- case SPACE_TOPBAR: /* Topbar (needed after topbar merge) */
+ case SPACE_TOPBAR: /* Topbar */
case SPACE_VIEW3D: /* 3D-View */
{
- if (ob && (ob->type == OB_GPENCIL)) {
- /* GP Object */
- if (r_ptr) {
- RNA_id_pointer_create(&ob->id, r_ptr);
- }
- return (bGPdata **)&ob->data;
- }
- else {
- /* Annotations */
- /* XXX: */
- if (r_ptr) {
- RNA_id_pointer_create(&scene->id, r_ptr);
- }
- return &scene->gpd;
+ if (r_ptr) {
+ RNA_id_pointer_create(&scene->id, r_ptr);
}
+ return &scene->gpd;
break;
}
@@ -156,7 +172,7 @@ bGPdata **ED_gpencil_data_get_pointers_direct(
return &snode->nodetree->gpd;
}
- /* even when there is no node-tree, don't allow this to flow to scene */
+ /* Even when there is no node-tree, don't allow this to flow to scene. */
return NULL;
}
case SPACE_SEQ: /* Sequencer */
@@ -165,7 +181,6 @@ bGPdata **ED_gpencil_data_get_pointers_direct(
/* For now, Grease Pencil data is associated with the space
* (actually preview region only). */
- /* XXX our convention for everything else is to link to data though... */
if (r_ptr) {
RNA_pointer_create(screen_id, &RNA_SpaceSequenceEditor, sseq, r_ptr);
}
@@ -175,8 +190,7 @@ bGPdata **ED_gpencil_data_get_pointers_direct(
{
SpaceImage *sima = (SpaceImage *)sl;
- /* for now, Grease Pencil data is associated with the space... */
- /* XXX our convention for everything else is to link to data though... */
+ /* For now, Grease Pencil data is associated with the space... */
if (r_ptr) {
RNA_pointer_create(screen_id, &RNA_SpaceImageEditor, sima, r_ptr);
}
@@ -221,34 +235,61 @@ bGPdata **ED_gpencil_data_get_pointers_direct(
* and an RNA-pointer to trace back to whatever owns it. */
bGPdata **ED_gpencil_data_get_pointers(const bContext *C, PointerRNA *r_ptr)
{
- ID *screen_id = (ID *)CTX_wm_screen(C);
- Scene *scene = CTX_data_scene(C);
ScrArea *sa = CTX_wm_area(C);
Object *ob = CTX_data_active_object(C);
- return ED_gpencil_data_get_pointers_direct(screen_id, sa, scene, ob, r_ptr);
+ return ED_gpencil_data_get_pointers_direct(sa, ob, r_ptr);
}
+/* Get pointer to active Grease Pencil datablock,
+ * and an RNA-pointer to trace back to whatever owns it. */
+bGPdata **ED_annotation_data_get_pointers(const bContext *C, PointerRNA *r_ptr)
+{
+ ID *screen_id = (ID *)CTX_wm_screen(C);
+ Scene *scene = CTX_data_scene(C);
+ ScrArea *sa = CTX_wm_area(C);
+
+ return ED_annotation_data_get_pointers_direct(screen_id, sa, scene, r_ptr);
+}
/* -------------------------------------------------------- */
/* Get the active Grease Pencil datablock, when context is not available */
-bGPdata *ED_gpencil_data_get_active_direct(ID *screen_id, ScrArea *sa, Scene *scene, Object *ob)
+bGPdata *ED_gpencil_data_get_active_direct(ScrArea *sa, Object *ob)
+{
+ bGPdata **gpd_ptr = ED_gpencil_data_get_pointers_direct(sa, ob, NULL);
+ return (gpd_ptr) ? *(gpd_ptr) : NULL;
+}
+
+/* Get the active Grease Pencil datablock, when context is not available */
+bGPdata *ED_annotation_data_get_active_direct(ID *screen_id, ScrArea *sa, Scene *scene)
{
- bGPdata **gpd_ptr = ED_gpencil_data_get_pointers_direct(screen_id, sa, scene, ob, NULL);
+ bGPdata **gpd_ptr = ED_annotation_data_get_pointers_direct(screen_id, sa, scene, NULL);
return (gpd_ptr) ? *(gpd_ptr) : NULL;
}
/**
* Get the active Grease Pencil datablock
+ */
+bGPdata *ED_gpencil_data_get_active(const bContext *C)
+{
+ Object *ob = CTX_data_active_object(C);
+ if (ob == NULL) {
+ return NULL;
+ }
+ bGPdata *gpd = (bGPdata *)ob->data;
+
+ return gpd;
+}
+
+/* Get the active Grease Pencil datablock
* \note This is the original (bmain) copy of the datablock, stored in files.
* Do not use for reading evaluated copies of GP Objects data
*/
-bGPdata *ED_gpencil_data_get_active(const bContext *C)
+bGPdata *ED_annotation_data_get_active(const bContext *C)
{
- bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
+ bGPdata **gpd_ptr = ED_annotation_data_get_pointers(C, NULL);
return (gpd_ptr) ? *(gpd_ptr) : NULL;
}
-
/**
* Get the evaluated copy of the active Grease Pencil datablock (where applicable)
* - For the 3D View (i.e. "GP Objects"), this gives the evaluated copy of the GP datablock
@@ -259,20 +300,13 @@ bGPdata *ED_gpencil_data_get_active(const bContext *C)
*/
bGPdata *ED_gpencil_data_get_active_evaluated(const bContext *C)
{
- ID *screen_id = (ID *)CTX_wm_screen(C);
ScrArea *sa = CTX_wm_area(C);
const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
- Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
Object *ob = CTX_data_active_object(C);
Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
-#if 0
- if (ob && ob->type == OB_GPENCIL) {
- BLI_assert(ob_eval->data == DEG_get_evaluated_id(ob->data));
- }
-#endif
- return ED_gpencil_data_get_active_direct(screen_id, sa, scene_eval, ob_eval);
+ return ED_gpencil_data_get_active_direct(sa, ob_eval);
}
/* -------------------------------------------------------- */
@@ -318,14 +352,23 @@ bool ED_gpencil_has_keyframe_v3d(Scene *UNUSED(scene), Object *ob, int cfra)
/* poll callback for adding data/layers - special */
bool gp_add_poll(bContext *C)
{
- /* the base line we have is that we have somewhere to add Grease Pencil data */
- return ED_gpencil_data_get_pointers(C, NULL) != NULL;
+ Object *ob = CTX_data_active_object(C);
+ if (ob == NULL) {
+ return false;
+ }
+ bGPdata *gpd = (bGPdata *)ob->data;
+
+ return (gpd != NULL);
}
/* poll callback for checking if there is an active layer */
bool gp_active_layer_poll(bContext *C)
{
- bGPdata *gpd = ED_gpencil_data_get_active(C);
+ Object *ob = CTX_data_active_object(C);
+ if (ob == NULL) {
+ return false;
+ }
+ bGPdata *gpd = (bGPdata *)ob->data;
bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
return (gpl != NULL);