Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <eiseljulian@gmail.com>2018-04-30 16:42:29 +0300
committerJulian Eisel <eiseljulian@gmail.com>2018-04-30 16:42:29 +0300
commite76a65e35902c128295cdf817664ab6f8d5737d5 (patch)
treed029976bbb5b3015cf115ce2dadd932ab436cca6
parent128506eeb1a2d87393061b4c9783289a5e4b3275 (diff)
UV editing: Make 'Select Linked' work consistent to 3D View
Don't see a good reason for the old behavior, so better have it consistent.
-rw-r--r--source/blender/editors/uvedit/uvedit_ops.c119
1 files changed, 53 insertions, 66 deletions
diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c
index 852c4ae5958..9c6f468532f 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -1213,7 +1213,7 @@ static int uv_select_edgeloop(
static void uv_select_linked(
Scene *scene, Image *ima, BMEditMesh *em, const float limit[2], UvNearestHit *hit_final,
- bool extend, bool select_faces)
+ bool extend, bool deselect, bool toggle, bool select_faces)
{
BMFace *efa;
BMLoop *l;
@@ -1317,89 +1317,65 @@ static void uv_select_linked(
}
}
- if (!extend) {
- BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) {
- if (select_faces) {
- if (flag[a])
- BM_face_select_set(em->bm, efa, true);
- else
- BM_face_select_set(em->bm, efa, false);
- }
- else {
- BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
- luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
-
- if (flag[a])
- luv->flag |= MLOOPUV_VERTSEL;
- else
- luv->flag &= ~MLOOPUV_VERTSEL;
- }
- }
- }
- }
- else {
+ /* Toggling - if any of the linked vertices is selected (and visible), we deselect. */
+ if ((toggle == true) && (extend == false) && (deselect == false)) {
BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) {
+ bool found_selected = false;
if (!flag[a]) {
continue;
}
if (select_faces) {
- if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN))
- break;
+ if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
+ found_selected = true;
+ }
}
else {
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
if (luv->flag & MLOOPUV_VERTSEL) {
- break;
+ found_selected = true;
}
}
- if (l) {
+ if (found_selected) {
+ deselect = true;
break;
}
}
}
+ }
- if (efa) {
- BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) {
- if (!flag[a]) {
- continue;
- }
+#define SET_SELECTION(value) \
+ if (select_faces) { \
+ BM_face_select_set(em->bm, efa, value); \
+ } \
+ else { \
+ BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { \
+ luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); \
+ luv->flag = (value) ? (luv->flag | MLOOPUV_VERTSEL) : (luv->flag & ~MLOOPUV_VERTSEL); \
+ } \
+ } (void)0
- if (select_faces) {
- BM_face_select_set(em->bm, efa, false);
- }
- else {
- BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
- luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
-
- luv->flag &= ~MLOOPUV_VERTSEL;
- }
- }
+ BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) {
+ if (!flag[a]) {
+ if (!extend && !deselect && !toggle) {
+ SET_SELECTION(false);
}
+ continue;
}
- else {
- BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) {
- if (!flag[a]) {
- continue;
- }
-
- if (select_faces) {
- BM_face_select_set(em->bm, efa, true);
- }
- else {
- BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
- luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
- luv->flag |= MLOOPUV_VERTSEL;
- }
- }
- }
+ if (!deselect) {
+ SET_SELECTION(true);
+ }
+ else {
+ SET_SELECTION(false);
}
}
-
+
+#undef SET_SELECTION
+
MEM_freeN(stack);
MEM_freeN(flag);
BM_uv_vert_map_free(vmap);
@@ -2316,7 +2292,8 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
flush = uv_select_edgeloop(scene, ima, em, &hit, limit, extend);
}
else if (selectmode == UV_SELECT_ISLAND) {
- uv_select_linked(scene, ima, em, limit, &hit, extend, false);
+ /* Current behavior of 'extend' is actually toggling, so pass extend flag as 'toggle' here */
+ uv_select_linked(scene, ima, em, limit, &hit, false, false, extend, false);
}
else if (extend) {
if (selectmode == UV_SELECT_VERTEX) {
@@ -2544,7 +2521,7 @@ static int uv_select_linked_internal(bContext *C, wmOperator *op, const wmEvent
Image *ima = CTX_data_edit_image(C);
BMEditMesh *em = BKE_editmesh_from_object(obedit);
float limit[2];
- int extend;
+ int extend, deselect;
bool select_faces = (ts->uv_flag & UV_SYNC_SELECTION) && (ts->selectmode & SCE_SELECT_FACE);
UvNearestHit hit = UV_NEAREST_HIT_INIT;
@@ -2555,6 +2532,7 @@ static int uv_select_linked_internal(bContext *C, wmOperator *op, const wmEvent
}
extend = RNA_boolean_get(op->ptr, "extend");
+ deselect = RNA_boolean_get(op->ptr, "deselect");
uvedit_pixel_to_float(sima, limit, 0.05f);
if (pick) {
@@ -2577,7 +2555,7 @@ static int uv_select_linked_internal(bContext *C, wmOperator *op, const wmEvent
}
}
- uv_select_linked(scene, ima, em, limit, pick ? &hit : NULL, extend, select_faces);
+ uv_select_linked(scene, ima, em, limit, pick ? &hit : NULL, extend, deselect, false, select_faces);
DAG_id_tag_update(obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
@@ -2605,6 +2583,7 @@ static void UV_OT_select_linked(wmOperatorType *ot)
/* properties */
RNA_def_boolean(ot->srna, "extend", 0,
"Extend", "Extend selection rather than clearing the existing selection");
+ RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Deselect linked UV vertices rather than selecting them");
}
static int uv_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
@@ -2633,7 +2612,7 @@ static void UV_OT_select_linked_pick(wmOperatorType *ot)
/* properties */
RNA_def_boolean(ot->srna, "extend", 0,
"Extend", "Extend selection rather than clearing the existing selection");
-
+ RNA_def_boolean(ot->srna, "deselect", 0, "Deselect", "Deselect linked UV vertices rather than selecting them");
RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX,
"Location", "Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds", -100.0f, 100.0f);
}
@@ -4510,10 +4489,18 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf)
RNA_boolean_set(kmi->ptr, "deselect", true);
/* 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);
- RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_linked", LKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0)->ptr, "extend", true);
- RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", true);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
+ RNA_boolean_set(kmi->ptr, "extend", true);
+ RNA_boolean_set(kmi->ptr, "deselect", false);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_select_linked_pick", LKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "extend", true);
+ RNA_boolean_set(kmi->ptr, "deselect", false);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_select_linked", LKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "extend", false);
+ RNA_boolean_set(kmi->ptr, "deselect", true);
+ kmi = WM_keymap_add_item(keymap, "UV_OT_select_linked_pick", LKEY, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "extend", false);
+ RNA_boolean_set(kmi->ptr, "deselect", true);
/* select more/less */
WM_keymap_add_item(keymap, "UV_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);