Patch #36622, by Henrik Aarnio: Fit backdrop image to the area dimensions.

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.
This commit is contained in:
Lukas Toenne
2013-09-01 09:50:56 +00:00
parent fe427f0561
commit 2b6d2bf322
4 changed files with 60 additions and 0 deletions

View 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):

View 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 */

View 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);

View 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 {