Add list of color to Assign color operator
It's more clear for user to see the name of the color
This commit is contained in:
@@ -3539,6 +3539,15 @@ class VIEW3D_MT_paint_gpencil(Menu):
|
||||
layout.operator("gpencil.delete", text="Delete Frame").type = 'FRAME'
|
||||
layout.operator("gpencil.active_frames_delete_all")
|
||||
|
||||
class VIEW3D_MT_assign_material(Menu):
|
||||
bl_label = "Assign Material"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
ob = context.active_object;
|
||||
|
||||
for mat in ob.data.materials:
|
||||
layout.operator("gpencil.stroke_change_color", text=mat.name).material = mat.name
|
||||
|
||||
class VIEW3D_MT_edit_gpencil(Menu):
|
||||
bl_label = "Strokes"
|
||||
@@ -3583,7 +3592,7 @@ class VIEW3D_MT_edit_gpencil(Menu):
|
||||
layout.separator()
|
||||
|
||||
layout.operator_menu_enum("gpencil.move_to_layer", "layer", text="Move to Layer")
|
||||
layout.operator("gpencil.stroke_change_color", text="Assign Material")
|
||||
layout.menu("VIEW3D_MT_assign_material")
|
||||
layout.operator_menu_enum("gpencil.stroke_arrange", "direction", text="Arrange Strokes...")
|
||||
|
||||
layout.separator()
|
||||
@@ -3633,7 +3642,7 @@ class VIEW3D_MT_sculpt_gpencil(Menu):
|
||||
layout.separator()
|
||||
|
||||
layout.operator_menu_enum("gpencil.move_to_layer", "layer", text="Move to Layer")
|
||||
layout.operator("gpencil.stroke_change_color", text="Assign Material")
|
||||
layout.menu("VIEW3D_MT_assign_material")
|
||||
layout.operator_menu_enum("gpencil.stroke_arrange", "direction", text="Arrange Strokes...")
|
||||
|
||||
layout.separator()
|
||||
@@ -4997,6 +5006,7 @@ classes = (
|
||||
VIEW3D_MT_edit_mesh_delete,
|
||||
VIEW3D_MT_edit_mesh_showhide,
|
||||
VIEW3D_MT_paint_gpencil,
|
||||
VIEW3D_MT_assign_material,
|
||||
VIEW3D_MT_edit_gpencil,
|
||||
VIEW3D_MT_edit_gpencil_delete,
|
||||
VIEW3D_MT_sculpt_gpencil,
|
||||
|
||||
@@ -1131,12 +1131,29 @@ void GPENCIL_OT_stroke_arrange(wmOperatorType *ot)
|
||||
|
||||
/* ******************* Move Stroke to new color ************************** */
|
||||
|
||||
static int gp_stroke_change_color_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
static int gp_stroke_change_color_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Main *bmain = CTX_data_main(C);
|
||||
Material *ma = NULL;
|
||||
char name[MAX_ID_NAME - 2];
|
||||
RNA_string_get(op->ptr, "material", name);
|
||||
|
||||
bGPdata *gpd = ED_gpencil_data_get_active(C);
|
||||
Object *ob = CTX_data_active_object(C);
|
||||
Material *ma = give_current_material(ob, ob->actcol);
|
||||
if (name[0] == '\0') {
|
||||
ma = give_current_material(ob, ob->actcol);
|
||||
}
|
||||
else {
|
||||
ma = (Material *)BKE_libblock_find_name(bmain, ID_MA, name);
|
||||
if (ma == NULL) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
}
|
||||
/* try to find slot */
|
||||
int idx = BKE_object_material_slot_find_index(ob, ma) - 1;
|
||||
if (idx == 0) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
/* sanity checks */
|
||||
if (ELEM(NULL, gpd)) {
|
||||
@@ -1200,6 +1217,9 @@ void GPENCIL_OT_stroke_change_color(wmOperatorType *ot)
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
RNA_def_string(ot->srna, "material", NULL, MAX_ID_NAME - 2, "Material", "Name of the material");
|
||||
|
||||
}
|
||||
|
||||
/* ******************* Lock color of non selected Strokes colors ************************** */
|
||||
|
||||
Reference in New Issue
Block a user