diff options
author | Joep Peters <Joep> | 2019-01-22 17:38:56 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-01-22 19:05:18 +0300 |
commit | 1651879d3419eed71d98bc46dba4adce3c09e573 (patch) | |
tree | 51396caa7c89440758c529a9a5480f0bb89559a0 /source | |
parent | babba31c49ef635cad8621444a2f7b7316690512 (diff) |
UV Editor: support snapping to center of pixels, in addition to corners.
Differential Revision: https://developer.blender.org/D4150
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/transform/transform_conversions.c | 21 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_space_types.h | 14 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_space.c | 13 |
3 files changed, 39 insertions, 9 deletions
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); |