public ImageInfo(ImageInfo info, Gdk.Rectangle allocation) { #if false Surface = new ImageSurface (Format.RGB24, allocation.Width, allocation.Height); Context ctx = new Context (Surface); #else Console.WriteLine ("source status = {0}", info.Surface.Status); Surface = info.Surface.CreateSimilar (Content.Color, allocation.Width, allocation.Height); System.Console.WriteLine ("status = {1} pointer = {0}", Surface.Handle.ToString (), Surface.Status); Context ctx = new Context (Surface); #endif Bounds = allocation; ctx.Matrix = info.Fill (allocation); Pattern p = new SurfacePattern (info.Surface); ctx.Source = p; ctx.Paint (); ((IDisposable)ctx).Dispose (); p.Destroy (); }
public static byte[] SurfaceToPngBytes(Surface surface) { using (var ms = new MemoryStream()) { SurfaceToPngStream(surface, ms); return ms.ToArray(); } }
public void DrawToSurface(Cairo.Surface surface, Gdk.Rectangle size) { Cairo.Context cr = new Cairo.Context(surface); Paper.Draw(cr, size); ((IDisposable)cr).Dispose(); }
public static void SurfaceToPngStream(Surface surface, BinaryWriter writer) { var obj = new CairoStreamWriter(writer); var fn = new cairo_write_func_t(obj.do_write); var status = cairo_surface_write_to_png_stream(surface.Handle, fn, IntPtr.Zero); if (status != Status.Success) throw new InvalidOperationException("Status: " + status); }
// Used by GeneratePDF public CairoContext(Cairo.Surface s, string font, int dpis) : base(s) { layout = Pango.CairoHelper.CreateLayout(this); font_description = layout.FontDescription = FontDescription.FromString(font); if (dpis > 0) { Pango.Context c = layout.Context; Pango.CairoHelper.ContextSetResolution(c, dpis); c.Dispose(); } FontLineSpace = def_linespace; }
public ImageInfo(ImageInfo info, Widget w, Gdk.Rectangle bounds) { Cairo.Surface similar = CairoUtils.CreateSurface (w.GdkWindow); Bounds = bounds; Surface = similar.CreateSimilar (Content.ColorAlpha, Bounds.Width, Bounds.Height); Context ctx = new Context (Surface); ctx.Matrix = info.Fill (Bounds); Pattern p = new SurfacePattern (info.Surface); ctx.Source = p; ctx.Paint (); ((IDisposable)ctx).Dispose (); p.Destroy (); }
public ImageInfo(ImageInfo info, Widget w, Gdk.Rectangle bounds) { Cairo.Surface similar = CairoUtils.CreateSurface(w.GdkWindow); Bounds = bounds; Surface = similar.CreateSimilar(Content.ColorAlpha, Bounds.Width, Bounds.Height); Context ctx = new Context(Surface); ctx.Matrix = info.Fill(Bounds); Pattern p = new SurfacePattern(info.Surface); ctx.Source = p; ctx.Paint(); ((IDisposable)ctx).Dispose(); p.Destroy(); }
private void CreateTexture() { var factory = _device.ResourceFactory; _texture?.Dispose(); _texture = factory.CreateTexture(TextureDescription.Texture2D( (uint)_size.Width, (uint)_size.Height, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled)); _textureView?.Dispose(); _textureView = factory.CreateTextureView(_texture); ResourceSet?.Dispose(); ResourceSet = factory.CreateResourceSet(new ResourceSetDescription( ResourceLayout, _textureView, _sampler )); _surface?.Dispose(); _surface = new ImageSurface(Format.Argb32, _size.Width, _size.Height); }
public CellRendererSurface(int width, int height) { // TODO: Respect cell padding (Xpad and Ypad). SetFixedSize (width, height); transparent = new Cairo.ImageSurface (Cairo.Format.ARGB32, width, height); Cairo.Color gray = new Cairo.Color (.75, .75, .75); // Create checkerboard background int grid_width = 4; using (Cairo.Context g = new Cairo.Context (transparent)) { g.Color = new Cairo.Color (1, 1, 1); g.Paint (); for (int y = 0; y < height; y += grid_width) for (int x = 0; x < width; x += grid_width) if ((x / grid_width % 2) + (y / grid_width % 2) == 1) g.FillRectangle (new Cairo.Rectangle (x, y, grid_width, grid_width), gray); } }
static void Main(string [] args) { Window win = new Window(500, 500); win.Show(); Cairo.Surface s = Cairo.Surface.CreateForXlib(win.Display, win.XWindow, X11.XDefaultVisual(win.Display, win.Screen), (int)win.Width, (int)win.Height); Cairo.Context g = new Cairo.Context(s); draw(g, 500, 500); IntPtr xev = new IntPtr(); while (true) { X11.XNextEvent(win.Display, xev); } }
public void MaskSurface(Surface surface, double surface_x, double surface_y) { NativeMethods.cairo_mask_surface (handle, surface.Handle, surface_x, surface_y); }
/// <summary> /// Inverts the selection. /// </summary> /// <param name="surface"> /// Surface for the selection path. /// </param> /// <param name='imageSize'> /// The size of the document. /// </param> public void Invert(Surface surface, Gdk.Size imageSize) { List<List<IntPoint>> resultingPolygons = new List<List<IntPoint>> (); var documentPolygon = CreateRectanglePolygon (new Rectangle (0, 0, imageSize.Width, imageSize.Height)); // Create a rectangle that is the size of the entire image, // and subtract all of the polygons in the current selection from it. SelectionClipper.AddPolygon (documentPolygon, PolyType.ptSubject); SelectionClipper.AddPolygons (SelectionPolygons, PolyType.ptClip); SelectionClipper.Execute (ClipType.ctDifference, resultingPolygons); SelectionClipper.Clear (); SelectionPolygons = resultingPolygons; using (Context g = new Context (surface)) { SelectionPath = g.CreatePolygonPath (ConvertToPolygonSet (resultingPolygons)); } }
/// <summary> /// Create an elliptical Selection from a bounding Rectangle. /// </summary> /// <param name="selectionSurface">The selection surface to use for calculating the elliptical Path.</param> /// <param name="r">The bounding Rectangle surrounding the ellipse.</param> public void CreateEllipseSelection(Surface selectionSurface, Rectangle r) { using (Context g = new Context(selectionSurface)) { SelectionPath = g.CreateEllipsePath(r); } //These values were calculated in the static CreateEllipsePath method //in Pinta.Core.CairoExtensions, so they were used here as well. double rx = r.Width / 2; //1/2 of the bounding Rectangle Width. double ry = r.Height / 2; //1/2 of the bounding Rectangle Height. double cx = r.X + rx; //The middle of the bounding Rectangle, horizontally speaking. double cy = r.Y + ry; //The middle of the bounding Rectangle, vertically speaking. double c1 = 0.552285; //A constant factor used to give the least approximation error. //Clear the Selection Polygons collection to start from a clean slate. SelectionPolygons.Clear(); //Calculate an appropriate interval at which to increment t based on //the bounding Rectangle's Width and Height properties. The increment //for t determines how many intermediate Points to calculate for the //ellipse. For each curve, t will go from tInterval to 1. The lower //the value of tInterval, the higher number of intermediate Points //that will be calculated and stored into the Polygon collection. double tInterval = 1d / (r.Width + r.Height); //Create a new Polygon to store the upcoming ellipse. List<IntPoint> newPolygon = new List<IntPoint>(); //These values were also calculated in the CreateEllipsePath method. This is where //the ellipse's 4 curves (and all of the Points on each curve) are determined. //Note: each curve is consecutive to the previous one, but they *do not* overlap, //other than the first/last Point (which is how it is supposed to work). //The starting Point. newPolygon.Add(new IntPoint((long)(cx + rx), (long)cy)); //Curve 1. newPolygon.AddRange(CalculateCurvePoints(tInterval, cx + rx, cy, cx + rx, cy - c1 * ry, cx + c1 * rx, cy - ry, cx, cy - ry)); //Curve 2. newPolygon.AddRange(CalculateCurvePoints(tInterval, cx, cy - ry, cx - c1 * rx, cy - ry, cx - rx, cy - c1 * ry, cx - rx, cy)); //Curve 3. newPolygon.AddRange(CalculateCurvePoints(tInterval, cx - rx, cy, cx - rx, cy + c1 * ry, cx - c1 * rx, cy + ry, cx, cy + ry)); //Curve 4. newPolygon.AddRange(CalculateCurvePoints(tInterval, cx, cy + ry, cx + c1 * rx, cy + ry, cx + rx, cy + c1 * ry, cx + rx, cy)); //Add the newly calculated elliptical Polygon. SelectionPolygons.Add(newPolygon); }
private static Gdk.Pixbuf CreatePixbuf(Surface s) { IntPtr result = f_pixbuf_from_cairo_surface (s.Handle); return (Gdk.Pixbuf) GLib.Object.GetObject (result, true); }
public void SetSourceSurface (Surface source, double x, double y) { CairoAPI.cairo_set_source_surface (state, source.Handle, x, y); }
public static void SetFill(this Context ctx, Surface surface, double x, double y) { ctx.SetSource (surface, x, y); }
public Graphics(Surface surface) : base(surface) { }
public Surface GetGroupTarget() { IntPtr surface = NativeMethods.cairo_get_group_target(handle); return(Surface.Lookup(surface, false)); }
public Surface GetTarget() { CheckDisposed(); return(Surface.Lookup(NativeMethods.cairo_get_target(handle), false)); }
public void SetSource(Surface source, double x, double y) { CheckDisposed(); NativeMethods.cairo_set_source_surface(handle, source.Handle, x, y); }
public void SetSource(Surface source) { CheckDisposed(); NativeMethods.cairo_set_source_surface(handle, source.Handle, 0, 0); }
public void SetSource(Surface source) { NativeMethods.cairo_set_source_surface (handle, source.Handle, 0, 0); }
public void SetTarget(Surface target) { if (handle != IntPtr.Zero) NativeMethods.cairo_destroy (handle); handle = NativeMethods.cairo_create (target.Handle); }
void SetPixbuf(Pixbuf pixbuf) { Surface = Hyena.Gui.PixbufImageSurface.Create(pixbuf); Bounds.Width = pixbuf.Width; Bounds.Height = pixbuf.Height; }
public Context(Surface surface) : this(NativeMethods.cairo_create(surface.Handle), true) { }
public ImageInfo(ImageInfo info, Widget w, Gdk.Rectangle bounds) { using (var similar = CairoUtils.CreateSurface (w.GdkWindow)) { Bounds = bounds; Surface = similar.CreateSimilar (Content.ColorAlpha, Bounds.Width, Bounds.Height); var ctx = new Context (Surface); ctx.Matrix = info.Fill (Bounds); Pattern p = new SurfacePattern (info.Surface); ctx.SetSource (p); ctx.Paint (); ctx.Dispose (); p.Dispose (); } }
public Graphics (Surface surface) { state = CairoAPI.cairo_create (surface.Pointer); }
public ImageInfo(ImageInfo info, Gdk.Rectangle allocation) { Surface = info.Surface.CreateSimilar (Content.Color, allocation.Width, allocation.Height); var ctx = new Context (Surface); Bounds = allocation; ctx.Matrix = info.Fill (allocation); Pattern p = new SurfacePattern (info.Surface); ctx.SetSource (p); ctx.Paint (); ctx.Dispose (); p.Dispose (); }
public void MaskSurface (Surface surface, double x, double y) { CairoAPI.cairo_mask_surface (state, surface.Handle, x, y); }
public Pattern(Surface surface) { pattern = NativeMethods.cairo_pattern_create_for_surface (surface.Handle); }
public void ClearDrawing() { drawings.Destroy(); drawings = new ImageSurface(Format.ARGB32,sourceWidth,sourceHeight); QueueDraw(); }
// Used by GeneratePDF public CairoContextEx(Cairo.Surface s, string font, int dpis) : base(s, font, dpis) { CommonConstructor(); }
/// <summary> /// Create a rectangular Selection from a Rectangle. /// </summary> /// <param name="selectionSurface">The selection surface to use for calculating the rectangular Path.</param> /// <param name="r">The Rectangle.</param> public void CreateRectangleSelection(Surface selectionSurface, Rectangle r) { using (Context g = new Context(selectionSurface)) { SelectionPath = g.CreateRectanglePath(r); } //Clear the Selection Polygons collection to start from a clean slate. SelectionPolygons.Clear(); SelectionPolygons.Add (CreateRectanglePolygon (r)); }
private void SetPixbuf(Pixbuf pixbuf) { Surface = CairoUtils.CreateSurface (pixbuf); Bounds.Width = pixbuf.Width; Bounds.Height = pixbuf.Height; }
/// <summary> /// Reset (clear) the Selection. /// </summary> /// <param name="selectionSurface"></param> /// <param name="imageSize"></param> public void ResetSelection(Surface selectionSurface, Gdk.Size imageSize) { using (Cairo.Context g = new Cairo.Context(selectionSurface)) { SelectionPath = g.CreateRectanglePath(new Rectangle(0, 0, imageSize.Width, imageSize.Height)); } SelectionPolygons.Clear(); }
public void SetSource(Surface source, double x, double y) { NativeMethods.cairo_set_source_surface (handle, source.Handle, x, y); }
//[Obsolete ("Use SetSource method (with double parameters)")] public void SetSourceSurface(Surface source, int x, int y) { ThrowIfDisposed(); NativeMethods.cairo_set_source_surface(handle, source.Handle, x, y); }
//[Obsolete ("Use SetSource method (with double parameters)")] public void SetSourceSurface(Surface source, int x, int y) { NativeMethods.cairo_set_source_surface (handle, source.Handle, x, y); }
public Context(Surface surface) { state = NativeMethods.cairo_create (surface.Handle); }
public Context(Surface surface) : this(NativeMethods.cairo_create (surface.Handle), true) { }
public static void SetFill(this Context ctx, Surface surface) { ctx.SetSource (surface); }
public static void DrawRadialGradient(this Context g, Surface oldsurface, GradientColorMode mode, Cairo.Color c1, Cairo.Color c2, PointD p1, PointD p2, double r1, double r2) { g.Save (); Gradient gradient = new Cairo.RadialGradient (p1.X, p1.Y, r1, p2.X, p2.Y, r2); if (mode == GradientColorMode.Color) { gradient.AddColorStop (0, c1); gradient.AddColorStop (1, c2); g.Source = gradient; g.Paint (); } else if (mode == GradientColorMode.Transparency) { gradient.AddColorStop (0, new Cairo.Color (0, 0, 0, 1)); gradient.AddColorStop (1, new Cairo.Color (0, 0, 0, 0)); g.Source = new SurfacePattern (oldsurface); g.Mask (gradient); } g.Restore (); }
public void MaskSurface(Surface surface, double surface_x, double surface_y) { CheckDisposed(); NativeMethods.cairo_mask_surface(handle, surface.Handle, surface_x, surface_y); }