Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/gpencil.c
| Show First 20 Lines • Show All 1,155 Lines • ▼ Show 20 Lines | if (brush) { | ||||
| if (ma) { | if (ma) { | ||||
| return ma; | return ma; | ||||
| } | } | ||||
| else if (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) { | else if (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) { | ||||
| /* it is easier to just unpin a NULL material, instead of setting a new one */ | /* it is easier to just unpin a NULL material, instead of setting a new one */ | ||||
| brush->gpencil_settings->flag &= ~GP_BRUSH_MATERIAL_PINNED; | brush->gpencil_settings->flag &= ~GP_BRUSH_MATERIAL_PINNED; | ||||
| } | } | ||||
| } | } | ||||
| return BKE_gpencil_object_material_ensure_from_active_input_material(bmain, ob); | return BKE_gpencil_object_material_ensure_from_active_input_material(ob); | ||||
| } | } | ||||
| /** | /** | ||||
| * Guaranteed to return a material assigned to object. Returns never NULL. | * Guaranteed to return a material assigned to object. Returns never NULL. | ||||
| * Only use this for materials unrelated to user input. | * Only use this for materials unrelated to user input. | ||||
| */ | */ | ||||
| Material *BKE_gpencil_object_material_ensure_from_active_input_material(Main *bmain, Object *ob) | Material *BKE_gpencil_object_material_ensure_from_active_input_material(Object *ob) | ||||
| { | { | ||||
| Material *ma = give_current_material(ob, ob->actcol); | Material *ma = give_current_material(ob, ob->actcol); | ||||
| if (ma) { | if (ma) { | ||||
| return ma; | return ma; | ||||
| } | } | ||||
| /* If the slot is empty, remove because will be added again, | |||||
| * if not, we will get an empty slot. */ | return &defgpencil_material; | ||||
| if ((ob->totcol > 0) && (ob->actcol == ob->totcol)) { | |||||
| BKE_object_material_slot_remove(bmain, ob); | |||||
| } | |||||
| return BKE_gpencil_object_material_new(bmain, ob, "Material", NULL); | |||||
| } | } | ||||
| /* Get active color, and add all default settings if we don't find anything */ | /* Get active color, and add all default settings if we don't find anything */ | ||||
| Material *BKE_gpencil_object_material_ensure_active(Main *bmain, Object *ob) | Material *BKE_gpencil_object_material_ensure_active(Object *ob) | ||||
| { | { | ||||
| Material *ma = NULL; | Material *ma = NULL; | ||||
| /* sanity checks */ | /* sanity checks */ | ||||
| if (ELEM(NULL, bmain, ob)) { | if (ob == NULL) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| ma = BKE_gpencil_object_material_ensure_from_active_input_material(bmain, ob); | ma = BKE_gpencil_object_material_ensure_from_active_input_material(ob); | ||||
| if (ma->gp_style == NULL) { | if (ma->gp_style == NULL) { | ||||
| BKE_material_init_gpencil_settings(ma); | BKE_material_init_gpencil_settings(ma); | ||||
| } | } | ||||
| return ma; | return ma; | ||||
| } | } | ||||
| /* ************************************************** */ | /* ************************************************** */ | ||||
| ▲ Show 20 Lines • Show All 799 Lines • ▼ Show 20 Lines | |||||
| void BKE_gpencil_material_index_reassign(bGPdata *gpd, int totcol, int index) | void BKE_gpencil_material_index_reassign(bGPdata *gpd, int totcol, int index) | ||||
| { | { | ||||
| for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { | for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { | ||||
| for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { | for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { | ||||
| for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { | for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { | ||||
| /* reassign strokes */ | /* reassign strokes */ | ||||
| if ((gps->mat_nr > index) || (gps->mat_nr > totcol - 1)) { | if ((gps->mat_nr > index) || (gps->mat_nr > totcol - 1)) { | ||||
| gps->mat_nr--; | gps->mat_nr--; | ||||
| CLAMP_MIN(gps->mat_nr, 0); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* remove strokes using a material */ | /* remove strokes using a material */ | ||||
| bool BKE_gpencil_material_index_used(bGPdata *gpd, int index) | bool BKE_gpencil_material_index_used(bGPdata *gpd, int index) | ||||
| ▲ Show 20 Lines • Show All 559 Lines • Show Last 20 Lines | |||||