diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-08-07 20:30:34 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-08-07 20:30:34 +0400 |
commit | 258b4a8dad5b357b465a14a3e3a32fe6fafcd767 (patch) | |
tree | 6c455f8ebfa78fb57d6987cbfeef6658c58c4160 /source/blender/editors/space_node/node_view.c | |
parent | 95465e7a28e381ff272429409df38875c3d011e7 (diff) |
add view selected for node view
Diffstat (limited to 'source/blender/editors/space_node/node_view.c')
-rw-r--r-- | source/blender/editors/space_node/node_view.c | 112 |
1 files changed, 72 insertions, 40 deletions
diff --git a/source/blender/editors/space_node/node_view.c b/source/blender/editors/space_node/node_view.c index 248998a3a56..77f24302af3 100644 --- a/source/blender/editors/space_node/node_view.c +++ b/source/blender/editors/space_node/node_view.c @@ -60,54 +60,52 @@ /* **************** View All Operator ************** */ -static void snode_home(ScrArea *UNUSED(sa), ARegion *ar, SpaceNode *snode) +static int snode_home(ScrArea *UNUSED(sa), ARegion *ar, SpaceNode *snode, const int node_flag) { bNode *node; - rctf *cur; + rctf cur_new; float oldwidth, oldheight, width, height; - int first = 1; + int change = FALSE; - cur = &ar->v2d.cur; - - oldwidth = cur->xmax - cur->xmin; - oldheight = cur->ymax - cur->ymin; - - cur->xmin = cur->ymin = 0.0f; - cur->xmax = ar->winx; - cur->ymax = ar->winy; + oldwidth = ar->v2d.cur.xmax - ar->v2d.cur.xmin; + oldheight = ar->v2d.cur.ymax - ar->v2d.cur.ymin; + + BLI_rctf_init_minmax(&cur_new); + if (snode->edittree) { for (node = snode->edittree->nodes.first; node; node = node->next) { - if (first) { - first = 0; - ar->v2d.cur = node->totr; - } - else { - BLI_rctf_union(cur, &node->totr); + if ((node->flag & node_flag) == node_flag) { + BLI_rctf_union(&cur_new, &node->totr); + change = TRUE; } } } - - snode->xof = 0; - snode->yof = 0; - width = cur->xmax - cur->xmin; - height = cur->ymax - cur->ymin; - - if (width > height) { - float newheight; - newheight = oldheight * width / oldwidth; - cur->ymin = cur->ymin - newheight / 4; - cur->ymax = cur->ymax + newheight / 4; - } - else { - float newwidth; - newwidth = oldwidth * height / oldheight; - cur->xmin = cur->xmin - newwidth / 4; - cur->xmax = cur->xmax + newwidth / 4; + + if (change) { + snode->xof = 0; + snode->yof = 0; + width = cur_new.xmax - cur_new.xmin; + height = cur_new.ymax - cur_new.ymin; + + if (width > height) { + float newheight; + newheight = oldheight * width / oldwidth; + cur_new.ymin = cur_new.ymin - newheight / 4; + cur_new.ymax = cur_new.ymax + newheight / 4; + } + else { + float newwidth; + newwidth = oldwidth * height / oldheight; + cur_new.xmin = cur_new.xmin - newwidth / 4; + cur_new.xmax = cur_new.xmax + newwidth / 4; + } + + ar->v2d.tot = ar->v2d.cur = cur_new; + UI_view2d_curRect_validate(&ar->v2d); } - ar->v2d.tot = ar->v2d.cur; - UI_view2d_curRect_validate(&ar->v2d); + return change; } static int node_view_all_exec(bContext *C, wmOperator *UNUSED(op)) @@ -116,10 +114,14 @@ static int node_view_all_exec(bContext *C, wmOperator *UNUSED(op)) ARegion *ar = CTX_wm_region(C); SpaceNode *snode = CTX_wm_space_node(C); - snode_home(sa, ar, snode); - ED_region_tag_redraw(ar); - - return OPERATOR_FINISHED; + if (snode_home(sa, ar, snode, 0)) { + ED_region_tag_redraw(ar); + + return OPERATOR_FINISHED; + } + else { + return OPERATOR_CANCELLED; + } } void NODE_OT_view_all(wmOperatorType *ot) @@ -137,6 +139,36 @@ void NODE_OT_view_all(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } +static int node_view_selected_exec(bContext *C, wmOperator *UNUSED(op)) +{ + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = CTX_wm_region(C); + SpaceNode *snode = CTX_wm_space_node(C); + + if (snode_home(sa, ar, snode, NODE_SELECT)) { + ED_region_tag_redraw(ar); + + return OPERATOR_FINISHED; + } + else { + return OPERATOR_CANCELLED; + } +} + +void NODE_OT_view_selected(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "View Selected"; + ot->idname = "NODE_OT_view_selected"; + ot->description = "Resize view so you can see selected nodes"; + + /* api callbacks */ + ot->exec = node_view_selected_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} /* **************** Backround Image Operators ************** */ |