diff options
Diffstat (limited to 'source/blender/editors/gpencil')
-rw-r--r-- | source/blender/editors/gpencil/gpencil_add_monkey.c | 2 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_add_stroke.c | 2 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_data.c | 41 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_edit.c | 13 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_fill.c | 31 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_merge.c | 2 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_paint.c | 8 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_primitive.c | 10 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_utils.c | 2 |
9 files changed, 82 insertions, 29 deletions
diff --git a/source/blender/editors/gpencil/gpencil_add_monkey.c b/source/blender/editors/gpencil/gpencil_add_monkey.c index c4528518009..139697ad0e3 100644 --- a/source/blender/editors/gpencil/gpencil_add_monkey.c +++ b/source/blender/editors/gpencil/gpencil_add_monkey.c @@ -54,7 +54,7 @@ static int gpencil_monkey_color( short *totcol = give_totcolp(ob); Material *ma = NULL; for (short i = 0; i < *totcol; i++) { - ma = give_current_material(ob, i + 1); + ma = BKE_material_gpencil_get(ob, i + 1); if (STREQ(ma->id.name, pct->name)) { return i; } diff --git a/source/blender/editors/gpencil/gpencil_add_stroke.c b/source/blender/editors/gpencil/gpencil_add_stroke.c index 80e239c9ae5..74617599eaa 100644 --- a/source/blender/editors/gpencil/gpencil_add_stroke.c +++ b/source/blender/editors/gpencil/gpencil_add_stroke.c @@ -53,7 +53,7 @@ static int gp_stroke_material(Main *bmain, Object *ob, const ColorTemplate *pct, short *totcol = give_totcolp(ob); Material *ma = NULL; for (short i = 0; i < *totcol; i++) { - ma = give_current_material(ob, i + 1); + ma = BKE_material_gpencil_get(ob, i + 1); if (STREQ(ma->id.name, pct->name)) { return i; } diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c index 34beceddfa2..e763eec1b0d 100644 --- a/source/blender/editors/gpencil/gpencil_data.c +++ b/source/blender/editors/gpencil/gpencil_data.c @@ -538,10 +538,12 @@ static int gp_layer_duplicate_object_exec(bContext *C, wmOperator *op) * otherwise add the slot with the material */ Material *ma_src = give_current_material(ob_src, gps_src->mat_nr + 1); - int idx = BKE_gpencil_object_material_ensure(bmain, ob_dst, ma_src); + if (ma_src != NULL) { + int idx = BKE_gpencil_object_material_ensure(bmain, ob_dst, ma_src); - /* Reassign the stroke material to the right slot in destination object. */ - gps_dst->mat_nr = idx; + /* Reassign the stroke material to the right slot in destination object. */ + gps_dst->mat_nr = idx; + } /* add new stroke to frame */ BLI_addtail(&gpf_dst->strokes, gps_dst); @@ -1423,7 +1425,7 @@ static int gp_stroke_change_color_exec(bContext *C, wmOperator *op) bGPdata *gpd = ED_gpencil_data_get_active(C); Object *ob = CTX_data_active_object(C); if (name[0] == '\0') { - ma = give_current_material(ob, ob->actcol); + ma = BKE_material_gpencil_get(ob, ob->actcol); } else { ma = (Material *)BKE_libblock_find_name(bmain, ID_MA, name); @@ -1543,9 +1545,10 @@ static int gp_stroke_lock_color_exec(bContext *C, wmOperator *UNUSED(op)) } /* unlock color */ Material *tmp_ma = give_current_material(ob, gps->mat_nr + 1); - - tmp_ma->gp_style->flag &= ~GP_STYLE_COLOR_LOCKED; - DEG_id_tag_update(&tmp_ma->id, ID_RECALC_COPY_ON_WRITE); + if (tmp_ma) { + tmp_ma->gp_style->flag &= ~GP_STYLE_COLOR_LOCKED; + DEG_id_tag_update(&tmp_ma->id, ID_RECALC_COPY_ON_WRITE); + } } } } @@ -2295,7 +2298,7 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) short *totcol = give_totcolp(ob_src); for (short i = 0; i < *totcol; i++) { - Material *tmp_ma = give_current_material(ob_src, i + 1); + Material *tmp_ma = BKE_material_gpencil_get(ob_src, i + 1); BKE_gpencil_object_material_ensure(bmain, ob_dst, tmp_ma); } @@ -2329,7 +2332,7 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { /* Reassign material. Look old material and try to find in destination. */ - ma_src = give_current_material(ob_src, gps->mat_nr + 1); + ma_src = BKE_material_gpencil_get(ob_src, gps->mat_nr + 1); gps->mat_nr = BKE_gpencil_object_material_ensure(bmain, ob_dst, ma_src); bGPDspoint *pt; @@ -2437,7 +2440,7 @@ static int gpencil_lock_layer_exec(bContext *C, wmOperator *UNUSED(op)) } for (short i = 0; i < *totcol; i++) { - ma = give_current_material(ob, i + 1); + ma = BKE_material_gpencil_get(ob, i + 1); if (ma) { gp_style = ma->gp_style; gp_style->flag |= GP_STYLE_COLOR_LOCKED; @@ -2457,7 +2460,7 @@ static int gpencil_lock_layer_exec(bContext *C, wmOperator *UNUSED(op)) continue; } - ma = give_current_material(ob, gps->mat_nr + 1); + ma = BKE_material_gpencil_get(ob, gps->mat_nr + 1); DEG_id_tag_update(&ma->id, ID_RECALC_COPY_ON_WRITE); gp_style = ma->gp_style; @@ -2500,7 +2503,7 @@ static int gpencil_color_isolate_exec(bContext *C, wmOperator *op) { bGPdata *gpd = ED_gpencil_data_get_active(C); Object *ob = CTX_data_active_object(C); - Material *active_ma = give_current_material(ob, ob->actcol); + Material *active_ma = BKE_material_gpencil_get(ob, ob->actcol); MaterialGPencilStyle *active_color = BKE_material_gpencil_settings_get(ob, ob->actcol); MaterialGPencilStyle *gp_style; @@ -2520,7 +2523,7 @@ static int gpencil_color_isolate_exec(bContext *C, wmOperator *op) Material *ma = NULL; short *totcol = give_totcolp(ob); for (short i = 0; i < *totcol; i++) { - ma = give_current_material(ob, i + 1); + ma = BKE_material_gpencil_get(ob, i + 1); /* Skip if this is the active one */ if ((ma == NULL) || (ma == active_ma)) { continue; @@ -2540,7 +2543,7 @@ static int gpencil_color_isolate_exec(bContext *C, wmOperator *op) if (isolate) { /* Set flags on all "other" colors */ for (short i = 0; i < *totcol; i++) { - ma = give_current_material(ob, i + 1); + ma = BKE_material_gpencil_get(ob, i + 1); if (ma == NULL) { continue; } @@ -2557,7 +2560,7 @@ static int gpencil_color_isolate_exec(bContext *C, wmOperator *op) else { /* Clear flags - Restore everything else */ for (short i = 0; i < *totcol; i++) { - ma = give_current_material(ob, i + 1); + ma = BKE_material_gpencil_get(ob, i + 1); if (ma == NULL) { continue; } @@ -2622,7 +2625,7 @@ static int gpencil_color_hide_exec(bContext *C, wmOperator *op) /* hide unselected */ MaterialGPencilStyle *color = NULL; for (short i = 0; i < *totcol; i++) { - ma = give_current_material(ob, i + 1); + ma = BKE_material_gpencil_get(ob, i + 1); if (ma) { color = ma->gp_style; if (active_color != color) { @@ -2685,7 +2688,7 @@ static int gpencil_color_reveal_exec(bContext *C, wmOperator *UNUSED(op)) MaterialGPencilStyle *gp_style = NULL; for (short i = 0; i < *totcol; i++) { - ma = give_current_material(ob, i + 1); + ma = BKE_material_gpencil_get(ob, i + 1); if (ma) { gp_style = ma->gp_style; gp_style->flag &= ~GP_STYLE_COLOR_HIDE; @@ -2738,7 +2741,7 @@ static int gpencil_color_lock_all_exec(bContext *C, wmOperator *UNUSED(op)) MaterialGPencilStyle *gp_style = NULL; for (short i = 0; i < *totcol; i++) { - ma = give_current_material(ob, i + 1); + ma = BKE_material_gpencil_get(ob, i + 1); if (ma) { gp_style = ma->gp_style; gp_style->flag |= GP_STYLE_COLOR_LOCKED; @@ -2791,7 +2794,7 @@ static int gpencil_color_unlock_all_exec(bContext *C, wmOperator *UNUSED(op)) MaterialGPencilStyle *gp_style = NULL; for (short i = 0; i < *totcol; i++) { - ma = give_current_material(ob, i + 1); + ma = BKE_material_gpencil_get(ob, i + 1); if (ma) { gp_style = ma->gp_style; gp_style->flag &= ~GP_STYLE_COLOR_LOCKED; diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index 709374fa519..8442c906ac1 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -1191,10 +1191,15 @@ static int gp_strokes_copy_exec(bContext *C, wmOperator *op) GHash *ma_to_name = gp_strokes_copypastebuf_colors_material_to_name_create(bmain); for (bGPDstroke *gps = gp_strokes_copypastebuf.first; gps; gps = gps->next) { if (ED_gpencil_stroke_can_use(C, gps)) { + Material *ma = give_current_material(ob, gps->mat_nr + 1); + /* Avoid default material. */ + if (ma == NULL) { + continue; + } + char **ma_name_val; if (!BLI_ghash_ensure_p( gp_strokes_copypastebuf_colors, &gps->mat_nr, (void ***)&ma_name_val)) { - Material *ma = give_current_material(ob, gps->mat_nr + 1); char *ma_name = BLI_ghash_lookup(ma_to_name, ma); *ma_name_val = MEM_dupallocN(ma_name); } @@ -1361,7 +1366,7 @@ static int gp_strokes_paste_exec(bContext *C, wmOperator *op) /* Remap material */ Material *ma = BLI_ghash_lookup(new_colors, POINTER_FROM_INT(new_stroke->mat_nr)); new_stroke->mat_nr = BKE_gpencil_object_material_get_index(ob, ma); - BLI_assert(new_stroke->mat_nr >= 0); /* have to add the material first */ + CLAMP_MIN(new_stroke->mat_nr, 0); } } } @@ -4068,7 +4073,7 @@ static int gp_stroke_separate_exec(bContext *C, wmOperator *op) /* add duplicate materials */ /* XXX same material can be in multiple slots. */ - ma = give_current_material(ob, gps->mat_nr + 1); + ma = BKE_material_gpencil_get(ob, gps->mat_nr + 1); idx = BKE_gpencil_object_material_ensure(bmain, ob_dst, ma); @@ -4141,7 +4146,7 @@ static int gp_stroke_separate_exec(bContext *C, wmOperator *op) if (ED_gpencil_stroke_can_use(C, gps) == false) { continue; } - ma = give_current_material(ob, gps->mat_nr + 1); + ma = BKE_material_gpencil_get(ob, gps->mat_nr + 1); gps->mat_nr = BKE_gpencil_object_material_ensure(bmain, ob_dst, ma); } } diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c index 5637e755198..372973e1040 100644 --- a/source/blender/editors/gpencil/gpencil_fill.c +++ b/source/blender/editors/gpencil/gpencil_fill.c @@ -48,6 +48,7 @@ #include "BKE_context.h" #include "BKE_screen.h" #include "BKE_paint.h" +#include "BKE_report.h" #include "ED_gpencil.h" #include "ED_screen.h" @@ -1038,7 +1039,15 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf) gps->flag |= GP_STROKE_CYCLIC; gps->flag |= GP_STROKE_3DSPACE; - gps->mat_nr = BKE_gpencil_object_material_ensure(tgpf->bmain, tgpf->ob, tgpf->mat); + gps->mat_nr = BKE_gpencil_object_material_get_index_from_brush(tgpf->ob, brush); + if (gps->mat_nr < 0) { + if (tgpf->ob->actcol - 1 < 0) { + gps->mat_nr = 0; + } + else { + gps->mat_nr = tgpf->ob->actcol - 1; + } + } /* allocate memory for storage points */ gps->totpoints = tgpf->sbuffer_used; @@ -1346,8 +1355,28 @@ static int gpencil_fill_init(bContext *C, wmOperator *op) /* start of interactive part of operator */ static int gpencil_fill_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { + Object *ob = CTX_data_active_object(C); + ToolSettings *ts = CTX_data_tool_settings(C); + Brush *brush = BKE_paint_brush(&ts->gp_paint->paint); tGPDfill *tgpf = NULL; + /* Fill tool needs a material (cannot use default material) */ + bool valid = true; + if ((brush) && (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED)) { + if (brush->gpencil_settings->material == NULL) { + valid = false; + } + } + else { + if (give_current_material(ob, ob->actcol) == NULL) { + valid = false; + } + } + if (!valid) { + BKE_report(op->reports, RPT_ERROR, "Fill tool needs active material."); + return OPERATOR_CANCELLED; + } + /* try to initialize context data needed */ if (!gpencil_fill_init(C, op)) { gpencil_fill_exit(C, op); diff --git a/source/blender/editors/gpencil/gpencil_merge.c b/source/blender/editors/gpencil/gpencil_merge.c index cb11bb4cd63..930911ffac5 100644 --- a/source/blender/editors/gpencil/gpencil_merge.c +++ b/source/blender/editors/gpencil/gpencil_merge.c @@ -449,7 +449,7 @@ static bool gp_strokes_merge_poll(bContext *C) /* check material */ Material *ma = NULL; - ma = give_current_material(ob, ob->actcol); + ma = BKE_material_gpencil_get(ob, ob->actcol); if ((ma == NULL) || (ma->gp_style == NULL)) { return false; } diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 900883bd0af..3217c94eebd 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -1244,6 +1244,14 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) /* Save material index */ gps->mat_nr = BKE_gpencil_object_material_get_index_from_brush(p->ob, p->brush); + if (gps->mat_nr < 0) { + if (p->ob->actcol - 1 < 0) { + gps->mat_nr = 0; + } + else { + gps->mat_nr = p->ob->actcol - 1; + } + } /* calculate UVs along the stroke */ ED_gpencil_calc_stroke_uv(obact, gps); diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c index e4b2e5540ea..8d4c75d2e8c 100644 --- a/source/blender/editors/gpencil/gpencil_primitive.c +++ b/source/blender/editors/gpencil/gpencil_primitive.c @@ -330,7 +330,15 @@ static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi) gps->flag |= GP_STROKE_3DSPACE; - gps->mat_nr = BKE_gpencil_object_material_get_index(tgpi->ob, tgpi->mat); + gps->mat_nr = BKE_gpencil_object_material_get_index_from_brush(tgpi->ob, tgpi->brush); + if (gps->mat_nr < 0) { + if (tgpi->ob->actcol - 1 < 0) { + gps->mat_nr = 0; + } + else { + gps->mat_nr = tgpi->ob->actcol - 1; + } + } /* allocate memory for storage points, but keep empty */ gps->totpoints = 0; diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c index 25b4036b8b1..d7492b5be4d 100644 --- a/source/blender/editors/gpencil/gpencil_utils.c +++ b/source/blender/editors/gpencil/gpencil_utils.c @@ -2064,7 +2064,7 @@ void ED_gpencil_update_color_uv(Main *bmain, Material *mat) if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false) { continue; } - gps_ma = give_current_material(ob, gps->mat_nr + 1); + gps_ma = BKE_material_gpencil_get(ob, gps->mat_nr + 1); /* update */ if ((gps_ma) && (gps_ma == mat)) { ED_gpencil_calc_stroke_uv(ob, gps); |