Commit b2355b8e authored by Victor Ananjevsky's avatar Victor Ananjevsky

improved images proccessing code

parent dd717c8c
......@@ -207,14 +207,14 @@ entry_create_widget (GtkWidget * dlg)
entry = gtk_bin_get_child (GTK_BIN (c));
if (options.entry_data.licon)
{
GdkPixbuf *pb = get_pixbuf (options.entry_data.licon, YAD_SMALL_ICON);
GdkPixbuf *pb = get_pixbuf (options.entry_data.licon, YAD_SMALL_ICON, TRUE);
if (pb)
gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, pb);
}
if (options.entry_data.ricon)
{
GdkPixbuf *pb = get_pixbuf (options.entry_data.ricon, YAD_SMALL_ICON);
GdkPixbuf *pb = get_pixbuf (options.entry_data.ricon, YAD_SMALL_ICON, TRUE);
if (pb)
gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY, pb);
......@@ -294,14 +294,14 @@ entry_create_widget (GtkWidget * dlg)
if (options.entry_data.licon)
{
GdkPixbuf *pb = get_pixbuf (options.entry_data.licon, YAD_SMALL_ICON);
GdkPixbuf *pb = get_pixbuf (options.entry_data.licon, YAD_SMALL_ICON, TRUE);
if (pb)
gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, pb);
}
if (options.entry_data.ricon)
{
GdkPixbuf *pb = get_pixbuf (options.entry_data.ricon, YAD_SMALL_ICON);
GdkPixbuf *pb = get_pixbuf (options.entry_data.ricon, YAD_SMALL_ICON, TRUE);
if (pb)
gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY, pb);
......
......@@ -236,11 +236,11 @@ handle_stdin (GIOChannel * channel, GIOCondition condition, gpointer data)
if (options.icons_data.compact)
{
if (*string->str)
spb = get_pixbuf (string->str, YAD_SMALL_ICON);
spb = get_pixbuf (string->str, YAD_SMALL_ICON, TRUE);
}
else
{
GdkPixbuf *pb = get_pixbuf (string->str, YAD_BIG_ICON);
GdkPixbuf *pb = get_pixbuf (string->str, YAD_BIG_ICON, FALSE);
if (pb)
{
spb = scale_pixbuf (pb);
......@@ -356,10 +356,10 @@ parse_desktop_file (gchar * filename)
if (icon)
{
if (options.icons_data.compact)
ent->pixbuf = get_pixbuf (icon, YAD_SMALL_ICON);
ent->pixbuf = get_pixbuf (icon, YAD_SMALL_ICON, TRUE);
else
{
GdkPixbuf *pb = get_pixbuf (icon, YAD_BIG_ICON);
GdkPixbuf *pb = get_pixbuf (icon, YAD_BIG_ICON, FALSE);
ent->pixbuf = scale_pixbuf (pb);
if (pb)
g_object_unref (pb);
......
......@@ -447,7 +447,7 @@ cell_set_data (GtkTreeIter *it, guint num, gchar *data)
}
case YAD_COLUMN_IMAGE:
{
GdkPixbuf *pb = get_pixbuf (data, YAD_SMALL_ICON);
GdkPixbuf *pb = get_pixbuf (data, YAD_SMALL_ICON, FALSE);
if (pb)
{
gtk_list_store_set (GTK_LIST_STORE (model), it, num, pb, -1);
......
......@@ -180,7 +180,7 @@ create_layout (GtkWidget *dlg)
{
GdkPixbuf *pb = NULL;
pb = get_pixbuf (options.data.dialog_image, YAD_BIG_ICON);
pb = get_pixbuf (options.data.dialog_image, YAD_BIG_ICON, FALSE);
image = gtk_image_new_from_pixbuf (pb);
if (pb)
g_object_unref (pb);
......
......@@ -196,7 +196,7 @@ popup_menu_cb (GtkStatusIcon * icon, guint button, guint activate_time, gpointer
{
if (d->icon)
{
GdkPixbuf *pb = get_pixbuf (d->icon, YAD_SMALL_ICON);
GdkPixbuf *pb = get_pixbuf (d->icon, YAD_SMALL_ICON, TRUE);
item = gtk_image_menu_item_new_with_mnemonic (d->name);
if (pb)
{
......
......@@ -287,7 +287,7 @@ yad_print_run (void)
{
GdkPixbuf *pb = NULL;
pb = get_pixbuf (options.data.dialog_image, YAD_BIG_ICON);
pb = get_pixbuf (options.data.dialog_image, YAD_BIG_ICON, FALSE);
img = gtk_image_new_from_pixbuf (pb);
if (pb)
g_object_unref (pb);
......
......@@ -152,30 +152,28 @@ write_settings (void)
}
GdkPixbuf *
get_pixbuf (gchar * name, YadIconSize size)
get_pixbuf (gchar * name, YadIconSize size, gboolean force)
{
gint w, h;
GdkPixbuf *pb = NULL;
GError *err = NULL;
if (size == YAD_BIG_ICON)
gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &w, &h);
else
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &w, &h);
if (g_file_test (name, G_FILE_TEST_EXISTS))
{
pb = gdk_pixbuf_new_from_file (name, &err);
if (!pb)
{
g_printerr ("yad_get_pixbuf(): %s\n", err->message);
g_printerr ("yad: get_pixbuf(): %s\n", err->message);
g_error_free (err);
}
}
else
{
if (size == YAD_BIG_ICON)
gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &w, &h);
else
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &w, &h);
pb = gtk_icon_theme_load_icon (settings.icon_theme, name, MIN (w, h), GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
}
pb = gtk_icon_theme_load_icon (settings.icon_theme, name, MIN (w, h), GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
if (!pb)
{
......@@ -185,6 +183,21 @@ get_pixbuf (gchar * name, YadIconSize size)
pb = g_object_ref (settings.small_fallback_image);
}
/* force scaling image to specific size */
if (force && pb)
{
gint iw = gdk_pixbuf_get_width (pb);
gint ih = gdk_pixbuf_get_height (pb);
if (w != iw || h != ih)
{
GdkPixbuf *spb;
spb = gdk_pixbuf_scale_simple (pb, w, h, GDK_INTERP_BILINEAR);
g_object_unref (pb);
pb = spb;
}
}
return pb;
}
......@@ -403,7 +416,7 @@ get_label (gchar * str, guint border)
if (gtk_stock_lookup (vals[0], &it))
{
l = gtk_label_new_with_mnemonic (it.label);
i = gtk_image_new_from_pixbuf (get_pixbuf (it.stock_id, YAD_SMALL_ICON));
i = gtk_image_new_from_pixbuf (get_pixbuf (it.stock_id, YAD_SMALL_ICON, TRUE));
}
else
{
......@@ -417,7 +430,7 @@ get_label (gchar * str, guint border)
}
if (vals[1] && *vals[1])
i = gtk_image_new_from_pixbuf (get_pixbuf (vals[1], YAD_SMALL_ICON));
i = gtk_image_new_from_pixbuf (get_pixbuf (vals[1], YAD_SMALL_ICON, TRUE));
}
if (i)
......
......@@ -622,7 +622,7 @@ void write_settings (void);
void update_preview (GtkFileChooser *chooser, GtkWidget *p);
void filechooser_mapped (GtkWidget *w, gpointer data);
GdkPixbuf *get_pixbuf (gchar *name, YadIconSize size);
GdkPixbuf *get_pixbuf (gchar *name, YadIconSize size, gboolean force);
#if GTK_CHECK_VERSION(3,0,0)
gchar *get_color (GdkRGBA *c);
#else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment