7 * This software is released under the GNU General Public License (GNU GPL).
8 * Please read the included file COPYING for more information.
9 * This software comes with no warranty of any kind, use at your own risk!
13 #include "image-overlay.h"
20 #include "pixbuf_util.h"
24 *----------------------------------------------------------------------------
26 *----------------------------------------------------------------------------
29 typedef struct _OverlayUpdate OverlayUpdate;
30 struct _OverlayUpdate {
37 #define IMAGE_OVERLAY_UPDATE_KEY "image-overlay-update"
39 #define IMAGE_OVERLAY_X 10
40 #define IMAGE_OVERLAY_Y -10
43 static GdkPixbuf *image_overlay_info_render(ImageWindow *imd)
57 name = image_get_name(imd);
60 name_escaped = g_markup_escape_text(name, -1);
67 cd = image_get_collection(imd, &info);
72 t = g_list_length(cd->list);
73 n = g_list_index(cd->list, info) + 1;
74 buf = g_markup_escape_text((cd->name) ? cd->name : _("Untitled"), -1);
75 ct = g_strdup_printf("<i>%s</i>\n", buf);
82 lw = layout_find_by_image(imd);
87 n = g_list_length(lw->slideshow->list_done);
88 t = n + g_list_length(lw->slideshow->list);
92 t = layout_list_count(lw, NULL);
93 n = layout_list_get_index(lw, image_get_path(lw->image)) + 1;
96 else if (view_window_find_image(imd, &n, &t))
112 size = text_from_size_abrev(imd->size);
115 text = g_strdup_printf(_("Untitled"));
117 else if (imd->unknown)
119 text = g_strdup_printf("%s(%d/%d) <b>%s</b>\n%s - %s", ct,
121 text_from_time(imd->mtime), size);
127 if (imd->delay_flip &&
128 imd->il && imd->il->pixbuf &&
129 imd->pixbuf != imd->il->pixbuf)
131 w = gdk_pixbuf_get_width(imd->il->pixbuf);
132 h = gdk_pixbuf_get_height(imd->il->pixbuf);
136 w = imd->image_width;
137 h = imd->image_height;
140 text = g_strdup_printf("%s(%d/%d) <b>%s</b>\n%d x %d - %s - %s", ct,
143 text_from_time(imd->mtime), size);
147 g_free(name_escaped);
149 layout = gtk_widget_create_pango_layout(imd->image, NULL);
150 pango_layout_set_markup(layout, text, -1);
153 pango_layout_get_pixel_size(layout, &width, &height);
158 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
159 pixbuf_set_rect_fill(pixbuf, 3, 3, width-6, height-6, 240, 240, 240, 210);
160 pixbuf_set_rect(pixbuf, 0, 0, width, height, 240, 240, 240, 80, 1, 1, 1, 1);
161 pixbuf_set_rect(pixbuf, 1, 1, width-2, height-2, 240, 240, 240, 130, 1, 1, 1, 1);
162 pixbuf_set_rect(pixbuf, 2, 2, width-4, height-4, 240, 240, 240, 180, 1, 1, 1, 1);
163 pixbuf_pixel_set(pixbuf, 0, 0, 0, 0, 0, 0);
164 pixbuf_pixel_set(pixbuf, width - 1, 0, 0, 0, 0, 0);
165 pixbuf_pixel_set(pixbuf, 0, height - 1, 0, 0, 0, 0);
166 pixbuf_pixel_set(pixbuf, width - 1, height - 1, 0, 0, 0, 0);
168 pixbuf_draw_layout(pixbuf, layout, imd->image, 5, 5, 0, 0, 0, 255);
170 g_object_unref(G_OBJECT(layout));
175 static void image_overlay_update_destroy_cb(GtkWidget *widget, gpointer data)
177 OverlayUpdate *ou = data;
179 g_source_remove(ou->idle_id);
183 static gint image_overlay_update_cb(gpointer data)
185 OverlayUpdate *ou = data;
188 pixbuf = image_overlay_info_render(ou->imd);
189 image_overlay_set(ou->imd, ou->id, pixbuf, IMAGE_OVERLAY_X, IMAGE_OVERLAY_Y);
190 g_object_unref(pixbuf);
192 g_object_set_data(G_OBJECT(ou->imd->image), IMAGE_OVERLAY_UPDATE_KEY, NULL);
193 g_signal_handler_disconnect(ou->imd->image, ou->destroy_id);
199 static void image_overlay_update_schedule(ImageWindow *imd, gint id)
203 ou = g_object_get_data(G_OBJECT(imd->image), IMAGE_OVERLAY_UPDATE_KEY);
206 ou = g_new0(OverlayUpdate, 1);
209 ou->idle_id = g_idle_add_full(G_PRIORITY_HIGH, image_overlay_update_cb, ou, NULL);
210 ou->destroy_id = g_signal_connect(G_OBJECT(imd->image), "destroy",
211 G_CALLBACK(image_overlay_update_destroy_cb), ou);
212 g_object_set_data(G_OBJECT(imd->image), IMAGE_OVERLAY_UPDATE_KEY, ou);
215 void image_overlay_update(ImageWindow *imd, gint id)
218 image_overlay_update_schedule(imd, id);
221 static void image_overlay_upate_cb(ImageWindow *imd, gpointer data)
225 id = GPOINTER_TO_INT(data);
226 image_overlay_update_schedule(imd, id);
229 gint image_overlay_info_enable(ImageWindow *imd)
234 pixbuf = image_overlay_info_render(imd);
235 id = image_overlay_add(imd, pixbuf, IMAGE_OVERLAY_X, IMAGE_OVERLAY_Y, TRUE, FALSE);
236 g_object_unref(pixbuf);
238 image_set_new_func(imd, image_overlay_upate_cb, GINT_TO_POINTER(id));
243 void image_overlay_info_disable(ImageWindow *imd, gint id)
245 image_set_new_func(imd, NULL, NULL);
246 image_overlay_remove(imd, id);