static void draw(Cairo.Context gr, int width, int height) { gr.Scale(width, height); gr.LineWidth = 0.04; LinearGradient pat; pat = new LinearGradient(0.0, 0.0, 0.0, 1.0); pat.AddColorStop(1, new Color(0, 0, 0, 1)); pat.AddColorStop(0, new Color(1, 1, 1, 1)); gr.Rectangle(new PointD(0, 0), 1, 1 ); gr.Pattern = pat; gr.Fill(); pat.Destroy(); RadialGradient pat2 = new RadialGradient(0.45, 0.4, 0.1, 0.4, 0.4, 0.5); pat2.AddColorStop(0, new Color(1, 1, 1, 1)); pat2.AddColorStop(1, new Color(0, 0, 0, 1)); gr.Pattern = pat2; gr.Arc(0.5, 0.5, 0.3, 0, 2 * M_PI); gr.Fill(); pat2.Destroy(); }
void DrawShape(Context g, int width, int height) { int inner_x = radius + border + inner; int cx = Center.X; int cy = Center.Y; g.Operator = Operator.Source; g.SetSource(new SolidPattern(new Cairo.Color(0, 0, 0, 0))); g.Rectangle(0, 0, width, height); g.Paint(); g.NewPath(); g.Translate(cx, cy); g.Rotate(angle); g.SetSource(new SolidPattern(new Cairo.Color(0.2, 0.2, 0.2, .6))); g.Operator = Operator.Over; g.Rectangle(0, -(border + inner), inner_x, 2 * (border + inner)); g.Arc(inner_x, 0, inner + border, 0, 2 * Math.PI); g.Arc(0, 0, radius + border, 0, 2 * Math.PI); g.Fill(); g.SetSource(new SolidPattern(new Cairo.Color(0, 0, 0, 1.0))); g.Operator = Operator.DestOut; g.Arc(inner_x, 0, inner, 0, 2 * Math.PI); #if true g.Fill(); #else g.FillPreserve(); g.Operator = Operator.Over; RadialGradient rg = new RadialGradient(inner_x - (inner * 0.3), inner * 0.3, inner * 0.1, inner_x, 0, inner); rg.AddColorStop(0, new Cairo.Color(0.0, 0.2, .8, 0.5)); rg.AddColorStop(0.7, new Cairo.Color(0.0, 0.2, .8, 0.1)); rg.AddColorStop(1.0, new Cairo.Color(0.0, 0.0, 0.0, 0.0)); g.Source = rg; g.Fill(); rg.Destroy(); #endif g.Operator = Operator.Over; g.Matrix = new Matrix(); g.Translate(cx, cy); if (source != null) { CairoHelper.SetSourcePixbuf(g, source, -source.Width / 2, -source.Height / 2); } g.Arc(0, 0, radius, 0, 2 * Math.PI); g.Fill(); if (overlay != null) { CairoHelper.SetSourcePixbuf(g, overlay, -overlay.Width / 2, -overlay.Height / 2); g.Arc(0, 0, radius, angle, angle + Math.PI); g.ClosePath(); g.FillPreserve(); g.SetSource(new SolidPattern(new Cairo.Color(1.0, 1.0, 1.0, 1.0))); g.Stroke(); } }
public override void DrawPie(double fraction) { // Calculate the pie path fraction = Theme.Clamp(0.0, 1.0, fraction); double a1 = 3.0 * Math.PI / 2.0; double a2 = a1 + 2.0 * Math.PI * fraction; if (fraction == 0.0) { return; } Context.Cairo.MoveTo(Context.X, Context.Y); Context.Cairo.Arc(Context.X, Context.Y, Context.Radius, a1, a2); Context.Cairo.LineTo(Context.X, Context.Y); // Fill the pie Color color_a = Colors.GetWidgetColor(GtkColorClass.Background, StateType.Selected); Color color_b = CairoExtensions.ColorShade(color_a, 1.4); RadialGradient fill = new RadialGradient(Context.X, Context.Y, 0, Context.X, Context.Y, 2.0 * Context.Radius); fill.AddColorStop(0, color_a); fill.AddColorStop(1, color_b); Context.Cairo.Pattern = fill; Context.Cairo.FillPreserve(); fill.Destroy(); // Stroke the pie Context.Cairo.Color = CairoExtensions.ColorShade(color_a, 0.8); Context.Cairo.LineWidth = Context.LineWidth; Context.Cairo.Stroke(); }
protected override void PaintIconSurface(DockySurface surface) { surface.Context.LineWidth = 1; surface.Context.MoveTo((surface.Width / 2) - 0.5, 0); surface.Context.LineTo((surface.Width / 2) - 0.5, surface.Height); RadialGradient rg = new RadialGradient(surface.Width / 2, surface.Height / 2, 0, surface.Width / 2, surface.Height / 2, surface.Height / 2); rg.AddColorStop(0, new Cairo.Color(1, 1, 1, .5)); rg.AddColorStop(1, new Cairo.Color(1, 1, 1, 0)); surface.Context.Pattern = rg; surface.Context.Stroke(); rg.Destroy(); surface.Context.MoveTo((surface.Width / 2) + 0.5, 0); surface.Context.LineTo((surface.Width / 2) + 0.5, surface.Height); rg = new RadialGradient(surface.Width / 2, surface.Height / 2, 0, surface.Width / 2, surface.Height / 2, surface.Height / 2); rg.AddColorStop(0, new Cairo.Color(0, 0, 0, 0.5)); rg.AddColorStop(1, new Cairo.Color(0, 0, 0, 0)); surface.Context.Pattern = rg; surface.Context.Stroke(); rg.Destroy(); }
protected override bool OnExposeEvent(EventExpose evnt) { if (!IsRealized) { return(false); } using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) { cr.LineWidth = 1; int x = Allocation.X; int width = Allocation.Width; int right = x + width; int xMiddle = x + width / 2; double yMiddle = Allocation.Y + Allocation.Height / 2.0; if (!string.IsNullOrEmpty(title)) { using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) { layout.SetText(title); layout.Width = Pango.Units.FromPixels(Allocation.Width - Allocation.Height); layout.FontDescription = Style.FontDescription; layout.Ellipsize = Pango.EllipsizeMode.End; layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels(8); layout.FontDescription.Weight = Pango.Weight.Bold; Pango.Rectangle logical, ink; layout.GetPixelExtents(out ink, out logical); cr.MoveTo(Allocation.X + 2, Allocation.Y + (Allocation.Height - logical.Height) / 2); Pango.CairoHelper.LayoutPath(cr, layout); cr.Color = TextColor.SetAlpha(.6); cr.Fill(); x += logical.Width + 5; layout.Context.Dispose(); } } if (DrawLine) { cr.MoveTo(x, yMiddle); cr.LineTo(right, yMiddle); RadialGradient rg = new RadialGradient( xMiddle, yMiddle, 0, xMiddle, yMiddle, width / 2); rg.AddColorStop(0, new Cairo.Color(0, 0, 0, 0.4)); rg.AddColorStop(1, new Cairo.Color(0, 0, 0, 0)); cr.Pattern = rg; cr.Stroke(); rg.Destroy(); cr.MoveTo(x, yMiddle + 1); cr.LineTo(right, yMiddle + 1); rg = new RadialGradient( xMiddle, yMiddle + 1, 0, xMiddle, yMiddle + 1, width / 2); rg.AddColorStop(0, new Cairo.Color(1, 1, 1, .4)); rg.AddColorStop(1, new Cairo.Color(1, 1, 1, 0)); cr.Pattern = rg; cr.Stroke(); rg.Destroy(); } (cr.Target as IDisposable).Dispose(); } return(false); }
void PaintBadgeSurface(DockySurface surface) { if (string.IsNullOrEmpty(BadgeText)) { return; } int padding = 4; int lineWidth = 2; double size = (IsSmall ? 0.9 : 0.65) * Math.Min(surface.Width, surface.Height); double x = surface.Width - size / 2; double y = size / 2; if (!IsSmall) { // draw outline shadow surface.Context.LineWidth = lineWidth; surface.Context.Color = new Cairo.Color(0, 0, 0, 0.5); surface.Context.Arc(x, y + 1, size / 2 - lineWidth, 0, Math.PI * 2); surface.Context.Stroke(); // draw filled gradient RadialGradient rg = new RadialGradient(x, lineWidth, 0, x, lineWidth, size); rg.AddColorStop(0, badgeColors [0]); rg.AddColorStop(1.0, badgeColors [1]); surface.Context.Pattern = rg; surface.Context.Arc(x, y, size / 2 - lineWidth, 0, Math.PI * 2); surface.Context.Fill(); rg.Destroy(); // draw outline surface.Context.Color = new Cairo.Color(1, 1, 1, 1); surface.Context.Arc(x, y, size / 2 - lineWidth, 0, Math.PI * 2); surface.Context.Stroke(); surface.Context.LineWidth = lineWidth / 2; surface.Context.Color = badgeColors [1]; surface.Context.Arc(x, y, size / 2 - 2 * lineWidth, 0, Math.PI * 2); surface.Context.Stroke(); surface.Context.Color = new Cairo.Color(0, 0, 0, 0.2); } else { lineWidth = 0; padding = 2; } using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) { layout.Width = Pango.Units.FromPixels(surface.Height / 2); layout.Ellipsize = Pango.EllipsizeMode.None; layout.FontDescription = new Gtk.Style().FontDescription; layout.FontDescription.Weight = Pango.Weight.Bold; Pango.Rectangle inkRect, logicalRect; layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels(surface.Height / 2); layout.SetText(BadgeText); layout.GetPixelExtents(out inkRect, out logicalRect); size -= 2 * padding + 2 * lineWidth; double scale = Math.Min(1, Math.Min(size / (double)logicalRect.Width, size / (double)logicalRect.Height)); if (!IsSmall) { surface.Context.Color = new Cairo.Color(0, 0, 0, 0.2); } else { surface.Context.Color = new Cairo.Color(0, 0, 0, 0.6); x = surface.Width - scale * logicalRect.Width / 2; y = scale * logicalRect.Height / 2; } surface.Context.MoveTo(x - scale * logicalRect.Width / 2, y - scale * logicalRect.Height / 2); // draw text surface.Context.Save(); if (scale < 1) { surface.Context.Scale(scale, scale); } surface.Context.LineWidth = 2; Pango.CairoHelper.LayoutPath(surface.Context, layout); surface.Context.StrokePreserve(); surface.Context.Color = new Cairo.Color(1, 1, 1, 1); surface.Context.Fill(); surface.Context.Restore(); layout.FontDescription.Dispose(); layout.Context.Dispose(); } }
protected override void PaintIconSurface(DockySurface surface) { int size = Math.Min(surface.Width, surface.Height); Context cr = surface.Context; double center = size / 2.0; Cairo.Color base_color = new Cairo.Color(1, .3, .3, .5).SetHue(120 * (1 - CPUUtilization)); double radius = Math.Max(Math.Min(CPUUtilization * 1.3, 1), .001); // draw underlay cr.Arc(center, center, center * RadiusPercent, 0, Math.PI * 2); cr.Color = new Cairo.Color(0, 0, 0, .5); cr.FillPreserve(); RadialGradient rg = new RadialGradient(center, center, 0, center, center, center * RadiusPercent); rg.AddColorStop(0, base_color); rg.AddColorStop(0.2, base_color); rg.AddColorStop(1, new Cairo.Color(base_color.R, base_color.G, base_color.B, 0.15)); cr.Pattern = rg; cr.FillPreserve(); rg.Destroy(); // draw cpu indicator rg = new RadialGradient(center, center, 0, center, center, center * RadiusPercent * radius); rg.AddColorStop(0, new Cairo.Color(base_color.R, base_color.G, base_color.B, 1)); rg.AddColorStop(0.2, new Cairo.Color(base_color.R, base_color.G, base_color.B, 1)); rg.AddColorStop(1, new Cairo.Color(base_color.R, base_color.G, base_color.B, Math.Max(0, CPUUtilization * 1.3 - 1))); cr.Pattern = rg; cr.Fill(); rg.Destroy(); // draw highlight cr.Arc(center, center * .8, center * .6, 0, Math.PI * 2); LinearGradient lg = new LinearGradient(0, 0, 0, center); lg.AddColorStop(0, new Cairo.Color(1, 1, 1, .35)); lg.AddColorStop(1, new Cairo.Color(1, 1, 1, 0)); cr.Pattern = lg; cr.Fill(); lg.Destroy(); // draw outer circles cr.LineWidth = 1; cr.Arc(center, center, center * RadiusPercent, 0, Math.PI * 2); cr.Color = new Cairo.Color(1, 1, 1, .75); cr.Stroke(); cr.LineWidth = 1; cr.Arc(center, center, center * RadiusPercent - 1, 0, Math.PI * 2); cr.Color = new Cairo.Color(.8, .8, .8, .75); cr.Stroke(); // draw memory indicate cr.LineWidth = size / 32.0; cr.ArcNegative(center, center, center * RadiusPercent - 1, Math.PI, Math.PI - Math.PI * (2 * MemoryUtilization)); cr.Color = new Cairo.Color(1, 1, 1, .8); cr.Stroke(); }