mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-22 20:41:43 +00:00
improved the new DND code.
2008-09-04 Sven Neumann <sven@gimp.org> * app/display/gimpdisplayshell-dnd.c: improved the new DND code. svn path=/trunk/; revision=26867
This commit is contained in:
parent
b8f94b37b3
commit
8172ba88a1
|
@ -1,3 +1,7 @@
|
|||
2008-09-04 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/display/gimpdisplayshell-dnd.c: improved the new DND code.
|
||||
|
||||
2008-09-04 Tor Lillqvist <tml@novell.com>
|
||||
|
||||
* app/base/base-utils.h
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "core/gimpcontext.h"
|
||||
#include "core/gimpdrawable-bucket-fill.h"
|
||||
#include "core/gimpimage.h"
|
||||
#include "core/gimpimage-colormap.h"
|
||||
#include "core/gimpimage-merge.h"
|
||||
#include "core/gimpimage-undo.h"
|
||||
#include "core/gimplayer.h"
|
||||
|
@ -176,10 +177,11 @@ gimp_display_shell_drop_drawable (GtkWidget *widget,
|
|||
GimpViewable *viewable,
|
||||
gpointer data)
|
||||
{
|
||||
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
|
||||
GimpImage *image = shell->display->image;
|
||||
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
|
||||
GimpImage *image = shell->display->image;
|
||||
GType new_type;
|
||||
GimpItem *new_item;
|
||||
gboolean new_image = FALSE;
|
||||
|
||||
GIMP_LOG (DND, NULL);
|
||||
|
||||
|
@ -188,12 +190,34 @@ gimp_display_shell_drop_drawable (GtkWidget *widget,
|
|||
|
||||
if (! image)
|
||||
{
|
||||
image = gimp_image_new (shell->display->gimp,
|
||||
gimp_item_width (GIMP_ITEM (viewable)),
|
||||
gimp_item_height (GIMP_ITEM (viewable)),
|
||||
GIMP_RGB);
|
||||
GimpImage *src_image = gimp_item_get_image (GIMP_ITEM (viewable));
|
||||
GimpDrawable *drawable = GIMP_DRAWABLE (viewable);
|
||||
GimpImageBaseType type;
|
||||
gdouble xres;
|
||||
gdouble yres;
|
||||
|
||||
type = GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (drawable));
|
||||
|
||||
image = gimp_create_image (shell->display->gimp,
|
||||
gimp_item_width (GIMP_ITEM (viewable)),
|
||||
gimp_item_height (GIMP_ITEM (viewable)),
|
||||
type, TRUE);
|
||||
gimp_image_undo_disable (image);
|
||||
|
||||
if (type == GIMP_INDEXED)
|
||||
gimp_image_set_colormap (image,
|
||||
gimp_image_get_colormap (src_image),
|
||||
gimp_image_get_colormap_size (src_image),
|
||||
FALSE);
|
||||
|
||||
gimp_image_get_resolution (src_image, &xres, &yres);
|
||||
gimp_image_set_resolution (image, xres, yres);
|
||||
gimp_image_set_unit (image, gimp_image_get_unit (src_image));
|
||||
|
||||
gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0);
|
||||
g_object_unref (image);
|
||||
|
||||
new_image = TRUE;
|
||||
}
|
||||
|
||||
if (GIMP_IS_LAYER (viewable))
|
||||
|
@ -205,23 +229,28 @@ gimp_display_shell_drop_drawable (GtkWidget *widget,
|
|||
|
||||
if (new_item)
|
||||
{
|
||||
GimpLayer *new_layer;
|
||||
gint x, y, width, height;
|
||||
gint off_x, off_y;
|
||||
|
||||
new_layer = GIMP_LAYER (new_item);
|
||||
GimpLayer *new_layer = GIMP_LAYER (new_item);
|
||||
|
||||
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_PASTE,
|
||||
_("Drop New Layer"));
|
||||
|
||||
gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);
|
||||
if (! new_image)
|
||||
{
|
||||
gint x, y;
|
||||
gint width, height;
|
||||
gint off_x, off_y;
|
||||
|
||||
gimp_item_offsets (new_item, &off_x, &off_y);
|
||||
gimp_item_offsets (new_item, &off_x, &off_y);
|
||||
|
||||
off_x = x + (width - gimp_item_width (new_item)) / 2 - off_x;
|
||||
off_y = y + (height - gimp_item_height (new_item)) / 2 - off_y;
|
||||
gimp_display_shell_untransform_viewport (shell,
|
||||
&x, &y, &width, &height);
|
||||
|
||||
off_x = x + (width - gimp_item_width (new_item)) / 2 - off_x;
|
||||
off_y = y + (height - gimp_item_height (new_item)) / 2 - off_y;
|
||||
|
||||
gimp_item_translate (new_item, off_x, off_y, FALSE);
|
||||
}
|
||||
|
||||
gimp_item_translate (new_item, off_x, off_y, FALSE);
|
||||
gimp_item_set_visible (new_item, TRUE, FALSE);
|
||||
gimp_item_set_linked (new_item, FALSE, FALSE);
|
||||
|
||||
|
@ -231,6 +260,9 @@ gimp_display_shell_drop_drawable (GtkWidget *widget,
|
|||
|
||||
gimp_display_shell_dnd_flush (shell, image);
|
||||
}
|
||||
|
||||
if (new_image)
|
||||
gimp_image_undo_enable (image);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -557,50 +589,76 @@ gimp_display_shell_drop_pixbuf (GtkWidget *widget,
|
|||
GdkPixbuf *pixbuf,
|
||||
gpointer data)
|
||||
{
|
||||
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
|
||||
GimpImage *image = shell->display->image;
|
||||
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
|
||||
GimpImage *image = shell->display->image;
|
||||
GimpLayer *new_layer;
|
||||
GimpImageType image_type;
|
||||
gboolean new_image = FALSE;
|
||||
|
||||
GIMP_LOG (DND, NULL);
|
||||
|
||||
if (shell->display->gimp->busy)
|
||||
return;
|
||||
|
||||
switch (gdk_pixbuf_get_n_channels (pixbuf))
|
||||
{
|
||||
case 1: image_type = GIMP_GRAY_IMAGE; break;
|
||||
case 2: image_type = GIMP_GRAYA_IMAGE; break;
|
||||
case 3: image_type = GIMP_RGB_IMAGE; break;
|
||||
case 4: image_type = GIMP_RGBA_IMAGE; break;
|
||||
break;
|
||||
|
||||
default:
|
||||
g_return_if_reached ();
|
||||
break;
|
||||
}
|
||||
|
||||
if (! image)
|
||||
{
|
||||
image = gimp_image_new (shell->display->gimp,
|
||||
gdk_pixbuf_get_width (pixbuf),
|
||||
gdk_pixbuf_get_height (pixbuf),
|
||||
GIMP_RGB);
|
||||
|
||||
image = gimp_create_image (shell->display->gimp,
|
||||
gdk_pixbuf_get_width (pixbuf),
|
||||
gdk_pixbuf_get_height (pixbuf),
|
||||
GIMP_IMAGE_TYPE_BASE_TYPE (image_type),
|
||||
FALSE);
|
||||
|
||||
gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0);
|
||||
g_object_unref (image);
|
||||
|
||||
gimp_image_undo_disable (image);
|
||||
|
||||
new_image = TRUE;
|
||||
}
|
||||
|
||||
new_layer =
|
||||
gimp_layer_new_from_pixbuf (pixbuf, image,
|
||||
gimp_image_base_type_with_alpha (image),
|
||||
gimp_layer_new_from_pixbuf (pixbuf, image, image_type,
|
||||
_("Dropped Buffer"),
|
||||
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
|
||||
|
||||
if (new_layer)
|
||||
{
|
||||
GimpItem *new_item;
|
||||
gint x, y, width, height;
|
||||
gint off_x, off_y;
|
||||
GimpItem *new_item = GIMP_ITEM (new_layer);
|
||||
|
||||
new_item = GIMP_ITEM (new_layer);
|
||||
|
||||
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_PASTE,
|
||||
_("Drop New Layer"));
|
||||
|
||||
gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);
|
||||
if (! new_image)
|
||||
{
|
||||
gint x, y;
|
||||
gint width, height;
|
||||
gint off_x, off_y;
|
||||
|
||||
gimp_item_offsets (new_item, &off_x, &off_y);
|
||||
gimp_display_shell_untransform_viewport (shell,
|
||||
&x, &y, &width, &height);
|
||||
|
||||
off_x = x + (width - gimp_item_width (new_item)) / 2 - off_x;
|
||||
off_y = y + (height - gimp_item_height (new_item)) / 2 - off_y;
|
||||
gimp_item_offsets (new_item, &off_x, &off_y);
|
||||
|
||||
gimp_item_translate (new_item, off_x, off_y, FALSE);
|
||||
off_x = x + (width - gimp_item_width (new_item)) / 2 - off_x;
|
||||
off_y = y + (height - gimp_item_height (new_item)) / 2 - off_y;
|
||||
|
||||
gimp_item_translate (new_item, off_x, off_y, FALSE);
|
||||
}
|
||||
|
||||
gimp_image_add_layer (image, new_layer, -1);
|
||||
|
||||
|
@ -608,4 +666,7 @@ gimp_display_shell_drop_pixbuf (GtkWidget *widget,
|
|||
|
||||
gimp_display_shell_dnd_flush (shell, image);
|
||||
}
|
||||
|
||||
if (new_image)
|
||||
gimp_image_undo_enable (image);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue