[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44643] trunk/blender/source/blender/ editors/space_clip: Added option to fit frame to the whole clip editor viewport instead of zooming

Sergey Sharybin sergey.vfx at gmail.com
Sun Mar 4 22:03:06 CET 2012


Revision: 44643
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44643
Author:   nazgul
Date:     2012-03-04 21:02:58 +0000 (Sun, 04 Mar 2012)
Log Message:
-----------
Added option to fit frame to the whole clip editor viewport instead of zooming
to a power-of-two factor. Shortcut is F.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_clip/clip_ops.c
    trunk/blender/source/blender/editors/space_clip/space_clip.c

Modified: trunk/blender/source/blender/editors/space_clip/clip_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_clip/clip_ops.c	2012-03-04 20:44:09 UTC (rev 44642)
+++ trunk/blender/source/blender/editors/space_clip/clip_ops.c	2012-03-04 21:02:58 UTC (rev 44643)
@@ -649,12 +649,14 @@
 
 /********************** 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,17 +672,26 @@
 	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
-		sclip_zoom_set(sc, ar, 1.0f, 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);
+	}
+
 	sc->xof= sc->yof= 0.0f;
 
 	ED_region_tag_redraw(CTX_wm_region(C));
@@ -697,6 +708,9 @@
 	/* 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 *********************/

Modified: trunk/blender/source/blender/editors/space_clip/space_clip.c
===================================================================
--- trunk/blender/source/blender/editors/space_clip/space_clip.c	2012-03-04 20:44:09 UTC (rev 44642)
+++ trunk/blender/source/blender/editors/space_clip/space_clip.c	2012-03-04 21:02:58 UTC (rev 44643)
@@ -461,6 +461,10 @@
 	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 */




More information about the Bf-blender-cvs mailing list