Permalink
Browse files

Add 'faded' icon option to St.Icon generation

  • Loading branch information...
1 parent 7959517 commit 33eaa06916f7cf2b023bf7e295193a166c9d3ce1 @mtwebster mtwebster committed Jul 18, 2012
Showing with 145 additions and 1 deletion.
  1. +5 −0 NEWS
  2. +1 −0 src/st-enum-types.c
  3. +137 −0 src/st/st-texture-cache.c
  4. +2 −1 src/st/st-types.h
View
5 NEWS
@@ -17,6 +17,11 @@ New features:
- New scale and expo applets
- Notifications applet
+API:
+
+ - New St.IconType.FADED icon style
+
+
Bug fixes:
- Gnome 3.4 changes (memory leak fixes, some configuration moved to gsettings, multiple bug fixes)
View
@@ -164,6 +164,7 @@ st_icon_type_get_type(void) {
{ ST_ICON_FULLCOLOR, "ST_ICON_FULLCOLOR", "fullcolor" },
{ ST_ICON_APPLICATION, "ST_ICON_APPLICATION", "application" },
{ ST_ICON_DOCUMENT, "ST_ICON_DOCUMENT", "document" },
+ { ST_ICON_FADED, "ST_ICON_FADED", "faded" },
{ 0, NULL, NULL }
};
enum_type_id = g_enum_register_static (g_intern_static_string ("StIconType"), values);
View
@@ -27,6 +27,7 @@
#include <libgnome-desktop/gnome-desktop-thumbnail.h>
#include <string.h>
#include <glib.h>
+#include "st.h"
#define CACHE_PREFIX_GICON "gicon:"
#define CACHE_PREFIX_URI "uri:"
@@ -1474,6 +1475,107 @@ symbolic_names_for_icon (const char *name)
return names;
}
+typedef struct {
+ char *name;
+ int size;
+} CreateFadedIconData;
+
+static CoglHandle
+create_faded_icon_cpu (StTextureCache *cache,
+ const char *key,
+ void *datap,
+ GError **error)
+{
+ CreateFadedIconData *data = datap;
+ char *name;
+ GdkPixbuf *pixbuf;
+ int size;
+ CoglHandle texture;
+ gint width, height, rowstride;
+ guint8 n_channels;
+ gboolean have_alpha;
+ gint fade_start;
+ gint fade_range;
+ guint i, j;
+ guint pixbuf_byte_size;
+ guint8 *orig_pixels;
+ guint8 *pixels;
+ GIcon *icon;
+ GtkIconInfo *info;
+
+ name = data->name;
+ size = data->size;
+
+ info = NULL;
+
+ icon = g_themed_icon_new_with_default_fallbacks (name);
+ if (icon != NULL)
+ {
+ info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
+ icon, size,
+ GTK_ICON_LOOKUP_FORCE_SIZE);
+ }
+
+ if (info == NULL)
+ {
+ icon = g_themed_icon_new ("application-x-executable");
+ info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
+ icon, size,
+ GTK_ICON_LOOKUP_FORCE_SIZE);
+ g_object_unref (icon);
+ }
+
+ if (info == NULL)
+ return COGL_INVALID_HANDLE;
+
+ pixbuf = gtk_icon_info_load_icon (info, NULL);
+ gtk_icon_info_free (info);
+
+ if (pixbuf == NULL)
+ return COGL_INVALID_HANDLE;
+
+ width = gdk_pixbuf_get_width (pixbuf);
+ height = gdk_pixbuf_get_height (pixbuf);
+ rowstride = gdk_pixbuf_get_rowstride (pixbuf);
+ n_channels = gdk_pixbuf_get_n_channels (pixbuf);
+ orig_pixels = gdk_pixbuf_get_pixels (pixbuf);
+ have_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
+
+ pixbuf_byte_size = (height - 1) * rowstride +
+ + width * ((n_channels * gdk_pixbuf_get_bits_per_sample (pixbuf) + 7) / 8);
+
+ pixels = g_malloc0 (rowstride * height);
+ memcpy (pixels, orig_pixels, pixbuf_byte_size);
+
+ fade_start = width / 2;
+ fade_range = width - fade_start;
+ for (i = fade_start; i < width; i++)
+ {
+ for (j = 0; j < height; j++)
+ {
+ guchar *pixel = &pixels[j * rowstride + i * n_channels];
+ float fade = 1.0 - ((float) i - fade_start) / fade_range;
+ pixel[0] = 0.5 + pixel[0] * fade;
+ pixel[1] = 0.5 + pixel[1] * fade;
+ pixel[2] = 0.5 + pixel[2] * fade;
+ if (have_alpha)
+ pixel[3] = 0.5 + pixel[3] * fade;
+ }
+ }
+
+ texture = cogl_texture_new_from_data (width,
+ height,
+ COGL_TEXTURE_NONE,
+ have_alpha ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
+ COGL_PIXEL_FORMAT_ANY,
+ rowstride,
+ pixels);
+ g_free (pixels);
+ g_object_unref (pixbuf);
+
+ return texture;
+}
+
/**
* st_texture_cache_load_icon_name:
* @cache: The texture cache instance
@@ -1496,8 +1598,11 @@ st_texture_cache_load_icon_name (StTextureCache *cache,
gint size)
{
ClutterActor *texture;
+ CoglHandle cogltexture;
GIcon *themed;
char **names;
+ char *cache_key;
+ CreateFadedIconData data;
g_return_val_if_fail (!(icon_type == ST_ICON_SYMBOLIC && theme_node == NULL), NULL);
@@ -1549,13 +1654,45 @@ st_texture_cache_load_icon_name (StTextureCache *cache,
g_object_unref (themed);
}
+ return CLUTTER_ACTOR (texture);
+ break;
+ case ST_ICON_FADED:
+ themed = g_themed_icon_new_with_default_fallbacks (name);
+ cache_key = g_strdup_printf ("faded-icon:%s,size=%d", name, size);
+ data.name = name;
+ data.size = size;
+ cogltexture = st_texture_cache_load (st_texture_cache_get_default (),
+ cache_key,
+ ST_TEXTURE_CACHE_POLICY_FOREVER,
+ create_faded_icon_cpu,
+ &data,
+ NULL);
+ g_free (cache_key);
+
+ if (cogltexture != COGL_INVALID_HANDLE)
+ {
+ texture = clutter_texture_new ();
+ clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (texture), cogltexture);
+ }
+ else
+ {
+ texture = load_gicon_with_colors (cache, themed, size, NULL);
+ g_object_unref (themed);
+ if (texture == NULL)
+ {
+ themed = g_themed_icon_new ("image-missing");
+ texture = load_gicon_with_colors (cache, themed, size, NULL);
+ g_object_unref (themed);
+ }
+ }
return CLUTTER_ACTOR (texture);
break;
default:
g_assert_not_reached ();
}
}
+
/**
* st_texture_cache_load_uri_async:
* @cache: The texture cache instance
View
@@ -47,7 +47,8 @@ typedef enum {
ST_ICON_SYMBOLIC,
ST_ICON_FULLCOLOR,
ST_ICON_APPLICATION,
- ST_ICON_DOCUMENT
+ ST_ICON_DOCUMENT,
+ ST_ICON_FADED
} StIconType;
G_END_DECLS

0 comments on commit 33eaa06

Please sign in to comment.