quick-lounge-applet r262 - in trunk: . src



Author: paobac
Date: Thu Feb  5 11:27:40 2009
New Revision: 262
URL: http://svn.gnome.org/viewvc/quick-lounge-applet?rev=262&view=rev

Log:
2009-02-05  Paolo Bacchilega  <paobac svn gnome org>

	* src/gtk-utils.h: 
	* src/gtk-utils.c (create_missing_pixbuf): scale the image if the size
	doesn't match the requested size.
	
	* src/dlg-add-from-menu.c: do not use the missing image icon in the
	application list.


Modified:
   trunk/ChangeLog
   trunk/src/dlg-add-from-menu.c
   trunk/src/gtk-utils.c
   trunk/src/gtk-utils.h

Modified: trunk/src/dlg-add-from-menu.c
==============================================================================
--- trunk/src/dlg-add-from-menu.c	(original)
+++ trunk/src/dlg-add-from-menu.c	Thu Feb  5 11:27:40 2009
@@ -161,7 +161,7 @@
 				int size;
 				
 				size = _gtk_icon_get_pixel_size (GTK_WIDGET (data->dialog), GTK_ICON_SIZE_BUTTON);
-				image = create_pixbuf_or_missing (data->quick_lounge->icon_theme, icon, size);
+				image = create_pixbuf (data->quick_lounge->icon_theme, icon, size);
 			}
 		
 			gtk_list_store_append (GTK_LIST_STORE (data->application_model), &iter);

Modified: trunk/src/gtk-utils.c
==============================================================================
--- trunk/src/gtk-utils.c	(original)
+++ trunk/src/gtk-utils.c	Thu Feb  5 11:27:40 2009
@@ -21,6 +21,7 @@
  */
 
 #include <config.h>
+#include <math.h>
 #include <string.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
@@ -471,7 +472,8 @@
                                 p[0] = 255;
                                 p[1] = 0;
                                 p[2] = 0;
-                        } else {
+                        } 
+                        else {
                                 p[0] = 255;
                                 p[1] = 255;
                                 p[2] = 255;
@@ -483,6 +485,37 @@
 }
 
 
+static gboolean
+scale_keeping_ratio (int      *width,
+		     int      *height,
+		     int       max_width,
+		     int       max_height,
+		     gboolean  allow_upscaling)
+{
+	double   w = *width;
+	double   h = *height;
+	double   max_w = max_width;
+	double   max_h = max_height;
+	double   factor;
+	int      new_width, new_height;
+	gboolean modified;
+
+	if ((*width < max_width) && (*height < max_height) && !allow_upscaling)
+		return FALSE;
+
+	factor = MIN (max_w / w, max_h / h);
+	new_width  = MAX ((int) floor (w * factor + 0.50), 1);
+	new_height = MAX ((int) floor (h * factor + 0.50), 1);
+
+	modified = (new_width != *width) || (new_height != *height);
+
+	*width = new_width;
+	*height = new_height;
+
+	return modified;
+}
+
+
 static GdkPixbuf *
 create_missing_pixbuf (GtkIconTheme *theme, 
 	               int           preffered_size)
@@ -490,6 +523,7 @@
 	GtkIconInfo *icon_info;
 	const char  *filename = NULL;
 	GdkPixbuf   *pixbuf;
+	int          w, h;
 	
 	icon_info = gtk_icon_theme_lookup_icon (theme,	
 						"gnome-panel-launcher", /*"gtk-missing-image",*/
@@ -503,6 +537,16 @@
 	else
 		pixbuf = create_internal_missing_pixbuf (preffered_size);
 
+	w = gdk_pixbuf_get_width (pixbuf);
+	h = gdk_pixbuf_get_height (pixbuf);	
+	if (scale_keeping_ratio (&w, &h, preffered_size, preffered_size, FALSE)) {
+		GdkPixbuf *scaled;
+		
+		scaled = gdk_pixbuf_scale_simple (pixbuf, w, h, GDK_INTERP_BILINEAR);
+		g_object_unref (pixbuf);
+		pixbuf = scaled;
+	}
+
 	if (icon_info != NULL)
 		gtk_icon_info_free (icon_info);
 		

Modified: trunk/src/gtk-utils.h
==============================================================================
--- trunk/src/gtk-utils.h	(original)
+++ trunk/src/gtk-utils.h	Thu Feb  5 11:27:40 2009
@@ -65,8 +65,7 @@
 					          int               preffered_size);					  
 GdkPixbuf *   create_pixbuf                      (GtkIconTheme     *icon_theme,
 					          const char       *icon_name,
-					          int               icon_size,
-					          gboolean          with_fallback);
+					          int               icon_size);
 GdkPixbuf *   create_pixbuf_or_missing           (GtkIconTheme     *theme, 
 					          const char       *icon_name,
 					          int               preffered_size);					  



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]