void DrawShadow(Cairo.Context ctx, Gdk.Rectangle ar, PositionType pos, List <Section> secs) { foreach (Section s in secs) { Cairo.Gradient pat = null; Gdk.Rectangle r = ar; switch (pos) { case PositionType.Top: r.Height = shadowSize > r.Height ? r.Height / 2 : shadowSize; r.X += s.Offset; r.Width = s.Size; pat = new Cairo.LinearGradient(r.X, r.Y, r.X, r.Bottom); break; case PositionType.Bottom: r.Y = r.Bottom - shadowSize; r.Height = shadowSize > r.Height ? r.Height / 2 : shadowSize; r.X = r.X + s.Offset; r.Width = s.Size; pat = new Cairo.LinearGradient(r.X, r.Bottom, r.X, r.Y); break; case PositionType.Left: r.Width = shadowSize > r.Width ? r.Width / 2 : shadowSize; r.Y += s.Offset; r.Height = s.Size; pat = new Cairo.LinearGradient(r.X, r.Y, r.Right, r.Y); break; case PositionType.Right: r.X = r.Right - shadowSize; r.Width = shadowSize > r.Width ? r.Width / 2 : shadowSize; r.Y += s.Offset; r.Height = s.Size; pat = new Cairo.LinearGradient(r.Right, r.Y, r.X, r.Y); break; } Cairo.Color c = darkColor.ToCairoColor(); pat.AddColorStop(0, c); c.A = 0; pat.AddColorStop(1, c); ctx.NewPath(); ctx.Rectangle(r.X, r.Y, r.Width, r.Height); ctx.SetSource(pat); ctx.Fill(); pat.Dispose(); } }
internal static Gdk.Color ReduceLight(Gdk.Color color, double factor) { return(ReduceLight(color.ToCairoColor(), factor).ToGdkColor()); }
internal static Gdk.Color IncreaseLight(Gdk.Color color, double factor) { return(IncreaseLight(color.ToCairoColor(), factor).ToGdkColor()); }
public void DrawBackground(Gtk.Widget w, Gdk.Rectangle allocation) { if (shadowSize == 0) { Gdk.Rectangle wr = new Gdk.Rectangle(allocation.X, allocation.Y, allocation.Width, allocation.Height); using (Cairo.Context ctx = Gdk.CairoHelper.Create(w.GdkWindow)) { ctx.Rectangle(wr.X, wr.Y, wr.Width, wr.Height); ctx.Color = lightColor.ToCairoColor(); ctx.Fill(); } return; } List <Section> secsT = new List <Section> (); List <Section> secsB = new List <Section> (); List <Section> secsR = new List <Section> (); List <Section> secsL = new List <Section> (); int x, y; w.GdkWindow.GetOrigin(out x, out y); Gdk.Rectangle rect = new Gdk.Rectangle(x + allocation.X, y + allocation.Y, allocation.Width, allocation.Height); Section s = new Section(); s.Size = rect.Width; secsT.Add(s); secsB.Add(s); s.Size = rect.Height; secsL.Add(s); secsR.Add(s); foreach (var rects in allocations) { int sx, sy; rects.Key.GdkWindow.GetOrigin(out sx, out sy); foreach (Gdk.Rectangle srt in rects.Value) { if (srt == rect) { continue; } Gdk.Rectangle sr = srt; sr.Offset(sx, sy); if (sr.Right == rect.X) { RemoveSection(secsL, sr.Y - rect.Y, sr.Height); } if (sr.Bottom == rect.Y) { RemoveSection(secsT, sr.X - rect.X, sr.Width); } if (sr.X == rect.Right) { RemoveSection(secsR, sr.Y - rect.Y, sr.Height); } if (sr.Y == rect.Bottom) { RemoveSection(secsB, sr.X - rect.X, sr.Width); } } } Gdk.Rectangle r = new Gdk.Rectangle(allocation.X, allocation.Y, allocation.Width, allocation.Height); using (Cairo.Context ctx = Gdk.CairoHelper.Create(w.GdkWindow)) { ctx.Rectangle(r.X, r.Y, r.Width, r.Height); ctx.Color = lightColor.ToCairoColor(); ctx.Fill(); DrawShadow(ctx, r, PositionType.Left, secsL); DrawShadow(ctx, r, PositionType.Top, secsT); DrawShadow(ctx, r, PositionType.Right, secsR); DrawShadow(ctx, r, PositionType.Bottom, secsB); } }