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 _OverlayStateData OverlayStateData;
31 struct _OverlayStateData {
33 ImageState changed_states;
40 gint icon_time[IMAGE_OSD_COUNT];
41 gint icon_id[IMAGE_OSD_COUNT];
49 typedef struct _OSDIcon OSDIcon;
56 static OSDIcon osd_icons[] = {
57 { 0, -10, PIXBUF_INLINE_ICON },
58 { -10, -10, "IMAGE_OSD_ROTATE_USER" },
59 { -10, -10, "IMAGE_OSD_ROTATE_AUTO" },
60 { -40, -10, "IMAGE_OSD_COLOR" },
61 { -70, -10, "IMAGE_OSD_FIRST" },
62 { -70, -10, "IMAGE_OSD_LAST" },
66 #define OSD_DATA "overlay-data"
69 #define OSD_INFO_Y -10
71 #define IMAGE_OSD_DEFAULT_DURATION 30
74 static void image_osd_timer_schedule(OverlayStateData *osd);
77 static GdkPixbuf *image_osd_info_render(ImageWindow *imd)
91 name = image_get_name(imd);
94 name_escaped = g_markup_escape_text(name, -1);
101 cd = image_get_collection(imd, &info);
106 t = g_list_length(cd->list);
107 n = g_list_index(cd->list, info) + 1;
108 buf = g_markup_escape_text((cd->name) ? cd->name : _("Untitled"), -1);
109 ct = g_strdup_printf("<i>%s</i>\n", buf);
116 lw = layout_find_by_image(imd);
121 n = g_list_length(lw->slideshow->list_done);
122 t = n + g_list_length(lw->slideshow->list);
127 t = layout_list_count(lw, NULL);
128 n = layout_list_get_index(lw, image_get_path(lw->image)) + 1;
131 else if (view_window_find_image(imd, &n, &t))
147 size = text_from_size_abrev(imd->size);
150 text = g_strdup_printf(_("Untitled"));
152 else if (imd->unknown)
154 text = g_strdup_printf("%s(%d/%d) <b>%s</b>\n%s - %s", ct,
156 text_from_time(imd->mtime), size);
162 if (imd->delay_flip &&
163 imd->il && imd->il->pixbuf &&
164 image_get_pixbuf(imd) != imd->il->pixbuf)
166 w = gdk_pixbuf_get_width(imd->il->pixbuf);
167 h = gdk_pixbuf_get_height(imd->il->pixbuf);
171 pixbuf_renderer_get_image_size(PIXBUF_RENDERER(imd->pr), &w, &h);
174 text = g_strdup_printf("%s(%d/%d) <b>%s</b>\n%d x %d - %s - %s", ct,
177 text_from_time(imd->mtime), size);
181 g_free(name_escaped);
183 layout = gtk_widget_create_pango_layout(imd->pr, NULL);
184 pango_layout_set_markup(layout, text, -1);
187 pango_layout_get_pixel_size(layout, &width, &height);
192 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
193 pixbuf_set_rect_fill(pixbuf, 3, 3, width-6, height-6, 240, 240, 240, 210);
194 pixbuf_set_rect(pixbuf, 0, 0, width, height, 240, 240, 240, 80, 1, 1, 1, 1);
195 pixbuf_set_rect(pixbuf, 1, 1, width-2, height-2, 240, 240, 240, 130, 1, 1, 1, 1);
196 pixbuf_set_rect(pixbuf, 2, 2, width-4, height-4, 240, 240, 240, 180, 1, 1, 1, 1);
197 pixbuf_pixel_set(pixbuf, 0, 0, 0, 0, 0, 0);
198 pixbuf_pixel_set(pixbuf, width - 1, 0, 0, 0, 0, 0);
199 pixbuf_pixel_set(pixbuf, 0, height - 1, 0, 0, 0, 0);
200 pixbuf_pixel_set(pixbuf, width - 1, height - 1, 0, 0, 0, 0);
202 pixbuf_draw_layout(pixbuf, layout, imd->pr, 5, 5, 0, 0, 0, 255);
204 g_object_unref(G_OBJECT(layout));
209 static GdkPixbuf *image_osd_icon_pixbuf(ImageOSDFlag flag)
211 static GdkPixbuf **icons = NULL;
212 GdkPixbuf *icon = NULL;
214 if (!icons) icons = g_new0(GdkPixbuf *, IMAGE_OSD_COUNT);
215 if (icons[flag]) return icons[flag];
217 icon = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 24, 24);
218 pixbuf_set_rect_fill(icon, 1, 1, 22, 22, 255, 255, 255, 200);
219 pixbuf_set_rect(icon, 0, 0, 24, 24, 0, 0, 0, 128, 1, 1, 1, 1);
222 case IMAGE_OSD_COLOR:
223 pixbuf_set_rect_fill(icon, 3, 3, 18, 6, 200, 0, 0, 255);
224 pixbuf_set_rect_fill(icon, 3, 9, 18, 6, 0, 200, 0, 255);
225 pixbuf_set_rect_fill(icon, 3, 15, 18, 6, 0, 0, 200, 255);
227 case IMAGE_OSD_FIRST:
228 pixbuf_set_rect(icon, 3, 3, 18, 18, 0, 0, 0, 200, 3, 3, 3, 0);
229 pixbuf_draw_triangle(icon, 6, 5, 12, 6,
230 12, 5, 18, 11, 6, 11,
234 pixbuf_set_rect(icon, 3, 3, 18, 18, 0, 0, 0, 200, 3, 3, 0, 3);
235 pixbuf_draw_triangle(icon, 6, 12, 12, 6,
236 12, 18, 6, 12, 18, 12,
248 static void image_osd_icon_show(OverlayStateData *osd, ImageOSDFlag flag)
252 if (osd->icon_id[flag]) return;
254 pixbuf = image_osd_icon_pixbuf(flag);
257 osd->icon_id[flag] = image_overlay_add(osd->imd, pixbuf,
258 osd_icons[flag].x, osd_icons[flag].y,
262 static void image_osd_icon_hide(OverlayStateData *osd, ImageOSDFlag flag)
264 if (osd->icon_id[flag])
266 image_overlay_remove(osd->imd, osd->icon_id[flag]);
267 osd->icon_id[flag] = 0;
271 static gint image_osd_update_cb(gpointer data)
273 OverlayStateData *osd = data;
277 if (osd->changed_states & IMAGE_STATE_IMAGE)
281 pixbuf = image_osd_info_render(osd->imd);
282 if (osd->ovl_info == 0)
284 osd->ovl_info = image_overlay_add(osd->imd, pixbuf,
285 OSD_INFO_X, OSD_INFO_Y, TRUE, FALSE);
289 image_overlay_set(osd->imd, osd->ovl_info, pixbuf, OSD_INFO_X, OSD_INFO_Y);
291 g_object_unref(pixbuf);
298 image_overlay_remove(osd->imd, osd->ovl_info);
303 if (osd->show_status)
307 if (osd->changed_states & IMAGE_STATE_IMAGE)
309 for (i = 0; i < IMAGE_OSD_COUNT; i++) osd->icon_time[i] = 0;
312 if (osd->changed_states & IMAGE_STATE_COLOR_ADJ)
314 osd->icon_time[IMAGE_OSD_COLOR] = IMAGE_OSD_DEFAULT_DURATION + 1;
315 image_osd_timer_schedule(osd);
318 for (i = 0; i < IMAGE_OSD_COUNT; i++)
320 if (osd->icon_time[i] > 0)
322 image_osd_icon_show(osd, i);
326 image_osd_icon_hide(osd, i);
334 for (i = 0; i < IMAGE_OSD_COUNT; i++)
336 image_osd_icon_hide(osd, i);
340 osd->changed_states = IMAGE_STATE_NONE;
345 static void image_osd_update_schedule(OverlayStateData *osd, gint force)
347 if (force) osd->changed_states |= IMAGE_STATE_IMAGE;
349 if (osd->idle_id == -1)
351 osd->idle_id = g_idle_add_full(G_PRIORITY_HIGH, image_osd_update_cb, osd, NULL);
355 void image_osd_update(ImageWindow *imd)
357 OverlayStateData *osd;
361 osd = g_object_get_data(G_OBJECT(imd->pr), "IMAGE_OVERLAY_DATA");
364 image_osd_update_schedule(osd, TRUE);
367 static gint image_osd_timer_cb(gpointer data)
369 OverlayStateData *osd = data;
371 gint changed = FALSE;
374 for (i = 0; i < IMAGE_OSD_COUNT; i++)
376 if (osd->icon_time[i] > 1)
379 if (osd->icon_time[i] < 2)
381 osd->icon_time[i] = 0;
391 if (changed) image_osd_update_schedule(osd, FALSE);
402 static void image_osd_timer_schedule(OverlayStateData *osd)
404 if (osd->timer_id == -1)
406 osd->timer_id = g_timeout_add(100, image_osd_timer_cb, osd);
410 static void image_osd_state_cb(ImageWindow *imd, ImageState state, gpointer data)
412 OverlayStateData *osd = data;
414 osd->changed_states |= state;
415 image_osd_update_schedule(osd, FALSE);
418 static void image_osd_free(OverlayStateData *osd)
422 if (osd->idle_id != -1) g_source_remove(osd->idle_id);
423 if (osd->timer_id != -1) g_source_remove(osd->timer_id);
429 g_object_set_data(G_OBJECT(osd->imd->pr), "IMAGE_OVERLAY_DATA", NULL);
430 g_signal_handler_disconnect(osd->imd->pr, osd->destroy_id);
432 image_set_state_func(osd->imd, NULL, NULL);
433 image_overlay_remove(osd->imd, osd->ovl_info);
435 for (i = 0; i < IMAGE_OSD_COUNT; i++)
437 image_osd_icon_hide(osd, i);
444 static void image_osd_remove(ImageWindow *imd)
446 OverlayStateData *osd;
448 osd = g_object_get_data(G_OBJECT(imd->pr), "IMAGE_OVERLAY_DATA");
452 static void image_osd_destroy_cb(GtkWidget *widget, gpointer data)
454 OverlayStateData *osd = data;
460 static void image_osd_enable(ImageWindow *imd, gint info, gint status)
462 OverlayStateData *osd;
464 osd = g_object_get_data(G_OBJECT(imd->pr), "IMAGE_OVERLAY_DATA");
467 osd = g_new0(OverlayStateData, 1);
472 osd->destroy_id = g_signal_connect(G_OBJECT(imd->pr), "destroy",
473 G_CALLBACK(image_osd_destroy_cb), osd);
474 g_object_set_data(G_OBJECT(imd->pr), "IMAGE_OVERLAY_DATA", osd);
476 image_set_state_func(osd->imd, image_osd_state_cb, osd);
479 if (osd->show_info != info ||
480 osd->show_status != status)
482 osd->show_info = info;
483 osd->show_status = status;
485 image_osd_update_schedule(osd, TRUE);
489 void image_osd_set(ImageWindow *imd, gint info, gint status)
493 if (!info && !status)
495 image_osd_remove(imd);
499 image_osd_enable(imd, info, status);
502 gint image_osd_get(ImageWindow *imd, gint *info, gint *status)
504 OverlayStateData *osd;
506 if (!imd) return FALSE;
508 osd = g_object_get_data(G_OBJECT(imd->pr), "IMAGE_OVERLAY_DATA");
509 if (!osd) return FALSE;
511 if (info) *info = osd->show_info;
512 if (status) *status = osd->show_status;
520 2+ = show for duration tenths of a second
521 -1 = use default duration
523 void image_osd_icon(ImageWindow *imd, ImageOSDFlag flag, gint duration)
525 OverlayStateData *osd;
529 osd = g_object_get_data(G_OBJECT(imd->pr), "IMAGE_OVERLAY_DATA");
532 if (flag < IMAGE_OSD_NONE || flag >= IMAGE_OSD_COUNT) return;
533 if (duration < 0) duration = IMAGE_OSD_DEFAULT_DURATION;
534 if (duration > 1) duration += 1;
536 osd->icon_time[flag] = duration;
538 image_osd_update_schedule(osd, FALSE);
539 image_osd_timer_schedule(osd);