Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2021-03-23 05:57:13 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-03-23 05:58:09 +0300
commit38b7563a4fbb0f06775e980b7439c0354dc78641 (patch)
treea7c8455b238c599106816d657e81638e51fd00cf /source/blender/editors
parenta7239c2bad8fa9cd3896d6c845d2ddc4d9b27946 (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')
-rw-r--r--source/blender/editors/gpencil/gpencil_add_lineart.c17
-rw-r--r--source/blender/editors/gpencil/gpencil_add_monkey.c17
-rw-r--r--source/blender/editors/gpencil/gpencil_add_stroke.c17
3 files changed, 9 insertions, 42 deletions
diff --git a/source/blender/editors/gpencil/gpencil_add_lineart.c b/source/blender/editors/gpencil/gpencil_add_lineart.c
index cd7e14278a4..6b28c6ec13e 100644
--- a/source/blender/editors/gpencil/gpencil_add_lineart.c
+++ b/source/blender/editors/gpencil/gpencil_add_lineart.c
@@ -55,19 +55,8 @@ static int gpencil_lineart_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);
@@ -79,7 +68,7 @@ static int gpencil_lineart_material(Main *bmain,
ma->gp_style->flag |= GP_MATERIAL_FILL_SHOW;
}
- return idx;
+ return index;
}
/* ***************************************************************** */
diff --git a/source/blender/editors/gpencil/gpencil_add_monkey.c b/source/blender/editors/gpencil/gpencil_add_monkey.c
index d86bad7ef3c..4497d963c6d 100644
--- a/source/blender/editors/gpencil/gpencil_add_monkey.c
+++ b/source/blender/editors/gpencil/gpencil_add_monkey.c
@@ -50,19 +50,8 @@ typedef struct ColorTemplate {
static int gpencil_monkey_color(
Main *bmain, Object *ob, const ColorTemplate *pct, bool stroke, 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);
@@ -81,7 +70,7 @@ static int gpencil_monkey_color(
ma->gp_style->flag |= GP_MATERIAL_FILL_SHOW;
}
- return idx;
+ return index;
}
/* ***************************************************************** */
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;
}
/* ***************************************************************** */