Commit: 45751065c0e13242e08ef0d0b3dbecf9b4a05baa
Author: Antonioya
Date:   Thu Aug 2 19:21:12 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB45751065c0e13242e08ef0d0b3dbecf9b4a05baa

Add list of color to Assign color operator

It's more clear for user to see the name of the color

===================================================================

M       release/scripts/startup/bl_ui/space_view3d.py
M       source/blender/editors/gpencil/gpencil_data.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_view3d.py 
b/release/scripts/startup/bl_ui/space_view3d.py
index ab01560351c..a6d66f20494 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -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,
diff --git a/source/blender/editors/gpencil/gpencil_data.c 
b/source/blender/editors/gpencil/gpencil_data.c
index 01cf8aeb7f1..8598d45ff01 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -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 
************************** */

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to