diff --git a/ChangeLog b/ChangeLog index f5300eb39f..8228bb8a31 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2008-08-10 Martin Nordholts + + 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 Bug #545990: GIMP color wheel is not antialiased diff --git a/app/display/gimpdisplayshell-handlers.c b/app/display/gimpdisplayshell-handlers.c index dfc2366fb8..05ebd69442 100644 --- a/app/display/gimpdisplayshell-handlers.c +++ b/app/display/gimpdisplayshell-handlers.c @@ -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 { diff --git a/app/display/gimpdisplayshell-scale.c b/app/display/gimpdisplayshell-scale.c index cf44df71bb..a98201809a 100644 --- a/app/display/gimpdisplayshell-scale.c +++ b/app/display/gimpdisplayshell-scale.c @@ -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); } /** diff --git a/app/display/gimpdisplayshell-scale.h b/app/display/gimpdisplayshell-scale.h index 094e339ddf..8509b2db2d 100644 --- a/app/display/gimpdisplayshell-scale.h +++ b/app/display/gimpdisplayshell-scale.h @@ -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, diff --git a/app/display/gimpdisplayshell-scroll.c b/app/display/gimpdisplayshell-scroll.c index 0d5979288c..c94990c7cd 100644 --- a/app/display/gimpdisplayshell-scroll.c +++ b/app/display/gimpdisplayshell-scroll.c @@ -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: diff --git a/app/display/gimpdisplayshell-scroll.h b/app/display/gimpdisplayshell-scroll.h index 261e4aa014..4f36093263 100644 --- a/app/display/gimpdisplayshell-scroll.h +++ b/app/display/gimpdisplayshell-scroll.h @@ -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, diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c index c38dcefb51..0a06abc5d9 100644 --- a/app/display/gimpdisplayshell.c +++ b/app/display/gimpdisplayshell.c @@ -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,