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:
authorJoep Peters <Joep>2019-01-22 17:38:56 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-01-22 19:05:18 +0300
commit1651879d3419eed71d98bc46dba4adce3c09e573 (patch)
tree51396caa7c89440758c529a9a5480f0bb89559a0
parentbabba31c49ef635cad8621444a2f7b7316690512 (diff)
UV Editor: support snapping to center of pixels, in addition to corners.
Differential Revision: https://developer.blender.org/D4150
-rw-r--r--release/scripts/startup/bl_ui/space_image.py2
-rw-r--r--source/blender/editors/transform/transform_conversions.c21
-rw-r--r--source/blender/makesdna/DNA_space_types.h14
-rw-r--r--source/blender/makesrna/intern/rna_space.c13
4 files changed, 40 insertions, 10 deletions
diff --git a/release/scripts/startup/bl_ui/space_image.py b/release/scripts/startup/bl_ui/space_image.py
index f3f49d82714..f163e254a48 100644
--- a/release/scripts/startup/bl_ui/space_image.py
+++ b/release/scripts/startup/bl_ui/space_image.py
@@ -353,7 +353,7 @@ class IMAGE_MT_uvs(Menu):
uv = sima.uv_editor
tool_settings = context.tool_settings
- layout.prop(uv, "use_snap_to_pixels")
+ layout.prop_menu_enum(uv, "pixel_snap_mode")
layout.prop(uv, "lock_bounds")
layout.separator()
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
index ce41aa85da1..5b07c0c2b49 100644
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -3326,7 +3326,8 @@ finally:
void flushTransUVs(TransInfo *t)
{
SpaceImage *sima = t->sa->spacedata.first;
- const bool use_pixel_snap = ((sima->flag & SI_PIXELSNAP) && (t->state != TRANS_CANCEL));
+ const bool use_pixel_snap = ((sima->pixel_snap_mode != SI_PIXEL_SNAP_DISABLED) &&
+ (t->state != TRANS_CANCEL));
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
TransData2D *td;
@@ -3349,8 +3350,22 @@ void flushTransUVs(TransInfo *t)
td->loc2d[1] = td->loc[1] * aspect_inv[1];
if (use_pixel_snap) {
- td->loc2d[0] = roundf(td->loc2d[0] * size[0]) / size[0];
- td->loc2d[1] = roundf(td->loc2d[1] * size[1]) / size[1];
+ td->loc2d[0] *= size[0];
+ td->loc2d[1] *= size[1];
+
+ switch(sima->pixel_snap_mode) {
+ case SI_PIXEL_SNAP_CENTER:
+ td->loc2d[0] = roundf(td->loc2d[0] - 0.5f) + 0.5f;
+ td->loc2d[1] = roundf(td->loc2d[1] - 0.5f) + 0.5f;
+ break;
+ case SI_PIXEL_SNAP_CORNER:
+ td->loc2d[0] = roundf(td->loc2d[0]);
+ td->loc2d[1] = roundf(td->loc2d[1]);
+ break;
+ }
+
+ td->loc2d[0] /= size[0];
+ td->loc2d[1] /= size[1];
}
}
}
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 4ffd6c4842e..999e160e03a 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -1020,10 +1020,11 @@ typedef struct SpaceImage {
char dt_uvstretch;
char around;
- int pad2;
-
int flag;
+ char pixel_snap_mode;
+ char pad[3];
+
MaskSpaceInfo mask_info;
} SpaceImage;
@@ -1042,6 +1043,13 @@ typedef enum eSpaceImage_UVDT_Stretch {
SI_UVDT_STRETCH_AREA = 1,
} eSpaceImage_UVDT_Stretch;
+/* SpaceImage.pixel_snap_mode */
+typedef enum eSpaceImage_PixelSnapMode {
+ SI_PIXEL_SNAP_DISABLED = 0,
+ SI_PIXEL_SNAP_CENTER = 1,
+ SI_PIXEL_SNAP_CORNER = 2,
+} eSpaceImage_Snap_Mode;
+
/* SpaceImage.mode */
typedef enum eSpaceImage_Mode {
SI_MODE_VIEW = 0,
@@ -1071,7 +1079,7 @@ typedef enum eSpaceImage_Flag {
SI_FLAG_DEPRECATED_7 = (1 << 7), /* cleared */
SI_FLAG_DEPRECATED_8 = (1 << 8), /* cleared */
SI_COORDFLOATS = (1 << 9),
- SI_PIXELSNAP = (1 << 10),
+ SI_FLAG_DEPRECATED_10 = (1 << 10),
SI_LIVE_UNWRAP = (1 << 11),
SI_USE_ALPHA = (1 << 12),
SI_SHOW_ALPHA = (1 << 13),
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 66729b53394..640929ead19 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -2194,6 +2194,13 @@ static void rna_def_space_image_uv(BlenderRNA *brna)
{0, NULL, 0, NULL, NULL}
};
+ static const EnumPropertyItem pixel_snap_mode_items[] = {
+ {SI_PIXEL_SNAP_DISABLED, "DISABLED", 0, "Disabled", "Don't snap to pixels"},
+ {SI_PIXEL_SNAP_CORNER, "CORNER", 0, "Corner", "Snap to pixel corners"},
+ {SI_PIXEL_SNAP_CENTER, "CENTER", 0, "Center", "Snap to pixel centers"},
+ {0, NULL, 0, NULL, NULL}
+ };
+
srna = RNA_def_struct(brna, "SpaceUVEditor", NULL);
RNA_def_struct_sdna(srna, "SpaceImage");
RNA_def_struct_nested(brna, srna, "SpaceImageEditor");
@@ -2265,9 +2272,9 @@ static void rna_def_space_image_uv(BlenderRNA *brna)
/* todo: move edge and face drawing options here from G.f */
- prop = RNA_def_property(srna, "use_snap_to_pixels", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", SI_PIXELSNAP);
- RNA_def_property_ui_text(prop, "Snap to Pixels", "Snap UVs to pixel locations while editing");
+ prop = RNA_def_property(srna, "pixel_snap_mode", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_items(prop, pixel_snap_mode_items);
+ RNA_def_property_ui_text(prop, "Snap to Pixels", "Snap UVs to pixels while editing");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, NULL);
prop = RNA_def_property(srna, "lock_bounds", PROP_BOOLEAN, PROP_NONE);