g_warning("Widget not found: %s", widget_name);
return found_widget;
}
+
+/**
+ * Returns a label widget that is made selectable (i.e. the user can copy the text)
+ * @param text String to display - maybe NULL
+ * @return The label widget
+ */
+GtkWidget* ui_label_new_selectable ( const gchar* text )
+{
+ GtkWidget *widget = gtk_label_new ( text );
+ gtk_label_set_selectable ( GTK_LABEL(widget), TRUE );
+ return widget;
+}
+
+/**
+ * Apply the alpha value to the specified pixbuf
+ */
+GdkPixbuf *ui_pixbuf_set_alpha ( GdkPixbuf *pixbuf, guint8 alpha )
+{
+ guchar *pixels;
+ gint width, height, iii, jjj;
+
+ if ( ! gdk_pixbuf_get_has_alpha ( pixbuf ) )
+ {
+ GdkPixbuf *tmp = gdk_pixbuf_add_alpha(pixbuf,FALSE,0,0,0);
+ g_object_unref(G_OBJECT(pixbuf));
+ pixbuf = tmp;
+ if ( !pixbuf )
+ return NULL;
+ }
+
+ pixels = gdk_pixbuf_get_pixels(pixbuf);
+ width = gdk_pixbuf_get_width(pixbuf);
+ height = gdk_pixbuf_get_height(pixbuf);
+
+ /* r,g,b,a,r,g,b,a.... */
+ for (iii = 0; iii < width; iii++) for (jjj = 0; jjj < height; jjj++)
+ {
+ pixels += 3;
+ *pixels++ = alpha;
+ }
+ return pixbuf;
+}
+
+
+/**
+ * Reduce the alpha value of the specified pixbuf by alpha / 255
+ */
+GdkPixbuf *ui_pixbuf_scale_alpha ( GdkPixbuf *pixbuf, guint8 alpha )
+{
+ guchar *pixels;
+ gint width, height, iii, jjj;
+
+ if ( ! gdk_pixbuf_get_has_alpha ( pixbuf ) )
+ {
+ GdkPixbuf *tmp = gdk_pixbuf_add_alpha(pixbuf,FALSE,0,0,0);
+ g_object_unref(G_OBJECT(pixbuf));
+ pixbuf = tmp;
+ if ( !pixbuf )
+ return NULL;
+ }
+
+ pixels = gdk_pixbuf_get_pixels(pixbuf);
+ width = gdk_pixbuf_get_width(pixbuf);
+ height = gdk_pixbuf_get_height(pixbuf);
+
+ /* r,g,b,a,r,g,b,a.... */
+ for (iii = 0; iii < width; iii++) for (jjj = 0; jjj < height; jjj++)
+ {
+ pixels += 3;
+ *pixels = (guint8)(((guint16)*pixels * (guint16)alpha) / 255);
+ pixels++;
+ }
+ return pixbuf;
+}
+
+
+
+/**
+ *
+ */
+void ui_add_recent_file ( const gchar *filename )
+{
+ if ( filename ) {
+ GtkRecentManager *manager = gtk_recent_manager_get_default();
+ GFile *file = g_file_new_for_commandline_arg ( filename );
+ gchar *uri = g_file_get_uri ( file );
+ if ( uri && manager )
+ gtk_recent_manager_add_item ( manager, uri );
+ g_object_unref( file );
+ g_free (uri);
+ }
+}