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:
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_edit.c')
-rw-r--r--source/blender/editors/gpencil/gpencil_edit.c126
1 files changed, 126 insertions, 0 deletions
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 3130e190ce2..2faf3ccbbda 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -60,6 +60,7 @@
#include "BKE_gpencil.h"
#include "BKE_image.h"
#include "BKE_library.h"
+#include "BKE_report.h"
#include "BKE_utildefines.h"
#include "BIF_gl.h"
@@ -123,6 +124,9 @@ bGPdata **gpencil_data_get_pointers (bContext *C, PointerRNA *ptr)
/* return the GP data for the active strips/image/etc. */
}
break;
+
+ default: /* unsupported space */
+ return NULL;
}
}
@@ -141,6 +145,128 @@ bGPdata *gpencil_data_get_active (bContext *C)
/* ************************************************ */
/* Panel Operators */
+/* 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;
+}
+
+/* ******************* Add New Data ************************ */
+
+/* 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 {
+ /* just add new datablock now */
+ *gpd_ptr= gpencil_data_addnew("GPencil");
+ }
+
+ /* notifiers */
+ WM_event_add_notifier(C, NC_SCREEN|ND_GPENCIL|NA_EDITED, NULL); // XXX please work!
+
+ return OPERATOR_FINISHED;
+}
+void GPENCIL_OT_data_add (wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Grease Pencil Add New";
+ ot->idname= "GPENCIL_OT_data_add";
+ ot->description= "Add new Grease Pencil datablock.";
+
+ /* callbacks */
+ ot->exec= gp_data_add_exec;
+ ot->poll= gp_add_poll;
+}
+
+/* ******************* Unlink Data ************************ */
+
+/* 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);
+}
+
+
+/* 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);
+
+ gpd->id.us--;
+ *gpd_ptr= NULL;
+ }
+
+ /* notifiers */
+ WM_event_add_notifier(C, NC_SCREEN|ND_GPENCIL|NA_EDITED, NULL); // XXX please work!
+
+ return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_data_unlink (wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Grease Pencil Unlink";
+ ot->idname= "GPENCIL_OT_data_unlink";
+ ot->description= "Unlink active Grease Pencil datablock.";
+
+ /* callbacks */
+ ot->exec= gp_data_unlink_exec;
+ ot->poll= gp_data_unlink_poll;
+}
+
+/* ******************* Add New Layer ************************ */
+
+/* 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("GPencil");
+
+ /* add new layer now */
+ gpencil_layer_addnew(*gpd_ptr);
+
+ /* notifiers */
+ WM_event_add_notifier(C, NC_SCREEN|ND_GPENCIL|NA_EDITED, NULL); // XXX please work!
+
+ return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_layer_add (wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Add New Layer";
+ ot->idname= "GPENCIL_OT_layer_add";
+ ot->description= "Add new Grease Pencil layer for the active Grease Pencil datablock.";
+
+ /* callbacks */
+ ot->exec= gp_layer_add_exec;
+ ot->poll= gp_add_poll;
+}
/* ************************************************ */