public void Render(Cairo.Context c, Gdk.Color @base) { // Fill the background var color = CairoExtensions.RandomShadeOfGdkColor(@base); c.Rectangle(X, Y, Width, Height); c.SetSourceRGB(color.R, color.G, color.B); c.Fill(); if (Children == null) { int w, h; // Render the item text using (var p = Pango.CairoHelper.CreateLayout(c)) { p.SetText(Title); p.Width = (int)(Pango.Scale.PangoScale * Width); p.Ellipsize = Pango.EllipsizeMode.End; p.GetPixelSize(out w, out h); c.SetSourceRGB(1.0, 1.0, 1.0); if (w <= Width && h <= Height) { c.MoveTo(X + ((Width - w) / 2), Y + ((Height - h) / 2)); Pango.CairoHelper.ShowLayout(c, p); } } } else { Children.ForEach(delegate(TreeMapItem i) { i.Render(c, @base); }); } // Lose our reference to the title Title = String.Empty; }
void UpdateBgImage() { m_bgImage = null; if (TextColumn < 0 || WeightColumn < 0) { return; } m_bgImage = new Cairo.ImageSurface(Format.Rgb24, Allocation.Width, this.Allocation.Height); using (var c = new Cairo.Context(m_bgImage)) { // Paint the default background (linear gradient) var g = new Cairo.LinearGradient(0, 0, 1, this.Allocation.Height); g.AddColorStop(0.2, CairoExtensions.GdkColorToCairoColor(m_Background)); g.AddColorStop(0.9, CairoExtensions.GdkColorToCairoColor(this.Style.Background(Gtk.StateType.Normal))); c.Rectangle(0, 0, this.Allocation.Width, this.Allocation.Height); c.Pattern = g; c.Paint(); g.Dispose(); Gtk.TreeIter iter; List <TreeMapItem> rootItems = new List <TreeMapItem> (); if (m_Model.GetIterFirst(out iter)) { do { var item = new TreeMapItem(m_Model, ref iter, true, m_TextColumn, m_WeightColumn); rootItems.Add(item); } while (m_Model.IterNext(ref iter)); double t = 0.0; rootItems.ForEach(delegate(TreeMapItem i) { t += Math.Abs(i.Weight); }); double x = 0, y = 0, w = this.Allocation.Width, h = this.Allocation.Height; double myx = 0, myy = 0, myw = 0, myh = 0; rootItems.ForEach(delegate(TreeMapItem i) { var ratio = Math.Abs(i.Weight) / t; myx = x; myy = y; myw = w * ratio; myh = h; x += myw; i.SetArea(myx, myy, myw, myh); i.Render(c, m_Background); }); // clear right away to lower refs if (this.m_rootItems != null) { this.m_rootItems.Clear(); } this.m_rootItems = rootItems; } } }