[Bf-blender-cvs] [b9029d6] GPencil_Editing_Stage3: GP Edit: "Change Layer" operator - Integrated into the D+W Pie Menu
Joshua Leung
noreply at git.blender.org
Sat Oct 17 16:53:43 CEST 2015
Commit: b9029d698c4735f878c677621dcf8e2ae37e20e1
Author: Joshua Leung
Date: Sun Oct 18 03:52:32 2015 +1300
Branches: GPencil_Editing_Stage3
https://developer.blender.org/rBb9029d698c4735f878c677621dcf8e2ae37e20e1
GP Edit: "Change Layer" operator - Integrated into the D+W Pie Menu
Create a "Change Stroke" operator for GP Layers which can be used to change
between layers without needing to have the layers list open. This can be
accessed via the D+W pie menu by clicking on the dropdown beside the active
layer's name. Also, added the ability to delete the active layer from the menu too.
===================================================================
M release/scripts/startup/bl_ui/properties_grease_pencil_common.py
M source/blender/editors/gpencil/gpencil_data.c
M source/blender/editors/gpencil/gpencil_edit.c
M source/blender/editors/gpencil/gpencil_ops.c
M source/blender/editors/gpencil/gpencil_utils.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index 766044d..428888a 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -300,8 +300,13 @@ class GPENCIL_PIE_settings_palette(Menu):
# XXX: this should show an operator to change the active layer instead
col = pie.column()
col.label("Active Layer: ")
- col.prop(gpl, "info", text="")
- # col.prop(gpd, "layers")
+
+ row = col.row()
+ row.operator_context = 'EXEC_REGION_WIN'
+ row.operator_menu_enum("gpencil.layer_change", "layer", text="", icon='GREASEPENCIL')
+ row.prop(gpl, "info", text="")
+ row.operator("gpencil.layer_remove", text="", icon='X')
+
row = col.row()
row.prop(gpl, "lock")
row.prop(gpl, "hide")
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index de96677..10dfe9a 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -59,12 +59,14 @@
#include "BKE_screen.h"
#include "UI_interface.h"
+#include "UI_resources.h"
#include "WM_api.h"
#include "WM_types.h"
#include "RNA_access.h"
#include "RNA_define.h"
+#include "RNA_enum_types.h"
#include "ED_gpencil.h"
@@ -444,4 +446,70 @@ void GPENCIL_OT_reveal(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
+/* ********************** Change Layer ***************************** */
+
+static int gp_layer_change_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(evt))
+{
+ 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;
+}
+
+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 */
+ gpl = gpencil_layer_addnew(gpd, DATA_("GP_Layer"), true);
+ }
+ 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 */
+ gpencil_layer_setactive(gpd, gpl);
+
+ /* updates */
+ WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
+
+ return OPERATOR_FINISHED;
+}
+
+void GPENCIL_OT_layer_change(wmOperatorType *ot)
+{
+ /* identifiers */
+ 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);
+}
+
/* ************************************************ */
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 4f8031a..4370e61 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -615,7 +615,6 @@ void GPENCIL_OT_move_to_layer(wmOperatorType *ot)
/* 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);
-
}
/* ******************* Delete Active Frame ************************ */
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index df02626..fc12a07 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -314,6 +314,7 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_paste);
WM_operatortype_append(GPENCIL_OT_move_to_layer);
+ WM_operatortype_append(GPENCIL_OT_layer_change);
WM_operatortype_append(GPENCIL_OT_brush_paint);
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 2e27f3f..df61b8f 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -256,7 +256,7 @@ EnumPropertyItem *ED_gpencil_layers_enum_itemf(bContext *C, PointerRNA *UNUSED(p
item_tmp.value = i;
if (gpl->flag & GP_LAYER_ACTIVE)
- item_tmp.icon = ICON_RESTRICT_VIEW_OFF;
+ item_tmp.icon = ICON_GREASEPENCIL;
else
item_tmp.icon = ICON_NONE;
@@ -303,7 +303,7 @@ EnumPropertyItem *ED_gpencil_layers_with_new_enum_itemf(bContext *C, PointerRNA
item_tmp.value = i;
if (gpl->flag & GP_LAYER_ACTIVE)
- item_tmp.icon = ICON_RESTRICT_VIEW_OFF;
+ item_tmp.icon = ICON_GREASEPENCIL;
else
item_tmp.icon = ICON_NONE;
More information about the Bf-blender-cvs
mailing list