Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/gpencil/gpencil_fill.c
| Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_brush.h" | #include "BKE_brush.h" | ||||
| #include "BKE_deform.h" | #include "BKE_deform.h" | ||||
| #include "BKE_image.h" | #include "BKE_image.h" | ||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| #include "BKE_material.h" | #include "BKE_material.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_screen.h" | #include "BKE_screen.h" | ||||
| #include "BKE_paint.h" | #include "BKE_paint.h" | ||||
| #include "BKE_report.h" | |||||
| #include "ED_gpencil.h" | #include "ED_gpencil.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "ED_space_api.h" | #include "ED_space_api.h" | ||||
| #include "ED_view3d.h" | #include "ED_view3d.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "RNA_define.h" | #include "RNA_define.h" | ||||
| ▲ Show 20 Lines • Show All 974 Lines • ▼ Show 20 Lines | static void gpencil_stroke_from_buffer(tGPDfill *tgpf) | ||||
| gps->gradient_f = brush->gpencil_settings->gradient_f; | gps->gradient_f = brush->gpencil_settings->gradient_f; | ||||
| copy_v2_v2(gps->gradient_s, brush->gpencil_settings->gradient_s); | copy_v2_v2(gps->gradient_s, brush->gpencil_settings->gradient_s); | ||||
| gps->inittime = 0.0f; | gps->inittime = 0.0f; | ||||
| /* the polygon must be closed, so enabled cyclic */ | /* the polygon must be closed, so enabled cyclic */ | ||||
| gps->flag |= GP_STROKE_CYCLIC; | gps->flag |= GP_STROKE_CYCLIC; | ||||
| gps->flag |= GP_STROKE_3DSPACE; | 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 */ | /* allocate memory for storage points */ | ||||
| gps->totpoints = tgpf->sbuffer_used; | gps->totpoints = tgpf->sbuffer_used; | ||||
| gps->points = MEM_callocN(sizeof(bGPDspoint) * tgpf->sbuffer_used, "gp_stroke_points"); | gps->points = MEM_callocN(sizeof(bGPDspoint) * tgpf->sbuffer_used, "gp_stroke_points"); | ||||
| /* initialize triangle memory to dummy data */ | /* initialize triangle memory to dummy data */ | ||||
| gps->tot_triangles = 0; | gps->tot_triangles = 0; | ||||
| gps->triangles = NULL; | gps->triangles = NULL; | ||||
| ▲ Show 20 Lines • Show All 291 Lines • ▼ Show 20 Lines | static int gpencil_fill_init(bContext *C, wmOperator *op) | ||||
| /* everything is now setup ok */ | /* everything is now setup ok */ | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| /* start of interactive part of operator */ | /* start of interactive part of operator */ | ||||
| static int gpencil_fill_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | 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; | 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 */ | /* try to initialize context data needed */ | ||||
| if (!gpencil_fill_init(C, op)) { | if (!gpencil_fill_init(C, op)) { | ||||
| gpencil_fill_exit(C, op); | gpencil_fill_exit(C, op); | ||||
| if (op->customdata) { | if (op->customdata) { | ||||
| MEM_freeN(op->customdata); | MEM_freeN(op->customdata); | ||||
| } | } | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 139 Lines • Show Last 20 Lines | |||||