Skip to content

Commit

Permalink
Fix OSD display when fullscreen info string is empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurent Monin committed Apr 18, 2008
1 parent 7df25c1 commit 763f843
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 30 deletions.
83 changes: 54 additions & 29 deletions src/image-overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,14 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v
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;
Expand Down Expand Up @@ -215,7 +219,7 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v

static GdkPixbuf *image_osd_info_render(ImageWindow *imd)
{
GdkPixbuf *pixbuf;
GdkPixbuf *pixbuf = NULL;
gint width, height;
PangoLayout *layout;
const gchar *name;
Expand Down Expand Up @@ -361,29 +365,40 @@ static GdkPixbuf *image_osd_info_render(ImageWindow *imd)
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;
}

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)
{
Expand All @@ -392,22 +407,24 @@ static GdkPixbuf *image_osd_info_render(ImageWindow *imd)
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));

Expand Down Expand Up @@ -509,16 +526,24 @@ static gint image_osd_update_cb(gpointer data)
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
Expand Down
2 changes: 1 addition & 1 deletion src/preferences.c
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ static void config_tab_advanced(GtkWidget *notebook)
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);

Expand Down

0 comments on commit 763f843

Please sign in to comment.