diff options
author | Lukas Toenne <lukas.toenne@googlemail.com> | 2013-04-17 21:12:12 +0400 |
---|---|---|
committer | Lukas Toenne <lukas.toenne@googlemail.com> | 2013-04-17 21:12:12 +0400 |
commit | 2cf167cd21dae8403bcd628106d376faeb919b30 (patch) | |
tree | 27e7fed8a7511c2ec2c8d96c8b2bcb3f6e3c8efa /source/blender/editors | |
parent | 3d7803225122476e5ea3db8da2585fcaff7c7f59 (diff) |
Fix for #34911, Compositor with multiple views autozooms to node when creating a link. In order to allow node trees have different offsets in different editor instances, the view_center is now stored primarily in the bNodeTreePath struct for each tree in a node space. The view_center in bNodeTree is only used as an initial setting when opening a node group or switching node trees.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/space_node/node_draw.c | 42 | ||||
-rw-r--r-- | source/blender/editors/space_node/space_node.c | 34 |
2 files changed, 41 insertions, 35 deletions
diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index 39b12b321dd..1f19374be17 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -1194,12 +1194,12 @@ static void draw_tree_path(SpaceNode *snode) BLF_draw_default(30, 30, 0.0f, info, sizeof(info)); } -static void snode_setup_v2d(SpaceNode *snode, ARegion *ar, float centerx, float centery) +static void snode_setup_v2d(SpaceNode *snode, ARegion *ar, float center[2]) { View2D *v2d = &ar->v2d; /* shift view to node tree center */ - UI_view2d_setcenter(v2d, centerx, centery); + UI_view2d_setcenter(v2d, center[0], center[1]); UI_view2d_view_ortho(v2d); /* aspect+font, set each time */ @@ -1274,43 +1274,47 @@ void drawnodespace(const bContext *C, ARegion *ar) bNodeLinkDrag *nldrag; LinkData *linkdata; + path = snode->treepath.last; + /* current View2D center, will be set temporarily for parent node trees */ UI_view2d_getcenter(v2d, ¢er[0], ¢er[1]); - /* store new view center in current edittree */ + /* store new view center in path and current edittree */ + copy_v2_v2(path->view_center, center); if (snode->edittree) copy_v2_v2(snode->edittree->view_center, center); depth = 0; - path = snode->treepath.last; while (path->prev && depth < max_depth) { path = path->prev; ++depth; } + /* parent node trees in the background */ - for (curdepth = depth; curdepth >= 0; path = path->next, --curdepth) { + for (curdepth = depth; curdepth > 0; path = path->next, --curdepth) { ntree = path->nodetree; - if (ntree) { - snode_setup_v2d(snode, ar, ntree->view_center[0], ntree->view_center[1]); - - if (curdepth == 0) { - /* grid, uses theme color based on node path depth */ - UI_view2d_multi_grid_draw(v2d, (depth > 0 ? TH_NODE_GROUP : TH_BACK), U.widget_unit, 5, 2); - - /* backdrop */ - draw_nodespace_back_pix(C, ar, snode); - } + snode_setup_v2d(snode, ar, path->view_center); draw_nodetree(C, ar, ntree, path->parent_key); - if (curdepth > 0) - draw_group_overlay(C, ar); + draw_group_overlay(C, ar); } } - /* reset View2D */ - UI_view2d_setcenter(v2d, center[0], center[1]); + /* top-level edit tree */ + ntree = path->nodetree; + if (ntree) { + snode_setup_v2d(snode, ar, center); + + /* grid, uses theme color based on node path depth */ + UI_view2d_multi_grid_draw(v2d, (depth > 0 ? TH_NODE_GROUP : TH_BACK), U.widget_unit, 5, 2); + + /* backdrop */ + draw_nodespace_back_pix(C, ar, snode); + + draw_nodetree(C, ar, ntree, path->parent_key); + } /* temporary links */ glEnable(GL_BLEND); diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c index 680d577a3b6..e234b4255ed 100644 --- a/source/blender/editors/space_node/space_node.c +++ b/source/blender/editors/space_node/space_node.c @@ -75,8 +75,13 @@ void ED_node_tree_start(SpaceNode *snode, bNodeTree *ntree, ID *id, ID *from) path = MEM_callocN(sizeof(bNodeTreePath), "node tree path"); path->nodetree = ntree; path->parent_key = NODE_INSTANCE_KEY_BASE; + + /* copy initial offset from bNodeTree */ + copy_v2_v2(path->view_center, ntree->view_center); + if (id) BLI_strncpy(path->node_name, id->name + 2, sizeof(path->node_name)); + BLI_addtail(&snode->treepath, path); } @@ -85,7 +90,6 @@ void ED_node_tree_start(SpaceNode *snode, bNodeTree *ntree, ID *id, ID *from) snode->id = id; snode->from = from; - /* listener updates the View2D center from edittree */ WM_main_add_notifier(NC_SCENE | ND_NODES, NULL); } @@ -105,12 +109,14 @@ void ED_node_tree_push(SpaceNode *snode, bNodeTree *ntree, bNode *gnode) else path->parent_key = NODE_INSTANCE_KEY_BASE; + /* copy initial offset from bNodeTree */ + copy_v2_v2(path->view_center, ntree->view_center); + BLI_addtail(&snode->treepath, path); /* update current tree */ snode->edittree = ntree; - /* listener updates the View2D center from edittree */ WM_main_add_notifier(NC_SCENE | ND_NODES, NULL); } @@ -205,20 +211,15 @@ void ED_node_tree_path_get_fixedbuf(SpaceNode *snode, char *value, int max_lengt void snode_group_offset(SpaceNode *snode, float *x, float *y) { bNodeTreePath *path = snode->treepath.last; - float cx, cy; - if (path) { - cx = path->nodetree->view_center[0]; - cy = path->nodetree->view_center[1]; - - if (path->prev) { - *x = cx - path->prev->nodetree->view_center[0]; - *y = cy - path->prev->nodetree->view_center[1]; - return; - } + if (path && path->prev) { + float dcenter[2]; + sub_v2_v2v2(dcenter, path->view_center, path->prev->view_center); + *x = dcenter[0]; + *y = dcenter[1]; } - - *x = *y = 0.0f; + else + *x = *y = 0.0f; } /* ******************** manage regions ********************* */ @@ -374,9 +375,10 @@ static void node_area_listener(ScrArea *sa, wmNotifier *wmn) switch (wmn->data) { case ND_NODES: { ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); + bNodeTreePath *path = snode->treepath.last; /* shift view to node tree center */ - if (ar && snode->edittree) - UI_view2d_setcenter(&ar->v2d, snode->edittree->view_center[0], snode->edittree->view_center[1]); + if (ar && path) + UI_view2d_setcenter(&ar->v2d, path->view_center[0], path->view_center[1]); ED_area_tag_refresh(sa); break; |