diff options
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_data.c')
-rw-r--r-- | source/blender/editors/gpencil/gpencil_data.c | 164 |
1 files changed, 82 insertions, 82 deletions
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c index 9d183222c2d..2e8e48b2f15 100644 --- a/source/blender/editors/gpencil/gpencil_data.c +++ b/source/blender/editors/gpencil/gpencil_data.c @@ -93,7 +93,7 @@ static int gp_data_add_exec(bContext *C, wmOperator *op) else { /* decrement user count and add new datablock */ bGPdata *gpd = (*gpd_ptr); - + id_us_min(&gpd->id); *gpd_ptr = BKE_gpencil_data_addnew(DATA_("GPencil")); @@ -106,10 +106,10 @@ static int gp_data_add_exec(bContext *C, wmOperator *op) } } - + /* notifiers */ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); - + return OPERATOR_FINISHED; } @@ -120,7 +120,7 @@ void GPENCIL_OT_data_add(wmOperatorType *ot) ot->idname = "GPENCIL_OT_data_add"; ot->description = "Add new Grease Pencil data-block"; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + /* callbacks */ ot->exec = gp_data_add_exec; ot->poll = gp_add_poll; @@ -132,7 +132,7 @@ void GPENCIL_OT_data_add(wmOperatorType *ot) static int gp_data_unlink_poll(bContext *C) { bGPdata **gpd_ptr = ED_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); } @@ -142,7 +142,7 @@ static int gp_data_unlink_poll(bContext *C) static int gp_data_unlink_exec(bContext *C, wmOperator *op) { bGPdata **gpd_ptr = ED_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; @@ -154,10 +154,10 @@ static int gp_data_unlink_exec(bContext *C, wmOperator *op) id_us_min(&gpd->id); *gpd_ptr = NULL; } - + /* notifiers */ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); - + return OPERATOR_FINISHED; } @@ -168,7 +168,7 @@ void GPENCIL_OT_data_unlink(wmOperatorType *ot) ot->idname = "GPENCIL_OT_data_unlink"; ot->description = "Unlink active Grease Pencil data-block"; ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + /* callbacks */ ot->exec = gp_data_unlink_exec; ot->poll = gp_data_unlink_poll; @@ -193,7 +193,7 @@ static int gp_layer_add_exec(bContext *C, wmOperator *op) } if (*gpd_ptr == NULL) *gpd_ptr = BKE_gpencil_data_addnew(DATA_("GPencil")); - + /* if not exist brushes, create a new set */ if (ts) { if (BLI_listbase_is_empty(&ts->gp_brushes)) { @@ -204,10 +204,10 @@ static int gp_layer_add_exec(bContext *C, wmOperator *op) /* add new layer now */ BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("GP_Layer"), true); - + /* notifiers */ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); - + return OPERATOR_FINISHED; } @@ -217,9 +217,9 @@ void GPENCIL_OT_layer_add(wmOperatorType *ot) ot->name = "Add New Layer"; ot->idname = "GPENCIL_OT_layer_add"; ot->description = "Add new Grease Pencil layer for the active Grease Pencil data-block"; - + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + /* callbacks */ ot->exec = gp_layer_add_exec; ot->poll = gp_add_poll; @@ -231,16 +231,16 @@ static int gp_layer_remove_exec(bContext *C, wmOperator *op) { bGPdata *gpd = ED_gpencil_data_get_active(C); bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); - + /* sanity checks */ if (ELEM(NULL, gpd, gpl)) return OPERATOR_CANCELLED; - + if (gpl->flag & GP_LAYER_LOCKED) { BKE_report(op->reports, RPT_ERROR, "Cannot delete locked layers"); return OPERATOR_CANCELLED; } - + /* make the layer before this the new active layer * - use the one after if this is the first * - if this is the only layer, this naturally becomes NULL @@ -249,13 +249,13 @@ static int gp_layer_remove_exec(bContext *C, wmOperator *op) BKE_gpencil_layer_setactive(gpd, gpl->prev); else BKE_gpencil_layer_setactive(gpd, gpl->next); - + /* delete the layer now... */ BKE_gpencil_layer_delete(gpd, gpl); - + /* notifiers */ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); - + return OPERATOR_FINISHED; } @@ -265,9 +265,9 @@ void GPENCIL_OT_layer_remove(wmOperatorType *ot) ot->name = "Remove Layer"; ot->idname = "GPENCIL_OT_layer_remove"; ot->description = "Remove active Grease Pencil layer"; - + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + /* callbacks */ ot->exec = gp_layer_remove_exec; ot->poll = gp_active_layer_poll; @@ -284,18 +284,18 @@ static int gp_layer_move_exec(bContext *C, wmOperator *op) { bGPdata *gpd = ED_gpencil_data_get_active(C); bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); - + int direction = RNA_enum_get(op->ptr, "type"); - + /* sanity checks */ if (ELEM(NULL, gpd, gpl)) return OPERATOR_CANCELLED; - + BLI_assert(ELEM(direction, -1, 0, 1)); /* we use value below */ if (BLI_listbase_link_move(&gpd->layers, gpl, direction)) { WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); } - + return OPERATOR_FINISHED; } @@ -306,19 +306,19 @@ void GPENCIL_OT_layer_move(wmOperatorType *ot) {GP_LAYER_MOVE_DOWN, "DOWN", 0, "Down", ""}, {0, NULL, 0, NULL, NULL} }; - + /* identifiers */ ot->name = "Move Grease Pencil Layer"; ot->idname = "GPENCIL_OT_layer_move"; ot->description = "Move the active Grease Pencil layer up/down in the list"; - + /* api callbacks */ ot->exec = gp_layer_move_exec; ot->poll = gp_active_layer_poll; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + ot->prop = RNA_def_enum(ot->srna, "type", slot_move, 0, "Type", ""); } @@ -329,22 +329,22 @@ static int gp_layer_copy_exec(bContext *C, wmOperator *UNUSED(op)) bGPdata *gpd = ED_gpencil_data_get_active(C); bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); bGPDlayer *new_layer; - + /* sanity checks */ if (ELEM(NULL, gpd, gpl)) return OPERATOR_CANCELLED; - + /* make copy of layer, and add it immediately after the existing layer */ new_layer = BKE_gpencil_layer_duplicate(gpl); BLI_insertlinkafter(&gpd->layers, gpl, new_layer); - + /* ensure new layer has a unique name, and is now the active layer */ BLI_uniquename(&gpd->layers, new_layer, DATA_("GP_Layer"), '.', offsetof(bGPDlayer, info), sizeof(new_layer->info)); BKE_gpencil_layer_setactive(gpd, new_layer); - + /* notifiers */ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); - + return OPERATOR_FINISHED; } @@ -354,11 +354,11 @@ void GPENCIL_OT_layer_duplicate(wmOperatorType *ot) ot->name = "Duplicate Layer"; ot->idname = "GPENCIL_OT_layer_duplicate"; ot->description = "Make a copy of the active Grease Pencil layer"; - + /* callbacks */ ot->exec = gp_layer_copy_exec; ot->poll = gp_active_layer_poll; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } @@ -370,14 +370,14 @@ static int gp_hide_exec(bContext *C, wmOperator *op) bGPdata *gpd = ED_gpencil_data_get_active(C); bGPDlayer *layer = BKE_gpencil_layer_getactive(gpd); bool unselected = RNA_boolean_get(op->ptr, "unselected"); - + /* sanity checks */ if (ELEM(NULL, gpd, layer)) return OPERATOR_CANCELLED; - + if (unselected) { bGPDlayer *gpl; - + /* hide unselected */ for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { if (gpl != layer) { @@ -389,10 +389,10 @@ static int gp_hide_exec(bContext *C, wmOperator *op) /* hide selected/active */ layer->flag |= GP_LAYER_HIDE; } - + /* notifiers */ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); - + return OPERATOR_FINISHED; } @@ -402,14 +402,14 @@ void GPENCIL_OT_hide(wmOperatorType *ot) ot->name = "Hide Layer(s)"; ot->idname = "GPENCIL_OT_hide"; ot->description = "Hide selected/unselected Grease Pencil layers"; - + /* callbacks */ ot->exec = gp_hide_exec; ot->poll = gp_active_layer_poll; /* NOTE: we need an active layer to play with */ - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + /* props */ RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected layers"); } @@ -452,7 +452,7 @@ static int gp_reveal_exec(bContext *C, wmOperator *op) /* sanity checks */ if (gpd == NULL) return OPERATOR_CANCELLED; - + for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { if (gpl->flag & GP_LAYER_HIDE) { @@ -476,10 +476,10 @@ static int gp_reveal_exec(bContext *C, wmOperator *op) } } } - + /* notifiers */ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); - + return OPERATOR_FINISHED; } @@ -489,11 +489,11 @@ void GPENCIL_OT_reveal(wmOperatorType *ot) ot->name = "Show All Layers"; ot->idname = "GPENCIL_OT_reveal"; ot->description = "Show all Grease Pencil layers"; - + /* callbacks */ ot->exec = gp_reveal_exec; ot->poll = gp_reveal_poll; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -507,19 +507,19 @@ static int gp_lock_all_exec(bContext *C, wmOperator *UNUSED(op)) { bGPdata *gpd = ED_gpencil_data_get_active(C); bGPDlayer *gpl; - + /* sanity checks */ if (gpd == NULL) return OPERATOR_CANCELLED; - + /* make all layers non-editable */ for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { gpl->flag |= GP_LAYER_LOCKED; } - + /* notifiers */ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); - + return OPERATOR_FINISHED; } @@ -529,11 +529,11 @@ void GPENCIL_OT_lock_all(wmOperatorType *ot) ot->name = "Lock All Layers"; ot->idname = "GPENCIL_OT_lock_all"; ot->description = "Lock all Grease Pencil layers to prevent them from being accidentally modified"; - + /* callbacks */ ot->exec = gp_lock_all_exec; ot->poll = gp_reveal_poll; /* XXX: could use dedicated poll later */ - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } @@ -544,19 +544,19 @@ static int gp_unlock_all_exec(bContext *C, wmOperator *UNUSED(op)) { bGPdata *gpd = ED_gpencil_data_get_active(C); bGPDlayer *gpl; - + /* sanity checks */ if (gpd == NULL) return OPERATOR_CANCELLED; - + /* make all layers editable again */ for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { gpl->flag &= ~GP_LAYER_LOCKED; } - + /* notifiers */ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); - + return OPERATOR_FINISHED; } @@ -566,11 +566,11 @@ void GPENCIL_OT_unlock_all(wmOperatorType *ot) ot->name = "Unlock All Layers"; ot->idname = "GPENCIL_OT_unlock_all"; ot->description = "Unlock all Grease Pencil layers so that they can be edited"; - + /* callbacks */ ot->exec = gp_unlock_all_exec; ot->poll = gp_reveal_poll; /* XXX: could use dedicated poll later */ - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } @@ -584,21 +584,21 @@ static int gp_isolate_layer_exec(bContext *C, wmOperator *op) bGPDlayer *gpl; int flags = GP_LAYER_LOCKED; bool isolate = false; - + if (RNA_boolean_get(op->ptr, "affect_visibility")) flags |= GP_LAYER_HIDE; - + if (ELEM(NULL, gpd, layer)) { BKE_report(op->reports, RPT_ERROR, "No active layer to isolate"); return OPERATOR_CANCELLED; } - + /* Test whether to isolate or clear all flags */ for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { /* Skip if this is the active layer */ if (gpl == layer) continue; - + /* If the flags aren't set, that means that the layer is * not alone, so we have some layers to isolate still */ @@ -607,7 +607,7 @@ static int gp_isolate_layer_exec(bContext *C, wmOperator *op) break; } } - + /* Set/Clear flags as appropriate */ /* TODO: Include onionskinning on this list? */ if (isolate) { @@ -625,10 +625,10 @@ static int gp_isolate_layer_exec(bContext *C, wmOperator *op) gpl->flag &= ~flags; } } - + /* notifiers */ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); - + return OPERATOR_FINISHED; } @@ -638,14 +638,14 @@ void GPENCIL_OT_layer_isolate(wmOperatorType *ot) ot->name = "Isolate Layer"; ot->idname = "GPENCIL_OT_layer_isolate"; ot->description = "Toggle whether the active layer is the only one that can be edited and/or visible"; - + /* callbacks */ ot->exec = gp_isolate_layer_exec; ot->poll = gp_active_layer_poll; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + /* properties */ RNA_def_boolean(ot->srna, "affect_visibility", false, "Affect Visibility", "In addition to toggling the editability, also affect the visibility"); @@ -712,13 +712,13 @@ static int gp_layer_change_invoke(bContext *C, wmOperator *op, const wmEvent *UN { uiPopupMenu *pup; uiLayout *layout; - + /* call the menu, which will call this operator again, hence the canceled */ pup = UI_popup_menu_begin(C, op->type->name, ICON_NONE); layout = UI_popup_menu_layout(pup); uiItemsEnumO(layout, "GPENCIL_OT_layer_change", "layer"); UI_popup_menu_end(C, pup); - + return OPERATOR_INTERFACE; } @@ -727,7 +727,7 @@ static int gp_layer_change_exec(bContext *C, wmOperator *op) bGPdata *gpd = CTX_data_gpencil_data(C); bGPDlayer *gpl = NULL; int layer_num = RNA_enum_get(op->ptr, "layer"); - + /* Get layer or create new one */ if (layer_num == -1) { /* Create layer */ @@ -736,19 +736,19 @@ static int gp_layer_change_exec(bContext *C, wmOperator *op) else { /* Try to get layer */ gpl = BLI_findlink(&gpd->layers, layer_num); - + if (gpl == NULL) { BKE_reportf(op->reports, RPT_ERROR, "Cannot change to non-existent layer (index = %d)", layer_num); return OPERATOR_CANCELLED; } } - + /* Set active layer */ BKE_gpencil_layer_setactive(gpd, gpl); - + /* updates */ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL); - + return OPERATOR_FINISHED; } @@ -758,15 +758,15 @@ void GPENCIL_OT_layer_change(wmOperatorType *ot) ot->name = "Change Layer"; ot->idname = "GPENCIL_OT_layer_change"; ot->description = "Change active Grease Pencil layer"; - + /* callbacks */ ot->invoke = gp_layer_change_invoke; ot->exec = gp_layer_change_exec; ot->poll = gp_active_layer_poll; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + /* gp layer to use (dynamic enum) */ ot->prop = RNA_def_enum(ot->srna, "layer", DummyRNA_DEFAULT_items, 0, "Grease Pencil Layer", ""); RNA_def_enum_funcs(ot->prop, ED_gpencil_layers_with_new_enum_itemf); |