/** * 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 || ! gimp_display_get_image (shell->display) || (! vertically && ! horizontally)) return; target_offset_x = shell->offset_x; target_offset_y = shell->offset_y; gimp_display_shell_scale_get_image_size (shell, &sw, &sh); if (horizontally) { target_offset_x = (sw - shell->disp_width) / 2; } if (vertically) { target_offset_y = (sh - shell->disp_height) / 2; } gimp_display_shell_scroll_set_offset (shell, target_offset_x, target_offset_y); }
static void gimp_display_shell_size_changed_detailed_handler (GimpImage *image, gint previous_origin_x, gint previous_origin_y, gint previous_width, gint previous_height, GimpDisplayShell *shell) { if (shell->display->config->resize_windows_on_resize) { GimpImageWindow *window = gimp_display_shell_get_window (shell); if (window && gimp_image_window_get_active_shell (window) == shell) { /* If the window is resized just center the image in it when it * has change size */ gimp_image_window_shrink_wrap (window, FALSE); } } else { GimpImage *image = gimp_display_get_image (shell->display); gint new_width = gimp_image_get_width (image); gint new_height = gimp_image_get_height (image); gint scaled_previous_origin_x = SCALEX (shell, previous_origin_x); gint scaled_previous_origin_y = SCALEY (shell, previous_origin_y); gboolean horizontally; gboolean vertically; horizontally = (SCALEX (shell, previous_width) > shell->disp_width && SCALEX (shell, new_width) <= shell->disp_width); vertically = (SCALEY (shell, previous_height) > shell->disp_height && SCALEY (shell, new_height) <= shell->disp_height); gimp_display_shell_scroll_set_offset (shell, shell->offset_x + scaled_previous_origin_x, shell->offset_y + scaled_previous_origin_y); gimp_display_shell_scroll_center_image (shell, horizontally, vertically); /* The above calls might not lead to a call to * gimp_display_shell_scroll_clamp_and_update() in all cases we * need it to be called, so simply call it explicitly here at * the end */ gimp_display_shell_scroll_clamp_and_update (shell); gimp_display_shell_expose_full (shell); } }
static void gimp_display_shell_size_changed_detailed_handler (GimpImage *image, gint previous_origin_x, gint previous_origin_y, gint previous_width, gint previous_height, GimpDisplayShell *shell) { GimpDisplayConfig *config = shell->display->config; gboolean resize_window; /* Resize windows only in multi-window mode */ resize_window = (config->resize_windows_on_resize && ! GIMP_GUI_CONFIG (config)->single_window_mode); if (resize_window) { GimpImageWindow *window = gimp_display_shell_get_window (shell); if (window && gimp_image_window_get_active_shell (window) == shell) { /* If the window is resized just center the image in it when it * has change size */ gimp_image_window_shrink_wrap (window, FALSE); } } else { GimpImage *image = gimp_display_get_image (shell->display); gint new_width = gimp_image_get_width (image); gint new_height = gimp_image_get_height (image); gint scaled_previous_origin_x; gint scaled_previous_origin_y; gboolean horizontally; gboolean vertically; scaled_previous_origin_x = SCALEX (shell, previous_origin_x); scaled_previous_origin_y = SCALEY (shell, previous_origin_y); horizontally = (SCALEX (shell, previous_width) > shell->disp_width && SCALEX (shell, new_width) <= shell->disp_width); vertically = (SCALEY (shell, previous_height) > shell->disp_height && SCALEY (shell, new_height) <= shell->disp_height); gimp_display_shell_scroll_set_offset (shell, shell->offset_x + scaled_previous_origin_x, shell->offset_y + scaled_previous_origin_y); gimp_display_shell_scroll_center_image (shell, horizontally, vertically); /* The above calls might not lead to a call to * gimp_display_shell_scroll_clamp_and_update() and * gimp_display_shell_expose_full() in all cases because when * scaling the old and new scroll offset might be the same. * * We need them to be called in all cases, so simply call them * explicitly here at the end */ gimp_display_shell_scroll_clamp_and_update (shell); gimp_display_shell_expose_full (shell); } }
void gimp_display_shell_canvas_size_allocate (GtkWidget *widget, GtkAllocation *allocation, GimpDisplayShell *shell) { /* are we in destruction? */ if (! shell->display || ! gimp_display_get_shell (shell->display)) return; if ((shell->disp_width != allocation->width) || (shell->disp_height != allocation->height)) { if (shell->zoom_on_resize && shell->disp_width > 64 && shell->disp_height > 64 && allocation->width > 64 && allocation->height > 64) { gdouble scale = gimp_zoom_model_get_factor (shell->zoom); gint offset_x; gint offset_y; /* FIXME: The code is a bit of a mess */ /* multiply the zoom_factor with the ratio of the new and * old canvas diagonals */ scale *= (sqrt (SQR (allocation->width) + SQR (allocation->height)) / sqrt (SQR (shell->disp_width) + SQR (shell->disp_height))); offset_x = UNSCALEX (shell, shell->offset_x); offset_y = UNSCALEX (shell, shell->offset_y); gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO, scale); shell->offset_x = SCALEX (shell, offset_x); shell->offset_y = SCALEY (shell, offset_y); } shell->disp_width = allocation->width; shell->disp_height = allocation->height; /* When we size-allocate due to resize of the top level window, * we want some additional logic. Don't apply it on * zoom_on_resize though. */ if (shell->size_allocate_from_configure_event && ! shell->zoom_on_resize) { gboolean center_horizontally; gboolean center_vertically; gint target_offset_x; gint target_offset_y; gint sw; gint sh; gimp_display_shell_scale_get_image_size (shell, &sw, &sh); center_horizontally = sw <= shell->disp_width; center_vertically = sh <= shell->disp_height; gimp_display_shell_scroll_center_image (shell, center_horizontally, center_vertically); /* This is basically the best we can do before we get an * API for storing the image offset at the start of an * image window resize using the mouse */ target_offset_x = shell->offset_x; target_offset_y = shell->offset_y; if (! center_horizontally) { target_offset_x = MAX (shell->offset_x, 0); } if (! center_vertically) { target_offset_y = MAX (shell->offset_y, 0); } gimp_display_shell_scroll_set_offset (shell, target_offset_x, target_offset_y); } gimp_display_shell_scroll_clamp_and_update (shell); gimp_display_shell_scaled (shell); /* Reset */ shell->size_allocate_from_configure_event = FALSE; } }