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.
This commit is contained in:
@@ -32,6 +32,7 @@ class NODE_HT_header(Header):
|
||||
snode = context.space_data
|
||||
snode_id = snode.id
|
||||
id_from = snode.id_from
|
||||
toolsettings = context.tool_settings
|
||||
|
||||
row = layout.row(align=True)
|
||||
row.template_header()
|
||||
@@ -86,6 +87,10 @@ class NODE_HT_header(Header):
|
||||
|
||||
layout.separator()
|
||||
|
||||
# Snap
|
||||
row = layout.row(align=True)
|
||||
row.prop(toolsettings, "use_snap", text="")
|
||||
|
||||
layout.template_running_jobs()
|
||||
|
||||
|
||||
|
@@ -166,6 +166,7 @@ void UI_view2d_view_restore(const struct bContext *C);
|
||||
View2DGrid *UI_view2d_grid_calc(struct Scene *scene, struct View2D *v2d, short xunits, short xclamp, short yunits, short yclamp, int winx, int winy);
|
||||
void UI_view2d_grid_draw(struct View2D *v2d, View2DGrid *grid, int flag);
|
||||
void UI_view2d_constant_grid_draw(struct View2D *v2d);
|
||||
void UI_view2d_multi_grid_draw(struct View2D *v2d, float step, int level_size, int totlevels);
|
||||
void UI_view2d_grid_size(View2DGrid *grid, float *r_dx, float *r_dy);
|
||||
void UI_view2d_grid_free(View2DGrid *grid);
|
||||
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -1095,7 +1095,9 @@ void drawnodespace(const bContext *C, ARegion *ar, View2D *v2d)
|
||||
snode->aspect= (v2d->cur.xmax - v2d->cur.xmin)/((float)ar->winx);
|
||||
// XXX snode->curfont= uiSetCurFont_ext(snode->aspect);
|
||||
|
||||
UI_view2d_constant_grid_draw(v2d);
|
||||
/* grid */
|
||||
UI_view2d_multi_grid_draw(v2d, 25.0f, 5, 2);
|
||||
|
||||
/* backdrop */
|
||||
draw_nodespace_back_pix(ar, snode, color_manage);
|
||||
|
||||
|
@@ -3542,6 +3542,11 @@ void initTranslation(TransInfo *t)
|
||||
t->snap[1] = 0.125f;
|
||||
t->snap[2] = 0.0625f;
|
||||
}
|
||||
else if (t->spacetype == SPACE_NODE) {
|
||||
t->snap[0] = 0.0f;
|
||||
t->snap[1] = 125.0f;
|
||||
t->snap[2] = 25.0f;
|
||||
}
|
||||
else {
|
||||
t->snap[0] = 0.0f;
|
||||
t->snap[1] = t->snap[2] = 1.0f;
|
||||
|
@@ -459,7 +459,7 @@ void initSnapping(TransInfo *t, wmOperator *op)
|
||||
}
|
||||
/* use scene defaults only when transform is modal */
|
||||
else if (t->flag & T_MODAL) {
|
||||
if (ELEM(t->spacetype, SPACE_VIEW3D, SPACE_IMAGE)) {
|
||||
if (ELEM3(t->spacetype, SPACE_VIEW3D, SPACE_IMAGE, SPACE_NODE)) {
|
||||
if (ts->snap_flag & SCE_SNAP) {
|
||||
t->modifiers |= MOD_SNAP;
|
||||
}
|
||||
|
Reference in New Issue
Block a user