public static void FillRegion(this Context g, Gdk.Region region, Cairo.Color color) { g.Save (); g.Color = color; foreach (Gdk.Rectangle r in region.GetRectangles()) { g.MoveTo (r.X, r.Y); g.LineTo (r.X + r.Width, r.Y); g.LineTo (r.X + r.Width, r.Y + r.Height); g.LineTo (r.X, r.Y + r.Height); g.LineTo (r.X, r.Y); g.Color = color; g.StrokeExtents (); g.Fill (); } g.Restore (); }
private static Gdk.Rectangle[] GetRectangles(Gdk.Region region) { #if true return new Gdk.Rectangle [] { region.Clipbox }; #else return region.GetRectangles (); #endif }
private void PreloadRegion (Gdk.Region region, int step) { Gdk.Rectangle [] rects = region.GetRectangles (); if (step < 0) System.Array.Reverse (rects); foreach (Gdk.Rectangle preload in rects) { Preload (preload, false); } }
private void RenderBackground(Gdk.Window window, Gdk.Region region) { rand = rand ?? new Random (); if (circles == null) { for (int i = 0, n = rand.Next (100, 150); i < n; i++) { circles = circles ?? new Circle[n]; circles[i] = new Circle { X = rand.Next (0, Screen.Width), Y = rand.Next (0, Screen.Height), R = rand.Next (10, 70), A = rand.NextDouble () * 0.08 }; } } Cairo.Context cr = Gdk.CairoHelper.Create (window); foreach (Gdk.Rectangle damage in region.GetRectangles ()) { cr.Rectangle (damage.X, damage.Y, damage.Width, damage.Height); cr.Clip (); cr.Translate (Allocation.X, Allocation.Y); cr.Rectangle (0, 0, Allocation.Width, Allocation.Height); if (render_gradient) { var grad = new Cairo.LinearGradient (0, 0, 0, Allocation.Height); grad.AddColorStop (0.7, CairoExtensions.GdkColorToCairoColor (Style.Base (StateType.Normal))); grad.AddColorStop (1, CairoExtensions.GdkColorToCairoColor (Style.Background (StateType.Normal))); cr.Pattern = grad; cr.Fill (); grad.Destroy (); foreach (var circle in circles) { cr.Color = new Cairo.Color (0, 0, 0, circle.A); cr.Arc (circle.X + circle.R, circle.Y + circle.R, circle.R, 0, 2 * Math.PI); cr.Fill (); } } else { cr.Color = new Cairo.Color (1, 1, 1); cr.Fill (); } if (window_decorator != null) { window_decorator.Render (cr); } if (render_debug) { cr.LineWidth = 1.0; cr.Color = CairoExtensions.RgbToColor ( (uint)rand.Next (0, 0xffffff)); cr.Rectangle (damage.X + 0.5, damage.Y + 0.5, damage.Width - 1, damage.Height - 1); cr.Stroke (); } cr.ResetClip (); } CairoExtensions.DisposeContext (cr); }