Mercurial > geeqie.yaz
annotate src/dnd.c @ 531:1149a7b0a3d7
cleanup: use image_get_image_size
author | nadvornik |
---|---|
date | Tue, 29 Apr 2008 18:12:49 +0000 |
parents | 48c8e49b571c |
children | c414002a1f27 |
rev | line source |
---|---|
1 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
1 | 5 * |
6 * Author: John Ellis | |
7 * | |
9 | 8 * This software is released under the GNU General Public License (GNU GPL). |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
1 | 11 */ |
12 | |
9 | 13 |
281 | 14 #include "main.h" |
9 | 15 #include "dnd.h" |
1 | 16 |
9 | 17 #include "collect.h" |
18 #include "image.h" | |
19 #include "ui_bookmark.h" | |
20 #include "ui_fileops.h" | |
1 | 21 |
9 | 22 |
23 GtkTargetEntry dnd_file_drag_types[] = { | |
1 | 24 { "text/uri-list", 0, TARGET_URI_LIST }, |
25 { "text/plain", 0, TARGET_TEXT_PLAIN } | |
26 }; | |
9 | 27 gint dnd_file_drag_types_count = 2; |
1 | 28 |
9 | 29 GtkTargetEntry dnd_file_drop_types[] = { |
316 | 30 { TARGET_APP_COLLECTION_MEMBER_STRING, 0, TARGET_APP_COLLECTION_MEMBER }, |
1 | 31 { "text/uri-list", 0, TARGET_URI_LIST } |
32 }; | |
9 | 33 gint dnd_file_drop_types_count = 2; |
34 | |
1 | 35 |
458
7a69309b91c8
Allow the user to set the drag'n drop icon size through
zas_
parents:
316
diff
changeset
|
36 #define DND_ICON_SIZE (options->dnd_icon_size) |
9 | 37 |
1 | 38 |
9 | 39 static void pixbuf_draw_border(GdkPixbuf *pixbuf, gint w, gint h) |
40 { | |
41 gint alpha; | |
42 gint rs; | |
43 guchar *pix; | |
44 guchar *p; | |
45 gint i; | |
1 | 46 |
9 | 47 alpha = gdk_pixbuf_get_has_alpha(pixbuf); |
48 rs = gdk_pixbuf_get_rowstride(pixbuf); | |
49 pix = gdk_pixbuf_get_pixels(pixbuf); | |
1 | 50 |
9 | 51 p = pix; |
52 for (i = 0; i < w; i++) | |
53 { | |
54 *p = 0; p++; *p = 0; p++; *p = 0; p++; | |
55 if (alpha) { *p= 255; p++; } | |
56 } | |
57 for (i = 1; i < h - 1; i++) | |
58 { | |
59 p = pix + rs * i; | |
60 *p = 0; p++; *p = 0; p++; *p = 0; p++; | |
61 if (alpha) *p= 255; | |
1 | 62 |
9 | 63 p = pix + rs * i + (w - 1) * ((alpha == TRUE) ? 4 : 3); |
64 *p = 0; p++; *p = 0; p++; *p = 0; p++; | |
65 if (alpha) *p= 255; | |
66 } | |
67 p = pix + rs * (h - 1); | |
68 for (i = 0; i < w; i++) | |
1 | 69 { |
9 | 70 *p = 0; p++; *p = 0; p++; *p = 0; p++; |
71 if (alpha) { *p= 255; p++; } | |
1 | 72 } |
73 } | |
74 | |
9 | 75 static void pixbuf_draw_rect(GdkPixbuf *pixbuf, gint x, gint y, gint w, gint h, guint8 val) |
1 | 76 { |
9 | 77 gint alpha; |
78 gint rs; | |
79 guchar *pix; | |
80 guchar *p; | |
81 gint i, j; | |
1 | 82 |
9 | 83 alpha = gdk_pixbuf_get_has_alpha(pixbuf); |
84 rs = gdk_pixbuf_get_rowstride(pixbuf); | |
85 pix = gdk_pixbuf_get_pixels(pixbuf); | |
1 | 86 |
9 | 87 for (j = 0; j < h; j++) |
88 { | |
89 p = pix + (rs * (y + j)) + (x * ((alpha) ? 4 : 3)); | |
90 for (i = 0; i < w; i++) | |
91 { | |
92 *p = (*p * (256-val)) >> 8; p++; | |
93 *p = (*p * (256-val)) >> 8; p++; | |
94 *p = (*p * (256-val)) >> 8; p++; | |
95 if (alpha) { *p = 255; p++; } | |
1 | 96 } |
97 } | |
98 } | |
99 | |
9 | 100 void dnd_set_drag_icon(GtkWidget *widget, GdkDragContext *context, GdkPixbuf *pixbuf, gint items) |
1 | 101 { |
9 | 102 GdkPixmap *pixmap; |
103 GdkBitmap *mask; | |
104 GdkPixbuf *dest; | |
105 gint w, h; | |
106 gint sw, sh; | |
107 PangoLayout *layout = NULL; | |
108 gint x, y; | |
1 | 109 |
9 | 110 x = y = 0; |
1 | 111 |
9 | 112 sw = gdk_pixbuf_get_width(pixbuf); |
113 sh = gdk_pixbuf_get_height(pixbuf); | |
1 | 114 |
9 | 115 if (sw <= DND_ICON_SIZE && sh <= DND_ICON_SIZE) |
116 { | |
117 w = sw; | |
118 h = sh; | |
119 } | |
120 else if (sw < sh) | |
1 | 121 { |
9 | 122 w = sw * DND_ICON_SIZE / sh; |
123 h = DND_ICON_SIZE; | |
124 } | |
125 else | |
126 { | |
127 w = DND_ICON_SIZE; | |
128 h = sh * DND_ICON_SIZE / sw; | |
1 | 129 } |
130 | |
9 | 131 dest = gdk_pixbuf_scale_simple(pixbuf, w, h, GDK_INTERP_BILINEAR); |
132 pixbuf_draw_border(dest, w, h); | |
1 | 133 |
9 | 134 if (items > 1) |
1 | 135 { |
9 | 136 gchar *buf; |
137 gint lw,lh; | |
1 | 138 |
9 | 139 layout = gtk_widget_create_pango_layout(widget, NULL); |
140 buf = g_strdup_printf("<small> %d </small>", items); | |
141 pango_layout_set_markup(layout, buf, -1); | |
142 g_free(buf); | |
1 | 143 |
9 | 144 pango_layout_get_pixel_size(layout, &lw, &lh); |
1 | 145 |
9 | 146 x = MAX(0, w - lw); |
147 y = MAX(0, h - lh); | |
148 lw = CLAMP(lw, 0, w - x - 1); | |
149 lh = CLAMP(lh, 0, h - y - 1); | |
1 | 150 |
9 | 151 pixbuf_draw_rect(dest, x, y, lw, lh, 128); |
1 | 152 } |
153 | |
9 | 154 gdk_pixbuf_render_pixmap_and_mask(dest, &pixmap, &mask, 128); |
155 g_object_unref(dest); | |
1 | 156 |
9 | 157 if (layout) |
158 { | |
159 gdk_draw_layout(pixmap, widget->style->black_gc, x+1, y+1, layout); | |
160 gdk_draw_layout(pixmap, widget->style->white_gc, x, y, layout); | |
1 | 161 |
9 | 162 g_object_unref(G_OBJECT(layout)); |
163 } | |
1 | 164 |
9 | 165 gtk_drag_set_icon_pixmap(context, gtk_widget_get_colormap(widget), pixmap, mask, -8, -6); |
1 | 166 |
9 | 167 g_object_unref(pixmap); |
168 if (mask) g_object_unref(mask); | |
1 | 169 } |