Index: source/blender/editors/mesh/editmesh_tools.c =================================================================== --- source/blender/editors/mesh/editmesh_tools.c (revision 46002) +++ source/blender/editors/mesh/editmesh_tools.c (working copy) @@ -4280,3 +4280,4 @@ RNA_def_boolean(ot->srna, "use_outset", FALSE, "Outset", "Outset rather than inset"); RNA_def_boolean(ot->srna, "use_select_inset", TRUE, "Select Outer", "Select the new inset faces"); } + Index: source/blender/editors/uvedit/uvedit_ops.c =================================================================== --- source/blender/editors/uvedit/uvedit_ops.c (revision 46002) +++ source/blender/editors/uvedit/uvedit_ops.c (working copy) @@ -47,6 +47,7 @@ #include "DNA_scene_types.h" #include "BLI_math.h" +#include "BLI_lasso.h" #include "BLI_blenlib.h" #include "BLI_array.h" #include "BLI_utildefines.h" @@ -2630,6 +2631,143 @@ RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX); } + + +/* ******************** lasso select operator **************** */ + +/* lasso operator gives properties, but since old code works + * with short array we convert */ + +static void lasso_select_boundbox(rcti *rect, int mcords[][2], short moves) +{ + short a; + + rect->xmin = rect->xmax = mcords[0][0]; + rect->ymin = rect->ymax = mcords[0][1]; + + for (a = 1; a < moves; a++) { + if (mcords[a][0] < rect->xmin) rect->xmin = mcords[a][0]; + else if (mcords[a][0] > rect->xmax) rect->xmax = mcords[a][0]; + if (mcords[a][1] < rect->ymin) rect->ymin = mcords[a][1]; + else if (mcords[a][1] > rect->ymax) rect->ymax = mcords[a][1]; + } +} + +static void do_lasso_select_mesh_uv(bContext *C, int mcords[][2], short moves, short select) +{ + Image *ima = CTX_data_edit_image(C); + ARegion *ar = CTX_wm_region(C); + ToolSettings *ts = CTX_data_tool_settings(C); + Object *obedit = CTX_data_edit_object(C); + Scene *scene = CTX_data_scene(C); + BMEditMesh *em = BMEdit_FromObject(obedit); + + BMIter iter, liter; + + BMFace *efa; + BMLoop *l; + MTexPoly *tf; + int screen_uv[2], change = TRUE; + rcti rect; + + lasso_select_boundbox(&rect, mcords, moves); + + if (ts->uv_selectmode == UV_SELECT_FACE) { /* Face Center Sel */ + change = FALSE; + BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { + /* assume not touched */ + if ((select) != (uvedit_face_select_test(scene, em, efa))) { + float cent[2]; + uv_poly_center(em, efa, cent); + UI_view2d_view_to_region(&ar->v2d, cent[0], cent[1], &screen_uv[0], &screen_uv[1]); + if (BLI_in_rcti(&rect, screen_uv[0], screen_uv[1]) && + BLI_lasso_is_point_inside(mcords, moves, screen_uv[0], screen_uv[1], V2D_IS_CLIPPED)) + { + uvedit_face_select_enable(scene, em, efa, FALSE); + change = TRUE; + } + } + } + } + else { /* Vert Sel*/ + BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { + tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); + if (uvedit_face_visible_test(scene, ima, efa, tf)) { + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + if ((select) != (uvedit_uv_select_test(em, scene, l))) { + MLoopUV *luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); + UI_view2d_view_to_region(&ar->v2d, luv->uv[0], luv->uv[1], &screen_uv[0], &screen_uv[1]); + if (BLI_in_rcti(&rect, screen_uv[0], screen_uv[1]) && + BLI_lasso_is_point_inside(mcords, moves, screen_uv[0], screen_uv[1], V2D_IS_CLIPPED)) + { + if (select) { + uvedit_uv_select_enable(em, scene, l, FALSE); + } + else { + uvedit_uv_select_disable(em, scene, l); + } + } + } + } + } + } + } + if (change && ts->uv_flag & UV_SYNC_SELECTION) { + if (select == FALSE) { + EDBM_deselect_flush(em); + } + } +} + +static int uv_lasso_select_exec(bContext *C, wmOperator *op) +{ + int i = 0; + int mcords[1024][2]; + + RNA_BEGIN(op->ptr, itemptr, "path") { + float loc[2]; + + RNA_float_get_array(&itemptr, "loc", loc); + mcords[i][0] = (int)loc[0]; + mcords[i][1] = (int)loc[1]; + i++; + if (i >= 1024) break; + } + RNA_END; + + if (i > 1) { + short select; + + select = !RNA_boolean_get(op->ptr, "deselect"); + do_lasso_select_mesh_uv(C, mcords, i, select); + + return OPERATOR_FINISHED; + } + return OPERATOR_PASS_THROUGH; +} + +void UV_OT_select_lasso(wmOperatorType *ot) +{ + ot->name = "Lasso Select UV"; + ot->description = "Select UVs using lasso selection"; + ot->idname = "UV_OT_select_lasso"; + + ot->invoke = WM_gesture_lasso_invoke; + ot->modal = WM_gesture_lasso_modal; + ot->exec = uv_lasso_select_exec; + ot->poll = ED_operator_image_active; + ot->cancel = WM_gesture_lasso_cancel; + + /* flags */ + ot->flag = OPTYPE_UNDO; + + RNA_def_collection_runtime(ot->srna, "path", &RNA_OperatorMousePath, "Path", ""); + RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Deselect rather than select items"); + RNA_def_boolean(ot->srna, "extend", 1, "Extend", "Extend selection instead of deselecting everything first"); +} + + + /* ******************** snap cursor operator **************** */ static void snap_uv_to_pixel(float *uvco, float w, float h) @@ -3540,6 +3678,7 @@ WM_operatortype_append(UV_OT_unlink_selected); WM_operatortype_append(UV_OT_select_pinned); WM_operatortype_append(UV_OT_select_border); + WM_operatortype_append(UV_OT_select_lasso); WM_operatortype_append(UV_OT_circle_select); WM_operatortype_append(UV_OT_snap_cursor); @@ -3600,6 +3739,8 @@ WM_keymap_add_item(keymap, "UV_OT_circle_select", CKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "UV_OT_select_lasso", ACTIONMOUSE, KM_PRESS, KM_CTRL, 0); + /* selection manipulation */ RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_linked", LKEY, KM_PRESS, KM_CTRL, 0)->ptr, "extend", FALSE); RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0)->ptr, "extend", FALSE);