Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--release/scripts/startup/bl_ui/space_node.py1
-rw-r--r--source/blender/editors/space_node/node_intern.h1
-rw-r--r--source/blender/editors/space_node/node_ops.c2
-rw-r--r--source/blender/editors/space_node/node_view.c112
4 files changed, 76 insertions, 40 deletions
diff --git a/release/scripts/startup/bl_ui/space_node.py b/release/scripts/startup/bl_ui/space_node.py
index adcf5a9e9df..46baef9b043 100644
--- a/release/scripts/startup/bl_ui/space_node.py
+++ b/release/scripts/startup/bl_ui/space_node.py
@@ -115,6 +115,7 @@ class NODE_MT_view(Menu):
layout.separator()
+ layout.operator("node.view_selected")
layout.operator("node.view_all")
if context.space_data.show_backdrop:
diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h
index a6bf8198cb4..048e09efab5 100644
--- a/source/blender/editors/space_node/node_intern.h
+++ b/source/blender/editors/space_node/node_intern.h
@@ -113,6 +113,7 @@ void NODE_OT_select_same_type_prev(wmOperatorType *ot);
/* node_view.c */
void NODE_OT_view_all(struct wmOperatorType *ot);
+void NODE_OT_view_selected(struct wmOperatorType *ot);
void NODE_OT_backimage_move(struct wmOperatorType *ot);
void NODE_OT_backimage_zoom(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_node/node_ops.c b/source/blender/editors/space_node/node_ops.c
index cfd373231ff..195dd60b72a 100644
--- a/source/blender/editors/space_node/node_ops.c
+++ b/source/blender/editors/space_node/node_ops.c
@@ -60,6 +60,7 @@ void node_operatortypes(void)
WM_operatortype_append(NODE_OT_select_same_type_prev);
WM_operatortype_append(NODE_OT_view_all);
+ WM_operatortype_append(NODE_OT_view_selected);
WM_operatortype_append(NODE_OT_mute_toggle);
WM_operatortype_append(NODE_OT_hide_toggle);
@@ -255,6 +256,7 @@ void node_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "NODE_OT_show_cyclic_dependencies", CKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "NODE_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
+ WM_keymap_add_item(keymap, "NODE_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
kmi = WM_keymap_add_item(keymap, "NODE_OT_select_border", BKEY, KM_PRESS, 0, 0);
RNA_boolean_set(kmi->ptr, "tweak", FALSE);
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 ************** */