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-renderer.h"
21 #include "pixbuf_util.h"
25 *----------------------------------------------------------------------------
27 *----------------------------------------------------------------------------
30 typedef struct _OverlayUpdate OverlayUpdate;
31 struct _OverlayUpdate {
38 #define IMAGE_OVERLAY_UPDATE_KEY "image-overlay-update"
40 #define IMAGE_OVERLAY_X 10
41 #define IMAGE_OVERLAY_Y -10
44 static GdkPixbuf *image_overlay_info_render(ImageWindow *imd)
58 name = image_get_name(imd);
61 name_escaped = g_markup_escape_text(name, -1);
68 cd = image_get_collection(imd, &info);
73 t = g_list_length(cd->list);
74 n = g_list_index(cd->list, info) + 1;
75 buf = g_markup_escape_text((cd->name) ? cd->name : _("Untitled"), -1);
76 ct = g_strdup_printf("<i>%s</i>\n", buf);
83 lw = layout_find_by_image(imd);
88 n = g_list_length(lw->slideshow->list_done);
89 t = n + g_list_length(lw->slideshow->list);
93 t = layout_list_count(lw, NULL);
94 n = layout_list_get_index(lw, image_get_path(lw->image)) + 1;
97 else if (view_window_find_image(imd, &n, &t))
113 size = text_from_size_abrev(imd->size);
116 text = g_strdup_printf(_("Untitled"));
118 else if (imd->unknown)
120 text = g_strdup_printf("%s(%d/%d) <b>%s</b>\n%s - %s", ct,
122 text_from_time(imd->mtime), size);
128 if (imd->delay_flip &&
129 imd->il && imd->il->pixbuf &&
130 image_get_pixbuf(imd) != imd->il->pixbuf)
132 w = gdk_pixbuf_get_width(imd->il->pixbuf);
133 h = gdk_pixbuf_get_height(imd->il->pixbuf);
137 pixbuf_renderer_get_image_size(PIXBUF_RENDERER(imd->pr), &w, &h);
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->pr, 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->pr, 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->pr), IMAGE_OVERLAY_UPDATE_KEY, NULL);
193 g_signal_handler_disconnect(ou->imd->pr, ou->destroy_id);
199 static void image_overlay_update_schedule(ImageWindow *imd, gint id)
203 ou = g_object_get_data(G_OBJECT(imd->pr), 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->pr), "destroy",
211 G_CALLBACK(image_overlay_update_destroy_cb), ou);
212 g_object_set_data(G_OBJECT(imd->pr), 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);