diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-03-23 05:57:13 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-03-23 05:58:09 +0300 |
commit | 38b7563a4fbb0f06775e980b7439c0354dc78641 (patch) | |
tree | a7c8455b238c599106816d657e81638e51fd00cf /source/blender/editors/gpencil/gpencil_add_stroke.c | |
parent | a7239c2bad8fa9cd3896d6c845d2ddc4d9b27946 (diff) |
Cleanup: de-duplicate gpencil logic to ensure materials
- Rename:
`BKE_gpencil_object_material_get_index_name`, to
`BKE_gpencil_object_material_index_get_by_name`
Matching `BKE_gpencil_layer_get_by_name`.
- Move logic to ensure named materials into a new function:
`BKE_gpencil_object_material_ensure_by_name`
Diffstat (limited to 'source/blender/editors/gpencil/gpencil_add_stroke.c')
-rw-r--r-- | source/blender/editors/gpencil/gpencil_add_stroke.c | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/source/blender/editors/gpencil/gpencil_add_stroke.c b/source/blender/editors/gpencil/gpencil_add_stroke.c index 1e1a70f9c1d..26237636526 100644 --- a/source/blender/editors/gpencil/gpencil_add_stroke.c +++ b/source/blender/editors/gpencil/gpencil_add_stroke.c @@ -52,19 +52,8 @@ static int gpencil_stroke_material(Main *bmain, const ColorTemplate *pct, const bool fill) { - short *totcol = BKE_object_material_len_p(ob); - Material *ma = NULL; - for (short i = 0; i < *totcol; i++) { - ma = BKE_gpencil_material(ob, i + 1); - if (STREQ(ma->id.name, pct->name)) { - return i; - } - } - - int idx; - - /* create a new one */ - ma = BKE_gpencil_object_material_new(bmain, ob, pct->name, &idx); + int index; + Material *ma = BKE_gpencil_object_material_ensure_by_name(bmain, ob, pct->name, &index); copy_v4_v4(ma->gp_style->stroke_rgba, pct->line); srgb_to_linearrgb_v4(ma->gp_style->stroke_rgba, ma->gp_style->stroke_rgba); @@ -76,7 +65,7 @@ static int gpencil_stroke_material(Main *bmain, ma->gp_style->flag |= GP_MATERIAL_FILL_SHOW; } - return idx; + return index; } /* ***************************************************************** */ |