234
static void draw_filled_lasso(wmGesture *gt)
236
ScanFillContext sf_ctx;
237
ScanFillVert *sf_vert = NULL, *sf_vert_last = NULL, *sf_vert_first = NULL;
238
ScanFillFace *sf_tri;
235
struct LassoFillData {
240
static void draw_filled_lasso_px_cb(int x, int y, void *user_data)
242
struct LassoFillData *data = user_data;
243
unsigned char *col = (unsigned char *)&(data->px[(y * data->width) + x]);
244
col[0] = col[1] = col[2] = 0xff;
248
static void draw_filled_lasso(wmWindow *win, wmGesture *gt)
239
250
short *lasso = (short *)gt->customdata;
251
const int tot = gt->points;
252
int (*moves)[2] = MEM_mallocN(sizeof(*moves) * (tot + 1), __func__);
242
BLI_scanfill_begin(&sf_ctx);
243
for (i = 0; i < gt->points; i++, lasso += 2) {
246
co[0] = (float)lasso[0];
247
co[1] = (float)lasso[1];
250
sf_vert = BLI_scanfill_vert_add(&sf_ctx, co);
252
/* e = */ /* UNUSED */ BLI_scanfill_edge_add(&sf_ctx, sf_vert_last, sf_vert);
253
sf_vert_last = sf_vert;
254
if (sf_vert_first == NULL) sf_vert_first = sf_vert;
257
for (i = 0; i < tot; i++, lasso += 2) {
258
moves[i][0] = lasso[0];
259
moves[i][1] = lasso[1];
257
/* highly unlikely this will fail, but could crash if (gt->points == 0) */
259
const float zvec[3] = {0.0f, 0.0f, 1.0f};
260
BLI_scanfill_edge_add(&sf_ctx, sf_vert_first, sf_vert);
261
BLI_scanfill_calc_ex(&sf_ctx, BLI_SCANFILL_CALC_REMOVE_DOUBLES | BLI_SCANFILL_CALC_HOLES, zvec);
262
BLI_lasso_boundbox(&rect, (const int (*)[2])moves, tot);
264
wm_subwindow_getrect(win, gt->swinid, &rect_win);
265
BLI_rcti_translate(&rect, rect_win.xmin, rect_win.ymin);
266
BLI_rcti_isect(&rect_win, &rect, &rect);
267
BLI_rcti_translate(&rect, -rect_win.xmin, -rect_win.ymin);
269
/* highly unlikely this will fail, but could crash if (tot == 0) */
270
if (BLI_rcti_is_empty(&rect) == false) {
271
const int w = BLI_rcti_size_x(&rect);
272
const int h = BLI_rcti_size_y(&rect);
273
unsigned int *pixel_buf = MEM_callocN(sizeof(*pixel_buf) * w * h, __func__);
274
struct LassoFillData lasso_fill_data = {pixel_buf, w};
277
rect.xmin, rect.ymin, rect.xmax, rect.ymax,
278
(const int (*)[2])moves, tot,
279
draw_filled_lasso_px_cb, &lasso_fill_data);
263
281
glEnable(GL_BLEND);
264
glColor4f(1.0, 1.0, 1.0, 0.05);
265
glBegin(GL_TRIANGLES);
266
for (sf_tri = sf_ctx.fillfacebase.first; sf_tri; sf_tri = sf_tri->next) {
267
glVertex2fv(sf_tri->v1->co);
268
glVertex2fv(sf_tri->v2->co);
269
glVertex2fv(sf_tri->v3->co);
282
// glColor4f(1.0, 1.0, 1.0, 0.05);
284
glRasterPos2f(rect.xmin, rect.ymin);
286
glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixel_buf);
272
288
glDisable(GL_BLEND);
274
BLI_scanfill_end(&sf_ctx);
289
MEM_freeN(pixel_buf);
278
static void wm_gesture_draw_lasso(wmGesture *gt)
296
static void wm_gesture_draw_lasso(wmWindow *win, wmGesture *gt)
280
298
short *lasso = (short *)gt->customdata;
283
draw_filled_lasso(gt);
301
draw_filled_lasso(win, gt);
285
303
glEnable(GL_LINE_STIPPLE);
286
304
glColor3ub(96, 96, 96);