add view selected for node view
authorCampbell Barton <ideasman42@gmail.com>
Tue, 7 Aug 2012 16:30:34 +0000 (16:30 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 7 Aug 2012 16:30:34 +0000 (16:30 +0000)
release/scripts/startup/bl_ui/space_node.py
source/blender/editors/space_node/node_intern.h
source/blender/editors/space_node/node_ops.c
source/blender/editors/space_node/node_view.c

index adcf5a9e9dfe0bdd4d348f3ceefa590ca611747d..46baef9b043cec5e74821814d779c349643b6bf3 100644 (file)
@@ -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:
index a6bf8198cb4678420b0a11df9cf7a91a519175b1..048e09efab55e6c6305e37b569f70684c9a29a68 100644 (file)
@@ -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);
index cfd373231ffffa0ed44f8b3241f64a6a63225f49..195dd60b72a14be893732fe565e041300166fdcb 100644 (file)
@@ -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);
index 248998a3a56b94dff3e50aafb65805b99b84cb1e..77f24302af383886c7050ed8454d6ea519a359aa 100644 (file)
 
 /* **************** 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 ************** */