From 6a7e9f2b7647fb1883fc77f72c3d411c0a692cf7 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Thu, 30 Apr 2020 16:12:34 +0200 Subject: GPencil: Add material selector to context menus Now it's possible to select the material in context menu and new menu to select material. The patch and workflow has been tested in greasepencil-object branch. * New Material selector in Draw mode Context menu: {F8499259} * Pressing `U`key in Draw mode display material menu. {F8503224} Reviewed By: mendio, pepeland Differential Revision: https://developer.blender.org/D7554 --- source/blender/editors/gpencil/gpencil_utils.c | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'source/blender/editors/gpencil/gpencil_utils.c') diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c index 3d571773bc8..6a7bb2012a7 100644 --- a/source/blender/editors/gpencil/gpencil_utils.c +++ b/source/blender/editors/gpencil/gpencil_utils.c @@ -481,6 +481,40 @@ const EnumPropertyItem *ED_gpencil_layers_with_new_enum_itemf(bContext *C, return item; } +/* Just existing Materials */ +const EnumPropertyItem *ED_gpencil_material_enum_itemf(bContext *C, + PointerRNA *UNUSED(ptr), + PropertyRNA *UNUSED(prop), + bool *r_free) +{ + Object *ob = CTX_data_active_object(C); + EnumPropertyItem *item = NULL, item_tmp = {0}; + int totitem = 0; + int i = 0; + + if (ELEM(NULL, C, ob)) { + return DummyRNA_DEFAULT_items; + } + + /* Existing materials */ + for (i = 1; i <= ob->totcol; i++) { + Material *ma = BKE_object_material_get(ob, i); + if (ma) { + item_tmp.identifier = ma->id.name + 2; + item_tmp.name = ma->id.name + 2; + item_tmp.value = i; + item_tmp.icon = ma->preview->icon_id; + + RNA_enum_item_add(&item, &totitem, &item_tmp); + } + } + + RNA_enum_item_end(&item, &totitem); + *r_free = true; + + return item; +} + /* ******************************************************** */ /* Brush Tool Core */ -- cgit v1.2.3