Patch #36622, by Henrik Aarnio: Fit backdrop image to the area dimensions.
authorLukas Toenne <lukas.toenne@googlemail.com>
Sun, 1 Sep 2013 09:50:56 +0000 (09:50 +0000)
committerLukas Toenne <lukas.toenne@googlemail.com>
Sun, 1 Sep 2013 09:50:56 +0000 (09:50 +0000)
A new operator to alter the backdrop zoom level so that it fits fully within the node editor area, and centers the image.
Shortcut alt-home, as home is used for fitting stuff into the view everywhere.

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 59fa52525ad03f728dd8286bc39b8c2b0d3d414e..436170d2ca3eac1bd210d2665f134575d5fd066c 100644 (file)
@@ -152,6 +152,7 @@ class NODE_MT_view(Menu):
             layout.operator("node.backimage_move", text="Backdrop move")
             layout.operator("node.backimage_zoom", text="Backdrop zoom in").factor = 1.2
             layout.operator("node.backimage_zoom", text="Backdrop zoom out").factor = 0.833
+            layout.operator("node.backimage_fit", text="Fit backdrop to available space")
 
         layout.separator()
 
@@ -361,6 +362,8 @@ class NODE_PT_backdrop(Panel):
         col.prop(snode, "backdrop_x", text="X")
         col.prop(snode, "backdrop_y", text="Y")
         col.operator("node.backimage_move", text="Move")
+        
+        layout.operator("node.backimage_fit", text="Fit")
 
 
 class NODE_PT_quality(bpy.types.Panel):
index 1a2e90e55225dfc9d6803768d94dfa6a6a70bbf3..6ad0675eadd2727aff927561fe6d9cbfe22c37e8 100644 (file)
@@ -129,6 +129,7 @@ void NODE_OT_view_selected(struct wmOperatorType *ot);
 
 void NODE_OT_backimage_move(struct wmOperatorType *ot);
 void NODE_OT_backimage_zoom(struct wmOperatorType *ot);
+void NODE_OT_backimage_fit(struct wmOperatorType *ot);
 void NODE_OT_backimage_sample(struct wmOperatorType *ot);
 
 /* drawnode.c */
index 566bb1600cc2b307a5f2a31d6e4f103f2b1aaed1..f0d3deb24dfd12f0cf602cdae557fb69e6472a97 100644 (file)
@@ -98,6 +98,7 @@ void node_operatortypes(void)
        
        WM_operatortype_append(NODE_OT_backimage_move);
        WM_operatortype_append(NODE_OT_backimage_zoom);
+       WM_operatortype_append(NODE_OT_backimage_fit);
        WM_operatortype_append(NODE_OT_backimage_sample);
        
        WM_operatortype_append(NODE_OT_add_file);
@@ -249,6 +250,7 @@ void node_keymap(struct wmKeyConfig *keyconf)
        RNA_float_set(kmi->ptr, "factor", 0.83333f);
        kmi = WM_keymap_add_item(keymap, "NODE_OT_backimage_zoom", VKEY, KM_PRESS, KM_ALT, 0);
        RNA_float_set(kmi->ptr, "factor", 1.2f);
+       WM_keymap_add_item(keymap, "NODE_OT_backimage_fit", HOMEKEY, KM_PRESS, KM_ALT, 0);
        WM_keymap_add_item(keymap, "NODE_OT_backimage_sample", ACTIONMOUSE, KM_PRESS, KM_ALT, 0);
 
        kmi = WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, 0, 0);
index 9e6e1e628f6ce92271d53610a5c63fddb61ce384..bd0ba3924dbe50b5b11ca0c9460c4917beff4a8b 100644 (file)
@@ -327,6 +327,60 @@ void NODE_OT_backimage_zoom(wmOperatorType *ot)
        RNA_def_float(ot->srna, "factor", 1.2f, 0.0f, 10.0f, "Factor", "", 0.0f, 10.0f);
 }
 
+static int backimage_fit_exec(bContext *C, wmOperator *op)
+{
+       SpaceNode *snode = CTX_wm_space_node(C);
+       ARegion *ar = CTX_wm_region(C);
+
+       Image *ima;
+       ImBuf *ibuf;
+
+       const float pad = 32.0f;
+
+       void *lock;
+
+       float facx, facy;
+
+       ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
+       ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
+
+       if (ibuf == NULL) {
+               BKE_image_release_ibuf(ima, ibuf, lock);
+               return OPERATOR_CANCELLED;
+       }
+
+       facx = 1.0f * (ar->sizex - pad) / (ibuf->x * snode->zoom);
+       facy = 1.0f * (ar->sizey - pad) / (ibuf->y * snode->zoom);
+
+       BKE_image_release_ibuf(ima, ibuf, lock);
+
+       snode->zoom *= min_ff(facx, facy);
+
+       snode->xof = 0;
+       snode->yof = 0;
+
+       ED_region_tag_redraw(ar);
+
+       return OPERATOR_FINISHED;
+}
+
+void NODE_OT_backimage_fit(wmOperatorType *ot)
+{
+
+       /* identifiers */
+       ot->name = "Background Image Fit";
+       ot->idname = "NODE_OT_backimage_fit";
+       ot->description = "Zoom in/out the background image";
+
+       /* api callbacks */
+       ot->exec = backimage_fit_exec;
+       ot->poll = composite_node_active;
+
+       /* flags */
+       ot->flag = OPTYPE_BLOCKING;
+
+}
+
 /******************** sample backdrop operator ********************/
 
 typedef struct ImageSampleInfo {