void DrawVertConditionText(Cairo.Context cr, int yCenter, string text) { using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) { Pango.Rectangle inkRect, logicalRect; layout.FontDescription = new Gtk.Style().FontDescription; layout.FontDescription.Weight = Pango.Weight.Bold; layout.Ellipsize = Pango.EllipsizeMode.None; layout.Width = Pango.Units.FromPixels(Allocation.Width); if (WeatherController.Weather.ForecastDays < 6) { layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels((int)(Allocation.Width / 10)); } else { layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels((int)(Allocation.Width / 7)); } cr.Color = new Cairo.Color(1, 1, 1, 0.9); layout.SetText(text); layout.GetPixelExtents(out inkRect, out logicalRect); cr.MoveTo((Allocation.Width - logicalRect.Width) / 2, yCenter - logicalRect.Height / 2); Pango.CairoHelper.LayoutPath(cr, layout); cr.Fill(); layout.FontDescription.Dispose(); layout.Context.Dispose(); } }
protected override void PaintIconSurface(DockySurface surface) { if (device == null) { return; } Context cr = surface.Context; using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) { layout.FontDescription = new Gtk.Style().FontDescription; layout.FontDescription.Weight = Pango.Weight.Bold; layout.Ellipsize = Pango.EllipsizeMode.None; layout.Alignment = Pango.Alignment.Center; int fontSize = surface.Height / 5; layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels(fontSize); layout.SetText(device.name); Pango.Rectangle inkRect, logicalRect; layout.GetPixelExtents(out inkRect, out logicalRect); cr.MoveTo((surface.Width - logicalRect.Width) / 2, 1); Pango.CairoHelper.LayoutPath(cr, layout); cr.LineWidth = 2; cr.Color = new Cairo.Color(0, 0, 0, 0.5); cr.StrokePreserve(); cr.Color = new Cairo.Color(1, 1, 1, 0.8); cr.Fill(); layout.FontDescription.Dispose(); layout.Context.Dispose(); } }
void RenderMonthName(Context cr) { string month = StartDate.ToString("MMMM").ToUpper(); using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) { layout.FontDescription = new Gtk.Style().FontDescription; layout.FontDescription.Weight = Pango.Weight.Bold; layout.Ellipsize = Pango.EllipsizeMode.None; layout.Width = Pango.Units.FromPixels(Allocation.Height); layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels(Allocation.Height / 6); cr.Save(); cr.Color = new Cairo.Color(1, 1, 1, .5); layout.SetText(month); Pango.Rectangle inkRect, logicalRect; layout.GetPixelExtents(out inkRect, out logicalRect); double scale = Math.Min(1, Math.Min(Allocation.Height / (double)inkRect.Width, (Allocation.Width / 9.0) / (double)logicalRect.Height)); cr.Rotate(Math.PI / -2.0); cr.MoveTo((Allocation.Height - scale * inkRect.Width) / 2 - Allocation.Height, Allocation.Width / 9 - scale * logicalRect.Height); if (scale < 1) { cr.Scale(scale, scale); } Pango.CairoHelper.LayoutPath(cr, layout); cr.Fill(); cr.Restore(); layout.FontDescription.Dispose(); layout.Context.Dispose(); } }
protected override void Render(Gdk.Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { using (var cr = Gdk.CairoHelper.Create(window)) { if (!widget.HasFocus) { cr.Rectangle(background_area.ToCairoRect()); cr.SetSourceColor(Styles.ObjectValueTreeDisabledBackgroundColor); cr.Fill(); } Pango.Rectangle ink, logical; using (var layout = new Pango.Layout(Context)) { layout.FontDescription = font; var selected = (flags & CellRendererState.Selected) != 0; var foregroundColor = Styles.GetStackFrameForegroundHexColor(selected, IsUserCode); layout.SetMarkup(GetFileMarkup(selected, foregroundColor)); layout.GetPixelExtents(out ink, out logical); var width = widget.Allocation.Width; cr.Translate(width - logical.Width - 10, cell_area.Y); cr.ShowLayout(layout); cr.IdentityMatrix(); layout.SetMarkup(GetMethodMarkup(selected, foregroundColor)); layout.Width = (int)((width - logical.Width - 35) * Pango.Scale.PangoScale); layout.Ellipsize = Pango.EllipsizeMode.Middle; cr.Translate(cell_area.X + 10, cell_area.Y); cr.ShowLayout(layout); } } }
void RenderHeader(Context cr, DateTime start) { int centerLine = LineHeight + ((Allocation.Height % LineHeight) / 2); int offsetSize = Allocation.Width / 9; DateTime day = CalendarStartDate; using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) { layout.FontDescription = new Gtk.Style().FontDescription; layout.FontDescription.Weight = Pango.Weight.Bold; layout.Ellipsize = Pango.EllipsizeMode.None; layout.Width = Pango.Units.FromPixels(offsetSize); layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels((int)(0.625 * LineHeight)); cr.Color = new Cairo.Color(1, 1, 1, .5); for (int i = 0; i < 7; i++) { layout.SetText(day.ToString("ddd").ToUpper()); Pango.Rectangle inkRect, logicalRect; layout.GetPixelExtents(out inkRect, out logicalRect); cr.MoveTo(offsetSize + offsetSize * i + (offsetSize - inkRect.Width) / 2, centerLine - logicalRect.Height); Pango.CairoHelper.LayoutPath(cr, layout); cr.Fill(); day = day.AddDays(1); } layout.FontDescription.Dispose(); layout.Context.Dispose(); } }
void CalcTextWidth() { using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) { char accel; string text = GLib.Markup.EscapeText(item.Text.Replace("\n", "")); if (item.Mnemonic.HasValue) { layout.SetMarkupWithAccel(text, '_', out accel); } else { layout.SetMarkup(text); } layout.FontDescription = Style.FontDescription; layout.Ellipsize = Pango.EllipsizeMode.End; layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels(FontSize); layout.FontDescription.Weight = Pango.Weight.Bold; Pango.Rectangle logical, ink; layout.GetPixelExtents(out ink, out logical); TextWidth = Math.Min(MaxWidth, Math.Max(MinWidth, logical.Width)); HasTooltip = TextWidth < logical.Width; layout.Context.Dispose(); } SetSize(); }
public void DrawSample(Gdk.Drawable drawable, string text) { using (Cairo.Context ctx = Gdk.CairoHelper.Create(drawable)) { using (Pango.Layout layout = Pango.CairoHelper.CreateLayout(ctx)) { AssignLayout(layout); layout.SetText(text); // dest size int width, height; drawable.GetSize(out width, out height); // set pos Pango.Rectangle te = Pango.Rectangle.Zero; if (text.Length > 0) { Pango.Rectangle unused; layout.GetPixelExtents(out unused, out te); te.X = (width - te.Width) / 2; te.Y = (height - te.Height) / 2; } // fill background ctx.Save(); int boxSize = 20, padding = 0; Cairo.Color clr1 = Gui.CairoExtensions.RgbToColor(0xE77817); Cairo.Color clr2 = Gui.CairoExtensions.RgbToColor(0x383431); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { ctx.Rectangle(i * (boxSize + padding), j * (boxSize + padding), boxSize, boxSize); if ((i + j) % 2 == 0) { ctx.SetSourceRGBA(clr1.R, clr1.G, clr1.B, clr1.A); } else { ctx.SetSourceRGBA(clr2.R, clr2.G, clr2.B, clr2.A); } ctx.Fill(); } } ctx.Restore(); // show text if (text.Length > 0) { ctx.Save(); ctx.MoveTo(te.X, te.Y); ctx.Color = new Cairo.Color(1.0, 1.0, 1.0, 1.0); ctx.Antialias = Cairo.Antialias.Gray; ctx.Operator = Cairo.Operator.Source; Pango.CairoHelper.ShowLayout(ctx, layout); ctx.Restore(); } } } }
public Rectangle GetLayoutBounds() { Pango.Rectangle ink, logical; layout.GetPixelExtents(out ink, out logical); Rectangle r = new Rectangle(ink.X + origin.X, ink.Y + origin.Y, ink.Width, ink.Height); return(r); }
/// <summary> /// Returns a <see cref="DockySurface"/> containing a visual representation of the HoverText /// </summary> /// <param name="model"> /// A <see cref="DockySurface"/> /// </param> /// <param name="style"> /// A <see cref="Style"/> /// </param> /// <returns> /// A <see cref="DockySurface"/> /// </returns> public DockySurface HoverTextSurface(DockySurface model, Style style, bool isLight) { if (string.IsNullOrEmpty(HoverText)) { return(null); } if (text_buffer == null) { using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) { layout.FontDescription = style.FontDescription; layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels(11); layout.FontDescription.Weight = Pango.Weight.Bold; layout.Ellipsize = Pango.EllipsizeMode.End; layout.SetText(HoverText); Pango.Rectangle inkRect, logicalRect; layout.GetPixelExtents(out inkRect, out logicalRect); if (logicalRect.Width > 0.8 * Gdk.Screen.Default.Width) { layout.Width = Pango.Units.FromPixels((int)(0.8 * Gdk.Screen.Default.Width)); layout.GetPixelExtents(out inkRect, out logicalRect); } int textWidth = logicalRect.Width; int textHeight = logicalRect.Height; int buffer = HoverTextHeight - textHeight; text_buffer = new DockySurface(Math.Max(HoverTextHeight, textWidth + buffer), HoverTextHeight, model); Cairo.Context cr = text_buffer.Context; cr.MoveTo(buffer / 2, buffer / 2); Pango.CairoHelper.LayoutPath(cr, layout); cr.Color = isLight ? new Cairo.Color(0.1, 0.1, 0.1) : new Cairo.Color(1, 1, 1); cr.Fill(); layout.Context.Dispose(); } } return(text_buffer); }
private Pango.Rectangle GetTextExtents(Pango.Layout layout, Cairo.Point p) { Pango.Rectangle unused = Pango.Rectangle.Zero; Pango.Rectangle te = Pango.Rectangle.Zero; layout.GetPixelExtents(out unused, out te); te.X += p.X; te.Y += p.Y; return(te); }
public Rectangle GetLayoutBounds() { Pango.Rectangle ink, logical; layout.GetPixelExtents(out ink, out logical); var cursor = GetCursorLocation(); // GetPixelExtents() doesn't really return a very sensible height. // Instead of doing some hacky arithmetic to correct it, the height will just // be the cursor's height times the number of lines. return(new Rectangle(origin.X, origin.Y, ink.Width, cursor.Height * LineCount)); }
public override void GetSize(Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) { using (var layout = new Pango.Layout(widget.PangoContext)) { layout.FontDescription = font; Pango.Rectangle ink, logical; layout.SetMarkup("<b>" + Text + "</b>"); layout.GetPixelExtents(out ink, out logical); width = logical.Width + 10; height = logical.Height + 2; x_offset = 0; y_offset = 0; } }
public override void GetSize(Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) { using (var layout = new Pango.Layout(Context)) { Pango.Rectangle ink, logical; layout.FontDescription = font; layout.SetMarkup(GetMethodMarkup(false)); layout.GetPixelExtents(out ink, out logical); height = logical.Height; width = 0; x_offset = 0; y_offset = 0; } }
protected override void PostProcessIconSurface(DockySurface surface) { if (Status == WeatherDockletStatus.Error) { return; } if (Status == WeatherDockletStatus.Initializing) { return; } int size = Math.Min(surface.Width, surface.Height); Context cr = surface.Context; using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) { layout.FontDescription = new Gtk.Style().FontDescription; layout.FontDescription.Weight = Pango.Weight.Bold; layout.Ellipsize = Pango.EllipsizeMode.None; Pango.Rectangle inkRect, logicalRect; layout.Width = Pango.Units.FromPixels(size); layout.SetText(WeatherController.Weather.Temp + AbstractWeatherSource.TempUnit); if (IsSmall) { layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels((int)(size / 2.5)); } else { layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels((int)(size / 3.5)); } layout.GetPixelExtents(out inkRect, out logicalRect); cr.MoveTo((size - inkRect.Width) / 2, size - logicalRect.Height); Pango.CairoHelper.LayoutPath(cr, layout); cr.LineWidth = 2; cr.Color = new Cairo.Color(0, 0, 0, 0.8); cr.StrokePreserve(); cr.Color = new Cairo.Color(1, 1, 1, 0.8); cr.Fill(); layout.FontDescription.Dispose(); layout.Context.Dispose(); } }
protected override bool OnExposeEvent(Gdk.EventExpose evnt) { if (calendarItem != null) { int triangleSize = 25; Gdk.Rectangle targetRectangle = this.Allocation; evnt.Window.DrawRectangle(Style.BackgroundGC(State), true, targetRectangle); Style.PaintLayout(Style, evnt.Window, State, true, targetRectangle, this, null, targetRectangle.X, targetRectangle.Y, PangoText); //Верхний правый треугольник if (calendarItem.TagColor != "" && calendarItem.id > 0) { Gdk.Color col = new Gdk.Color(); Gdk.Color.Parse(calendarItem.TagColor, ref col); Gdk.GC TagGC = new Gdk.GC(evnt.Window); TagGC.RgbFgColor = col; Gdk.Point[] triangle = new Gdk.Point[] { new Gdk.Point(targetRectangle.X + targetRectangle.Width, targetRectangle.Top), new Gdk.Point(targetRectangle.X + targetRectangle.Width - triangleSize, targetRectangle.Top), new Gdk.Point(targetRectangle.X + targetRectangle.Width, targetRectangle.Top + triangleSize) }; evnt.Window.DrawPolygon(TagGC, true, triangle); if (calendarItem.Tag != "") { Pango.Rectangle logicExt, inkExt; PangoTag.GetPixelExtents(out inkExt, out logicExt); evnt.Window.DrawLayout(Style.WhiteGC, targetRectangle.Right - triangleSize * 5 / 16 - logicExt.Width / 2, targetRectangle.Top + triangleSize * 5 / 16 - logicExt.Height / 2, PangoTag); } } if (calendarItem.MessageCount > 0) { Pango.Rectangle logicExt, inkExt; PangoMessages.GetPixelExtents(out inkExt, out logicExt); var messagebox = new Gdk.Rectangle(targetRectangle.Right - logicExt.Width, targetRectangle.Bottom - logicExt.Height, logicExt.Height, logicExt.Width); evnt.Window.DrawLayoutWithColors(Style.BlackGC, targetRectangle.Right - logicExt.Width + 1, targetRectangle.Bottom - logicExt.Height + 1, PangoMessages, ColorUtil.Create("Cornsilk"), ColorUtil.Create("Gray")); } return(true); } return(base.OnExposeEvent(evnt)); }
public override void GetSize(Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) { using (var layout = new Pango.Layout(Context)) { Pango.Rectangle ink, logical; layout.Width = (int)(MaxMarkupWidth * Pango.Scale.PangoScale); layout.SetMarkup(GetMarkup(false, widget)); layout.GetPixelExtents(out ink, out logical); width = Padding + RoundedRectangleWidth + Padding + Padding + logical.Width + Padding; height = Padding + Math.Max(RoundedRectangleHeight, logical.Height) + Padding; x_offset = 0; y_offset = 0; } }
public override void GetSize(Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) { using (var layout = new Pango.Layout(Context)) { Pango.Rectangle ink, logical; layout.FontDescription = font; var selected = false; var foregroundColor = Styles.GetStackFrameForegroundHexColor(selected, IsUserCode); layout.SetMarkup(GetMethodMarkup(selected, foregroundColor)); layout.GetPixelExtents(out ink, out logical); height = logical.Height; width = 0; x_offset = 0; y_offset = 0; } }
protected override void Render(Gdk.Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { using (var cr = Gdk.CairoHelper.Create(window)) { using (var layout = new Pango.Layout(Context)) { Pango.Rectangle ink, logical; layout.Width = (int)(MaxMarkupWidth * Pango.Scale.PangoScale); layout.SetMarkup(GetMarkup((flags & CellRendererState.Selected) != 0, widget)); layout.GetPixelExtents(out ink, out logical); RenderLineNumberIcon(widget, cr, cell_area, logical.Height, ink.Y); cr.Rectangle(expose_area.X, expose_area.Y, expose_area.Width, expose_area.Height); cr.Clip(); cr.Translate(cell_area.X + Padding + RoundedRectangleWidth + Padding + Padding, cell_area.Y + Padding); cr.ShowLayout(layout); } } }
/// <summary> /// Calculates size needed for this cell /// </summary> /// <param name="aWidth"> /// Cell width <see cref="System.Double"/> /// </param> /// <param name="aHeight"> /// Cell height <see cref="System.Double"/> /// </param> public override void GetSize(out double aWidth, out double aHeight) { aWidth = 0; aHeight = 0; Pango.Context pContext = PangoContext; if (((SizeText == "") && (text == null) || (text == "")) || (pContext == null)) { return; } if (lastStr == SizeText) { if ((lastH != -1) && (lastW != -1)) { aWidth = lastW; aHeight = lastH; return; } } Pango.Layout layout = SetLayout(); int w, h = 0; layout.SetMarkup("Mj"); Pango.Rectangle r1; Pango.Rectangle r2; layout.GetPixelExtents(out r1, out r2); xSize = r1.Width; h = ySize = r1.Height; w = 0; if ((SizeText != null) && (SizeText != "")) { layout.SetMarkup(SizeText); layout.GetPixelSize(out w, out h); } aWidth = w; aHeight = h; layout.SetMarkup(""); FreeLayout(layout); }
protected override void Render(Gdk.Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { using (var cr = Gdk.CairoHelper.Create(window)) { Pango.Rectangle ink, logical; using (var layout = new Pango.Layout(Context)) { layout.FontDescription = font; layout.SetMarkup(GetFileMarkup((flags & CellRendererState.Selected) != 0)); layout.GetPixelExtents(out ink, out logical); var width = widget.Allocation.Width; cr.Translate(width - logical.Width - 10, cell_area.Y); cr.ShowLayout(layout); cr.IdentityMatrix(); layout.SetMarkup(GetMethodMarkup((flags & CellRendererState.Selected) != 0)); layout.Width = (int)((width - logical.Width - 35) * Pango.Scale.PangoScale); layout.Ellipsize = Pango.EllipsizeMode.Middle; cr.Translate(cell_area.X + 10, cell_area.Y); cr.ShowLayout(layout); } } }
public override void GetSize (Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) { using (var layout = new Pango.Layout (Context)) { Pango.Rectangle ink, logical; layout.FontDescription = font; layout.SetMarkup (GetMethodMarkup (false)); layout.GetPixelExtents (out ink, out logical); height = logical.Height; width = 0; x_offset = 0; y_offset = 0; } }
protected override void Render (Gdk.Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { using (var cr = Gdk.CairoHelper.Create (window)) { Pango.Rectangle ink, logical; using (var layout = new Pango.Layout (Context)) { layout.FontDescription = font; layout.SetMarkup (GetFileMarkup ((flags & CellRendererState.Selected) != 0)); layout.GetPixelExtents (out ink, out logical); var width = widget.Allocation.Width; cr.Translate (width - logical.Width - 10, cell_area.Y); cr.ShowLayout (layout); cr.IdentityMatrix (); layout.SetMarkup (GetMethodMarkup ((flags & CellRendererState.Selected) != 0)); layout.Width = (int)((width - logical.Width - 35) * Pango.Scale.PangoScale); layout.Ellipsize = Pango.EllipsizeMode.Middle; cr.Translate (cell_area.X + 10, cell_area.Y); cr.ShowLayout (layout); } } }
void RenderLine(Context cr, DateTime start, int line) { DateTime lineStart = start.AddDays((line - 1) * 7); int offsetSize = Allocation.Width / 9; int centerLine = LineHeight + LineHeight * line + ((Allocation.Height % LineHeight) / 2); int dayOffset = 0; using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) { Pango.Rectangle inkRect, logicalRect; layout.FontDescription = new Gtk.Style().FontDescription; layout.Ellipsize = Pango.EllipsizeMode.None; layout.Width = Pango.Units.FromPixels(offsetSize); layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels((int)(0.625 * LineHeight)); for (int i = 0; i < 7; i++) { layout.FontDescription.Weight = Pango.Weight.Normal; DateTime day = lineStart.AddDays(dayOffset); if (day.Month == CalendarStartDate.AddDays(6).Month) { cr.Color = new Cairo.Color(1, 1, 1); } else { cr.Color = new Cairo.Color(1, 1, 1, 0.5); } if (day.Date == DateTime.Today) { layout.FontDescription.Weight = Pango.Weight.Bold; Gdk.Color color = Style.Backgrounds [(int)StateType.Selected].SetMinimumValue(100); cr.Color = new Cairo.Color((double)color.Red / ushort.MaxValue, (double)color.Green / ushort.MaxValue, (double)color.Blue / ushort.MaxValue, 1.0); } dayOffset++; layout.SetText(string.Format("{0:00}", day.Day)); layout.GetPixelExtents(out inkRect, out logicalRect); cr.MoveTo(offsetSize + offsetSize * i + (offsetSize - inkRect.Width) / 2, centerLine - logicalRect.Height); Pango.CairoHelper.LayoutPath(cr, layout); cr.Fill(); } cr.Color = new Cairo.Color(1, 1, 1, 0.4); int woy = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(lineStart.AddDays(6), DateTimeFormatInfo.CurrentInfo.CalendarWeekRule, DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek); layout.FontDescription.Weight = Pango.Weight.Bold; layout.SetText(string.Format("W{0:00}", woy)); layout.GetPixelExtents(out inkRect, out logicalRect); cr.MoveTo(offsetSize * 8, centerLine - logicalRect.Height); Pango.CairoHelper.LayoutPath(cr, layout); cr.Fill(); layout.FontDescription.Dispose(); layout.Context.Dispose(); } }
public override void GetSize (Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) { using (var layout = new Pango.Layout (widget.PangoContext)) { layout.FontDescription = font; Pango.Rectangle ink, logical; layout.SetMarkup ("<b>" + Text + "</b>"); layout.GetPixelExtents (out ink, out logical); width = logical.Width + 10; height = logical.Height + 2; x_offset = 0; y_offset = 0; } }
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(); } }
void MakeRectangularDigitalIcon(DockySurface surface) { Context cr = surface.Context; // useful sizes int timeSize = surface.Height / 3; int dateSize = surface.Height / 4; int ampmSize = surface.Height / 4; int spacing = timeSize / 2; // shared by all text using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) { layout.FontDescription = new Gtk.Style().FontDescription; layout.FontDescription.Weight = Pango.Weight.Bold; layout.Ellipsize = Pango.EllipsizeMode.None; layout.Width = Pango.Units.FromPixels(surface.Width); // draw the time, outlined layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels(timeSize); if (ShowMilitary) { layout.SetText(DateTime.Now.ToString("HH:mm")); } else { layout.SetText(DateTime.Now.ToString("h:mm")); } Pango.Rectangle inkRect, logicalRect; layout.GetPixelExtents(out inkRect, out logicalRect); int timeYOffset = timeSize / 2; if (!ShowDate) { timeYOffset += timeSize / 2; } cr.MoveTo((surface.Width - inkRect.Width) / 2, timeYOffset); Pango.CairoHelper.LayoutPath(cr, layout); cr.LineWidth = 2; cr.Color = new Cairo.Color(0, 0, 0, 0.5); cr.StrokePreserve(); cr.Color = new Cairo.Color(1, 1, 1, 0.8); cr.Fill(); // draw the date, outlined if (ShowDate) { layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels(dateSize); layout.SetText(DateTime.Now.ToString("MMM dd")); layout.GetPixelExtents(out inkRect, out logicalRect); cr.MoveTo((surface.Width - inkRect.Width) / 2, surface.Height - spacing - dateSize); Pango.CairoHelper.LayoutPath(cr, layout); cr.Color = new Cairo.Color(0, 0, 0, 0.5); cr.StrokePreserve(); cr.Color = new Cairo.Color(1, 1, 1, 0.8); cr.Fill(); } if (!ShowMilitary) { layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels(ampmSize); if (DateTime.Now.Hour < 12) { layout.SetText("am"); } else { layout.SetText("pm"); } layout.GetPixelExtents(out inkRect, out logicalRect); int yOffset = timeSize; if (!ShowDate) { yOffset += timeSize / 2; } cr.MoveTo(surface.Width - logicalRect.Width, yOffset - inkRect.Height); Pango.CairoHelper.LayoutPath(cr, layout); cr.Color = new Cairo.Color(1, 1, 1, 0.8); cr.Fill(); } layout.FontDescription.Dispose(); layout.Context.Dispose(); } }
protected override void Render (Gdk.Drawable window, Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags) { using (var cr = Gdk.CairoHelper.Create (window)) { using (var layout = new Pango.Layout (Context)) { Pango.Rectangle ink, logical; layout.Width = (int) (MaxMarkupWidth * Pango.Scale.PangoScale); layout.SetMarkup (GetMarkup ((flags & CellRendererState.Selected) != 0)); layout.GetPixelExtents (out ink, out logical); RenderLineNumberIcon (widget, cr, cell_area, logical.Height, ink.Y); cr.Rectangle (expose_area.X, expose_area.Y, expose_area.Width, expose_area.Height); cr.Clip (); cr.Translate (cell_area.X + Padding + RoundedRectangleWidth + Padding + Padding, cell_area.Y + Padding); cr.ShowLayout (layout); } } }
public override void GetSize (Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) { using (var layout = new Pango.Layout (Context)) { Pango.Rectangle ink, logical; layout.Width = (int) (MaxMarkupWidth * Pango.Scale.PangoScale); layout.SetMarkup (GetMarkup (false)); layout.GetPixelExtents (out ink, out logical); width = Padding + RoundedRectangleWidth + Padding + Padding + logical.Width + Padding; height = Padding + Math.Max (RoundedRectangleHeight, logical.Height) + Padding; x_offset = 0; y_offset = 0; } }
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); }
/// <summary> /// Paints the forecast temperatures as a chart. /// </summary> /// <param name="cr"> /// A <see cref="Cairo.Context"/> to do the painting. /// </param> void DrawTempGraph(Cairo.Context cr) { int max = -1000, min = 1000; for (int day = 0; day < WeatherController.Weather.ForecastDays; day++) { if (WeatherController.Weather.Forecasts [day].high > max) { max = WeatherController.Weather.Forecasts [day].high; } if (WeatherController.Weather.Forecasts [day].low > max) { max = WeatherController.Weather.Forecasts [day].low; } if (WeatherController.Weather.Forecasts [day].high < min) { min = WeatherController.Weather.Forecasts [day].high; } if (WeatherController.Weather.Forecasts [day].low < min) { min = WeatherController.Weather.Forecasts [day].low; } } if (max <= min) { return; } using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) { Pango.Rectangle inkRect, logicalRect; layout.FontDescription = new Gtk.Style().FontDescription; layout.FontDescription.Weight = Pango.Weight.Bold; layout.Ellipsize = Pango.EllipsizeMode.None; layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels((int)(Allocation.Height / 5)); // high/low temp layout.Width = Pango.Units.FromPixels(Allocation.Height); cr.Color = colorHigh; layout.SetText(string.Format("{0}{1}", max, AbstractWeatherSource.TempUnit)); layout.GetPixelExtents(out inkRect, out logicalRect); cr.MoveTo(Allocation.Width - Allocation.Height + (Allocation.Height - inkRect.Width) / 2 - BUTTON_SIZE, Allocation.Height / 6 - logicalRect.Height / 2); Pango.CairoHelper.LayoutPath(cr, layout); cr.Fill(); cr.Color = colorLow; layout.SetText(string.Format("{0}{1}", min, AbstractWeatherSource.TempUnit)); layout.GetPixelExtents(out inkRect, out logicalRect); cr.MoveTo(Allocation.Width - Allocation.Height + (Allocation.Height - inkRect.Width) / 2 - BUTTON_SIZE, Allocation.Height * 6 / 9 - logicalRect.Height / 2); Pango.CairoHelper.LayoutPath(cr, layout); cr.Fill(); // day names layout.Width = Pango.Units.FromPixels(2 * Allocation.Height); cr.Color = colorTitle; for (int day = 0; day < WeatherController.Weather.ForecastDays; day++) { layout.SetText(WeatherForecast.DayShortName(WeatherController.Weather.Forecasts [day].dow)); layout.GetPixelExtents(out inkRect, out logicalRect); cr.MoveTo(BUTTON_SIZE + day * Allocation.Height * 2 + (Allocation.Height - inkRect.Width) / 2, Allocation.Height * 8 / 9 - logicalRect.Height / 2); Pango.CairoHelper.LayoutPath(cr, layout); } cr.Fill(); cr.Save(); layout.FontDescription.Dispose(); layout.Context.Dispose(); } // draw tick lines cr.Color = new Cairo.Color(0.627, 0.627, 0.627, .8); cr.LineWidth = 1; cr.LineCap = LineCap.Round; int lines = 5; for (int line = 0; line < lines - 1; line++) { cr.MoveTo(BUTTON_SIZE + Allocation.Height / 4, 4.5 + Allocation.Height * line / lines); cr.LineTo(BUTTON_SIZE + (2 * WeatherController.Weather.ForecastDays - 1) * Allocation.Height - Allocation.Height / 4, 4.5 + Allocation.Height * line / lines); cr.Stroke(); } for (int line = 0; ; line++) { double x = BUTTON_SIZE + Allocation.Height / 2 + line * 2 * Allocation.Height - 0.5; if (x >= BUTTON_SIZE + (2 * WeatherController.Weather.ForecastDays - 1) * Allocation.Height - Allocation.Height / 4) { break; } cr.MoveTo(x, 4.5); cr.LineTo(x, 4.5 + Allocation.Height * (lines - 2) / lines); cr.Stroke(); } cr.Restore(); cr.LineWidth = 3; double height = ((double)Allocation.Height * 2 / 3 - 5) / (max - min); // high temp graph cr.Color = colorHigh; cr.MoveTo(BUTTON_SIZE + Allocation.Height / 2, 5 + height * (max - WeatherController.Weather.Forecasts [0].high)); for (int day = 1; day < WeatherController.Weather.ForecastDays; day++) { cr.LineTo(BUTTON_SIZE + day * Allocation.Height * 2 + Allocation.Height / 2, 5 + height * (max - WeatherController.Weather.Forecasts [day].high)); } cr.Stroke(); // low temp graph cr.Color = colorLow; cr.MoveTo(BUTTON_SIZE + Allocation.Height / 2, 5 + height * (max - WeatherController.Weather.Forecasts [0].low)); for (int day = 1; day < WeatherController.Weather.ForecastDays; day++) { cr.LineTo(BUTTON_SIZE + day * Allocation.Height * 2 + Allocation.Height / 2, 5 + height * (max - WeatherController.Weather.Forecasts [day].low)); } cr.Stroke(); // high temp points for (int day = 0; day < WeatherController.Weather.ForecastDays; day++) { DrawDataPoint(cr, Allocation.Height, height, max, day, WeatherController.Weather.Forecasts [day].high); } // low temp points for (int day = 0; day < WeatherController.Weather.ForecastDays; day++) { DrawDataPoint(cr, Allocation.Height, height, max, day, WeatherController.Weather.Forecasts [day].low); } }
void PaintMessage(DockySurface surface, string icon, string message, int slot) { surface.Context.LineWidth = 0.5; double slotHeight = surface.Height / (double)MaxMessages; double yOffset = slot * slotHeight; surface.Context.RoundedRectangle(1, 1 + yOffset, surface.Width - 2, slotHeight - 2, 2 * (1 + (int)(IconSize / 64))); surface.Context.Color = new Cairo.Color(1, 1, 1, 0.9); surface.Context.StrokePreserve(); surface.Context.Color = new Cairo.Color(0, 0, 0, 0.7); surface.Context.Fill(); int iconSize = 0; if (!string.IsNullOrEmpty(icon)) { iconSize = (int)slotHeight - 4; using (Gdk.Pixbuf pbuf = DockServices.Drawing.LoadIcon(icon, iconSize, iconSize)) { Gdk.CairoHelper.SetSourcePixbuf(surface.Context, pbuf, 2 + (iconSize - pbuf.Width) / 2, 2 + yOffset + (iconSize - pbuf.Height) / 2); surface.Context.Paint(); } } using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) { int maxWidth = surface.Width - iconSize - 6; layout.Width = Pango.Units.FromPixels(2 * maxWidth); layout.Ellipsize = Pango.EllipsizeMode.None; layout.FontDescription = new Gtk.Style().FontDescription; layout.FontDescription.Weight = Pango.Weight.Bold; Pango.Rectangle inkRect, logicalRect; int fontSize = (int)slotHeight - 6; while (true) { layout.FontDescription.AbsoluteSize = Math.Max(1, Pango.Units.FromPixels(fontSize--)); layout.SetText(message); layout.GetPixelExtents(out inkRect, out logicalRect); if (logicalRect.Width <= maxWidth || fontSize < 1) { break; } } surface.Context.MoveTo(iconSize + 4 + (surface.Width - iconSize - 6 - logicalRect.Width) / 2, yOffset + (slotHeight - 2 - logicalRect.Height) / 2); Pango.CairoHelper.LayoutPath(surface.Context, layout); surface.Context.LineWidth = 2; surface.Context.StrokePreserve(); surface.Context.Color = new Cairo.Color(1, 1, 1, 1); surface.Context.Fill(); layout.FontDescription.Dispose(); layout.Context.Dispose(); } }
/// <summary> /// Paints an overview of the forecast including high/low temps and a condition icon. /// </summary> /// <param name="cr"> /// A <see cref="Cairo.Context"/> to do the painting. /// </param> void DrawVertForecast(Cairo.Context cr) { int cellHeight = (int)((Allocation.Height - BUTTON_SIZE) / WeatherController.Weather.ForecastDays / 1.5); double xOffset = 0; double yOffset = cellHeight / 4.0; using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) { Pango.Rectangle inkRect, logicalRect; layout.FontDescription = new Gtk.Style().FontDescription; layout.FontDescription.Weight = Pango.Weight.Bold; layout.Ellipsize = Pango.EllipsizeMode.None; layout.Width = Pango.Units.FromPixels(cellHeight); for (int day = 0; day < WeatherController.Weather.ForecastDays; day++) { layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels((int)(cellHeight / 5)); cr.Color = colorTitle; layout.SetText(string.Format("{0}", WeatherForecast.DayShortName(WeatherController.Weather.Forecasts [day].dow))); layout.GetPixelExtents(out inkRect, out logicalRect); cr.MoveTo(xOffset + (cellHeight - inkRect.Width) / 2, yOffset); Pango.CairoHelper.LayoutPath(cr, layout); cr.Fill(); cr.Color = colorHigh; layout.SetText(string.Format("{0}{1}", WeatherController.Weather.Forecasts [day].high, AbstractWeatherSource.TempUnit)); layout.GetPixelExtents(out inkRect, out logicalRect); cr.MoveTo(xOffset + (cellHeight - inkRect.Width) / 2, yOffset + (cellHeight - logicalRect.Height) / 2); Pango.CairoHelper.LayoutPath(cr, layout); cr.Fill(); cr.Color = colorLow; layout.SetText(string.Format("{0}{1}", WeatherController.Weather.Forecasts [day].low, AbstractWeatherSource.TempUnit)); layout.GetPixelExtents(out inkRect, out logicalRect); cr.MoveTo(xOffset + (cellHeight - inkRect.Width) / 2, yOffset + cellHeight - logicalRect.Height); Pango.CairoHelper.LayoutPath(cr, layout); cr.Fill(); using (Gdk.Pixbuf pbuf = DockServices.Drawing.LoadIcon(WeatherController.Weather.Forecasts [day].image, cellHeight - 5)) { Gdk.CairoHelper.SetSourcePixbuf(cr, pbuf, xOffset + 5 + cellHeight, yOffset + 2); cr.PaintWithAlpha(WeatherController.Weather.Forecasts [day].chanceOf ? .6 : 1); } if (WeatherController.Weather.Forecasts [day].chanceOf) { layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels((int)(cellHeight / 2)); layout.SetText("?"); layout.GetPixelExtents(out inkRect, out logicalRect); cr.MoveTo(xOffset + cellHeight + (cellHeight - inkRect.Width) / 2, yOffset + (cellHeight - logicalRect.Height) / 2); cr.LineWidth = 4; cr.Color = new Cairo.Color(0, 0, 0, 0.3); Pango.CairoHelper.LayoutPath(cr, layout); cr.StrokePreserve(); cr.Color = new Cairo.Color(1, 1, 1, .6); cr.Fill(); } yOffset += (int)(1.5 * cellHeight); } layout.FontDescription.Dispose(); layout.Context.Dispose(); } }
protected override bool OnExposeEvent(EventExpose evnt) { if (!IsRealized) { return(false); } Gdk.Rectangle allocation = Allocation; int pixbufSize = allocation.Height - IconBuffer * 2; if (item.ShowIcons && (icon_surface == null || (icon_surface.Height != pixbufSize && icon_surface.Width != pixbufSize))) { if (icon_surface != null) { icon_surface.Dispose(); } if (emblem_surface != null) { emblem_surface.Dispose(); } if (item.ForcePixbuf == null) { icon_surface = LoadIcon(item.Icon, pixbufSize); } else { icon_surface = LoadIcon(item.ForcePixbuf, pixbufSize); } if (!string.IsNullOrEmpty(item.Emblem)) { emblem_surface = LoadIcon(item.Emblem, pixbufSize); } } using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) { if (Selected && !item.Disabled) { cr.Rectangle(allocation.X, allocation.Y, allocation.Width, allocation.Height); cr.Color = TextColor.SetAlpha(.1); cr.Fill(); } if (item.ShowIcons) { PlaceSurface(cr, icon_surface, allocation); cr.PaintWithAlpha(item.Disabled ? 0.5 : 1); if (item.Bold) { cr.Operator = Operator.Add; PlaceSurface(cr, icon_surface, allocation); cr.PaintWithAlpha(.8); cr.Operator = Operator.Over; } if (!string.IsNullOrEmpty(item.Emblem)) { PlaceSurface(cr, emblem_surface, allocation); cr.Paint(); } } using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) { char accel; string text = GLib.Markup.EscapeText(item.Text.Replace("\n", "")); if (item.Mnemonic.HasValue) { layout.SetMarkupWithAccel(text, '_', out accel); } else { layout.SetMarkup(text); } layout.Width = Pango.Units.FromPixels(TextWidth); layout.FontDescription = Style.FontDescription; layout.Ellipsize = Pango.EllipsizeMode.End; layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels(FontSize); layout.FontDescription.Weight = Pango.Weight.Bold; Pango.Rectangle logical, ink; layout.GetPixelExtents(out ink, out logical); int offset = Padding; if (MenuShowingIcons) { offset += MenuHeight + Padding; } cr.MoveTo(allocation.X + offset, allocation.Y + (allocation.Height - logical.Height) / 2); Pango.CairoHelper.LayoutPath(cr, layout); cr.Color = TextColor.SetAlpha(item.Disabled ? 0.5 : 1); cr.Fill(); layout.Context.Dispose(); } (cr.Target as IDisposable).Dispose(); } return(true); }