static void
gimp_view_renderer_buffer_render (GimpViewRenderer *renderer,
                                  GtkWidget        *widget)
{
  gint         buffer_width;
  gint         buffer_height;
  gint         view_width;
  gint         view_height;
  gboolean     scaling_up;
  GimpTempBuf *render_buf = NULL;

  gimp_viewable_get_size (renderer->viewable, &buffer_width, &buffer_height);

  gimp_viewable_calc_preview_size (buffer_width,
                                   buffer_height,
                                   renderer->width,
                                   renderer->height,
                                   TRUE, 1.0, 1.0,
                                   &view_width,
                                   &view_height,
                                   &scaling_up);

  if (scaling_up)
    {
      GimpTempBuf *temp_buf;

      temp_buf = gimp_viewable_get_new_preview (renderer->viewable,
                                                renderer->context,
                                                buffer_width, buffer_height);

      if (temp_buf)
        {
          render_buf = gimp_temp_buf_scale (temp_buf, view_width, view_height);

          gimp_temp_buf_unref (temp_buf);
        }
    }
  else
    {
      render_buf = gimp_viewable_get_new_preview (renderer->viewable,
                                                  renderer->context,
                                                  view_width, view_height);
    }

  if (render_buf)
    {
      gimp_view_renderer_render_temp_buf_simple (renderer, render_buf);

      gimp_temp_buf_unref (render_buf);
    }
  else /* no preview available */
    {
      const gchar *icon_name;

      icon_name = gimp_viewable_get_icon_name (renderer->viewable);

      gimp_view_renderer_render_icon (renderer, widget, icon_name);
    }
}
Exemple #2
0
static gboolean
gimp_brush_pipe_get_popup_size (GimpViewable *viewable,
                                gint          width,
                                gint          height,
                                gboolean      dot_for_dot,
                                gint         *popup_width,
                                gint         *popup_height)
{
  return gimp_viewable_get_size (viewable, popup_width, popup_height);
}
Exemple #3
0
static GdkPixbuf *
gimp_view_drag_pixbuf (GtkWidget *widget,
                       gpointer   data)
{
    GimpView     *view     = GIMP_VIEW (widget);
    GimpViewable *viewable = view->viewable;
    gint          width;
    gint          height;

    if (viewable && gimp_viewable_get_size (viewable, &width, &height))
        return gimp_viewable_get_new_pixbuf (viewable, view->renderer->context,
                                             width, height);

    return NULL;
}
Exemple #4
0
void
gimp_edit_get_paste_offset (GimpImage    *image,
                            GimpDrawable *drawable,
                            GimpObject   *paste,
                            gint          viewport_x,
                            gint          viewport_y,
                            gint          viewport_width,
                            gint          viewport_height,
                            gint         *offset_x,
                            gint         *offset_y)
{
  gint     image_width;
  gint     image_height;
  gint     width;
  gint     height;
  gboolean clamp_to_image = TRUE;

  g_return_if_fail (GIMP_IS_IMAGE (image));
  g_return_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable));
  g_return_if_fail (drawable == NULL ||
                    gimp_item_is_attached (GIMP_ITEM (drawable)));
  g_return_if_fail (GIMP_IS_VIEWABLE (paste));
  g_return_if_fail (offset_x != NULL);
  g_return_if_fail (offset_y != NULL);

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

  gimp_viewable_get_size (GIMP_VIEWABLE (paste), &width, &height);

  if (viewport_width  == image_width &&
      viewport_height == image_height)
    {
      /* if the whole image is visible, act as if there was no viewport */

      viewport_x      = 0;
      viewport_y      = 0;
      viewport_width  = 0;
      viewport_height = 0;
    }

  if (drawable)
    {
      /*  if pasting to a drawable  */

      GimpContainer *children;
      gint           off_x, off_y;
      gint           target_x, target_y;
      gint           target_width, target_height;
      gint           paste_x, paste_y;
      gint           paste_width, paste_height;
      gboolean       have_mask;

      have_mask = ! gimp_channel_is_empty (gimp_image_get_mask (image));

      gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);

      children = gimp_viewable_get_children (GIMP_VIEWABLE (drawable));

      if (children && gimp_container_get_n_children (children) == 0)
        {
          /* treat empty layer groups as image-sized, use the selection
           * as target
           */
          gimp_item_bounds (GIMP_ITEM (gimp_image_get_mask (image)),
                            &target_x, &target_y,
                            &target_width, &target_height);
        }
      else
        {
          gimp_item_mask_intersect (GIMP_ITEM (drawable),
                                    &target_x, &target_y,
                                    &target_width, &target_height);
        }

      if (! have_mask         &&    /* if we have no mask */
          viewport_width  > 0 &&    /* and we have a viewport */
          viewport_height > 0 &&
          (width  < target_width || /* and the paste is smaller than the target */
           height < target_height) &&

          /* and the viewport intersects with the target */
          gimp_rectangle_intersect (viewport_x, viewport_y,
                                    viewport_width, viewport_height,
                                    off_x, off_y, /* target_x,y are 0 */
                                    target_width, target_height,
                                    &paste_x, &paste_y,
                                    &paste_width, &paste_height))
        {
          /*  center on the viewport  */

          *offset_x = paste_x + (paste_width - width)  / 2;
          *offset_y = paste_y + (paste_height- height) / 2;
        }
      else
        {
          /*  otherwise center on the target  */

          *offset_x = off_x + target_x + (target_width  - width)  / 2;
          *offset_y = off_y + target_y + (target_height - height) / 2;

          /*  and keep it that way  */
          clamp_to_image = FALSE;
        }
    }
  else if (viewport_width  > 0 &&  /* if we have a viewport */
           viewport_height > 0 &&
           (width  < image_width || /* and the paste is       */
            height < image_height)) /* smaller than the image */
    {
      /*  center on the viewport  */

      *offset_x = viewport_x + (viewport_width  - width)  / 2;
      *offset_y = viewport_y + (viewport_height - height) / 2;
    }
  else
    {
      /*  otherwise center on the image  */

      *offset_x = (image_width  - width)  / 2;
      *offset_y = (image_height - height) / 2;

      /*  and keep it that way  */
      clamp_to_image = FALSE;
    }

  if (clamp_to_image)
    {
      /*  Ensure that the pasted layer is always within the image, if it
       *  fits and aligned at top left if it doesn't. (See bug #142944).
       */
      *offset_x = MIN (*offset_x, image_width  - width);
      *offset_y = MIN (*offset_y, image_height - height);
      *offset_x = MAX (*offset_x, 0);
      *offset_y = MAX (*offset_y, 0);
    }
}
Exemple #5
0
static void
gimp_view_real_set_viewable (GimpView     *view,
                             GimpViewable *old,
                             GimpViewable *viewable)
{
    GType viewable_type = G_TYPE_NONE;

    if (viewable == view->viewable)
        return;

    if (viewable)
    {
        viewable_type = G_TYPE_FROM_INSTANCE (viewable);

        g_return_if_fail (g_type_is_a (viewable_type,
                                       view->renderer->viewable_type));
    }

    if (view->viewable)
    {
        g_object_remove_weak_pointer (G_OBJECT (view->viewable),
                                      (gpointer) &view->viewable);

        if (! viewable && ! view->renderer->is_popup)
        {
            if (gimp_dnd_viewable_source_remove (GTK_WIDGET (view),
                                                 G_TYPE_FROM_INSTANCE (view->viewable)))
            {
                if (gimp_viewable_get_size (view->viewable, NULL, NULL))
                    gimp_dnd_pixbuf_source_remove (GTK_WIDGET (view));

                gtk_drag_source_unset (GTK_WIDGET (view));
            }
        }
    }
    else if (viewable && ! view->renderer->is_popup)
    {
        if (gimp_dnd_drag_source_set_by_type (GTK_WIDGET (view),
                                              GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
                                              viewable_type,
                                              GDK_ACTION_COPY))
        {
            gimp_dnd_viewable_source_add (GTK_WIDGET (view),
                                          viewable_type,
                                          gimp_view_drag_viewable,
                                          NULL);

            if (gimp_viewable_get_size (viewable, NULL, NULL))
                gimp_dnd_pixbuf_source_add (GTK_WIDGET (view),
                                            gimp_view_drag_pixbuf,
                                            NULL);
        }
    }

    gimp_view_renderer_set_viewable (view->renderer, viewable);
    view->viewable = viewable;

    if (view->viewable)
    {
        g_object_add_weak_pointer (G_OBJECT (view->viewable),
                                   (gpointer) &view->viewable);
    }
}