Put functions to center the image in the display shell where they belong,

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

	Put functions to center the image in the display shell where they
	belong, and give them proper names.

	* app/display/gimpdisplayshell-scale.[ch]: Get rid of functions
	and use the new names.

	* app/display/gimpdisplayshell-scroll.[ch]: Put the functions here
	and call them gimp_display_shell_scroll_center_image() and
	gimp_display_shell_scroll_center_image_on_next_size_allocate().

	* app/display/gimpdisplayshell.c:
	* app/display/gimpdisplayshell-handlers.c: Use the new names.

svn path=/trunk/; revision=26470
This commit is contained in:
Martin Nordholts 2008-08-10 07:23:14 +00:00 committed by Martin Nordholts
parent f05da183c7
commit a736df49e2
7 changed files with 119 additions and 102 deletions

View File

@ -1,3 +1,18 @@
2008-08-10 Martin Nordholts <martinn@svn.gnome.org>
Put functions to center the image in the display shell where they
belong, and give them proper names.
* app/display/gimpdisplayshell-scale.[ch]: Get rid of functions
and use the new names.
* app/display/gimpdisplayshell-scroll.[ch]: Put the functions here
and call them gimp_display_shell_scroll_center_image() and
gimp_display_shell_scroll_center_image_on_next_size_allocate().
* app/display/gimpdisplayshell.c:
* app/display/gimpdisplayshell-handlers.c: Use the new names.
2008-08-08 Michael Natterer <mitch@gimp.org>
Bug #545990: GIMP color wheel is not antialiased

View File

@ -492,7 +492,7 @@ gimp_display_shell_size_changed_detailed_handler (GimpImage *image,
* has change size
*/
gimp_display_shell_shrink_wrap (shell, FALSE);
gimp_display_shell_center_image_on_next_size_allocate (shell);
gimp_display_shell_scroll_center_image_on_next_size_allocate (shell);
}
else
{

View File

@ -452,7 +452,7 @@ gimp_display_shell_scale_fit_in (GimpDisplayShell *shell)
(gdouble) shell->disp_height / (gdouble) image_height);
gimp_display_shell_scale (shell, GIMP_ZOOM_TO, zoom_factor);
gimp_display_shell_center_image (shell, TRUE, TRUE);
gimp_display_shell_scroll_center_image (shell, TRUE, TRUE);
}
/**
@ -491,97 +491,7 @@ gimp_display_shell_scale_fill (GimpDisplayShell *shell)
(gdouble) shell->disp_height / (gdouble) image_height);
gimp_display_shell_scale (shell, GIMP_ZOOM_TO, zoom_factor);
gimp_display_shell_center_image (shell, TRUE, TRUE);
}
/**
* gimp_display_shell_center_image:
* @shell:
* @horizontally:
* @vertically:
*
* Centers the image in the display shell on the desired axes.
*
**/
void
gimp_display_shell_center_image (GimpDisplayShell *shell,
gboolean horizontally,
gboolean vertically)
{
gint sw, sh;
gint target_offset_x, target_offset_y;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
if (! shell->display)
return;
target_offset_x = shell->offset_x;
target_offset_y = shell->offset_y;
gimp_display_shell_get_scaled_image_size (shell, &sw, &sh);
if (horizontally)
{
if (sw < shell->disp_width)
{
target_offset_x = -(shell->disp_width - sw) / 2;
}
else
{
target_offset_x = (sw - shell->disp_width) / 2;
}
}
if (vertically)
{
if (sh < shell->disp_height)
{
target_offset_y = -(shell->disp_height - sh) / 2;
}
else
{
target_offset_y = (sh - shell->disp_height) / 2;
}
}
/* Note that we can't use gimp_display_shell_scroll_private() here
* because that would expose the image twice, causing unwanted
* flicker.
*/
gimp_display_shell_scale_by_values (shell, gimp_zoom_model_get_factor (shell->zoom),
target_offset_x, target_offset_y,
FALSE);
}
static void
gimp_display_shell_size_allocate_center_image_callback (GimpDisplayShell *shell,
GtkAllocation *allocation,
GtkWidget *canvas)
{
gimp_display_shell_center_image (shell, TRUE, TRUE);
g_signal_handlers_disconnect_by_func (canvas,
gimp_display_shell_size_allocate_center_image_callback,
shell);
}
/**
* gimp_display_shell_center_image_on_next_size_allocate:
* @shell:
*
* Centers the image in the display as soon as the canvas has got its
* new size
*
**/
void
gimp_display_shell_center_image_on_next_size_allocate (GimpDisplayShell *shell)
{
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_signal_connect_swapped (shell->canvas, "size-allocate",
G_CALLBACK (gimp_display_shell_size_allocate_center_image_callback),
shell);
gimp_display_shell_scroll_center_image (shell, TRUE, TRUE);
}
/**

View File

@ -38,11 +38,6 @@ void gimp_display_shell_scale_to (GimpDisplayShell *shell,
gdouble y);
void gimp_display_shell_scale_fit_in (GimpDisplayShell *shell);
void gimp_display_shell_scale_fill (GimpDisplayShell *shell);
void gimp_display_shell_center_image (GimpDisplayShell *shell,
gboolean horizontally,
gboolean vertically);
void gimp_display_shell_center_image_on_next_size_allocate
(GimpDisplayShell *shell);
void gimp_display_shell_scale_by_values (GimpDisplayShell *shell,
gdouble scale,
gint offset_x,

View File

@ -204,6 +204,96 @@ gimp_display_shell_scroll_clamp_offsets (GimpDisplayShell *shell)
}
}
/**
* gimp_display_shell_scroll_center_image:
* @shell:
* @horizontally:
* @vertically:
*
* Centers the image in the display shell on the desired axes.
*
**/
void
gimp_display_shell_scroll_center_image (GimpDisplayShell *shell,
gboolean horizontally,
gboolean vertically)
{
gint sw, sh;
gint target_offset_x, target_offset_y;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
if (! shell->display)
return;
target_offset_x = shell->offset_x;
target_offset_y = shell->offset_y;
gimp_display_shell_get_scaled_image_size (shell, &sw, &sh);
if (horizontally)
{
if (sw < shell->disp_width)
{
target_offset_x = -(shell->disp_width - sw) / 2;
}
else
{
target_offset_x = (sw - shell->disp_width) / 2;
}
}
if (vertically)
{
if (sh < shell->disp_height)
{
target_offset_y = -(shell->disp_height - sh) / 2;
}
else
{
target_offset_y = (sh - shell->disp_height) / 2;
}
}
/* Note that we can't use gimp_display_shell_scroll_private() here
* because that would expose the image twice, causing unwanted
* flicker.
*/
gimp_display_shell_scale_by_values (shell, gimp_zoom_model_get_factor (shell->zoom),
target_offset_x, target_offset_y,
FALSE);
}
static void
gimp_display_shell_scroll_center_image_callback (GimpDisplayShell *shell,
GtkAllocation *allocation,
GtkWidget *canvas)
{
gimp_display_shell_scroll_center_image (shell, TRUE, TRUE);
g_signal_handlers_disconnect_by_func (canvas,
gimp_display_shell_scroll_center_image_callback,
shell);
}
/**
* gimp_display_shell_scroll_center_image_on_next_size_allocate:
* @shell:
*
* Centers the image in the display as soon as the canvas has got its
* new size
*
**/
void
gimp_display_shell_scroll_center_image_on_next_size_allocate (GimpDisplayShell *shell)
{
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
g_signal_connect_swapped (shell->canvas, "size-allocate",
G_CALLBACK (gimp_display_shell_scroll_center_image_callback),
shell);
}
/**
* gimp_display_shell_get_scaled_viewport:
* @shell:

View File

@ -26,6 +26,13 @@ void gimp_display_shell_center_around_image_coordinate (GimpDisplayShell
void gimp_display_shell_scroll_clamp_offsets (GimpDisplayShell *shell);
void gimp_display_shell_scroll_center_image (GimpDisplayShell *shell,
gboolean horizontally,
gboolean vertically);
void gimp_display_shell_scroll_center_image_on_next_size_allocate
(GimpDisplayShell *shell);
void gimp_display_shell_get_scaled_viewport (const GimpDisplayShell *shell,
gint *x,
gint *y,

View File

@ -1206,7 +1206,7 @@ gimp_display_shell_new (GimpDisplay *display,
gimp_display_shell_connect (shell);
/* after connecting to the image we want to center it */
gimp_display_shell_center_image_on_next_size_allocate (shell);
gimp_display_shell_scroll_center_image_on_next_size_allocate (shell);
}
else
{
@ -1345,9 +1345,9 @@ gimp_display_shell_center_image_callback (GimpDisplayShell *shell,
center_horizontally = sw < shell->disp_width;
center_vertically = sh < shell->disp_height;
gimp_display_shell_center_image (shell,
center_horizontally,
center_vertically);
gimp_display_shell_scroll_center_image (shell,
center_horizontally,
center_vertically);
g_signal_handlers_disconnect_by_func (canvas,
gimp_display_shell_center_image_callback,