Allow to choose what axes to center on.
2008-07-13 Martin Nordholts <martinn@svn.gnome.org> * app/display/gimpdisplayshell-scale.[ch] (gimp_display_shell_center_image): Allow to choose what axes to center on. (gimp_display_shell_scale_fill) (gimp_display_shell_scale_fit_in): Explicitly center on both axes. * app/display/gimpdisplayshell.c (gimp_display_shell_fill): Center the image in the filled display shell. Rather hackish, but seems to work fine. svn path=/trunk/; revision=26185
This commit is contained in:

committed by
Martin Nordholts

parent
f56bc8493f
commit
805a3f5f8b
13
ChangeLog
13
ChangeLog
@ -1,3 +1,16 @@
|
|||||||
|
2008-07-13 Martin Nordholts <martinn@svn.gnome.org>
|
||||||
|
|
||||||
|
* app/display/gimpdisplayshell-scale.[ch]
|
||||||
|
(gimp_display_shell_center_image): Allow to choose what axes to
|
||||||
|
center on.
|
||||||
|
|
||||||
|
(gimp_display_shell_scale_fill)
|
||||||
|
(gimp_display_shell_scale_fit_in): Explicitly center on both axes.
|
||||||
|
|
||||||
|
* app/display/gimpdisplayshell.c (gimp_display_shell_fill): Center
|
||||||
|
the image in the filled display shell. Rather hackish, but seems
|
||||||
|
to work fine.
|
||||||
|
|
||||||
2008-07-13 Sven Neumann <sven@gimp.org>
|
2008-07-13 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* app/widgets/Makefile.am
|
* app/widgets/Makefile.am
|
||||||
|
@ -431,7 +431,7 @@ gimp_display_shell_scale_fit_in (GimpDisplayShell *shell)
|
|||||||
(gdouble) shell->disp_height / (gdouble) image_height);
|
(gdouble) shell->disp_height / (gdouble) image_height);
|
||||||
|
|
||||||
gimp_display_shell_scale (shell, GIMP_ZOOM_TO, zoom_factor);
|
gimp_display_shell_scale (shell, GIMP_ZOOM_TO, zoom_factor);
|
||||||
gimp_display_shell_center_image (shell);
|
gimp_display_shell_center_image (shell, TRUE, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -470,18 +470,22 @@ gimp_display_shell_scale_fill (GimpDisplayShell *shell)
|
|||||||
(gdouble) shell->disp_height / (gdouble) image_height);
|
(gdouble) shell->disp_height / (gdouble) image_height);
|
||||||
|
|
||||||
gimp_display_shell_scale (shell, GIMP_ZOOM_TO, zoom_factor);
|
gimp_display_shell_scale (shell, GIMP_ZOOM_TO, zoom_factor);
|
||||||
gimp_display_shell_center_image (shell);
|
gimp_display_shell_center_image (shell, TRUE, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gimp_display_shell_center_image:
|
* gimp_display_shell_center_image:
|
||||||
* @shell:
|
* @shell:
|
||||||
|
* @horizontally:
|
||||||
|
* @vertically:
|
||||||
*
|
*
|
||||||
* Centers the image in the display shell.
|
* Centers the image in the display shell on the desired axes.
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
void
|
void
|
||||||
gimp_display_shell_center_image (GimpDisplayShell *shell)
|
gimp_display_shell_center_image (GimpDisplayShell *shell,
|
||||||
|
gboolean horizontally,
|
||||||
|
gboolean vertically)
|
||||||
{
|
{
|
||||||
gint sw, sh;
|
gint sw, sh;
|
||||||
gint target_offset_x, target_offset_y;
|
gint target_offset_x, target_offset_y;
|
||||||
@ -491,24 +495,33 @@ gimp_display_shell_center_image (GimpDisplayShell *shell)
|
|||||||
if (! shell->display)
|
if (! shell->display)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
target_offset_x = shell->offset_x;
|
||||||
|
target_offset_y = shell->offset_y;
|
||||||
|
|
||||||
gimp_display_shell_get_scaled_image_size (shell, &sw, &sh);
|
gimp_display_shell_get_scaled_image_size (shell, &sw, &sh);
|
||||||
|
|
||||||
if (sw < shell->disp_width)
|
if (horizontally)
|
||||||
{
|
{
|
||||||
target_offset_x = -(shell->disp_width - sw) / 2;
|
if (sw < shell->disp_width)
|
||||||
}
|
{
|
||||||
else
|
target_offset_x = -(shell->disp_width - sw) / 2;
|
||||||
{
|
}
|
||||||
target_offset_x = (sw - shell->disp_width) / 2;
|
else
|
||||||
|
{
|
||||||
|
target_offset_x = (sw - shell->disp_width) / 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sh < shell->disp_height)
|
if (vertically)
|
||||||
{
|
{
|
||||||
target_offset_y = -(shell->disp_height - sh) / 2;
|
if (sh < shell->disp_height)
|
||||||
}
|
{
|
||||||
else
|
target_offset_y = -(shell->disp_height - sh) / 2;
|
||||||
{
|
}
|
||||||
target_offset_y = (sh - shell->disp_height) / 2;
|
else
|
||||||
|
{
|
||||||
|
target_offset_y = (sh - shell->disp_height) / 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Note that we can't use gimp_display_shell_scroll_private() here
|
/* Note that we can't use gimp_display_shell_scroll_private() here
|
||||||
|
@ -38,7 +38,9 @@ void gimp_display_shell_scale_to (GimpDisplayShell *shell,
|
|||||||
gdouble y);
|
gdouble y);
|
||||||
void gimp_display_shell_scale_fit_in (GimpDisplayShell *shell);
|
void gimp_display_shell_scale_fit_in (GimpDisplayShell *shell);
|
||||||
void gimp_display_shell_scale_fill (GimpDisplayShell *shell);
|
void gimp_display_shell_scale_fill (GimpDisplayShell *shell);
|
||||||
void gimp_display_shell_center_image (GimpDisplayShell *shell);
|
void gimp_display_shell_center_image (GimpDisplayShell *shell,
|
||||||
|
gboolean horizontally,
|
||||||
|
gboolean vertically);
|
||||||
void gimp_display_shell_scale_by_values (GimpDisplayShell *shell,
|
void gimp_display_shell_scale_by_values (GimpDisplayShell *shell,
|
||||||
gdouble scale,
|
gdouble scale,
|
||||||
gint offset_x,
|
gint offset_x,
|
||||||
|
@ -1316,6 +1316,35 @@ gimp_display_shell_empty (GimpDisplayShell *shell)
|
|||||||
gimp_ui_manager_update (shell->popup_manager, shell->display);
|
gimp_ui_manager_update (shell->popup_manager, shell->display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gimp_display_shell_center_image_callback (GimpDisplayShell *shell,
|
||||||
|
GtkAllocation *allocation,
|
||||||
|
GtkWidget *canvas)
|
||||||
|
{
|
||||||
|
gint sw, sh;
|
||||||
|
gboolean center_horizontally;
|
||||||
|
gboolean center_vertically;
|
||||||
|
|
||||||
|
gimp_display_shell_get_scaled_image_size (shell, &sw, &sh);
|
||||||
|
|
||||||
|
/* We only want to center on the axes on which the image is smaller
|
||||||
|
* than the display canvas. If it is larger, it will be centered on
|
||||||
|
* that axis later, and if we center on all axis unconditionally, we
|
||||||
|
* end up with the wrong centering if the image is larger than the
|
||||||
|
* display canvas.
|
||||||
|
*/
|
||||||
|
center_horizontally = sw < shell->disp_width;
|
||||||
|
center_vertically = sh < shell->disp_height;
|
||||||
|
|
||||||
|
gimp_display_shell_center_image (shell,
|
||||||
|
center_horizontally,
|
||||||
|
center_vertically);
|
||||||
|
|
||||||
|
g_signal_handlers_disconnect_by_func (canvas,
|
||||||
|
gimp_display_shell_center_image_callback,
|
||||||
|
shell);
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gimp_display_shell_fill_idle (GimpDisplayShell *shell)
|
gimp_display_shell_fill_idle (GimpDisplayShell *shell)
|
||||||
{
|
{
|
||||||
@ -1351,6 +1380,15 @@ gimp_display_shell_fill (GimpDisplayShell *shell,
|
|||||||
|
|
||||||
gimp_help_set_help_data (shell->canvas, NULL, NULL);
|
gimp_help_set_help_data (shell->canvas, NULL, NULL);
|
||||||
|
|
||||||
|
/* Not pretty, but we need to center the image as soon as the canvas
|
||||||
|
* has got its new size allocated. The centering will be wrong if we
|
||||||
|
* do it too early, and if we do it too late flickering will occur
|
||||||
|
* due to the image being rendered twice.
|
||||||
|
*/
|
||||||
|
g_signal_connect_swapped (shell->canvas, "size-allocate",
|
||||||
|
G_CALLBACK (gimp_display_shell_center_image_callback),
|
||||||
|
shell);
|
||||||
|
|
||||||
shell->fill_idle_id = g_idle_add_full (G_PRIORITY_LOW,
|
shell->fill_idle_id = g_idle_add_full (G_PRIORITY_LOW,
|
||||||
(GSourceFunc) gimp_display_shell_fill_idle,
|
(GSourceFunc) gimp_display_shell_fill_idle,
|
||||||
shell, NULL);
|
shell, NULL);
|
||||||
|
Reference in New Issue
Block a user