Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDalai Felinto <dfelinto@gmail.com>2013-08-21 03:40:46 +0400
committerDalai Felinto <dfelinto@gmail.com>2013-08-21 03:40:46 +0400
commit0b0540db3a7c08a1d28653dc8e601e119743e22b (patch)
tree2d097967f8791b7557374dc4252922e2b04d4fa8 /source/blender/editors/space_image
parenta47db8fff6b98f888e549493917ae27e30852f54 (diff)
Image Editor: implement FKey to call 'View All' with 'fit_view'
This mimics the behaviour we have in the Clip Editor. I personally would prefer if we had no border once in fullscreen (current border is 5 pixels). I will consult Sergey Sharybin first to see if we can change that in the clip editor as well (though there I believe the border is useful - the bottom of the editor is used to indicate 'tracked' frames.
Diffstat (limited to 'source/blender/editors/space_image')
-rw-r--r--source/blender/editors/space_image/image_ops.c34
-rw-r--r--source/blender/editors/space_image/space_image.c4
2 files changed, 30 insertions, 8 deletions
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 2da3f3adb67..301b7b99f38 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -646,12 +646,13 @@ void IMAGE_OT_view_ndof(wmOperatorType *ot)
* Default behavior is to reset the position of the image and set the zoom to 1
* If the image will not fit within the window rectangle, the zoom is adjusted */
-static int image_view_all_exec(bContext *C, wmOperator *UNUSED(op))
+static int image_view_all_exec(bContext *C, wmOperator *op)
{
SpaceImage *sima;
ARegion *ar;
float aspx, aspy, zoomx, zoomy, w, h;
int width, height;
+ int fit_view = RNA_boolean_get(op->ptr, "fit_view");
/* retrieve state */
sima = CTX_wm_space_image(C);
@@ -667,14 +668,25 @@ static int image_view_all_exec(bContext *C, wmOperator *UNUSED(op))
width = BLI_rcti_size_x(&ar->winrct) + 1;
height = BLI_rcti_size_y(&ar->winrct) + 1;
- if ((w >= width || h >= height) && (width > 0 && height > 0)) {
- /* find the zoom value that will fit the image in the image space */
- zoomx = width / w;
- zoomy = height / h;
- sima_zoom_set(sima, ar, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), NULL);
+ if (fit_view) {
+ const int margin = 5; /* margin from border */
+
+ zoomx = (float) width / (w + 2 * margin);
+ zoomy = (float) height / (h + 2 * margin);
+
+ sima_zoom_set(sima, ar, min_ff(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 */
+ sima_zoom_set(sima, ar, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), NULL);
+ }
+ else
+ sima_zoom_set(sima, ar, 1.0f, NULL);
}
- else
- sima_zoom_set(sima, ar, 1.0f, NULL);
sima->xof = sima->yof = 0.0f;
@@ -685,6 +697,8 @@ static int image_view_all_exec(bContext *C, wmOperator *UNUSED(op))
void IMAGE_OT_view_all(wmOperatorType *ot)
{
+ PropertyRNA *prop;
+
/* identifiers */
ot->name = "View All";
ot->idname = "IMAGE_OT_view_all";
@@ -693,6 +707,10 @@ void IMAGE_OT_view_all(wmOperatorType *ot)
/* api callbacks */
ot->exec = image_view_all_exec;
ot->poll = space_image_main_area_poll;
+
+ /* properties */
+ prop = RNA_def_boolean(ot->srna, "fit_view", 0, "Fit View", "Fit frame to the viewport");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
/********************** view selected operator *********************/
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index c0ef59e9e25..693da62c2be 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -277,6 +277,10 @@ static void image_keymap(struct wmKeyConfig *keyconf)
keymap = WM_keymap_find(keyconf, "Image", SPACE_IMAGE, 0);
WM_keymap_add_item(keymap, "IMAGE_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
+
+ kmi = WM_keymap_add_item(keymap, "IMAGE_OT_view_all", FKEY, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "fit_view", TRUE);
+
WM_keymap_add_item(keymap, "IMAGE_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);