[baobab/wip/valacharts] style fixup



commit a38bdbe0b148f12fdd05c539d95a4e2e35e88946
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Tue Jun 11 15:46:56 2013 +0200

    style fixup

 src/baobab-chart.vala      |    3 -
 src/baobab-ringschart.vala |  226 ++++++++++++++++++++++----------------------
 2 files changed, 114 insertions(+), 115 deletions(-)
---
diff --git a/src/baobab-chart.vala b/src/baobab-chart.vala
index d61d24a..957f1f9 100644
--- a/src/baobab-chart.vala
+++ b/src/baobab-chart.vala
@@ -33,7 +33,6 @@ namespace Baobab {
         uint info_column;
         uint percentage_column;
         uint valid_column;
-        bool button_pressed;
         bool is_frozen;
 
         bool model_changed;
@@ -342,8 +341,6 @@ namespace Baobab {
                 return;
             }
 
-            Gtk.TreePath root_path = null;
-
             var root_depth = root.get_depth ();
             var node_depth = path.get_depth ();
 
diff --git a/src/baobab-ringschart.vala b/src/baobab-ringschart.vala
index a899eb4..8b339f4 100644
--- a/src/baobab-ringschart.vala
+++ b/src/baobab-ringschart.vala
@@ -2,10 +2,10 @@
 namespace Baobab {
 
     public class RingschartItem : ChartItem {
-        public double min_radius = 0;
-        public double max_radius = 0;
-        public double start_angle = 0;
-        public double angle = 0;
+        public double min_radius;
+        public double max_radius;
+        public double start_angle;
+        public double angle;
         public bool continued = false;
     }
 
@@ -54,123 +54,125 @@ namespace Baobab {
         }
 
         protected override void post_draw (Cairo.Context cr) {
-            if (drawing_subtips) {
-                Gtk.Allocation allocation;
-                get_allocation (out allocation);
+            if (!drawing_subtips) {
+                return;
+            }
+
+            Gtk.Allocation allocation;
+            get_allocation (out allocation);
 
-                var q_width = allocation.width / 2;
-                var q_height = allocation.height / 2;
-                var q_angle = Math.atan2 (q_height, q_width);
+            var q_width = allocation.width / 2;
+            var q_height = allocation.height / 2;
+            var q_angle = Math.atan2 (q_height, q_width);
 
-                Gdk.Rectangle last_rect = {0};
+            Gdk.Rectangle last_rect = {0};
 
-                foreach (ChartItem item in subtip_items) {
-                    RingschartItem ringsitem = item as RingschartItem;
+            foreach (ChartItem item in subtip_items) {
+                RingschartItem ringsitem = item as RingschartItem;
 
-                    // get the middle angle
-                    var middle_angle = ringsitem.start_angle + ringsitem.angle / 2;
-                    // normalize the middle angle (take it to the first quadrant
-                    var middle_angle_n = middle_angle;
-                    while (middle_angle_n > Math.PI / 2) {
-                        middle_angle_n -= Math.PI;
-                    }
-                    middle_angle_n = Math.fabs (middle_angle_n);
-
-                    // get the pango layout and its enclosing rectangle
-                    var layout = create_pango_layout (null);
-                    var markup = "<span size=\"small\">" + Markup.escape_text (item.name) + "</span>";
-                    layout.set_markup (markup, -1);
-                    layout.set_indent (0);
-                    layout.set_spacing (0);
-                    Pango.Rectangle layout_rect;
-                    layout.get_pixel_extents (null, out layout_rect);
-
-                    // get the center point of the tooltip rectangle
-                    double tip_x, tip_y;
-                    if (middle_angle_n < q_angle) {
-                        tip_x = q_width - layout_rect.width / 2 - SUBFOLDER_TIP_PADDING * 2;
-                        tip_y = Math.tan (middle_angle_n) * tip_x;
-                    } else {
-                        tip_y = q_height - layout_rect.height / 2 - SUBFOLDER_TIP_PADDING * 2;
-                        tip_x = tip_y / Math.tan (middle_angle_n);
-                    }
+                // get the middle angle
+                var middle_angle = ringsitem.start_angle + ringsitem.angle / 2;
+                // normalize the middle angle (take it to the first quadrant
+                var middle_angle_n = middle_angle;
+                while (middle_angle_n > Math.PI / 2) {
+                    middle_angle_n -= Math.PI;
+                }
+                middle_angle_n = Math.fabs (middle_angle_n);
+
+                // get the pango layout and its enclosing rectangle
+                var layout = create_pango_layout (null);
+                var markup = "<span size=\"small\">" + Markup.escape_text (item.name) + "</span>";
+                layout.set_markup (markup, -1);
+                layout.set_indent (0);
+                layout.set_spacing (0);
+                Pango.Rectangle layout_rect;
+                layout.get_pixel_extents (null, out layout_rect);
+
+                // get the center point of the tooltip rectangle
+                double tip_x, tip_y;
+                if (middle_angle_n < q_angle) {
+                    tip_x = q_width - layout_rect.width / 2 - SUBFOLDER_TIP_PADDING * 2;
+                    tip_y = Math.tan (middle_angle_n) * tip_x;
+                } else {
+                    tip_y = q_height - layout_rect.height / 2 - SUBFOLDER_TIP_PADDING * 2;
+                    tip_x = tip_y / Math.tan (middle_angle_n);
+                }
 
-                    // get the tooltip rectangle
-                    Cairo.Rectangle tooltip_rect = Cairo.Rectangle ();
-                    tooltip_rect.x = q_width + tip_x - layout_rect.width/2 - SUBFOLDER_TIP_PADDING;
-                    tooltip_rect.y = q_height + tip_y - layout_rect.height/2 - SUBFOLDER_TIP_PADDING;
-                    tooltip_rect.width = layout_rect.width + SUBFOLDER_TIP_PADDING * 2;
-                    tooltip_rect.height = layout_rect.height + SUBFOLDER_TIP_PADDING * 2;
+                // get the tooltip rectangle
+                Cairo.Rectangle tooltip_rect = Cairo.Rectangle ();
+                tooltip_rect.x = q_width + tip_x - layout_rect.width/2 - SUBFOLDER_TIP_PADDING;
+                tooltip_rect.y = q_height + tip_y - layout_rect.height/2 - SUBFOLDER_TIP_PADDING;
+                tooltip_rect.width = layout_rect.width + SUBFOLDER_TIP_PADDING * 2;
+                tooltip_rect.height = layout_rect.height + SUBFOLDER_TIP_PADDING * 2;
 
-                    // check tooltip's width is not greater than half of the widget
-                    if (tooltip_rect.width > q_width) {
-                        continue;
-                    }
+                // check tooltip's width is not greater than half of the widget
+                if (tooltip_rect.width > q_width) {
+                    continue;
+                }
 
-                    // translate tooltip rectangle and edge angles to the original quadrant
-                    var a = middle_angle;
-                    int i = 0;
-                    while (a > Math.PI/2) {
-                        if (i % 2 == 0) {
-                            tooltip_rect.x = allocation.width - tooltip_rect.x - tooltip_rect.width;
-                        } else {
-                            tooltip_rect.y = allocation.height - tooltip_rect.y - tooltip_rect.height;
-                        }
-                        i++;
-                        a -= Math.PI/2;
+                // translate tooltip rectangle and edge angles to the original quadrant
+                var a = middle_angle;
+                int i = 0;
+                while (a > Math.PI/2) {
+                    if (i % 2 == 0) {
+                        tooltip_rect.x = allocation.width - tooltip_rect.x - tooltip_rect.width;
+                    } else {
+                        tooltip_rect.y = allocation.height - tooltip_rect.y - tooltip_rect.height;
                     }
+                    i++;
+                    a -= Math.PI/2;
+                }
 
-                    // get the Gdk.Rectangle of the tooltip (with a little padding)
-                    Gdk.Rectangle _rect = Gdk.Rectangle ();
-                    _rect.x = (int) (tooltip_rect.x - 1);
-                    _rect.y = (int) (tooltip_rect.y - 1);
-                    _rect.width = (int) (tooltip_rect.width + 2);
-                    _rect.height = (int) (tooltip_rect.height + 2);
-
-                    // check if tooltip overlaps
-                    if (!_rect.intersect (last_rect, null)) {
-                        last_rect = _rect;
-
-                        // finally draw the tooltip!
-
-                        // TODO: do not hardcode colors
-
-                        // avoid blurred lines
-                        tooltip_rect.x = (int) Math.floor (tooltip_rect.x) + 0.5;
-                        tooltip_rect.y = (int) Math.floor (tooltip_rect.y) + 0.5;
-
-                        var middle_radius = ringsitem.min_radius + (ringsitem.max_radius - 
ringsitem.min_radius) / 2;
-                        var sector_center_x = q_width + middle_radius * Math.cos (middle_angle);
-                        var sector_center_y = q_height + middle_radius * Math.sin (middle_angle);
-
-                        // draw line from sector center to tooltip center
-                        cr.set_line_width (1);
-                        cr.move_to (sector_center_x, sector_center_y);
-                        cr.set_source_rgb (0.8275, 0.8431, 0.8118); // tango: #d3d7cf
-                        cr.line_to (tooltip_rect.x + tooltip_rect.width / 2,
-                                    tooltip_rect.y + tooltip_rect.height / 2);
-                        cr.stroke ();
-
-                        // draw a tiny circle in sector center
-                        cr.set_source_rgba (1.0, 1.0, 1.0, 0.6666);
-                        cr.arc (sector_center_x, sector_center_y, 1.0, 0, 2 * Math.PI);
-                        cr.stroke ();
-
-                        // draw tooltip box
-                        cr.set_line_width (0.5);
-                        cr.rectangle (tooltip_rect.x, tooltip_rect.y, tooltip_rect.width, 
tooltip_rect.height);
-                        cr.set_source_rgb (0.8275, 0.8431, 0.8118);  // tango: #d3d7cf
-                        cr.fill_preserve ();
-                        cr.set_source_rgb (0.5333, 0.5412, 0.5216);  // tango: #888a85
-                        cr.stroke ();
-
-                        // draw the text inside the box
-                        cr.set_source_rgb (0, 0, 0);
-                        cr.move_to (tooltip_rect.x + SUBFOLDER_TIP_PADDING, tooltip_rect.y + 
SUBFOLDER_TIP_PADDING);
-                        Pango.cairo_show_layout (cr, layout);
-                        cr.set_line_width (1);
-                        cr.stroke ();
-                    }
+                // get the Gdk.Rectangle of the tooltip (with a little padding)
+                Gdk.Rectangle _rect = Gdk.Rectangle ();
+                _rect.x = (int) (tooltip_rect.x - 1);
+                _rect.y = (int) (tooltip_rect.y - 1);
+                _rect.width = (int) (tooltip_rect.width + 2);
+                _rect.height = (int) (tooltip_rect.height + 2);
+
+                // check if tooltip overlaps
+                if (!_rect.intersect (last_rect, null)) {
+                    last_rect = _rect;
+
+                    // finally draw the tooltip!
+
+                    // TODO: do not hardcode colors
+
+                    // avoid blurred lines
+                    tooltip_rect.x = (int) Math.floor (tooltip_rect.x) + 0.5;
+                    tooltip_rect.y = (int) Math.floor (tooltip_rect.y) + 0.5;
+
+                    var middle_radius = ringsitem.min_radius + (ringsitem.max_radius - ringsitem.min_radius) 
/ 2;
+                    var sector_center_x = q_width + middle_radius * Math.cos (middle_angle);
+                    var sector_center_y = q_height + middle_radius * Math.sin (middle_angle);
+
+                    // draw line from sector center to tooltip center
+                    cr.set_line_width (1);
+                    cr.move_to (sector_center_x, sector_center_y);
+                    cr.set_source_rgb (0.8275, 0.8431, 0.8118); // tango: #d3d7cf
+                    cr.line_to (tooltip_rect.x + tooltip_rect.width / 2,
+                                tooltip_rect.y + tooltip_rect.height / 2);
+                    cr.stroke ();
+
+                    // draw a tiny circle in sector center
+                    cr.set_source_rgba (1.0, 1.0, 1.0, 0.6666);
+                    cr.arc (sector_center_x, sector_center_y, 1.0, 0, 2 * Math.PI);
+                    cr.stroke ();
+
+                    // draw tooltip box
+                    cr.set_line_width (0.5);
+                    cr.rectangle (tooltip_rect.x, tooltip_rect.y, tooltip_rect.width, tooltip_rect.height);
+                    cr.set_source_rgb (0.8275, 0.8431, 0.8118);  // tango: #d3d7cf
+                    cr.fill_preserve ();
+                    cr.set_source_rgb (0.5333, 0.5412, 0.5216);  // tango: #888a85
+                    cr.stroke ();
+
+                    // draw the text inside the box
+                    cr.set_source_rgb (0, 0, 0);
+                    cr.move_to (tooltip_rect.x + SUBFOLDER_TIP_PADDING, tooltip_rect.y + 
SUBFOLDER_TIP_PADDING);
+                    Pango.cairo_show_layout (cr, layout);
+                    cr.set_line_width (1);
+                    cr.stroke ();
                 }
             }
         }


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