[baobab] Use an offscreen surface for chart drawing
- From: Stefano Facchini <sfacchini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab] Use an offscreen surface for chart drawing
- Date: Sun, 6 Jul 2014 10:42:15 +0000 (UTC)
commit 15475b2920e88d4da90f39e55c1da0e5b88d7b29
Author: Stefano Facchini <stefano facchini gmail com>
Date: Sun Jul 6 12:29:17 2014 +0200
Use an offscreen surface for chart drawing
Previously the border between angular sectors in Ringschart was obtained
by a cairo_stroke() with the background color. The problem with this is that
we needed to fetch the color from the theme somehow and this was not always
possible (for instance the HighContrast theme does not define @theme_bg_color).
Now we just draw to an offscreen surface and obtain the borders by clearing the
relevant pixels. The surface is finally painted on the window.
src/baobab-chart.vala | 14 +++++++++++++-
src/baobab-ringschart.vala | 10 ++++------
src/baobab.css | 4 ----
3 files changed, 17 insertions(+), 11 deletions(-)
---
diff --git a/src/baobab-chart.vala b/src/baobab-chart.vala
index 48e2f7a..2837c74 100644
--- a/src/baobab-chart.vala
+++ b/src/baobab-chart.vala
@@ -454,7 +454,19 @@ namespace Baobab {
}
}
- draw_chart (cr);
+ // Here we use an intermediate offscreen surface because in this way draw_chart()
+ // can obtain transparent pixels just by painting with CAIRO_OPERATOR_CLEAR,
+ // instead of relying on the knowledge of the background color as defined by the theme.
+ Gtk.Allocation allocation;
+ get_allocation (out allocation);
+
+ var source = new Cairo.ImageSurface (Cairo.Format.ARGB32, allocation.width,
allocation.height);
+ var source_cr = new Cairo.Context (source);
+
+ draw_chart (source_cr);
+
+ cr.set_source_surface (source, 0, 0);
+ cr.paint ();
}
return false;
diff --git a/src/baobab-ringschart.vala b/src/baobab-ringschart.vala
index 0b37f6c..22d8550 100644
--- a/src/baobab-ringschart.vala
+++ b/src/baobab-ringschart.vala
@@ -238,11 +238,8 @@ namespace Baobab {
get_allocation (out allocation);
var context = get_style_context ();
- context.save ();
- context.add_class ("ringschart-item");
var border_color = context.get_border_color (Gtk.StateFlags.NORMAL);
- var bg_color = context.get_background_color (Gtk.StateFlags.NORMAL);
var center_x = allocation.width / 2;
var center_y = allocation.height / 2;
@@ -279,9 +276,12 @@ namespace Baobab {
Gdk.cairo_set_source_rgba (cr, fill_color);
cr.fill_preserve ();
- Gdk.cairo_set_source_rgba (cr, bg_color);
+
+ cr.set_operator (Cairo.Operator.CLEAR);
cr.stroke ();
+ cr.set_operator (Cairo.Operator.OVER);
+
if (ringsitem.continued) {
Gdk.cairo_set_source_rgba (cr, border_color);
cr.set_line_width (3);
@@ -289,8 +289,6 @@ namespace Baobab {
cr.stroke ();
}
}
-
- context.restore ();
}
protected override void calculate_item_geometry (ChartItem item) {
diff --git a/src/baobab.css b/src/baobab.css
index 5bc9aa3..b2ee94c 100644
--- a/src/baobab.css
+++ b/src/baobab.css
@@ -69,10 +69,6 @@ BaobabRingschart {
padding: 13px 13px 13px 13px;
}
-.ringschart-item {
- background-color: @theme_bg_color;
-}
-
BaobabRingschart.subfolder-tip {
padding: 3px 3px 3px 3px;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]