diff options
author | Chris Blackbourn <chrisbblend@gmail.com> | 2022-10-12 01:26:14 +0300 |
---|---|---|
committer | Chris Blackbourn <chrisbblend@gmail.com> | 2022-10-12 01:27:41 +0300 |
commit | b7decab07ef85aeda1be3391c2e85e3265b12091 (patch) | |
tree | 06951d5ae1ac8c58d60b35e4fc18c8672d218610 /source/blender/editors/space_image | |
parent | c2256bf7f714bbd41388af3e184b3d84b496fbf3 (diff) |
UV: add grid shape source to the uv editor, and add new "pixel" option
This change is part of a wider set of changes to implement Grid and Pixel
snapping in the UV Editor. This particular change adds a new third option,
`pixel grid`, to the previous grid options, `dynamic grid` and `fixed grid`.
Maniphest Tasks : T78391
Differential Revision: https://developer.blender.org/D16197
Diffstat (limited to 'source/blender/editors/space_image')
-rw-r--r-- | source/blender/editors/space_image/image_draw.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c index 42ebed6ec3a..85b1e2b6707 100644 --- a/source/blender/editors/space_image/image_draw.c +++ b/source/blender/editors/space_image/image_draw.c @@ -589,15 +589,27 @@ void ED_space_image_grid_steps(SpaceImage *sima, float grid_steps_y[SI_GRID_STEPS_LEN], const int grid_dimension) { - const int flag = sima->flag; + const eSpaceImage_GridShapeSource grid_shape_source = sima->grid_shape_source; for (int step = 0; step < SI_GRID_STEPS_LEN; step++) { - if (flag & SI_CUSTOM_GRID) { - grid_steps_x[step] = 1.0f / sima->custom_grid_subdiv[0]; - grid_steps_y[step] = 1.0f / sima->custom_grid_subdiv[1]; - } - else { - grid_steps_x[step] = powf(grid_dimension, step - SI_GRID_STEPS_LEN); - grid_steps_y[step] = powf(grid_dimension, step - SI_GRID_STEPS_LEN); + switch (grid_shape_source) { + case SI_GRID_SHAPE_DYNAMIC: + grid_steps_x[step] = powf(grid_dimension, step - SI_GRID_STEPS_LEN); + grid_steps_y[step] = powf(grid_dimension, step - SI_GRID_STEPS_LEN); + break; + case SI_GRID_SHAPE_FIXED: + grid_steps_x[step] = 1.0f / sima->custom_grid_subdiv[0]; + grid_steps_y[step] = 1.0f / sima->custom_grid_subdiv[1]; + break; + case SI_GRID_SHAPE_PIXEL: { + int pixel_width = IMG_SIZE_FALLBACK; + int pixel_height = IMG_SIZE_FALLBACK; + ED_space_image_get_size(sima, &pixel_width, &pixel_height); + BLI_assert(pixel_width > 0 && pixel_height > 0); + grid_steps_x[step] = 1.0f / pixel_width; + grid_steps_y[step] = 1.0f / pixel_height; + } break; + default: + BLI_assert_unreachable(); } } } |