/** * gimp_display_shell_scale_by_values: * @shell: the #GimpDisplayShell * @scale: the new scale * @offset_x: the new X offset * @offset_y: the new Y offset * @resize_window: whether the display window should be resized * * Directly sets the image scale and image offsets used by the display. If * @resize_window is %TRUE then the display window is resized to better * accommodate the image, see gimp_display_shell_shrink_wrap(). **/ void gimp_display_shell_scale_by_values (GimpDisplayShell *shell, gdouble scale, gint offset_x, gint offset_y, gboolean resize_window) { g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); /* Abort early if the values are all setup already. We don't * want to inadvertently resize the window (bug #164281). */ if (SCALE_EQUALS (gimp_zoom_model_get_factor (shell->zoom), scale) && shell->offset_x == offset_x && shell->offset_y == offset_y) return; gimp_display_shell_scale_save_revert_values (shell); /* freeze the active tool */ gimp_display_shell_pause (shell); gimp_zoom_model_zoom (shell->zoom, GIMP_ZOOM_TO, scale); shell->offset_x = offset_x; shell->offset_y = offset_y; gimp_display_shell_rotate_update_transform (shell); gimp_display_shell_scale_resize (shell, resize_window, FALSE); /* re-enable the active tool */ gimp_display_shell_resume (shell); }
void gimp_display_shell_scroll (GimpDisplayShell *shell, gint x_offset, gint y_offset) { gint old_x; gint old_y; g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); if (x_offset == 0 && y_offset == 0) return; old_x = shell->offset_x; old_y = shell->offset_y; shell->offset_x += x_offset; shell->offset_y += y_offset; gimp_display_shell_scroll_clamp_offsets (shell); /* the actual changes in offset */ x_offset = (shell->offset_x - old_x); y_offset = (shell->offset_y - old_y); if (x_offset || y_offset) { /* reset the old values so that the tool can accurately redraw */ shell->offset_x = old_x; shell->offset_y = old_y; gimp_display_shell_pause (shell); /* set the offsets back to the new values */ shell->offset_x += x_offset; shell->offset_y += y_offset; gimp_display_shell_rotate_update_transform (shell); gimp_overlay_box_scroll (GIMP_OVERLAY_BOX (shell->canvas), -x_offset, -y_offset); /* Update scrollbars and rulers */ gimp_display_shell_scale_update_scrollbars (shell); gimp_display_shell_scale_update_rulers (shell); gimp_display_shell_resume (shell); gimp_display_shell_scrolled (shell); } }
/** * gimp_display_shell_scroll_clamp_and_update: * @shell: * * Helper function for calling two functions that are commonly called * in pairs. **/ void gimp_display_shell_scroll_clamp_and_update (GimpDisplayShell *shell) { GimpImage *image; g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); image = gimp_display_get_image (shell->display); if (image) { gint bounds_x; gint bounds_y; gint bounds_width; gint bounds_height; gint min_offset_x; gint max_offset_x; gint min_offset_y; gint max_offset_y; gint offset_x; gint offset_y; gimp_display_shell_rotate_update_transform (shell); gimp_display_shell_scale_get_image_bounds (shell, &bounds_x, &bounds_y, &bounds_width, &bounds_height); if (shell->disp_width < bounds_width) { min_offset_x = bounds_x - shell->disp_width * OVERPAN_FACTOR; max_offset_x = bounds_x + bounds_width - shell->disp_width * (1.0 - OVERPAN_FACTOR); } else { gint overpan_amount; overpan_amount = shell->disp_width - bounds_width * (1.0 - OVERPAN_FACTOR); min_offset_x = bounds_x - overpan_amount; max_offset_x = bounds_x + bounds_width - shell->disp_width + overpan_amount; } if (shell->disp_height < bounds_height) { min_offset_y = bounds_y - shell->disp_height * OVERPAN_FACTOR; max_offset_y = bounds_y + bounds_height - shell->disp_height * (1.0 - OVERPAN_FACTOR); } else { gint overpan_amount; overpan_amount = shell->disp_height - bounds_height * (1.0 - OVERPAN_FACTOR); min_offset_y = bounds_y - overpan_amount; max_offset_y = bounds_y + bounds_height + overpan_amount - shell->disp_height; } /* Clamp */ offset_x = CLAMP (shell->offset_x, min_offset_x, max_offset_x); offset_y = CLAMP (shell->offset_y, min_offset_y, max_offset_y); if (offset_x != shell->offset_x || offset_y != shell->offset_y) { shell->offset_x = offset_x; shell->offset_y = offset_y; gimp_display_shell_rotate_update_transform (shell); } /* Set scrollbar stepper sensitiity */ gimp_display_shell_scrollbars_update_steppers (shell, min_offset_x, max_offset_x, min_offset_y, max_offset_y); } else { shell->offset_x = 0; shell->offset_y = 0; } gimp_display_shell_scrollbars_update (shell); gimp_display_shell_rulers_update (shell); }