public override void SetAsSource(Cairo.Context ctx, Rectangle bounds = default(Rectangle)) { Cairo.Gradient grad = null; switch (GradientType) { case Type.Vertical: grad = new Cairo.LinearGradient(bounds.Left, bounds.Top, bounds.Left, bounds.Bottom); break; case Type.Horizontal: grad = new Cairo.LinearGradient(bounds.Left, bounds.Top, bounds.Right, bounds.Top); break; case Type.Oblic: grad = new Cairo.LinearGradient(bounds.Left, bounds.Top, bounds.Right, bounds.Bottom); break; case Type.Radial: throw new NotImplementedException(); } foreach (ColorStop cs in Stops) { grad.AddColorStop(cs.Offset, cs.Color); } ctx.SetSource(grad); grad.Dispose(); }
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(); } }
private void DrawBackground(Cairo.Context g, Cairo.Rectangle rect, StyleInfo si) { // LinearGradientBrush linGrBrush = null; // SolidBrush sb = null; if (si.BackgroundColor.IsEmpty) { return; } g.Save(); Cairo.Color c = si.BackgroundColor.ToCairoColor(); Cairo.Gradient gradient = null; if (si.BackgroundGradientType != BackgroundGradientTypeEnum.None && !si.BackgroundGradientEndColor.IsEmpty) { Cairo.Color ec = si.BackgroundGradientEndColor.ToCairoColor(); switch (si.BackgroundGradientType) { case BackgroundGradientTypeEnum.LeftRight: // linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal); gradient = new Cairo.LinearGradient(rect.X, rect.Y, rect.X + rect.Width, rect.Y); break; case BackgroundGradientTypeEnum.TopBottom: // linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Vertical); gradient = new Cairo.LinearGradient(rect.X, rect.Y, rect.X, rect.Y + rect.Height); break; case BackgroundGradientTypeEnum.Center: // linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal); throw new NotSupportedException(); // break; case BackgroundGradientTypeEnum.DiagonalLeft: // linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.ForwardDiagonal); gradient = new Cairo.LinearGradient(rect.X, rect.Y, rect.X + rect.Width, rect.Y + rect.Height); break; case BackgroundGradientTypeEnum.DiagonalRight: // linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.BackwardDiagonal); gradient = new Cairo.LinearGradient(rect.X + rect.Width, rect.Y + rect.Height, rect.X, rect.Y); break; case BackgroundGradientTypeEnum.HorizontalCenter: // linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal); throw new NotSupportedException(); // break; case BackgroundGradientTypeEnum.VerticalCenter: // linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Vertical); throw new NotSupportedException(); // break; default: break; } gradient.AddColorStop(0, c); gradient.AddColorStop(1, ec); } if (gradient != null) { //// g.FillRectangle(linGrBrush, rect); g.FillRectangle(rect, gradient); gradient.Destroy(); } else if (!si.BackgroundColor.IsEmpty) { g.FillRectangle(rect, c); // g.DrawRoundedRectangle (rect, 2, c, 1); // g.FillRoundedRectangle (rect, 8, c); } g.Restore(); }
public override void AddColorStop(object backend, double position, Xwt.Drawing.Color color) { Cairo.Gradient g = (Cairo.Gradient)backend; g.AddColorStop(position, color.ToCairoColor()); }
public static void AddColorStop(this Cairo.Gradient grad, double offset, Color c) { grad.AddColorStop(offset, new Cairo.Color(c.R, c.G, c.B, c.A)); }
void DrawFocus(Gdk.Window window, Color c) { int x, y, width, height; window.GetPosition(out x, out y); window.GetSize(out width, out height); System.Drawing.Rectangle r = new System.Drawing.Rectangle(x, y, width, height); using (Cairo.Context context = Gdk.CairoHelper.Create(window)) { uint b = mainBox.BorderWidth; // Top using (Cairo.Gradient gradient = createGradient(0.0, 0.0, 0, b, c)) { context.SetSource(gradient); context.MoveTo(0, 0); context.LineTo(r.Width, 0); context.LineTo(r.Width - b + 1, b); context.LineTo(b - 1, b); context.ClosePath(); context.Fill(); } // Left using (Cairo.Gradient gradient = createGradient(0.0, 0.0, b, 0, c)) { context.SetSource(gradient); context.MoveTo(0, 0); context.LineTo(b, b - 1); context.LineTo(b, r.Height - b + 1); context.LineTo(0, r.Height); context.ClosePath(); context.Fill(); } // Bottom using (Cairo.Gradient gradient = createGradient(0.0, r.Height, 0, r.Height - b, c)) { context.SetSource(gradient); context.MoveTo(0, r.Height); context.LineTo(b - 1, r.Height - b); context.LineTo(r.Width - b + 1, r.Height - b); context.LineTo(r.Width, r.Height); context.ClosePath(); context.Fill(); } // Right using (Cairo.Gradient gradient = createGradient(r.Width, 0, r.Width - b, 0, c)) { context.SetSource(gradient); context.MoveTo(r.Width, 0); context.LineTo(r.Width - b, b - 1); context.LineTo(r.Width - b, r.Height - b + 1); context.LineTo(r.Width, r.Height); context.ClosePath(); context.Fill(); } } }