diff options
author | Lukas Toenne <lukas.toenne@googlemail.com> | 2012-06-28 12:47:22 +0400 |
---|---|---|
committer | Lukas Toenne <lukas.toenne@googlemail.com> | 2012-06-28 12:47:22 +0400 |
commit | 855b6391ea3ee5eef819cfa73c72e016e461d74b (patch) | |
tree | b969e7905ded2e174478a26224e46c902a302e25 /source/blender/editors/interface | |
parent | edf244cbf70d569484b937f58aa9fd69b4243bd5 (diff) |
Basic snapping in node transform operator.
Snapping actually was working already, but grid spacing was set to 1.0, which is basically pixel size in the node editor. Increased this to 1x grid step for fine snapping and 5x grid step for rough snapping.
Grid drawing in node editor now draws 2 levels in slightly different shades to indicate the different snapping modes better.
Node editor also supports the general use_snap tool setting to enable automatic snapping during transform. For now only the incremental snapping is supported, in future could be extended to enable alignment between nodes in a number of ways.
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r-- | source/blender/editors/interface/view2d.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index 51e1b30f0bf..9a783b461a0 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -1328,6 +1328,54 @@ void UI_view2d_constant_grid_draw(View2D *v2d) glEnd(); } +/* Draw a multi-level grid in given 2d-region */ +void UI_view2d_multi_grid_draw(View2D *v2d, float step, int level_size, int totlevels) +{ + int offset = -10; + float lstep = step; + int level; + + for (level = 0; level < totlevels; ++level) { + int i; + float start; + + UI_ThemeColorShade(TH_BACK, offset); + + i = (v2d->cur.xmin >= 0.0f ? -(int)(-v2d->cur.xmin / lstep) : (int)(v2d->cur.xmin / lstep)); + start = i * lstep; + + glBegin(GL_LINES); + for (; start < v2d->cur.xmax; start += lstep, ++i) { + if (i == 0 || (level < totlevels-1 && i % level_size == 0)) + continue; + glVertex2f(start, v2d->cur.ymin); + glVertex2f(start, v2d->cur.ymax); + } + + i = (v2d->cur.ymin >= 0.0f ? -(int)(-v2d->cur.ymin / lstep) : (int)(v2d->cur.ymin / lstep)); + start = i * lstep; + + for (; start < v2d->cur.ymax; start += lstep, ++i) { + if (i == 0 || (level < totlevels-1 && i % level_size == 0)) + continue; + glVertex2f(v2d->cur.xmin, start); + glVertex2f(v2d->cur.xmax, start); + } + + /* X and Y axis */ + UI_ThemeColorShade(TH_BACK, offset-8); + glVertex2f(0.0f, v2d->cur.ymin); + glVertex2f(0.0f, v2d->cur.ymax); + glVertex2f(v2d->cur.xmin, 0.0f); + glVertex2f(v2d->cur.xmax, 0.0f); + + glEnd(); + + lstep *= level_size; + offset -= 6; + } +} + /* the price we pay for not exposting structs :( */ void UI_view2d_grid_size(View2DGrid *grid, float *r_dx, float *r_dy) { |