Mercurial > geeqie
annotate src/dnd.c @ 964:ba1d3c4bc0cd
implemented marks filter
author | nadvornik |
---|---|
date | Sat, 16 Aug 2008 20:34:14 +0000 |
parents | c414002a1f27 |
children | 1f634178a14f |
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_fileops.h" | |
1 | 20 |
9 | 21 |
22 GtkTargetEntry dnd_file_drag_types[] = { | |
1 | 23 { "text/uri-list", 0, TARGET_URI_LIST }, |
24 { "text/plain", 0, TARGET_TEXT_PLAIN } | |
25 }; | |
9 | 26 gint dnd_file_drag_types_count = 2; |
1 | 27 |
9 | 28 GtkTargetEntry dnd_file_drop_types[] = { |
316 | 29 { TARGET_APP_COLLECTION_MEMBER_STRING, 0, TARGET_APP_COLLECTION_MEMBER }, |
1 | 30 { "text/uri-list", 0, TARGET_URI_LIST } |
31 }; | |
9 | 32 gint dnd_file_drop_types_count = 2; |
33 | |
1 | 34 |
458
7a69309b91c8
Allow the user to set the drag'n drop icon size through
zas_
parents:
316
diff
changeset
|
35 #define DND_ICON_SIZE (options->dnd_icon_size) |
9 | 36 |
1 | 37 |
9 | 38 static void pixbuf_draw_border(GdkPixbuf *pixbuf, gint w, gint h) |
39 { | |
40 gint alpha; | |
41 gint rs; | |
42 guchar *pix; | |
43 guchar *p; | |
44 gint i; | |
1 | 45 |
9 | 46 alpha = gdk_pixbuf_get_has_alpha(pixbuf); |
47 rs = gdk_pixbuf_get_rowstride(pixbuf); | |
48 pix = gdk_pixbuf_get_pixels(pixbuf); | |
1 | 49 |
9 | 50 p = pix; |
51 for (i = 0; i < w; i++) | |
52 { | |
53 *p = 0; p++; *p = 0; p++; *p = 0; p++; | |
54 if (alpha) { *p= 255; p++; } | |
55 } | |
56 for (i = 1; i < h - 1; i++) | |
57 { | |
58 p = pix + rs * i; | |
59 *p = 0; p++; *p = 0; p++; *p = 0; p++; | |
60 if (alpha) *p= 255; | |
1 | 61 |
9 | 62 p = pix + rs * i + (w - 1) * ((alpha == TRUE) ? 4 : 3); |
63 *p = 0; p++; *p = 0; p++; *p = 0; p++; | |
64 if (alpha) *p= 255; | |
65 } | |
66 p = pix + rs * (h - 1); | |
67 for (i = 0; i < w; i++) | |
1 | 68 { |
9 | 69 *p = 0; p++; *p = 0; p++; *p = 0; p++; |
70 if (alpha) { *p= 255; p++; } | |
1 | 71 } |
72 } | |
73 | |
9 | 74 static void pixbuf_draw_rect(GdkPixbuf *pixbuf, gint x, gint y, gint w, gint h, guint8 val) |
1 | 75 { |
9 | 76 gint alpha; |
77 gint rs; | |
78 guchar *pix; | |
79 guchar *p; | |
80 gint i, j; | |
1 | 81 |
9 | 82 alpha = gdk_pixbuf_get_has_alpha(pixbuf); |
83 rs = gdk_pixbuf_get_rowstride(pixbuf); | |
84 pix = gdk_pixbuf_get_pixels(pixbuf); | |
1 | 85 |
9 | 86 for (j = 0; j < h; j++) |
87 { | |
88 p = pix + (rs * (y + j)) + (x * ((alpha) ? 4 : 3)); | |
89 for (i = 0; i < w; i++) | |
90 { | |
91 *p = (*p * (256-val)) >> 8; p++; | |
92 *p = (*p * (256-val)) >> 8; p++; | |
93 *p = (*p * (256-val)) >> 8; p++; | |
94 if (alpha) { *p = 255; p++; } | |
1 | 95 } |
96 } | |
97 } | |
98 | |
9 | 99 void dnd_set_drag_icon(GtkWidget *widget, GdkDragContext *context, GdkPixbuf *pixbuf, gint items) |
1 | 100 { |
9 | 101 GdkPixmap *pixmap; |
102 GdkBitmap *mask; | |
103 GdkPixbuf *dest; | |
104 gint w, h; | |
105 gint sw, sh; | |
106 PangoLayout *layout = NULL; | |
107 gint x, y; | |
1 | 108 |
9 | 109 x = y = 0; |
1 | 110 |
9 | 111 sw = gdk_pixbuf_get_width(pixbuf); |
112 sh = gdk_pixbuf_get_height(pixbuf); | |
1 | 113 |
9 | 114 if (sw <= DND_ICON_SIZE && sh <= DND_ICON_SIZE) |
115 { | |
116 w = sw; | |
117 h = sh; | |
118 } | |
119 else if (sw < sh) | |
1 | 120 { |
9 | 121 w = sw * DND_ICON_SIZE / sh; |
122 h = DND_ICON_SIZE; | |
123 } | |
124 else | |
125 { | |
126 w = DND_ICON_SIZE; | |
127 h = sh * DND_ICON_SIZE / sw; | |
1 | 128 } |
129 | |
9 | 130 dest = gdk_pixbuf_scale_simple(pixbuf, w, h, GDK_INTERP_BILINEAR); |
131 pixbuf_draw_border(dest, w, h); | |
1 | 132 |
9 | 133 if (items > 1) |
1 | 134 { |
9 | 135 gchar *buf; |
136 gint lw,lh; | |
1 | 137 |
9 | 138 layout = gtk_widget_create_pango_layout(widget, NULL); |
139 buf = g_strdup_printf("<small> %d </small>", items); | |
140 pango_layout_set_markup(layout, buf, -1); | |
141 g_free(buf); | |
1 | 142 |
9 | 143 pango_layout_get_pixel_size(layout, &lw, &lh); |
1 | 144 |
9 | 145 x = MAX(0, w - lw); |
146 y = MAX(0, h - lh); | |
147 lw = CLAMP(lw, 0, w - x - 1); | |
148 lh = CLAMP(lh, 0, h - y - 1); | |
1 | 149 |
9 | 150 pixbuf_draw_rect(dest, x, y, lw, lh, 128); |
1 | 151 } |
152 | |
9 | 153 gdk_pixbuf_render_pixmap_and_mask(dest, &pixmap, &mask, 128); |
154 g_object_unref(dest); | |
1 | 155 |
9 | 156 if (layout) |
157 { | |
158 gdk_draw_layout(pixmap, widget->style->black_gc, x+1, y+1, layout); | |
159 gdk_draw_layout(pixmap, widget->style->white_gc, x, y, layout); | |
1 | 160 |
9 | 161 g_object_unref(G_OBJECT(layout)); |
162 } | |
1 | 163 |
9 | 164 gtk_drag_set_icon_pixmap(context, gtk_widget_get_colormap(widget), pixmap, mask, -8, -6); |
1 | 165 |
9 | 166 g_object_unref(pixmap); |
167 if (mask) g_object_unref(mask); | |
1 | 168 } |