Пример #1
0
void
gimp_display_shell_scale_drag (GimpDisplayShell *shell,
                               gdouble           start_x,
                               gdouble           start_y,
                               gdouble           delta_x,
                               gdouble           delta_y)
{
  gdouble scale;

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

  scale = gimp_zoom_model_get_factor (shell->zoom);

  gimp_display_shell_push_zoom_focus_pointer_pos (shell, start_x, start_y);

  if (delta_y > 0)
    {
      gimp_display_shell_scale (shell,
                                GIMP_ZOOM_TO,
                                scale * 1.1,
                                GIMP_ZOOM_FOCUS_POINTER);
    }
  else if (delta_y < 0)
    {
      gimp_display_shell_scale (shell,
                                GIMP_ZOOM_TO,
                                scale * 0.9,
                                GIMP_ZOOM_FOCUS_POINTER);
    }
}
/**
 * gimp_display_shell_scale_fill:
 * @shell: the #GimpDisplayShell
 *
 * Sets the scale such that the entire display area is precisely
 * filled by the image.
 **/
void
gimp_display_shell_scale_fill (GimpDisplayShell *shell)
{
  GimpImage *image;
  gint       image_width;
  gint       image_height;
  gdouble    xres;
  gdouble    yres;
  gdouble    zoom_factor;

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));

  image = gimp_display_get_image (shell->display);

  image_width  = gimp_image_get_width  (image);
  image_height = gimp_image_get_height (image);

  gimp_image_get_resolution (image, &xres, &yres);

  if (! shell->dot_for_dot)
    {
      image_width  = ROUND (image_width  * shell->monitor_xres / xres);
      image_height = ROUND (image_height * shell->monitor_yres / yres);
    }

  zoom_factor = MAX ((gdouble) shell->disp_width  / (gdouble) image_width,
                     (gdouble) shell->disp_height / (gdouble) image_height);

  gimp_display_shell_scale (shell,
                            GIMP_ZOOM_TO,
                            zoom_factor,
                            GIMP_ZOOM_FOCUS_BEST_GUESS);

  gimp_display_shell_scroll_center_image (shell, TRUE, TRUE);
}
Пример #3
0
static void
gimp_display_shell_scale_dialog_response (GtkWidget       *widget,
                                          gint             response_id,
                                          ScaleDialogData *dialog)
{
  if (response_id == GTK_RESPONSE_OK)
    {
      gdouble scale;

      scale = gtk_adjustment_get_value (dialog->scale_adj);

      gimp_display_shell_scale (dialog->shell,
                                GIMP_ZOOM_TO,
                                scale / 100.0,
                                GIMP_ZOOM_FOCUS_BEST_GUESS);
    }
  else
    {
      /*  need to emit "scaled" to get the menu updated  */
      gimp_display_shell_scaled (dialog->shell);
    }

  dialog->shell->other_scale = - fabs (dialog->shell->other_scale);

  gtk_widget_destroy (dialog->shell->scale_dialog);
}
Пример #4
0
static gboolean
gimp_navigation_editor_zoom_adj_changed_timeout (gpointer data)
{
  GimpNavigationEditor *editor = GIMP_NAVIGATION_EDITOR (data);
  GtkAdjustment        *adj    = editor->zoom_adjustment;

  if (gimp_display_get_image (editor->shell->display))
    gimp_display_shell_scale (editor->shell,
                              GIMP_ZOOM_TO,
                              pow (2.0, gtk_adjustment_get_value (adj)),
                              GIMP_ZOOM_FOCUS_BEST_GUESS);

  editor->scale_timeout = 0;

  return FALSE;
}
Пример #5
0
static void
gimp_navigation_editor_zoom (GimpNavigationView   *view,
                             GimpZoomType          direction,
                             GimpNavigationEditor *editor)
{
  g_return_if_fail (direction != GIMP_ZOOM_TO);

  if (editor->shell)
    {
      if (gimp_display_get_image (editor->shell->display))
        gimp_display_shell_scale (editor->shell,
                                  direction,
                                  0.0,
                                  GIMP_ZOOM_FOCUS_BEST_GUESS);
    }
}
Пример #6
0
/**
 * gimp_display_shell_scale_fit_or_fill:
 * @shell: the #GimpDisplayShell
 * @fill:  whether to scale the image to fill the viewport,
 *         or fit inside the viewport
 *
 * A common implementation for gimp_display_shell_scale_{fit_in,fill}().
 **/
static void
gimp_display_shell_scale_fit_or_fill (GimpDisplayShell *shell,
                                      gboolean          fill)
{
  GimpImage *image;
  gdouble    image_x;
  gdouble    image_y;
  gdouble    image_width;
  gdouble    image_height;
  gdouble    current_scale;
  gdouble    zoom_factor;

  image = gimp_display_get_image (shell->display);

  gimp_display_shell_transform_bounds (shell,
                                       0, 0,
                                       gimp_image_get_width  (image),
                                       gimp_image_get_height (image),
                                       &image_x, &image_y,
                                       &image_width, &image_height);

  image_width  -= image_x;
  image_height -= image_y;

  current_scale = gimp_zoom_model_get_factor (shell->zoom);

  if (fill)
    {
      zoom_factor = MAX (shell->disp_width  / image_width,
                         shell->disp_height / image_height);
    }
  else
    {
      zoom_factor = MIN (shell->disp_width  / image_width,
                         shell->disp_height / image_height);
    }

  gimp_display_shell_scale (shell,
                            GIMP_ZOOM_TO,
                            zoom_factor * current_scale,
                            GIMP_ZOOM_FOCUS_BEST_GUESS);

  gimp_display_shell_scroll_center_image (shell, TRUE, TRUE);
}
Пример #7
0
void
view_zoom_explicit_cmd_callback (GtkAction *action,
                                 GtkAction *current,
                                 gpointer   data)
{
  GimpDisplayShell *shell;
  gint              value;
  return_if_no_shell (shell, data);

  value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));

  if (value != 0 /* not Other... */)
    {
      if (fabs (value - gimp_zoom_model_get_factor (shell->zoom)) > 0.0001)
        gimp_display_shell_scale (shell,
                                  GIMP_ZOOM_TO,
                                  (gdouble) value / 10000,
                                  GIMP_ZOOM_FOCUS_RETAIN_CENTERING_ELSE_BEST_GUESS);
    }
}
Пример #8
0
void
view_zoom_cmd_callback (GtkAction *action,
                        gint       value,
                        gpointer   data)
{
  GimpDisplayShell *shell;
  return_if_no_shell (shell, data);

  switch ((GimpActionSelectType) value)
    {
    case GIMP_ACTION_SELECT_FIRST:
      gimp_display_shell_scale (shell,
                                GIMP_ZOOM_OUT_MAX,
                                0.0,
                                GIMP_ZOOM_FOCUS_BEST_GUESS);
      break;

    case GIMP_ACTION_SELECT_LAST:
      gimp_display_shell_scale (shell,
                                GIMP_ZOOM_IN_MAX,
                                0.0,
                                GIMP_ZOOM_FOCUS_BEST_GUESS);
      break;

    case GIMP_ACTION_SELECT_PREVIOUS:
      gimp_display_shell_scale (shell,
                                GIMP_ZOOM_OUT,
                                0.0,
                                GIMP_ZOOM_FOCUS_BEST_GUESS);
      break;

    case GIMP_ACTION_SELECT_NEXT:
      gimp_display_shell_scale (shell,
                                GIMP_ZOOM_IN,
                                0.0,
                                GIMP_ZOOM_FOCUS_BEST_GUESS);
      break;

    case GIMP_ACTION_SELECT_SKIP_PREVIOUS:
      gimp_display_shell_scale (shell,
                                GIMP_ZOOM_OUT_MORE,
                                0.0,
                                GIMP_ZOOM_FOCUS_BEST_GUESS);
      break;

    case GIMP_ACTION_SELECT_SKIP_NEXT:
      gimp_display_shell_scale (shell,
                                GIMP_ZOOM_IN_MORE,
                                0.0,
                                GIMP_ZOOM_FOCUS_BEST_GUESS);
      break;

    default:
      {
        gdouble scale = gimp_zoom_model_get_factor (shell->zoom);

        scale = action_select_value ((GimpActionSelectType) value,
                                     scale,
                                     0.0, 512.0, 1.0,
                                     1.0 / 8.0, 1.0, 16.0, 0.0,
                                     FALSE);

        /* min = 1.0 / 256,  max = 256.0                */
        /* scale = min *  (max / min)**(i/n), i = 0..n  */
        scale = pow (65536.0, scale / 512.0) / 256.0;

        gimp_display_shell_scale (shell,
                                  GIMP_ZOOM_TO,
                                  scale,
                                  GIMP_ZOOM_FOCUS_BEST_GUESS);
        break;
      }
    }
}