GP: Replace custom function by standard API

Replace BKE_gpencil_get_material_index by BKE_object_material_slot_find_index
This commit is contained in:
Antonio Vazquez 2018-08-27 23:16:02 +02:00
parent 35c1baef27
commit 9195b5b3b1
14 changed files with 20 additions and 35 deletions

@ -1 +1 @@
Subproject commit 9ae033c49c1b16718eac6306bdc271a5e6e6bf38
Subproject commit 371960484a38fc64e0a2635170a41a0d8ab2f6bd

@ -1 +1 @@
Subproject commit f178e6c933a25c621a5cc7d92935b66cd2ec2f5d
Subproject commit 15b25a42783d1e516b5298d70b582fae2559ae17

View File

@ -94,7 +94,6 @@ void BKE_gpencil_frame_delete_laststroke(struct bGPDlayer *gpl, struct bGPDframe
/* materials */
void BKE_gpencil_material_index_remove(struct bGPdata *gpd, int index);
void BKE_gpencil_material_remap(struct bGPdata *gpd, const unsigned int *remap, unsigned int remap_len);
int BKE_gpencil_get_material_index(struct Object *ob, struct Material *ma);
/* statistics functions */
void BKE_gpencil_stats_update(struct bGPdata *gpd);

View File

@ -1543,18 +1543,3 @@ void BKE_gpencil_stats_update(bGPdata *gpd)
}
}
/* get material index */
int BKE_gpencil_get_material_index(Object *ob, Material *ma)
{
short *totcol = give_totcolp(ob);
Material *read_ma = NULL;
for (short i = 0; i < *totcol; i++) {
read_ma = give_current_material(ob, i + 1);
if (ma == read_ma) {
return i + 1;
}
}
return 0;
}

View File

@ -72,7 +72,7 @@ static int gpencil_monkey_color(Main *bmain, Object *ob, const ColorTemplate *pc
copy_v4_v4(ma->gp_style->stroke_rgba, pct->line);
copy_v4_v4(ma->gp_style->fill_rgba, pct->fill);
return BKE_gpencil_get_material_index(ob, ma) - 1;
return BKE_object_material_slot_find_index(ob, ma) - 1;
}
/* ***************************************************************** */

View File

@ -72,7 +72,7 @@ static int gp_stroke_material(Main *bmain, Object *ob, const ColorTemplate *pct)
copy_v4_v4(ma->gp_style->stroke_rgba, pct->line);
copy_v4_v4(ma->gp_style->fill_rgba, pct->fill);
return BKE_gpencil_get_material_index(ob, ma) - 1;
return BKE_object_material_slot_find_index(ob, ma) - 1;
}
/* ***************************************************************** */

View File

@ -1066,8 +1066,8 @@ static void gp_brush_clone_add(bContext *C, tGP_BrushEditData *gso)
/* Fix color references */
Material *ma = BLI_ghash_lookup(data->new_colors, &new_stroke->mat_nr);
if ((ma) && (BKE_gpencil_get_material_index(ob, ma) > 0)) {
gps->mat_nr = BKE_gpencil_get_material_index(ob, ma) - 1;
if ((ma) && (BKE_object_material_slot_find_index(ob, ma) > 0)) {
gps->mat_nr = BKE_object_material_slot_find_index(ob, ma) - 1;
CLAMP_MIN(gps->mat_nr, 0);
}
else {

View File

@ -1373,7 +1373,7 @@ static int gp_stroke_change_color_exec(bContext *C, wmOperator *op)
}
}
/* try to find slot */
int idx = BKE_gpencil_get_material_index(ob, ma) - 1;
int idx = BKE_object_material_slot_find_index(ob, ma) - 1;
if (idx <= 0) {
return OPERATOR_CANCELLED;
}
@ -2123,7 +2123,7 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op)
for (short i = 0; i < *totcol; i++) {
Material *tmp_ma = give_current_material(ob_src, i + 1);
if (BKE_gpencil_get_material_index(ob_dst, tmp_ma) == 0) {
if (BKE_object_material_slot_find_index(ob_dst, tmp_ma) == 0) {
BKE_object_material_slot_add(bmain, ob_dst);
assign_material(bmain, ob_dst, tmp_ma, ob_dst->totcol, BKE_MAT_ASSIGN_USERPREF);
}
@ -2163,7 +2163,7 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op)
/* reasign material. Look old material and try to find in dst */
ma_src = give_current_material(ob_src, gps->mat_nr + 1);
if (ma_src != NULL) {
idx = BKE_gpencil_get_material_index(ob_dst, ma_src);
idx = BKE_object_material_slot_find_index(ob_dst, ma_src);
if (idx > 0) {
gps->mat_nr = idx - 1;
}

View File

@ -768,7 +768,7 @@ GHash *gp_copybuf_validate_colormap(bContext *C)
char *ma_name = BLI_ghashIterator_getValue(&gh_iter);
Material *ma = BLI_ghash_lookup(name_to_ma, ma_name);
if (ma != NULL && BKE_gpencil_get_material_index(ob, ma) == 0) {
if (ma != NULL && BKE_object_material_slot_find_index(ob, ma) == 0) {
BKE_object_material_slot_add(bmain, ob);
assign_material(bmain, ob, ma, ob->totcol, BKE_MAT_ASSIGN_USERPREF);
}
@ -1022,8 +1022,8 @@ static int gp_strokes_paste_exec(bContext *C, wmOperator *op)
/* Remap material */
Material *ma = BLI_ghash_lookup(new_colors, &new_stroke->mat_nr);
if ((ma) && (BKE_gpencil_get_material_index(ob, ma) > 0)) {
gps->mat_nr = BKE_gpencil_get_material_index(ob, ma) - 1;
if ((ma) && (BKE_object_material_slot_find_index(ob, ma) > 0)) {
gps->mat_nr = BKE_object_material_slot_find_index(ob, ma) - 1;
CLAMP_MIN(gps->mat_nr, 0);
}
else {
@ -3240,7 +3240,7 @@ static int gp_stroke_separate_exec(bContext *C, wmOperator *op)
/* add duplicate materials */
ma = give_current_material(ob, gps->mat_nr + 1);
idx = BKE_gpencil_get_material_index(ob_dst, ma);
idx = BKE_object_material_slot_find_index(ob_dst, ma);
if (idx == 0) {
totadd++;

View File

@ -1164,7 +1164,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p)
}
/* Save material index */
gps->mat_nr = BKE_gpencil_get_material_index(p->ob, p->material) - 1;
gps->mat_nr = BKE_object_material_slot_find_index(p->ob, p->material) - 1;
/* calculate UVs along the stroke */
ED_gpencil_calc_stroke_uv(obact, gps);
@ -1616,7 +1616,7 @@ static void gp_init_colors(tGPsdata *p)
}
/* check if the material is already on object material slots and add it if missing */
if (BKE_gpencil_get_material_index(p->ob, p->material) == 0) {
if (BKE_object_material_slot_find_index(p->ob, p->material) == 0) {
BKE_object_material_slot_add(p->bmain, p->ob);
assign_material(p->bmain, p->ob, ma, p->ob->totcol, BKE_MAT_ASSIGN_USERPREF);
}

View File

@ -177,7 +177,7 @@ static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi)
gps->flag |= GP_STROKE_CYCLIC;
gps->flag |= GP_STROKE_3DSPACE;
gps->mat_nr = BKE_gpencil_get_material_index(tgpi->ob, tgpi->mat) - 1;
gps->mat_nr = BKE_object_material_slot_find_index(tgpi->ob, tgpi->mat) - 1;
/* allocate memory for storage points, but keep empty */
gps->totpoints = 0;

View File

@ -171,7 +171,7 @@ void gpencil_apply_modifier_material(
DEG_id_tag_update(&newmat->id, DEG_TAG_COPY_ON_WRITE);
}
/* reasign color index */
int idx = BKE_gpencil_get_material_index(ob, newmat);
int idx = BKE_object_material_slot_find_index(ob, newmat);
gps->mat_nr = idx - 1;
}
else {

View File

@ -171,6 +171,7 @@ static EnumPropertyItem rna_enum_gpencil_brush_icons_items[] = {
#include "BKE_colorband.h"
#include "BKE_brush.h"
#include "BKE_icons.h"
#include "BKE_material.h"
#include "BKE_gpencil.h"
#include "BKE_paint.h"
@ -425,7 +426,7 @@ static void rna_Brush_material_update(bContext *C, PointerRNA *ptr)
BrushGpencilSettings *gpencil_settings = br->gpencil_settings;
if (gpencil_settings->material != NULL) {
index = BKE_gpencil_get_material_index(ob, gpencil_settings->material);
index = BKE_object_material_slot_find_index(ob, gpencil_settings->material);
if ((index > 0) && (ob->actcol != index)) {
ob->actcol = index;
/* update other brushes to keep all synchro */

@ -1 +1 @@
Subproject commit ca3e38d89666c422d6681bb06967a59ef1a4a7df
Subproject commit 11656ebaf7f912cdb1b5eb39c5d0a3b5d492c1aa