static void
gimp_display_shell_hadjustment_changed (GtkAdjustment    *adjustment,
                                        GimpDisplayShell *shell)
{
  /* If we are panning with mouse, scrollbars are to be ignored or
   * they will cause jitter in motion
   */
  if (! shell->scrolling)
    gimp_display_shell_scroll (shell,
                               gtk_adjustment_get_value (adjustment) -
                               shell->offset_x,
                               0);
}
Esempio n. 2
0
/**
 * 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 image_x;
  gint image_y;
  gint image_width;
  gint image_height;
  gint center_x;
  gint center_y;
  gint offset_x = 0;
  gint offset_y = 0;

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

  if (! shell->display                          ||
      ! gimp_display_get_image (shell->display) ||
      (! vertically && ! horizontally))
    return;

  gimp_display_shell_scale_get_image_bounds (shell,
                                             &image_x, &image_y,
                                             &image_width, &image_height);

  if (shell->disp_width > image_width)
    {
      image_x     -= (shell->disp_width - image_width) / 2;
      image_width  = shell->disp_width;
    }

  if (shell->disp_height > image_height)
    {
      image_y      -= (shell->disp_height - image_height) / 2;
      image_height  = shell->disp_height;
    }

  center_x = image_x + image_width  / 2;
  center_y = image_y + image_height / 2;

  if (horizontally)
    offset_x = center_x - shell->disp_width / 2 - shell->offset_x;

  if (vertically)
    offset_y = center_y - shell->disp_height / 2 - shell->offset_y;

  gimp_display_shell_scroll (shell, offset_x, offset_y);
}
Esempio n. 3
0
/**
 * gimp_display_shell_scroll_center_image_xy:
 * @shell:
 * @image_x:
 * @image_y:
 *
 * Center the viewport around the passed image coordinate
 **/
void
gimp_display_shell_scroll_center_image_xy (GimpDisplayShell *shell,
                                           gdouble           image_x,
                                           gdouble           image_y)
{
  gint viewport_x;
  gint viewport_y;

  gimp_display_shell_transform_xy (shell,
                                   image_x, image_y,
                                   &viewport_x, &viewport_y);

  gimp_display_shell_scroll (shell,
                             viewport_x - shell->disp_width  / 2,
                             viewport_y - shell->disp_height / 2);
}
/**
 * gimp_display_shell_scale_to:
 * @shell:
 * @scale:
 * @viewport_x:
 * @viewport_y:
 *
 * Zooms. The display offsets are adjusted so that the point specified
 * by @x and @y doesn't change it's position on screen.
 **/
static void
gimp_display_shell_scale_to (GimpDisplayShell *shell,
                             gdouble           scale,
                             gdouble           viewport_x,
                             gdouble           viewport_y)
{
  gdouble image_x, image_y;
  gdouble new_viewport_x, new_viewport_y;

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

  if (! shell->display)
    return;

  /* freeze the active tool */
  gimp_display_shell_pause (shell);

  gimp_display_shell_untransform_xy_f (shell,
                                       viewport_x,
                                       viewport_y,
                                       &image_x,
                                       &image_y);

  /* Note that we never come here if we need to resize_windows_on_zoom
   */
  gimp_display_shell_scale_by_values (shell,
                                      scale,
                                      shell->offset_x,
                                      shell->offset_y,
                                      FALSE);

  gimp_display_shell_transform_xy_f (shell,
                                     image_x,
                                     image_y,
                                     &new_viewport_x,
                                     &new_viewport_y);

  gimp_display_shell_scroll (shell,
                             new_viewport_x - viewport_x,
                             new_viewport_y - viewport_y);

  /* re-enable the active tool */
  gimp_display_shell_resume (shell);
}
/**
 * gimp_display_shell_scroll_center_image_coordinate:
 * @shell:
 * @image_x:
 * @image_y:
 *
 * Center the viewport around the passed image coordinate
 *
 **/
void
gimp_display_shell_scroll_center_image_coordinate (GimpDisplayShell *shell,
                                                   gdouble           image_x,
                                                   gdouble           image_y)
{
  gint scaled_image_x;
  gint scaled_image_y;
  gint offset_to_apply_x;
  gint offset_to_apply_y;

  scaled_image_x = RINT (image_x * shell->scale_x);
  scaled_image_y = RINT (image_y * shell->scale_y);

  offset_to_apply_x = scaled_image_x - shell->disp_width  / 2 - shell->offset_x;
  offset_to_apply_y = scaled_image_y - shell->disp_height / 2 - shell->offset_y;

  gimp_display_shell_scroll (shell,
                             offset_to_apply_x,
                             offset_to_apply_y);
}
static gboolean
gimp_display_shell_autoscroll_timeout (gpointer data)
{
  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
  ScrollInfo       *info  = shell->scroll_info;
  GimpCoords        device_coords;
  GimpCoords        image_coords;
  gint              dx = 0;
  gint              dy = 0;

  gimp_device_info_get_device_coords (info->device,
                                      gtk_widget_get_window (shell->canvas),
                                      &device_coords);

  if (device_coords.x < 0)
    dx = device_coords.x;
  else if (device_coords.x > shell->disp_width)
    dx = device_coords.x - shell->disp_width;

  if (device_coords.y < 0)
    dy = device_coords.y;
  else if (device_coords.y > shell->disp_height)
    dy = device_coords.y - shell->disp_height;

  if (dx || dy)
    {
      GimpDisplay *display         = shell->display;
      GimpTool    *active_tool     = tool_manager_get_active (display->gimp);
      gint         scroll_amount_x = AUTOSCROLL_DX * dx;
      gint         scroll_amount_y = AUTOSCROLL_DX * dy;

      info->time += AUTOSCROLL_DT;

      gimp_display_shell_scroll_unoverscrollify (shell,
                                                 scroll_amount_x,
                                                 scroll_amount_y,
                                                 &scroll_amount_x,
                                                 &scroll_amount_y);

      gimp_display_shell_scroll (shell,
                                 scroll_amount_x,
                                 scroll_amount_y);

      gimp_display_shell_untransform_coords (shell,
                                             &device_coords,
                                             &image_coords);

      if (gimp_tool_control_get_snap_to (active_tool->control))
        {
          gint x, y, width, height;

          gimp_tool_control_get_snap_offsets (active_tool->control,
                                              &x, &y, &width, &height);

          gimp_display_shell_snap_coords (shell,
                                          &image_coords,
                                          x, y, width, height);
        }

      tool_manager_motion_active (display->gimp,
                                  &image_coords,
                                  info->time, info->state,
                                  display);

      return TRUE;
    }
  else
    {
      g_slice_free (ScrollInfo, info);
      shell->scroll_info = NULL;

      return FALSE;
    }
}