Bug 560903 – Explicit zooming with e.g. '1' should handle

zoom-focus better

* app/display/display-enums.h: Added
GIMP_ZOOM_FOCUS_RETAIN_CENTERING_ELSE_BEST_GUESS.

* app/display/gimpdisplayshell-scale.c
(gimp_display_shell_scale_get_zoom_focus): Take the new enum into
account; if the image is centered, keep it centered, else use the
best-guess method.

* app/actions/view-commands.c (view_zoom_explicit_cmd_callback):
Use the new enum for explicit zooming.

* app/display/display-enums.c: Regenerated.

svn path=/trunk/; revision=27653
This commit is contained in:
Martin Nordholts
2008-11-15 10:24:56 +00:00
parent 9089377f32
commit 1dd185c397
5 changed files with 72 additions and 15 deletions

View File

@ -1,3 +1,21 @@
2008-11-15 Martin Nordholts <martinn@svn.gnome.org>
Bug 560903 Explicit zooming with e.g. '1' should handle
zoom-focus better
* app/display/display-enums.h: Added
GIMP_ZOOM_FOCUS_RETAIN_CENTERING_ELSE_BEST_GUESS.
* app/display/gimpdisplayshell-scale.c
(gimp_display_shell_scale_get_zoom_focus): Take the new enum into
account; if the image is centered, keep it centered, else use the
best-guess method.
* app/actions/view-commands.c (view_zoom_explicit_cmd_callback):
Use the new enum for explicit zooming.
* app/display/display-enums.c: Regenerated.
2008-11-15 Martin Nordholts <martinn@svn.gnome.org>
Bug 560245 Zoom selection always centered in the Navigation tab

View File

@ -220,7 +220,7 @@ view_zoom_explicit_cmd_callback (GtkAction *action,
gimp_display_shell_scale (shell,
GIMP_ZOOM_TO,
(gdouble) value / 10000,
GIMP_ZOOM_FOCUS_IMAGE_CENTER);
GIMP_ZOOM_FOCUS_RETAIN_CENTERING_ELSE_BEST_GUESS);
}
}

View File

@ -171,6 +171,7 @@ gimp_zoom_focus_get_type (void)
{ GIMP_ZOOM_FOCUS_BEST_GUESS, "GIMP_ZOOM_FOCUS_BEST_GUESS", "best-guess" },
{ GIMP_ZOOM_FOCUS_POINTER, "GIMP_ZOOM_FOCUS_POINTER", "pointer" },
{ GIMP_ZOOM_FOCUS_IMAGE_CENTER, "GIMP_ZOOM_FOCUS_IMAGE_CENTER", "image-center" },
{ GIMP_ZOOM_FOCUS_RETAIN_CENTERING_ELSE_BEST_GUESS, "GIMP_ZOOM_FOCUS_RETAIN_CENTERING_ELSE_BEST_GUESS", "retain-centering-else-best-guess" },
{ 0, NULL, NULL }
};
@ -179,6 +180,7 @@ gimp_zoom_focus_get_type (void)
{ GIMP_ZOOM_FOCUS_BEST_GUESS, "GIMP_ZOOM_FOCUS_BEST_GUESS", NULL },
{ GIMP_ZOOM_FOCUS_POINTER, "GIMP_ZOOM_FOCUS_POINTER", NULL },
{ GIMP_ZOOM_FOCUS_IMAGE_CENTER, "GIMP_ZOOM_FOCUS_IMAGE_CENTER", NULL },
{ GIMP_ZOOM_FOCUS_RETAIN_CENTERING_ELSE_BEST_GUESS, "GIMP_ZOOM_FOCUS_RETAIN_CENTERING_ELSE_BEST_GUESS", NULL },
{ 0, NULL, NULL }
};

View File

@ -87,9 +87,20 @@ GType gimp_zoom_focus_get_type (void) G_GNUC_CONST;
typedef enum
{
GIMP_ZOOM_FOCUS_BEST_GUESS, /* Make a best guess */
GIMP_ZOOM_FOCUS_POINTER, /* Use the mouse cursor (if within canvas) */
GIMP_ZOOM_FOCUS_IMAGE_CENTER /* Use the image center */
/* Make a best guess */
GIMP_ZOOM_FOCUS_BEST_GUESS,
/* Use the mouse cursor (if within canvas) */
GIMP_ZOOM_FOCUS_POINTER,
/* Use the image center */
GIMP_ZOOM_FOCUS_IMAGE_CENTER,
/* If the image is centered, retain the centering. Else use
* _BEST_GUESS
*/
GIMP_ZOOM_FOCUS_RETAIN_CENTERING_ELSE_BEST_GUESS
} GimpZoomFocus;

View File

@ -61,7 +61,7 @@ static gboolean gimp_display_shell_scale_image_starts_to_fit
gdouble current_scale,
gboolean *vertically,
gboolean *horizontally);
static void gimp_display_shell_scale_viewport_coord_almost_centered
static gboolean gimp_display_shell_scale_viewport_coord_almost_centered
(GimpDisplayShell *shell,
gint x,
gint y,
@ -887,21 +887,28 @@ gimp_display_shell_scale_image_stops_to_fit (GimpDisplayShell *shell,
* @vertically:
*
**/
static void
static gboolean
gimp_display_shell_scale_viewport_coord_almost_centered (GimpDisplayShell *shell,
gint x,
gint y,
gboolean *horizontally,
gboolean *vertically)
{
gint center_x = shell->disp_width / 2;
gint center_y = shell->disp_height / 2;
gboolean local_horizontally;
gboolean local_vertically;
gint center_x = shell->disp_width / 2;
gint center_y = shell->disp_height / 2;
*horizontally = x > center_x - ALMOST_CENTERED_THRESHOLD &&
x < center_x + ALMOST_CENTERED_THRESHOLD;
local_horizontally = (x > center_x - ALMOST_CENTERED_THRESHOLD &&
x < center_x + ALMOST_CENTERED_THRESHOLD);
*vertically = y > center_y - ALMOST_CENTERED_THRESHOLD &&
y < center_y + ALMOST_CENTERED_THRESHOLD;
local_vertically = (y > center_y - ALMOST_CENTERED_THRESHOLD &&
y < center_y + ALMOST_CENTERED_THRESHOLD);
if (horizontally) *horizontally = local_horizontally;
if (vertically) *vertically = local_vertically;
return local_horizontally && local_vertically;
}
static void
@ -937,8 +944,9 @@ gimp_display_shell_scale_get_zoom_focus (GimpDisplayShell *shell,
gint *y,
GimpZoomFocus zoom_focus)
{
gint image_center_x, image_center_y;
gint other_x, other_y;
GimpZoomFocus real_zoom_focus = zoom_focus;
gint image_center_x, image_center_y;
gint other_x, other_y;
/* Calculate stops-to-fit focus point */
gimp_display_shell_scale_get_image_center_viewport (shell,
@ -995,7 +1003,25 @@ gimp_display_shell_scale_get_zoom_focus (GimpDisplayShell *shell,
}
/* Decide which one to use for each axis */
switch (zoom_focus)
if (zoom_focus == GIMP_ZOOM_FOCUS_RETAIN_CENTERING_ELSE_BEST_GUESS)
{
gboolean centered;
centered = gimp_display_shell_scale_viewport_coord_almost_centered (shell,
image_center_x,
image_center_y,
NULL,
NULL);
real_zoom_focus = (centered ?
GIMP_ZOOM_FOCUS_IMAGE_CENTER :
GIMP_ZOOM_FOCUS_BEST_GUESS);
}
else
{
real_zoom_focus = zoom_focus;
}
switch (real_zoom_focus)
{
case GIMP_ZOOM_FOCUS_POINTER:
*x = other_x;