diff options
author | Joshua Leung <aligorith@gmail.com> | 2009-08-29 10:50:32 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2009-08-29 10:50:32 +0400 |
commit | 8930a4fd332e69442b4de2efe42019bf5a41c946 (patch) | |
tree | 6a276c12cb665324543e67f484a84e6657a32411 /source/blender/editors/gpencil/gpencil_edit.c | |
parent | f46f6dc7ba32411a8031a243bba635c8cc3ade29 (diff) |
Grease Pencil: UI (i.e. Panel) for Settings
Restored the UI for access to the GP layers.
There are still a few minor bugs here:
* Wrong icons on the toggles - even when they're enabled, they only show a single state
* The ID-template doesn't seem to be showing up. Dunno what's going wrong there...
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_edit.c')
-rw-r--r-- | source/blender/editors/gpencil/gpencil_edit.c | 126 |
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; +} /* ************************************************ */ |