changeset 410:603206ffa644

Fix OSD display when fullscreen info string is empty.
author zas_
date Fri, 18 Apr 2008 21:42:00 +0000
parents 319cd8857399
children f744baaa71a5
files src/image-overlay.c src/preferences.c
diffstat 2 files changed, 55 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/image-overlay.c	Fri Apr 18 21:30:12 2008 +0000
+++ b/src/image-overlay.c	Fri Apr 18 21:42:00 2008 +0000
@@ -129,10 +129,14 @@
 	gint pos, prev;
 	gint last;
 	gchar *name, *data;
-	GString *new = g_string_new(str);
+	GString *new;
 	gchar *ret;
 	ExifData *exif;
 
+	if (!str || !*str) return g_strdup("");
+	
+	new = g_string_new(str);
+
 	exif = exif_read_fd(imd->image_fd, FALSE);
 	prev = 0;
 	last = FALSE;
@@ -215,7 +219,7 @@
 
 static GdkPixbuf *image_osd_info_render(ImageWindow *imd)
 {
-	GdkPixbuf *pixbuf;
+	GdkPixbuf *pixbuf = NULL;
 	gint width, height;
 	PangoLayout *layout;
 	const gchar *name;
@@ -361,7 +365,10 @@
 				g_string_append_printf(buf, fd->marks[mark] ? " <span background='#FF00FF'>%c</span>" : " %c", '1' + mark);
     				}
 
-			text2 = g_strdup_printf("%s\n%s", text, buf->str);
+			if (*text)
+				text2 = g_strdup_printf("%s\n%s", text, buf->str);
+			else
+				text2 = g_strdup(buf->str);
 			g_string_free(buf, TRUE);
 			g_free(text);
 			text = text2;
@@ -369,21 +376,29 @@
 
     		if (with_hist)
 			{
-			text2 = g_strdup_printf("%s\n%s", text, histogram_label(lw->histogram));
+			if (*text)
+				text2 = g_strdup_printf("%s\n%s", text, histogram_label(lw->histogram));
+			else
+				text2 = g_strdup(histogram_label(lw->histogram));
 			g_free(text);
 			text = text2;
 			}
 		}
 	}
-        
+
 	layout = gtk_widget_create_pango_layout(imd->pr, NULL);
 	pango_layout_set_markup(layout, text, -1);
+printf("|%s|\n",text);
 	g_free(text);
     
 	pango_layout_get_pixel_size(layout, &width, &height);
-
-	width += 10;
-	height += 10;
+	/* with empty text width is set to 0, but not height) */
+	if (width == 0)
+		height = 0;
+	else if (height == 0)
+		width = 0;
+	if (width > 0) width += 10;
+	if (height > 0) height += 10;
 
 	if (with_hist)
 		{
@@ -392,22 +407,24 @@
 		height += HISTOGRAM_HEIGHT + 5;
 		}
 
-
-	/* TODO: make osd color configurable --Zas */
-	pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
-	pixbuf_set_rect_fill(pixbuf, 3, 3, width-6, height-6, 240, 240, 240, 210);
-	pixbuf_set_rect(pixbuf, 0, 0, width, height, 240, 240, 240, 80, 1, 1, 1, 1);
-	pixbuf_set_rect(pixbuf, 1, 1, width-2, height-2, 240, 240, 240, 130, 1, 1, 1, 1);
-	pixbuf_set_rect(pixbuf, 2, 2, width-4, height-4, 240, 240, 240, 180, 1, 1, 1, 1);
-	pixbuf_pixel_set(pixbuf, 0, 0, 0, 0, 0, 0);
-	pixbuf_pixel_set(pixbuf, width - 1, 0, 0, 0, 0, 0);
-	pixbuf_pixel_set(pixbuf, 0, height - 1, 0, 0, 0, 0);
-	pixbuf_pixel_set(pixbuf, width - 1, height - 1, 0, 0, 0, 0);
-
-	if (with_hist)
-		histogram_draw(lw->histogram, pixbuf, 5, height - HISTOGRAM_HEIGHT - 5 , width - 10, HISTOGRAM_HEIGHT);
+	if (width > 0 && height > 0)
+		{
+		/* TODO: make osd color configurable --Zas */
+		pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
+		pixbuf_set_rect_fill(pixbuf, 3, 3, width-6, height-6, 240, 240, 240, 210);
+		pixbuf_set_rect(pixbuf, 0, 0, width, height, 240, 240, 240, 80, 1, 1, 1, 1);
+		pixbuf_set_rect(pixbuf, 1, 1, width-2, height-2, 240, 240, 240, 130, 1, 1, 1, 1);
+		pixbuf_set_rect(pixbuf, 2, 2, width-4, height-4, 240, 240, 240, 180, 1, 1, 1, 1);
+		pixbuf_pixel_set(pixbuf, 0, 0, 0, 0, 0, 0);
+		pixbuf_pixel_set(pixbuf, width - 1, 0, 0, 0, 0, 0);
+		pixbuf_pixel_set(pixbuf, 0, height - 1, 0, 0, 0, 0);
+		pixbuf_pixel_set(pixbuf, width - 1, height - 1, 0, 0, 0, 0);
+	
+		if (with_hist)
+			histogram_draw(lw->histogram, pixbuf, 5, height - HISTOGRAM_HEIGHT - 5 , width - 10, HISTOGRAM_HEIGHT);
 		
-	pixbuf_draw_layout(pixbuf, layout, imd->pr, 5, 5, 0, 0, 0, 255);
+		pixbuf_draw_layout(pixbuf, layout, imd->pr, 5, 5, 0, 0, 0, 255);
+	}
 
 	g_object_unref(G_OBJECT(layout));
 
@@ -509,16 +526,24 @@
 			GdkPixbuf *pixbuf;
 
 			pixbuf = image_osd_info_render(osd->imd);
-			if (osd->ovl_info == 0)
+			if (pixbuf)
 				{
-				osd->ovl_info = image_overlay_add(osd->imd, pixbuf,
-								  OSD_INFO_X, OSD_INFO_Y, TRUE, FALSE);
+				if (osd->ovl_info == 0)
+					{
+					osd->ovl_info = image_overlay_add(osd->imd, pixbuf,
+									  OSD_INFO_X, OSD_INFO_Y, TRUE, FALSE);
+					}
+				else
+					{
+					image_overlay_set(osd->imd, osd->ovl_info, pixbuf, OSD_INFO_X, OSD_INFO_Y);
+					}
+				g_object_unref(pixbuf);
 				}
-			else
+			else if (osd->ovl_info)
 				{
-				image_overlay_set(osd->imd, osd->ovl_info, pixbuf, OSD_INFO_X, OSD_INFO_Y);
+				image_overlay_remove(osd->imd, osd->ovl_info);
+				osd->ovl_info = 0;
 				}
-			g_object_unref(pixbuf);
 			}
 		}
 	else
--- a/src/preferences.c	Fri Apr 18 21:30:12 2008 +0000
+++ b/src/preferences.c	Fri Apr 18 21:42:00 2008 +0000
@@ -1342,7 +1342,7 @@
 	gtk_widget_show(button);
 
 	buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(fullscreen_info_view));
-	gtk_text_buffer_set_text(buffer, options->fullscreen.info, -1);
+	if (options->fullscreen.info) gtk_text_buffer_set_text(buffer, options->fullscreen.info, -1);
 	g_signal_connect(G_OBJECT(buffer), "changed",
 			 G_CALLBACK(fullscreen_info_view_changed_cb), fullscreen_info_view);