[libgd] pixbuf-renderer: Support for activity on top of icons
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgd] pixbuf-renderer: Support for activity on top of icons
- Date: Mon, 17 Jun 2013 09:27:47 +0000 (UTC)
commit a1f754372958b6d67e4116e8b7da8ef702dd1668
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Sun Jun 9 17:01:54 2013 +0300
pixbuf-renderer: Support for activity on top of icons
This will be useful to indicate that there is some automated activity
going on the item the icon in question represents.
The main use case I have in mind with this is Boxes indicating VMs that
are under installation.
https://bugzilla.gnome.org/show_bug.cgi?id=702212
libgd/gd-main-icon-view.c | 2 +
libgd/gd-main-view-generic.h | 1 +
libgd/gd-toggle-pixbuf-renderer.c | 108 +++++++++++++++++++++++++++++--------
3 files changed, 89 insertions(+), 22 deletions(-)
---
diff --git a/libgd/gd-main-icon-view.c b/libgd/gd-main-icon-view.c
index 644a653..2048d31 100644
--- a/libgd/gd-main-icon-view.c
+++ b/libgd/gd-main-icon-view.c
@@ -106,6 +106,8 @@ gd_main_icon_view_constructed (GObject *obj)
"active", GD_MAIN_COLUMN_SELECTED);
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell,
"pixbuf", GD_MAIN_COLUMN_ICON);
+ gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell,
+ "pulse", GD_MAIN_COLUMN_PULSE);
cell = gd_two_lines_renderer_new ();
g_object_set (cell,
diff --git a/libgd/gd-main-view-generic.h b/libgd/gd-main-view-generic.h
index 4df84ff..dd53e0e 100644
--- a/libgd/gd-main-view-generic.h
+++ b/libgd/gd-main-view-generic.h
@@ -36,6 +36,7 @@ typedef enum {
GD_MAIN_COLUMN_ICON,
GD_MAIN_COLUMN_MTIME,
GD_MAIN_COLUMN_SELECTED,
+ GD_MAIN_COLUMN_PULSE,
GD_MAIN_COLUMN_LAST
} GdMainColumns;
diff --git a/libgd/gd-toggle-pixbuf-renderer.c b/libgd/gd-toggle-pixbuf-renderer.c
index 3267938..39f4386 100644
--- a/libgd/gd-toggle-pixbuf-renderer.c
+++ b/libgd/gd-toggle-pixbuf-renderer.c
@@ -26,6 +26,7 @@ G_DEFINE_TYPE (GdTogglePixbufRenderer, gd_toggle_pixbuf_renderer, GTK_TYPE_CELL_
enum {
PROP_ACTIVE = 1,
PROP_TOGGLE_VISIBLE,
+ PROP_PULSE,
NUM_PROPERTIES
};
@@ -34,38 +35,29 @@ static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
struct _GdTogglePixbufRendererPrivate {
gboolean active;
gboolean toggle_visible;
+
+ gint pulse;
};
static void
-gd_toggle_pixbuf_renderer_render (GtkCellRenderer *cell,
- cairo_t *cr,
- GtkWidget *widget,
- const GdkRectangle *background_area,
- const GdkRectangle *cell_area,
- GtkCellRendererState flags)
+render_check (GdTogglePixbufRenderer *self,
+ cairo_t *cr,
+ GtkWidget *widget,
+ const GdkRectangle *cell_area,
+ gint icon_size,
+ gint xpad,
+ gint ypad)
{
- gint icon_size = -1;
- gint check_x, check_y, x_offset, xpad, ypad;
GtkStyleContext *context;
- GdTogglePixbufRenderer *self = GD_TOGGLE_PIXBUF_RENDERER (cell);
+ gint check_x, check_y, x_offset;
GtkTextDirection direction;
- GTK_CELL_RENDERER_CLASS (gd_toggle_pixbuf_renderer_parent_class)->render
- (cell, cr, widget,
- background_area, cell_area, flags);
+ context = gtk_widget_get_style_context (widget);
if (!self->priv->toggle_visible)
return;
- gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
direction = gtk_widget_get_direction (widget);
- gtk_widget_style_get (widget,
- "check-icon-size", &icon_size,
- NULL);
-
- if (icon_size == -1)
- icon_size = 40;
-
if (direction == GTK_TEXT_DIR_RTL)
x_offset = xpad;
else
@@ -74,7 +66,6 @@ gd_toggle_pixbuf_renderer_render (GtkCellRenderer *cell,
check_x = cell_area->x + x_offset;
check_y = cell_area->y + cell_area->height - icon_size - ypad;
- context = gtk_widget_get_style_context (widget);
gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_CHECK);
@@ -84,11 +75,68 @@ gd_toggle_pixbuf_renderer_render (GtkCellRenderer *cell,
gtk_render_check (context, cr,
check_x, check_y,
icon_size, icon_size);
-
gtk_style_context_restore (context);
}
static void
+render_activity (GdTogglePixbufRenderer *self,
+ cairo_t *cr,
+ GtkWidget *widget,
+ const GdkRectangle *cell_area,
+ gint icon_size,
+ gint xpad,
+ gint ypad)
+{
+ gint x, y, width, height;
+
+ if (self->priv->pulse == G_MAXINT)
+ return;
+
+ width = cell_area->width / 4;
+ height = cell_area->height / 4;
+
+ x = cell_area->x + (cell_area->width / 2) - (width / 2) - xpad;
+ y = cell_area->y + (cell_area->height / 2) - (height / 2) - ypad;
+
+ gtk_paint_spinner (gtk_widget_get_style (widget),
+ cr,
+ GTK_STATE_FLAG_ACTIVE,
+ widget,
+ NULL,
+ (guint) self->priv->pulse,
+ x, y,
+ width, height);
+}
+
+static void
+gd_toggle_pixbuf_renderer_render (GtkCellRenderer *cell,
+ cairo_t *cr,
+ GtkWidget *widget,
+ const GdkRectangle *background_area,
+ const GdkRectangle *cell_area,
+ GtkCellRendererState flags)
+{
+ gint icon_size = -1;
+ GdTogglePixbufRenderer *self = GD_TOGGLE_PIXBUF_RENDERER (cell);
+ gint xpad, ypad;
+
+ GTK_CELL_RENDERER_CLASS (gd_toggle_pixbuf_renderer_parent_class)->render
+ (cell, cr, widget,
+ background_area, cell_area, flags);
+
+ gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
+ gtk_widget_style_get (widget,
+ "check-icon-size", &icon_size,
+ NULL);
+
+ if (icon_size == -1)
+ icon_size = 40;
+
+ render_activity (self, cr, widget, cell_area, icon_size, xpad, ypad);
+ render_check (self, cr, widget, cell_area, icon_size, xpad, ypad);
+}
+
+static void
gd_toggle_pixbuf_renderer_get_size (GtkCellRenderer *cell,
GtkWidget *widget,
const GdkRectangle *cell_area,
@@ -126,6 +174,9 @@ gd_toggle_pixbuf_renderer_get_property (GObject *object,
case PROP_TOGGLE_VISIBLE:
g_value_set_boolean (value, self->priv->toggle_visible);
break;
+ case PROP_PULSE:
+ g_value_set_int (value, self->priv->pulse);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -148,6 +199,9 @@ gd_toggle_pixbuf_renderer_set_property (GObject *object,
case PROP_TOGGLE_VISIBLE:
self->priv->toggle_visible = g_value_get_boolean (value);
break;
+ case PROP_PULSE:
+ self->priv->pulse = g_value_get_int (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -179,6 +233,16 @@ gd_toggle_pixbuf_renderer_class_init (GdTogglePixbufRendererClass *klass)
FALSE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
+ properties[PROP_PULSE] =
+ g_param_spec_int ("pulse",
+ "Pulse",
+ "Set to any value other than %G_MAXINT to display a "
+ "spinner on top of the pixbuf.",
+ G_MININT,
+ G_MAXINT,
+ G_MAXINT,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS);
g_type_class_add_private (klass, sizeof (GdTogglePixbufRendererPrivate));
g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]