Added option to fit frame to the whole clip editor viewport instead of zooming
to a power-of-two factor. Shortcut is F.
This commit is contained in:
@@ -649,12 +649,14 @@ void CLIP_OT_view_zoom_ratio(wmOperatorType *ot)
|
||||
|
||||
/********************** view all operator *********************/
|
||||
|
||||
static int view_all_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
static int view_all_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
SpaceClip *sc;
|
||||
ARegion *ar;
|
||||
int w, h, width, height;
|
||||
float aspx, aspy;
|
||||
int fit_view= RNA_boolean_get(op->ptr, "fit_view");
|
||||
float zoomx, zoomy;
|
||||
|
||||
/* retrieve state */
|
||||
sc= CTX_wm_space_clip(C);
|
||||
@@ -670,16 +672,25 @@ static int view_all_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
width= ar->winrct.xmax - ar->winrct.xmin + 1;
|
||||
height= ar->winrct.ymax - ar->winrct.ymin + 1;
|
||||
|
||||
if((w >= width || h >= height) && (width > 0 && height > 0)) {
|
||||
float zoomx, zoomy;
|
||||
if(fit_view) {
|
||||
const int margin = 5; /* margin from border */
|
||||
|
||||
/* find the zoom value that will fit the image in the image space */
|
||||
zoomx= (float)width/w;
|
||||
zoomy= (float)height/h;
|
||||
sclip_zoom_set(sc, ar, 1.0f/power_of_2(1/MIN2(zoomx, zoomy)), NULL);
|
||||
zoomx= (float)width / (w + 2*margin);
|
||||
zoomy= (float)height / (h + 2*margin);
|
||||
|
||||
sclip_zoom_set(sc, ar, MIN2(zoomx, zoomy), NULL);
|
||||
}
|
||||
else {
|
||||
if((w >= width || h >= height) && (width > 0 && height > 0)) {
|
||||
zoomx= (float)width/w;
|
||||
zoomy= (float)height/h;
|
||||
|
||||
/* find the zoom value that will fit the image in the image space */
|
||||
sclip_zoom_set(sc, ar, 1.0f/power_of_2(1/MIN2(zoomx, zoomy)), NULL);
|
||||
}
|
||||
else
|
||||
sclip_zoom_set(sc, ar, 1.0f, NULL);
|
||||
}
|
||||
else
|
||||
sclip_zoom_set(sc, ar, 1.0f, NULL);
|
||||
|
||||
sc->xof= sc->yof= 0.0f;
|
||||
|
||||
@@ -697,6 +708,9 @@ void CLIP_OT_view_all(wmOperatorType *ot)
|
||||
/* api callbacks */
|
||||
ot->exec= view_all_exec;
|
||||
ot->poll= ED_space_clip_poll;
|
||||
|
||||
/* properties */
|
||||
RNA_def_boolean(ot->srna, "fit_view", 0, "Fit View", "Fit frame to the viewport");
|
||||
}
|
||||
|
||||
/********************** view selected operator *********************/
|
||||
|
||||
@@ -461,6 +461,10 @@ static void clip_keymap(struct wmKeyConfig *keyconf)
|
||||
RNA_float_set(WM_keymap_add_item(keymap, "CLIP_OT_view_zoom_ratio", PAD8, KM_PRESS, 0, 0)->ptr, "ratio", 0.125f);
|
||||
|
||||
WM_keymap_add_item(keymap, "CLIP_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
|
||||
|
||||
kmi = WM_keymap_add_item(keymap, "CLIP_OT_view_all", FKEY, KM_PRESS, 0, 0);
|
||||
RNA_boolean_set(kmi->ptr, "fit_view", TRUE);
|
||||
|
||||
WM_keymap_add_item(keymap, "CLIP_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
|
||||
|
||||
/* jump to special frame */
|
||||
|
||||
Reference in New Issue
Block a user