diff options
author | Lukas Toenne <lukas.toenne@googlemail.com> | 2013-09-01 13:50:56 +0400 |
---|---|---|
committer | Lukas Toenne <lukas.toenne@googlemail.com> | 2013-09-01 13:50:56 +0400 |
commit | 2b6d2bf322f9eb26661939d7b84c7f47417cebb7 (patch) | |
tree | 0841d01a440493451f399b399a97c46ab00716ca /source/blender/editors/space_node/node_view.c | |
parent | fe427f056186d6ac932d075c58f522e878ae6536 (diff) |
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.
Diffstat (limited to 'source/blender/editors/space_node/node_view.c')
-rw-r--r-- | source/blender/editors/space_node/node_view.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/source/blender/editors/space_node/node_view.c b/source/blender/editors/space_node/node_view.c index 9e6e1e628f6..bd0ba3924db 100644 --- a/source/blender/editors/space_node/node_view.c +++ b/source/blender/editors/space_node/node_view.c @@ -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 { |