[baobab/wip/vala: 5/45] reimplement the progress bar cell renderer



commit 45f9fef5157dd1243942bc674986b9c8c5025eea
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Jan 5 16:06:51 2012 -0500

    reimplement the progress bar cell renderer
    
    If we base this on GtkCellRendererProgress then we can drop a lot of
    lines (really, we only need to implement the draw function).

 data/baobab-main-window.ui          |    7 +-
 src/Makefile.am                     |    1 -
 src/baobab-cell-renderer-progress.c |  262 -----------------------------------
 src/baobab-cell-renderer-progress.h |   57 --------
 src/baobab-cellrenderers.vala       |   43 ++++++
 5 files changed, 48 insertions(+), 322 deletions(-)
---
diff --git a/data/baobab-main-window.ui b/data/baobab-main-window.ui
index 07e1291..145bb2a 100644
--- a/data/baobab-main-window.ui
+++ b/data/baobab-main-window.ui
@@ -229,9 +229,12 @@
                     <property name="reorderable">True</property>
                     <property name="sort_column_id">2</property>
                     <child>
-                      <object class="BaobabCellRendererProgress" id="usage-column-bar-renderer"/>
+                      <object class="BaobabCellRendererProgress" id="usage-column-bar-renderer">
+                        <property name="xpad">4</property>
+                        <property name="ypad">4</property>
+                      </object>
                       <attributes>
-                        <attribute name="perc">2</attribute>
+                        <attribute name="value">2</attribute>
                       </attributes>
                     </child>
                     <child>
diff --git a/src/Makefile.am b/src/Makefile.am
index 4acfbd6..740b776 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,7 +21,6 @@ baobab_SOURCES = \
 	baobab-treemap.c		\
 	baobab-ringschart.c		\
 	baobab-scanner.vala		\
-	baobab-cell-renderer-progress.c	\
 	baobab-cellrenderers.vala	\
 	baobab-application.vala		\
 	baobab-window.vala		\
diff --git a/src/baobab-cellrenderers.vala b/src/baobab-cellrenderers.vala
index b23401d..743b56f 100644
--- a/src/baobab-cellrenderers.vala
+++ b/src/baobab-cellrenderers.vala
@@ -34,4 +34,47 @@ namespace Baobab {
 			}
 		}
 	}
+
+	public class CellRendererProgress : Gtk.CellRendererProgress {
+		public override void render (Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) {
+			int xpad;
+			int ypad;
+			get_padding (out xpad, out ypad);
+
+			// fill entire drawing area with black
+			var x = cell_area.x + xpad;
+			var y = cell_area.y + ypad;
+			var w = cell_area.width - xpad * 2;
+			var h = cell_area.height - ypad * 2;
+			cr.rectangle (x, y, w, h);
+			cr.set_source_rgb (0, 0, 0);
+			cr.fill ();
+
+			// draw a smaller white rectangle on top, leaving a black outline
+			var style = widget.get_style ();
+			x += style.xthickness;
+			y += style.xthickness;
+			w -= style.xthickness * 2;
+			h -= style.xthickness * 2;
+			cr.rectangle (x, y, w, h);
+			cr.set_source_rgb (1, 1, 1);
+			cr.fill ();
+
+			// fill in remaining area according to percentage value
+			var percent = value;
+			var perc_w = (w * percent) / 100;
+			if (widget.get_direction () == Gtk.TextDirection.RTL) {
+				x += w - perc_w;
+			}
+			cr.rectangle (x, y, perc_w, h);
+			if (percent <= 33) {
+				cr.set_source_rgb (0x73 / 255.0, 0xd2 / 255.0, 0x16 / 255.0);
+			} else if (percent <= 66) {
+				cr.set_source_rgb (0xed / 255.0, 0xd4 / 255.0, 0x00 / 255.0);
+			} else {
+				cr.set_source_rgb (0xcc / 255.0, 0x00 / 255.0, 0x00 / 255.0);
+			}
+			cr.fill ();
+		}
+	}
 }



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