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 (); }
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 = CairoExtensions.GdkRGBAToCairoColor ( Widget.StyleContext.GetBackgroundColor (StateFlags.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 (); }
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 (); } }
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 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; }
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 (); }
public override void Render (CellContext context) { if (inner_allocation.IsEmpty) { return; } // Need to call this again here to make sure we have the latest artwork var album = BoundObject as AlbumInfo; if (album != null) { image_surface = artwork_manager != null ? artwork_manager.LookupScaleSurface (album.ArtworkId, (int)ImageSize, true) : null; } context.Context.Translate (inner_allocation.X, inner_allocation.Y); RenderImageSurface (context, image_allocation, image_surface); // Render the overlay if (IsGridLayout && prelight_opacity > 0) { var cr = context.Context; var x = image_allocation.Width / 2.0; var y = image_allocation.Height / 2.0; var grad = new RadialGradient (x, y, 0, x, y, x); grad.AddColorStop (0, new Color (0, 0, 0, 0.1 * prelight_opacity)); grad.AddColorStop (1, new Color (0, 0, 0, 0.35 * prelight_opacity)); cr.Pattern = grad; CairoExtensions.RoundedRectangle (cr, image_allocation.X, image_allocation.Y, image_allocation.Width, image_allocation.Height, context.Theme.Context.Radius); cr.Fill (); grad.Destroy (); /*cr.Save (); cr.LineWidth = 2; cr.Antialias = Cairo.Antialias.Default; // math prep for rendering multiple controls... double max_controls = 3; double spacing = 4; double radius = (width - ((max_controls + 1) * spacing)) / max_controls / 2; // render first control cr.Arc (width / 2, height - radius - 2 * spacing, radius, 0, 2 * Math.PI); cr.Color = new Color (0, 0, 0, 0.4); cr.FillPreserve (); cr.Color = new Color (1, 1, 1, 0.8); cr.Stroke (); cr.Restore ();*/ } if (lines == null || lines.Length < 2) { return; } var text_color = context.Theme.Colors.GetWidgetColor (GtkColorClass.Text, context.State); var layout = context.Layout; layout.Ellipsize = Pango.EllipsizeMode.End; layout.Width = (int)(first_line_allocation.Width * Pango.Scale.PangoScale); int normal_size = layout.FontDescription.Size; int small_size = (int)(normal_size * Pango.Scale.Small); if (!String.IsNullOrEmpty (lines[0])) { layout.FontDescription.Size = small_size; layout.SetText (lines[0]); context.Context.Color = text_color; context.Context.MoveTo (first_line_allocation.X, first_line_allocation.Y); PangoCairoHelper.ShowLayout (context.Context, layout); } if (!String.IsNullOrEmpty (lines[1])) { layout.FontDescription.Weight = Pango.Weight.Normal; layout.FontDescription.Size = small_size; layout.SetText (lines[1]); text_color.A = 0.60; context.Context.Color = text_color; context.Context.MoveTo (second_line_allocation.X, second_line_allocation.Y); PangoCairoHelper.ShowLayout (context.Context, layout); } layout.FontDescription.Size = normal_size; }
DockySurface CreateUrgentGlowBuffer () { // FIXME: create gconf value Gdk.Color gdkColor = Style.Backgrounds [(int) StateType.Selected].SetMinimumValue (90); Cairo.Color color = new Cairo.Color ((double) gdkColor.Red / ushort.MaxValue, (double) gdkColor.Green / ushort.MaxValue, (double) gdkColor.Blue / ushort.MaxValue, 1.0); color = color.AddHue (DockServices.Theme.UrgentHueShift).SetSaturation (1); int size = (int) 2.5 * IconSize; DockySurface surface = new DockySurface (size, size, background_buffer); surface.Clear (); Cairo.Context cr = surface.Context; double x = size / 2; double y = x; cr.MoveTo (x, y); cr.Arc (x, y, size / 2, 0, Math.PI * 2); RadialGradient rg = new RadialGradient (x, y, 0, x, y, size / 2); rg.AddColorStop (0, new Cairo.Color (1, 1, 1, 1)); rg.AddColorStop (.33, color.SetAlpha (.66)); rg.AddColorStop (.66, color.SetAlpha (.33)); rg.AddColorStop (1.0, color.SetAlpha (0.0)); cr.Pattern = rg; cr.Fill (); rg.Destroy (); return surface; }
DockySurface CreateIndicatorBuffer (int size, Cairo.Color color) { DockySurface surface = new DockySurface (size, size, background_buffer); surface.Clear (); Cairo.Context cr = surface.Context; double x = size / 2; double y = x; cr.MoveTo (x, y); cr.Arc (x, y, size / 2, 0, Math.PI * 2); RadialGradient rg = new RadialGradient (x, y, 0, x, y, size / 2); rg.AddColorStop (0, new Cairo.Color (1, 1, 1, 1)); rg.AddColorStop (.10, color.SetAlpha (1.0)); rg.AddColorStop (.20, color.SetAlpha (.60)); rg.AddColorStop (.25, color.SetAlpha (.25)); rg.AddColorStop (.50, color.SetAlpha (.15)); rg.AddColorStop (1.0, color.SetAlpha (0.0)); cr.Pattern = rg; cr.Fill (); rg.Destroy (); return surface; }
/// <summary>Draws an application button.</summary> public void DrawApplicationButton(Context cr, Gdk.Rectangle bodyAllocation, ButtonState state, double lineWidth, BaseButton widget) { const double dropShadowOffset = 1; double radius = (bodyAllocation.Height - dropShadowOffset) / 2; double x = bodyAllocation.X + radius + dropShadowOffset; double y = bodyAllocation.Y + radius + dropShadowOffset; cr.Arc (x, y, radius, 0, 2 * Math.PI); cr.Color = new Color (0, 0, 0, 0.5); cr.Fill (); cr.Arc (bodyAllocation.X + radius, bodyAllocation.Y + radius, radius, 0, 2 * Math.PI); switch(state) { case ButtonState.Hover: cr.Color = new Color (0.9, 0.815, 0.533); break; case ButtonState.Pressed: cr.Color = new Color (0.886, 0.639, 0.356); break; default: cr.Color = new Color (0.8, 0.8, 0.8); break; } cr.Fill (); cr.Arc (bodyAllocation.X + radius, bodyAllocation.Y + radius, radius, 0, 2 * Math.PI); LinearGradient linGrad = new LinearGradient (0, bodyAllocation.Y, 0, bodyAllocation.Y + bodyAllocation.Height); linGrad.AddColorStop (0.0, new Color (1, 1, 1, 0.9)); linGrad.AddColorStop (0.5, new Color (1, 1, 1, 0.0)); linGrad.AddColorStop (1.0, new Color (1, 1, 1, 1.0)); cr.Pattern = linGrad; cr.Fill (); linGrad.Destroy (); cr.Arc (bodyAllocation.X + radius, bodyAllocation.Y + radius, radius, 0, 2 * Math.PI); linGrad = new LinearGradient (0, bodyAllocation.Y, 0, bodyAllocation.Y + bodyAllocation.Height); linGrad.AddColorStop (0.0, new Color (0, 0, 0, 0.0)); linGrad.AddColorStop (0.4, new Color (0, 0, 0, 0.0)); linGrad.AddColorStop (0.5, new Color (0, 0, 0, 0.1)); linGrad.AddColorStop (0.75, new Color (0, 0, 0, 0.0)); linGrad.AddColorStop (1.0, new Color (0, 0, 0, 0.0)); cr.Pattern = linGrad; cr.Fill (); linGrad.Destroy (); cr.Arc (bodyAllocation.X + radius, bodyAllocation.Y + radius, radius, 0, Math.PI); linGrad = new LinearGradient (0, bodyAllocation.Y + radius, 0, bodyAllocation.Y + bodyAllocation.Height); linGrad.AddColorStop (0.0, new Color (0, 0, 0, 0.0)); linGrad.AddColorStop (1.0, new Color (0, 0, 0, 0.5)); cr.Pattern = linGrad; cr.LineWidth = 1.0; cr.Stroke (); linGrad.Destroy (); cr.Arc (bodyAllocation.X + radius, bodyAllocation.Y + radius, radius, Math.PI, 0); linGrad = new LinearGradient (0, bodyAllocation.Y, 0, bodyAllocation.Y + radius); linGrad.AddColorStop (0.0, new Color (1, 1, 1, 0.5)); linGrad.AddColorStop (1.0, new Color (1, 1, 1, 0.0)); cr.LineWidth = 1.0; cr.Stroke (); linGrad.Destroy (); cr.Arc (bodyAllocation.X + radius, bodyAllocation.Y + radius, radius, 0, 2 * Math.PI); RadialGradient radGrad = new RadialGradient (bodyAllocation.X + radius, bodyAllocation.Y + 1.5 * radius, 0, bodyAllocation.X + radius, bodyAllocation.Y + 1.5 * radius, 0.5 * radius); radGrad.AddColorStop (0, new Color (1, 1, 1, 0.4)); radGrad.AddColorStop (1, new Color (1, 1, 1, 0.0)); cr.Pattern = radGrad; cr.Fill (); radGrad.Destroy (); }
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 (); }