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/blender/editors | |
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/blender/editors')
-rw-r--r-- | source/blender/editors/transform/transform_conversions.c | 21 |
1 files changed, 18 insertions, 3 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]; } } } |