UV: add Snap Cursor to Origin

Similar to snapping to the world origin in the 3D viewport. This can be found
in the Shift+S pie menu and UV > Snap menu.

Differential Revision: https://developer.blender.org/D15055
This commit is contained in:
Tomek Gubala 2022-07-19 19:24:20 +02:00 committed by Brecht Van Lommel
parent 75e62df429
commit 3b7ac10d62
2 changed files with 17 additions and 0 deletions

View File

@ -306,6 +306,7 @@ class IMAGE_MT_uvs_snap(Menu):
layout.operator("uv.snap_cursor", text="Cursor to Pixels").target = 'PIXELS'
layout.operator("uv.snap_cursor", text="Cursor to Selected").target = 'SELECTED'
layout.operator("uv.snap_cursor", text="Cursor to Origin").target = 'ORIGIN'
class IMAGE_MT_uvs_mirror(Menu):
@ -572,6 +573,11 @@ class IMAGE_MT_uvs_snap_pie(Menu):
text="Selected to Adjacent Unselected",
icon='RESTRICT_SELECT_OFF',
).target = 'ADJACENT_UNSELECTED'
pie.operator(
"uv.snap_cursor",
text="Cursor to Origin",
icon='PIVOT_CURSOR',
).target = 'ORIGIN'
class IMAGE_MT_view_pie(Menu):

View File

@ -1036,6 +1036,12 @@ static bool uv_snap_cursor_to_selection(Scene *scene,
return ED_uvedit_center_multi(scene, objects_edit, objects_len, sima->cursor, sima->around);
}
static void uv_snap_cursor_to_origin(float uvco[2])
{
uvco[0] = 0;
uvco[1] = 0;
}
static int uv_snap_cursor_exec(bContext *C, wmOperator *op)
{
SpaceImage *sima = CTX_wm_space_image(C);
@ -1058,6 +1064,10 @@ static int uv_snap_cursor_exec(bContext *C, wmOperator *op)
MEM_freeN(objects);
break;
}
case 2:
uv_snap_cursor_to_origin(sima->cursor);
changed = true;
break;
}
if (!changed) {
@ -1074,6 +1084,7 @@ static void UV_OT_snap_cursor(wmOperatorType *ot)
static const EnumPropertyItem target_items[] = {
{0, "PIXELS", 0, "Pixels", ""},
{1, "SELECTED", 0, "Selected", ""},
{2, "ORIGIN", 0, "Origin", ""},
{0, NULL, 0, NULL, NULL},
};