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.

This commit is contained in:
Lukas Toenne 2013-04-17 17:12:12 +00:00
parent 3d78032251
commit 2cf167cd21
3 changed files with 42 additions and 35 deletions

@ -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, &center[0], &center[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);

@ -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;

@ -891,6 +891,7 @@ typedef struct bNodeTreePath {
struct bNodeTree *nodetree;
bNodeInstanceKey parent_key; /* base key for nodes in this tree instance */
int pad;
float view_center[2]; /* v2d center point, so node trees can have different offsets in editors */
/* XXX this is not automatically updated when node names are changed! */
char node_name[64]; /* MAX_NAME */
} bNodeTreePath;