New function.

2008-08-13  Martin Nordholts  <martinn@svn.gnome.org>

	* app/display/gimpdisplayshell-scale.c
	(gimp_display_shell_scale_image_is_within_viewport): New function.

	* app/display/gimpdisplayshell.c (gimp_display_shell_new): When
	the zoom button is toggled, implicitly do a View -> Fit Image in
	Window if the (scaled) image is within the viewport.

svn path=/trunk/; revision=26529
This commit is contained in:
Martin Nordholts 2008-08-13 17:36:29 +00:00 committed by Martin Nordholts
parent a9bb68a248
commit 47b34e973d
4 changed files with 84 additions and 34 deletions

View File

@ -1,3 +1,12 @@
2008-08-13 Martin Nordholts <martinn@svn.gnome.org>
* app/display/gimpdisplayshell-scale.c
(gimp_display_shell_scale_image_is_within_viewport): New function.
* app/display/gimpdisplayshell.c (gimp_display_shell_new): When
the zoom button is toggled, implicitly do a View -> Fit Image in
Window if the (scaled) image is within the viewport.
2008-08-13 Martin Nordholts <martinn@svn.gnome.org>
* app/paint/gimppaintcore.c: Include gimpprojection.h for

View File

@ -38,6 +38,7 @@
#include "gimpdisplay.h"
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-draw.h"
#include "gimpdisplayshell-scale.h"
#include "gimpdisplayshell-scroll.h"
#include "gimpdisplayshell-title.h"
@ -445,6 +446,30 @@ gimp_display_shell_scale_fit_in (GimpDisplayShell *shell)
gimp_display_shell_scroll_center_image (shell, TRUE, TRUE);
}
/**
* gimp_display_shell_scale_image_is_within_viewport:
* @shell:
*
* Returns: %TRUE if the (scaled) image is smaller than and within the
* viewport.
**/
gboolean
gimp_display_shell_scale_image_is_within_viewport (GimpDisplayShell *shell)
{
gint sw, sh;
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
gimp_display_shell_draw_get_scaled_image_size (shell, &sw, &sh);
return sw < shell->disp_width &&
sh < shell->disp_height &&
shell->offset_x < 0 &&
shell->offset_y < 0 &&
shell->offset_x > sw - shell->disp_width &&
shell->offset_y > sh - shell->disp_height;
}
/**
* gimp_display_shell_scale_fill:
* @shell: the #GimpDisplayShell

View File

@ -20,42 +20,43 @@
#define __GIMP_DISPLAY_SHELL_SCALE_H__
void gimp_display_shell_update_scrollbars_and_rulers (GimpDisplayShell *shell);
void gimp_display_shell_update_scrollbars_and_rulers (GimpDisplayShell *shell);
gboolean gimp_display_shell_scale_revert (GimpDisplayShell *shell);
gboolean gimp_display_shell_scale_can_revert (GimpDisplayShell *shell);
gboolean gimp_display_shell_scale_revert (GimpDisplayShell *shell);
gboolean gimp_display_shell_scale_can_revert (GimpDisplayShell *shell);
void gimp_display_shell_scale_set_dot_for_dot (GimpDisplayShell *shell,
gboolean dot_for_dot);
void gimp_display_shell_scale_set_dot_for_dot (GimpDisplayShell *shell,
gboolean dot_for_dot);
void gimp_display_shell_scale (GimpDisplayShell *shell,
GimpZoomType zoom_type,
gdouble scale);
void gimp_display_shell_scale_to (GimpDisplayShell *shell,
GimpZoomType zoom_type,
gdouble scale,
gdouble x,
gdouble y);
void gimp_display_shell_scale_fit_in (GimpDisplayShell *shell);
void gimp_display_shell_scale_fill (GimpDisplayShell *shell);
void gimp_display_shell_scale_handle_zoom_revert (GimpDisplayShell *shell);
void gimp_display_shell_scale_by_values (GimpDisplayShell *shell,
gdouble scale,
gint offset_x,
gint offset_y,
gboolean resize_window);
void gimp_display_shell_scale_shrink_wrap (GimpDisplayShell *shell,
gboolean grow_only);
void gimp_display_shell_scale (GimpDisplayShell *shell,
GimpZoomType zoom_type,
gdouble scale);
void gimp_display_shell_scale_to (GimpDisplayShell *shell,
GimpZoomType zoom_type,
gdouble scale,
gdouble x,
gdouble y);
void gimp_display_shell_scale_fit_in (GimpDisplayShell *shell);
gboolean gimp_display_shell_scale_image_is_within_viewport (GimpDisplayShell *shell);
void gimp_display_shell_scale_fill (GimpDisplayShell *shell);
void gimp_display_shell_scale_handle_zoom_revert (GimpDisplayShell *shell);
void gimp_display_shell_scale_by_values (GimpDisplayShell *shell,
gdouble scale,
gint offset_x,
gint offset_y,
gboolean resize_window);
void gimp_display_shell_scale_shrink_wrap (GimpDisplayShell *shell,
gboolean grow_only);
void gimp_display_shell_scale_resize (GimpDisplayShell *shell,
gboolean resize_window,
gboolean grow_only);
void gimp_display_shell_set_initial_scale (GimpDisplayShell *shell,
gdouble scale,
gint *display_width,
gint *display_height);
void gimp_display_shell_scale_resize (GimpDisplayShell *shell,
gboolean resize_window,
gboolean grow_only);
void gimp_display_shell_set_initial_scale (GimpDisplayShell *shell,
gdouble scale,
gint *display_width,
gint *display_height);
void gimp_display_shell_scale_dialog (GimpDisplayShell *shell);
void gimp_display_shell_scale_dialog (GimpDisplayShell *shell);
#endif /* __GIMP_DISPLAY_SHELL_SCALE_H__ */

View File

@ -718,6 +718,21 @@ gimp_display_shell_get_icc_profile (GimpColorManaged *managed,
return NULL;
}
static void
gimp_display_shell_zoom_button_callback (GimpDisplayShell *shell,
GtkWidget *zoom_button)
{
shell->zoom_on_resize =
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (zoom_button));
if (shell->zoom_on_resize &&
gimp_display_shell_scale_image_is_within_viewport (shell))
{
/* Implicitly make a View -> Fit Image in Window */
gimp_display_shell_scale_fit_in (shell);
}
}
/* public functions */
@ -1079,9 +1094,9 @@ gimp_display_shell_new (GimpDisplay *display,
_("Zoom image when window size changes"),
GIMP_HELP_IMAGE_WINDOW_ZOOM_FOLLOW_BUTTON);
g_signal_connect (shell->zoom_button, "toggled",
G_CALLBACK (gimp_toggle_button_update),
&shell->zoom_on_resize);
g_signal_connect_swapped (shell->zoom_button, "toggled",
G_CALLBACK (gimp_display_shell_zoom_button_callback),
shell);
/* create the contents of the lower_hbox *********************************/