Fix T42660 snapping not working nicely on graph editor.

Basically, get the grid increments and reuse them when snapping. System
is slightly crappy here, we should calculate those factors only once,
but leaving as todo for later.
This commit is contained in:
Antonis Ryakiotakis 2014-11-20 17:44:47 +01:00
parent 2f43befed9
commit 4bf40bb646
Notes: blender-bot 2023-02-14 20:01:59 +01:00
Referenced by issue blender/blender-addons#42660, SHIFT+CTRL snapping not right in Graph Editor
2 changed files with 18 additions and 0 deletions

View File

@ -4061,6 +4061,11 @@ static void initTranslation(TransInfo *t)
t->snap[1] = ED_node_grid_size() * NODE_GRID_STEPS;
t->snap[2] = ED_node_grid_size();
}
else if (t->spacetype == SPACE_IPO) {
t->snap[0] = 0.0f;
t->snap[1] = 1.0;
t->snap[2] = 0.1f;
}
else {
t->snap[0] = 0.0f;
t->snap[1] = t->snap[2] = 1.0f;

View File

@ -2457,6 +2457,19 @@ static void applyGridIncrement(TransInfo *t, float *val, int max_index, const fl
ED_space_image_get_uv_aspect(t->sa->spacedata.first, asp, asp + 1);
}
}
else if ((t->spacetype == SPACE_IPO) && (t->mode == TFM_TRANSLATION)) {
View2D *v2d = &t->ar->v2d;
View2DGrid *grid;
SpaceIpo *sipo = t->sa->spacedata.first;
int unity = V2D_UNIT_VALUES;
int unitx = (sipo->flag & SIPO_DRAWTIME) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMESCALE;
/* grid */
grid = UI_view2d_grid_calc(t->scene, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP, t->ar->winx, t->ar->winy);
UI_view2d_grid_size(grid, &asp[0], &asp[1]);
UI_view2d_grid_free(grid);
}
for (i = 0; i <= max_index; i++) {
val[i] = fac[action] * asp[i] * floorf(val[i] / (fac[action] * asp[i]) + 0.5f);