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:
@@ -1194,12 +1194,12 @@ static void draw_tree_path(SpaceNode *snode)
|
|||||||
BLF_draw_default(30, 30, 0.0f, info, sizeof(info));
|
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;
|
View2D *v2d = &ar->v2d;
|
||||||
|
|
||||||
/* shift view to node tree center */
|
/* 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);
|
UI_view2d_view_ortho(v2d);
|
||||||
|
|
||||||
/* aspect+font, set each time */
|
/* aspect+font, set each time */
|
||||||
@@ -1274,43 +1274,47 @@ void drawnodespace(const bContext *C, ARegion *ar)
|
|||||||
bNodeLinkDrag *nldrag;
|
bNodeLinkDrag *nldrag;
|
||||||
LinkData *linkdata;
|
LinkData *linkdata;
|
||||||
|
|
||||||
|
path = snode->treepath.last;
|
||||||
|
|
||||||
/* current View2D center, will be set temporarily for parent node trees */
|
/* current View2D center, will be set temporarily for parent node trees */
|
||||||
UI_view2d_getcenter(v2d, ¢er[0], ¢er[1]);
|
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)
|
if (snode->edittree)
|
||||||
copy_v2_v2(snode->edittree->view_center, center);
|
copy_v2_v2(snode->edittree->view_center, center);
|
||||||
|
|
||||||
depth = 0;
|
depth = 0;
|
||||||
path = snode->treepath.last;
|
|
||||||
while (path->prev && depth < max_depth) {
|
while (path->prev && depth < max_depth) {
|
||||||
path = path->prev;
|
path = path->prev;
|
||||||
++depth;
|
++depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parent node trees in the background */
|
/* 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;
|
ntree = path->nodetree;
|
||||||
|
|
||||||
if (ntree) {
|
if (ntree) {
|
||||||
snode_setup_v2d(snode, ar, ntree->view_center[0], ntree->view_center[1]);
|
snode_setup_v2d(snode, ar, path->view_center);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
draw_nodetree(C, ar, ntree, path->parent_key);
|
draw_nodetree(C, ar, ntree, path->parent_key);
|
||||||
|
|
||||||
if (curdepth > 0)
|
draw_group_overlay(C, ar);
|
||||||
draw_group_overlay(C, ar);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reset View2D */
|
/* top-level edit tree */
|
||||||
UI_view2d_setcenter(v2d, center[0], center[1]);
|
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 */
|
/* temporary links */
|
||||||
glEnable(GL_BLEND);
|
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 = MEM_callocN(sizeof(bNodeTreePath), "node tree path");
|
||||||
path->nodetree = ntree;
|
path->nodetree = ntree;
|
||||||
path->parent_key = NODE_INSTANCE_KEY_BASE;
|
path->parent_key = NODE_INSTANCE_KEY_BASE;
|
||||||
|
|
||||||
|
/* copy initial offset from bNodeTree */
|
||||||
|
copy_v2_v2(path->view_center, ntree->view_center);
|
||||||
|
|
||||||
if (id)
|
if (id)
|
||||||
BLI_strncpy(path->node_name, id->name + 2, sizeof(path->node_name));
|
BLI_strncpy(path->node_name, id->name + 2, sizeof(path->node_name));
|
||||||
|
|
||||||
BLI_addtail(&snode->treepath, path);
|
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->id = id;
|
||||||
snode->from = from;
|
snode->from = from;
|
||||||
|
|
||||||
/* listener updates the View2D center from edittree */
|
|
||||||
WM_main_add_notifier(NC_SCENE | ND_NODES, NULL);
|
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
|
else
|
||||||
path->parent_key = NODE_INSTANCE_KEY_BASE;
|
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);
|
BLI_addtail(&snode->treepath, path);
|
||||||
|
|
||||||
/* update current tree */
|
/* update current tree */
|
||||||
snode->edittree = ntree;
|
snode->edittree = ntree;
|
||||||
|
|
||||||
/* listener updates the View2D center from edittree */
|
|
||||||
WM_main_add_notifier(NC_SCENE | ND_NODES, NULL);
|
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)
|
void snode_group_offset(SpaceNode *snode, float *x, float *y)
|
||||||
{
|
{
|
||||||
bNodeTreePath *path = snode->treepath.last;
|
bNodeTreePath *path = snode->treepath.last;
|
||||||
float cx, cy;
|
|
||||||
|
|
||||||
if (path) {
|
if (path && path->prev) {
|
||||||
cx = path->nodetree->view_center[0];
|
float dcenter[2];
|
||||||
cy = path->nodetree->view_center[1];
|
sub_v2_v2v2(dcenter, path->view_center, path->prev->view_center);
|
||||||
|
*x = dcenter[0];
|
||||||
if (path->prev) {
|
*y = dcenter[1];
|
||||||
*x = cx - path->prev->nodetree->view_center[0];
|
|
||||||
*y = cy - path->prev->nodetree->view_center[1];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
*x = *y = 0.0f;
|
*x = *y = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ******************** manage regions ********************* */
|
/* ******************** manage regions ********************* */
|
||||||
@@ -374,9 +375,10 @@ static void node_area_listener(ScrArea *sa, wmNotifier *wmn)
|
|||||||
switch (wmn->data) {
|
switch (wmn->data) {
|
||||||
case ND_NODES: {
|
case ND_NODES: {
|
||||||
ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
|
ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
|
||||||
|
bNodeTreePath *path = snode->treepath.last;
|
||||||
/* shift view to node tree center */
|
/* shift view to node tree center */
|
||||||
if (ar && snode->edittree)
|
if (ar && path)
|
||||||
UI_view2d_setcenter(&ar->v2d, snode->edittree->view_center[0], snode->edittree->view_center[1]);
|
UI_view2d_setcenter(&ar->v2d, path->view_center[0], path->view_center[1]);
|
||||||
|
|
||||||
ED_area_tag_refresh(sa);
|
ED_area_tag_refresh(sa);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -891,6 +891,7 @@ typedef struct bNodeTreePath {
|
|||||||
struct bNodeTree *nodetree;
|
struct bNodeTree *nodetree;
|
||||||
bNodeInstanceKey parent_key; /* base key for nodes in this tree instance */
|
bNodeInstanceKey parent_key; /* base key for nodes in this tree instance */
|
||||||
int pad;
|
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! */
|
/* XXX this is not automatically updated when node names are changed! */
|
||||||
char node_name[64]; /* MAX_NAME */
|
char node_name[64]; /* MAX_NAME */
|
||||||
} bNodeTreePath;
|
} bNodeTreePath;
|
||||||
|
|||||||
Reference in New Issue
Block a user