added icon scaling for icons that are bigger than requested
authormishas <mikhail.sobolev@gmail.com>
Fri, 11 May 2007 14:52:59 +0000 (14:52 +0000)
committermishas <mikhail.sobolev@gmail.com>
Fri, 11 May 2007 14:52:59 +0000 (14:52 +0000)
git-svn-id: file:///svnroot/simple-launcher/trunk@206 3ba93dab-e023-0410-b42a-de7732cf370a

debian/changelog
launcher-item.cc

index 5d4e3ec..126ac32 100644 (file)
@@ -1,4 +1,4 @@
-simple-launcher (0.9.4~18) unstable; urgency=low
+simple-launcher (0.9.4~19) unstable; urgency=low
 
   * NOT RELEASED YET
   * settings dialog is moved into a separate class
@@ -27,8 +27,9 @@ simple-launcher (0.9.4~18) unstable; urgency=low
   * make a private copy of icons obtained through GtkIconTheme
   * implemented a different widget for icon size selection
   * set active item if found in the list
+  * added icon scaling for icons that are bigger than requested
 
- -- Mikhail Sobolev <mss@mawhrin.net>  Fri, 11 May 2007 16:24:30 +0300
+ -- Mikhail Sobolev <mss@mawhrin.net>  Fri, 11 May 2007 17:51:43 +0300
 
 simple-launcher (0.9.3) unstable; urgency=low
 
index a72ff1b..1b10593 100644 (file)
@@ -18,6 +18,7 @@
 #include <string>
 
 #include <libintl.h>
+#include <math.h>
 
 #include <glib/gmem.h>
 #include <glib/gkeyfile.h>
@@ -132,6 +133,29 @@ bool LauncherItem::load(const std::string& filename) {
   return (myEnabled = checkSanity());
 }
 
+// The function below is taken verbatim from exo library -- xfce supporting library
+static GdkPixbuf *exo_gdk_pixbuf_scale_ratio(GdkPixbuf *source, gint dest_size) {
+  gdouble wratio, hratio;
+  gint    source_width, source_height;
+  gint    dest_width, dest_height;
+
+  source_width = gdk_pixbuf_get_width(source);
+  source_height = gdk_pixbuf_get_height(source);
+
+  wratio = (gdouble)source_width / (gdouble)dest_size;
+  hratio = (gdouble)source_height / (gdouble)dest_size;
+
+  if (hratio > wratio) {
+    dest_width = (gint)rint(source_width / hratio);
+    dest_height = dest_size;
+  } else {
+    dest_width = dest_size;
+    dest_height = (gint)rint(source_height / wratio);
+  }
+
+  return gdk_pixbuf_scale_simple(source, MAX(dest_width, 1), MAX(dest_height, 1), GDK_INTERP_BILINEAR);
+}
+
 GdkPixbuf *LauncherItem::getIcon(int icon_size) const {
   if (ourTheme == NULL) {
     ourTheme = gtk_icon_theme_get_default();
@@ -159,7 +183,13 @@ GdkPixbuf *LauncherItem::getIcon(int icon_size) const {
   }
 
   if (pixbuf != NULL) {
-    GdkPixbuf *tempo = gdk_pixbuf_copy(pixbuf);
+    GdkPixbuf *tempo;
+
+    if (gdk_pixbuf_get_width(pixbuf) > icon_size || gdk_pixbuf_get_height(pixbuf) > icon_size) {
+      tempo = exo_gdk_pixbuf_scale_ratio(pixbuf, icon_size);
+    } else {
+      tempo = gdk_pixbuf_copy(pixbuf);
+    }
 
     g_object_unref(pixbuf);