GPencil: New Operator to set the active object material based on the selected stroke material

The operator set as active object material the material used in the selected stroke.

Access to the operator were added in the stroke menu and context stroke menu.

Reviewers: antoniov, pepeland

Tags: #bf_blender, #grease_pencil

Differential Revision: https://developer.blender.org/D5692
This commit is contained in:
Matias Mendiola 2019-09-05 13:28:42 +02:00 committed by Antonio Vazquez
parent 3a0b22b2da
commit d0462dca90
4 changed files with 55 additions and 2 deletions

View File

@ -4374,7 +4374,7 @@ class VIEW3D_MT_edit_armature_delete(Menu):
layout.operator("armature.dissolve", text="Dissolve Bones")
# ********** Grease Pencil Stroke menus **********
# ********** Grease Pencil menus **********
class VIEW3D_MT_gpencil_autoweights(Menu):
bl_label = "Generate Weights"
@ -4504,6 +4504,7 @@ class VIEW3D_MT_edit_gpencil_stroke(Menu):
layout.menu("GPENCIL_MT_move_to_layer")
layout.menu("VIEW3D_MT_assign_material")
layout.operator("gpencil.set_active_material", text="Set as Active Material")
layout.operator_menu_enum("gpencil.stroke_arrange", "direction", text="Arrange Strokes")
layout.separator()
@ -6392,8 +6393,9 @@ class VIEW3D_MT_gpencil_edit_context_menu(Menu):
col.separator()
# Layer and Materials operators
col.menu("GPENCIL_MT_move_to_layer")
col.menu("GPENCIL_MT_move_to_layer")
col.menu("VIEW3D_MT_assign_material")
col.operator("gpencil.set_active_material", text="Set as Active Material")
col.operator_menu_enum("gpencil.stroke_arrange", "direction", text="Arrange Strokes")
col.separator()

View File

@ -2920,6 +2920,54 @@ void GPENCIL_OT_color_select(wmOperatorType *ot)
RNA_def_property_flag(ot->prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
/* ***************** Set selected stroke material the active material ************************ */
static int gpencil_set_active_material_exec(bContext *C, wmOperator *op)
{
Object *ob = CTX_data_active_object(C);
bGPdata *gpd = ED_gpencil_data_get_active(C);
bool changed = false;
/* Sanity checks. */
if (gpd == NULL) {
BKE_report(op->reports, RPT_ERROR, "No Grease Pencil data");
return OPERATOR_CANCELLED;
}
/* Loop all selected strokes. */
GP_EDITABLE_STROKES_BEGIN (gpstroke_iter, C, gpl, gps) {
if (gps->flag & GP_STROKE_SELECT) {
/* Change Active material. */
ob->actcol = gps->mat_nr + 1;
changed = true;
break;
}
}
GP_EDITABLE_STROKES_END(gpstroke_iter);
/* notifiers */
if (changed) {
WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
}
return OPERATOR_FINISHED;
}
void GPENCIL_OT_set_active_material(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Set active material";
ot->idname = "GPENCIL_OT_set_active_material";
ot->description = "Set the selected stroke material as the active material";
/* callbacks */
ot->exec = gpencil_set_active_material_exec;
ot->poll = gpencil_active_color_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/* Parent GPencil object to Lattice */
bool ED_gpencil_add_lattice_modifier(const bContext *C,
ReportList *reports,

View File

@ -528,6 +528,7 @@ void GPENCIL_OT_color_reveal(struct wmOperatorType *ot);
void GPENCIL_OT_color_lock_all(struct wmOperatorType *ot);
void GPENCIL_OT_color_unlock_all(struct wmOperatorType *ot);
void GPENCIL_OT_color_select(struct wmOperatorType *ot);
void GPENCIL_OT_set_active_material(struct wmOperatorType *ot);
/* convert old 2.7 files to 2.8 */
void GPENCIL_OT_convert_old_files(struct wmOperatorType *ot);

View File

@ -264,6 +264,8 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_move_to_layer);
WM_operatortype_append(GPENCIL_OT_layer_change);
WM_operatortype_append(GPENCIL_OT_set_active_material);
WM_operatortype_append(GPENCIL_OT_snap_to_grid);
WM_operatortype_append(GPENCIL_OT_snap_to_cursor);
WM_operatortype_append(GPENCIL_OT_snap_cursor_to_selected);