public CairoContextBackend CreateContext() { CairoContextBackend ctx = new CairoContextBackend(Util.GetScaleFactor(this)); if (!IsRealized) { Cairo.Surface sf = new Cairo.ImageSurface(Cairo.Format.ARGB32, 1, 1); ctx.Context = new Cairo.Context(sf); ctx.TempSurface = sf; } else { ctx.Context = Gdk.CairoHelper.Create(GdkWindow); } if (!VisibleWindow) { ctx.Context.Translate(Allocation.X, Allocation.Y); #if limada_8b3c8a // Set ContextBackend Origin ctx.Origin.X = Allocation.X; ctx.Origin.Y = Allocation.Y; #endif } return(ctx); }
public override void DrawTextLayout(object backend, TextLayout layout, double x, double y) { Pango.Layout pl = (Pango.Layout)WidgetRegistry.GetBackend(layout); CairoContextBackend ctx = (CairoContextBackend)backend; ctx.Context.MoveTo(x, y); if (layout.Height <= 0) { Pango.CairoHelper.ShowLayout(ctx.Context, pl); } else { var lc = pl.LineCount; var scale = Pango.Scale.PangoScale; double h = 0; for (int i = 0; i < lc; i++) { var line = pl.Lines [i]; var ext = new Pango.Rectangle(); var extl = new Pango.Rectangle(); line.GetExtents(ref ext, ref extl); h += (extl.Height / scale); if (h > layout.Height) { break; } ctx.Context.MoveTo(x, y + h); Pango.CairoHelper.ShowLayoutLine(ctx.Context, line); } } }
public void Draw(ApplicationContext actx, Cairo.Context ctx, double scaleFactor, double x, double y, ImageDescription idesc) { if (stockId != null) { Gdk.Pixbuf img = null; if (frames != null) { img = frames.FirstOrDefault(p => p.Width == (int)idesc.Size.Width && p.Height == (int)idesc.Size.Height); } if (img == null) { img = ImageHandler.CreateBitmap(stockId, idesc.Size.Width, idesc.Size.Height); AddFrame(img); } DrawPixbuf(ctx, img, x, y, idesc); } else if (drawCallback != null) { CairoContextBackend c = new CairoContextBackend(scaleFactor) { Context = ctx }; actx.InvokeUserCode(delegate { drawCallback(c, new Rectangle(x, y, idesc.Size.Width, idesc.Size.Height)); }); } else { DrawPixbuf(ctx, GetBestFrame(actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false), x, y, idesc); } }
protected override void OnRender(Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, CellRendererState flags) { int wx, wy, dx = 0, dy = 0; var tree = widget as Gtk.TreeView; // Tree coordinates must be converted to widget coordinates, // otherwise custom cell bounds will have an offset to the parent widget if (tree != null) { tree.ConvertBinWindowToWidgetCoords(cell_area.X, cell_area.Y, out wx, out wy); dx = wx - cell_area.X; dy = wy - cell_area.Y; cell_area.X += dx; background_area.X += dx; cell_area.Y += dy; background_area.Y += dy; } Parent.StartDrawing(new Rectangle(background_area.X, background_area.Y, background_area.Width, background_area.Height), new Rectangle(cell_area.X, cell_area.Y, cell_area.Width, cell_area.Height), flags); CellView.ApplicationContext.InvokeUserCode(delegate { CairoContextBackend ctx = new CairoContextBackend(Util.GetScaleFactor(widget)); ctx.Context = cr; ctx.Context.Translate(-dx, -dy); using (ctx) { CellView.Draw(ctx, new Rectangle(cell_area.X, cell_area.Y, cell_area.Width, cell_area.Height)); } }); Parent.EndDrawing(); }
protected void OnDraw(Rectangle dirtyRect, CairoContextBackend context) { Backend.ApplicationContext.InvokeUserCode(delegate { using (context) { EventSink.OnDraw(context, dirtyRect); } }); }
public override object CreateContext(object backend) { Cairo.Surface sf = (Cairo.Surface)backend; CairoContextBackend ctx = new CairoContextBackend(1); ctx.Context = new Cairo.Context(sf); return(ctx); }
protected void OnDraw(Rectangle dirtyRect, CairoContextBackend context) { Backend.ApplicationContext.InvokeUserCode(delegate { using (context) { var r = new Rectangle(dirtyRect.X - context.Origin.X, dirtyRect.Y - context.Origin.Y, dirtyRect.Width, dirtyRect.Height); EventSink.OnDraw(context, r); } }); }
protected override void Render(Gdk.Drawable window, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags) { cellView.ApplicationContext.InvokeUserCode(delegate { CairoContextBackend ctx = new CairoContextBackend(Util.GetScaleFactor(widget)); ctx.Context = Gdk.CairoHelper.Create(window); using (ctx) { cellView.Draw(ctx, new Rectangle(cell_area.X, cell_area.Y, cell_area.Width, cell_area.Height)); } }); }
protected override void OnRender(Cairo.Context cr, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, CellRendererState flags) { Parent.StartDrawing(new Rectangle(background_area.X, background_area.Y, background_area.Width, background_area.Height), new Rectangle(cell_area.X, cell_area.Y, cell_area.Width, cell_area.Height), flags); CellView.ApplicationContext.InvokeUserCode(delegate { CairoContextBackend ctx = new CairoContextBackend(Util.GetScaleFactor(widget)); ctx.Context = cr; using (ctx) { CellView.Draw(ctx, new Rectangle(cell_area.X, cell_area.Y, cell_area.Width, cell_area.Height)); } }); Parent.EndDrawing(); }
public void Draw(ApplicationContext actx, Cairo.Context ctx, double scaleFactor, double x, double y, ImageDescription idesc) { if (stockId != null) { ImageFrame frame = null; // PERF: lambdas capture here, this is a hot path. if (frames != null) { foreach (var f in frames) { if (f.Width == (int)idesc.Size.Width && f.Height == (int)idesc.Size.Height && f.Scale == scaleFactor) { frame = f; break; } } } if (frame == null) { frame = new ImageFrame(ImageHandler.CreateBitmap(stockId, idesc.Size.Width, idesc.Size.Height, scaleFactor), (int)idesc.Size.Width, (int)idesc.Size.Height, false); frame.Scale = scaleFactor; AddFrame(frame); } DrawPixbuf(ctx, frame.Pixbuf, x, y, idesc); } else if (drawCallback != null) { CairoContextBackend c = new CairoContextBackend(scaleFactor) { Context = ctx }; if (actx != null) { actx.InvokeUserCode(delegate { drawCallback(c, new Rectangle(x, y, idesc.Size.Width, idesc.Size.Height), idesc, actx.Toolkit); }); } else { drawCallback(c, new Rectangle(x, y, idesc.Size.Width, idesc.Size.Height), idesc, Toolkit.CurrentEngine); } } else { DrawPixbuf(ctx, GetBestFrame(actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false), x, y, idesc); } }
public object CreateContext() { CairoContextBackend ctx = new CairoContextBackend(); if (!IsRealized) { Cairo.Surface sf = new Cairo.ImageSurface(Cairo.Format.ARGB32, 1, 1); Cairo.Context c = new Cairo.Context(sf); ctx.Context = c; ctx.TempSurface = sf; } else { ctx.Context = Gdk.CairoHelper.Create(GdkWindow); } return(ctx); }
public void Draw(ApplicationContext actx, Cairo.Context ctx, double scaleFactor, double x, double y, ImageDescription idesc) { if (stockId != null) { ImageFrame frame = null; if (frames != null) { frame = frames.FirstOrDefault(f => f.Width == (int)idesc.Size.Width && f.Height == (int)idesc.Size.Height && f.Scale == scaleFactor); } if (frame == null) { frame = new ImageFrame(ImageHandler.CreateBitmap(stockId, idesc.Size.Width, idesc.Size.Height, scaleFactor), (int)idesc.Size.Width, (int)idesc.Size.Height, false); frame.Scale = scaleFactor; AddFrame(frame); } DrawPixbuf(ctx, frame.Pixbuf, x, y, idesc); } else if (drawCallback != null) { CairoContextBackend c = new CairoContextBackend(scaleFactor) { Context = ctx }; if (actx != null) { actx.InvokeUserCode(delegate { drawCallback(c, new Rectangle(x, y, idesc.Size.Width, idesc.Size.Height)); }); } else { drawCallback(c, new Rectangle(x, y, idesc.Size.Width, idesc.Size.Height)); } } else { DrawPixbuf(ctx, GetBestFrame(actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false), x, y, idesc); } }
public void Wrap(TextLayout layout, CairoContextBackend ctx) { var text = layout.Text; var be = (GtkTextLayoutBackendHandler.PangoBackend)Toolkit.GetBackend(layout); var pl = be.Layout; var fe = ctx.Context.FontExtents; Baseline = fe.Ascent / (fe.Ascent + fe.Descent); LineHeight = fe.Ascent + fe.Descent; LineY = LineHeight; var iLf = text.IndexOfAny(new char[] { '\n', '\r' }); HasLineFeed = iLf >= 0; var textWidth = layout.Width; if (!HasLineFeed && (layout.Height <= 0 || layout.Height <= LineHeight) && (layout.Width <= 0 || textWidth <= layout.Width)) { LineWidth = textWidth; SingleLine(this); } else { var ellipsize = pl.Ellipsize; pl.Ellipsize = Pango.EllipsizeMode.None; var lc = pl.LineCount; var scale = Pango.Scale.PangoScale; var wrap = pl.Wrap; var layoutHeight = layout.Height; if (layoutHeight <= 0) { var plw = 0; var plh = 0; pl.GetSize(out plw, out plh); layoutHeight = plh / scale; } MaxHeight = PreferedSize.Height > 0 ? PreferedSize.Height : (layoutHeight <= 0 ? double.MaxValue : layoutHeight); MaxWidth = PreferedSize.Width > 0 ? PreferedSize.Width : (layout.Width <= 0 ? textWidth : layout.Width); CursorPos = 0; LineStart = 0; foreach (var ll in Analyselayout(pl)) { if (LineY > MaxHeight) { break; } LineWidth = ll.Width; LineStart = ll.Pos; CursorPos = ll.Pos + ll.Len; MultiLine(this); LineY += ll.Height; } pl.Ellipsize = ellipsize; } }
public object Create(Context context) { CairoContextBackend c = (CairoContextBackend)WidgetRegistry.GetBackend(context); return(Pango.CairoHelper.CreateLayout(c.Context)); }