Наследование: IDisposable
Пример #1
0
        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 ();
        }
Пример #2
0
		public static byte[] SurfaceToPngBytes(Surface surface)
		{
			using (var ms = new MemoryStream())
			{
				SurfaceToPngStream(surface, ms);
				return ms.ToArray();
			}
		}
Пример #3
0
        public void DrawToSurface(Cairo.Surface surface, Gdk.Rectangle size)
        {
            Cairo.Context cr = new Cairo.Context(surface);

            Paper.Draw(cr, size);

            ((IDisposable)cr).Dispose();
        }
Пример #4
0
		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);
		}
Пример #5
0
        // 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;
        }
Пример #6
0
        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 ();
        }
Пример #7
0
        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();
        }
Пример #8
0
        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);
        }
Пример #9
0
        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);
            }
        }
Пример #10
0
    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);
        }
    }
Пример #11
0
 public void MaskSurface(Surface surface, double surface_x, double surface_y)
 {
     NativeMethods.cairo_mask_surface (handle, surface.Handle, surface_x, surface_y);
 }
Пример #12
0
        /// <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));
            }
        }
Пример #13
0
        /// <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);
        }
Пример #14
0
 private static Gdk.Pixbuf CreatePixbuf(Surface s)
 {
     IntPtr result = f_pixbuf_from_cairo_surface (s.Handle);
     return (Gdk.Pixbuf) GLib.Object.GetObject (result, true);
 }
Пример #15
0
		public void SetSourceSurface (Surface source, double x, double y)
		{
			CairoAPI.cairo_set_source_surface (state, source.Handle, x, y);
		}
Пример #16
0
 public static void SetFill(this Context ctx, Surface surface, double x, double y)
 {
     ctx.SetSource (surface, x, y);
 }
Пример #17
0
 public Graphics(Surface surface)
     : base(surface)
 {
 }
Пример #18
0
        public Surface GetGroupTarget()
        {
            IntPtr surface = NativeMethods.cairo_get_group_target(handle);

            return(Surface.Lookup(surface, false));
        }
Пример #19
0
 public Surface GetTarget()
 {
     CheckDisposed();
     return(Surface.Lookup(NativeMethods.cairo_get_target(handle), false));
 }
Пример #20
0
 public void SetSource(Surface source, double x, double y)
 {
     CheckDisposed();
     NativeMethods.cairo_set_source_surface(handle, source.Handle, x, y);
 }
Пример #21
0
 public void SetSource(Surface source)
 {
     CheckDisposed();
     NativeMethods.cairo_set_source_surface(handle, source.Handle, 0, 0);
 }
Пример #22
0
 public void SetSource(Surface source)
 {
     NativeMethods.cairo_set_source_surface (handle, source.Handle, 0, 0);
 }
Пример #23
0
 public void SetTarget(Surface target)
 {
     if (handle != IntPtr.Zero)
         NativeMethods.cairo_destroy (handle);
     handle = NativeMethods.cairo_create (target.Handle);
 }
Пример #24
0
 void SetPixbuf(Pixbuf pixbuf)
 {
     Surface = Hyena.Gui.PixbufImageSurface.Create(pixbuf);
     Bounds.Width = pixbuf.Width;
     Bounds.Height = pixbuf.Height;
 }
Пример #25
0
 public Context(Surface surface) : this(NativeMethods.cairo_create(surface.Handle), true)
 {
 }
Пример #26
0
        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 ();
            }
        }
Пример #27
0
                public Graphics (Surface surface)
                {
			state = CairoAPI.cairo_create (surface.Pointer);
                }
Пример #28
0
        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 ();
        }
Пример #29
0
		public void MaskSurface (Surface surface, double x, double y)
		{
			CairoAPI.cairo_mask_surface (state, surface.Handle, x, y);
		}
Пример #30
0
 public Pattern(Surface surface)
 {
     pattern = NativeMethods.cairo_pattern_create_for_surface (surface.Handle);
 }
Пример #31
0
 public void ClearDrawing()
 {
     drawings.Destroy();
     drawings = new ImageSurface(Format.ARGB32,sourceWidth,sourceHeight);
     QueueDraw();
 }
Пример #32
0
 // Used by GeneratePDF
 public CairoContextEx(Cairo.Surface s, string font, int dpis) : base(s, font, dpis)
 {
     CommonConstructor();
 }
Пример #33
0
        /// <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));
        }
Пример #34
0
 private void SetPixbuf(Pixbuf pixbuf)
 {
     Surface = CairoUtils.CreateSurface (pixbuf);
     Bounds.Width = pixbuf.Width;
     Bounds.Height = pixbuf.Height;
 }
Пример #35
0
        /// <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();
        }
Пример #36
0
 public Graphics(Surface surface) : base(surface)
 {
 }
Пример #37
0
 public void SetSource(Surface source, double x, double y)
 {
     NativeMethods.cairo_set_source_surface (handle, source.Handle, x, y);
 }
Пример #38
0
 //[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);
 }
Пример #39
0
 //[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);
 }
Пример #40
0
 public Context(Surface surface)
 {
     state = NativeMethods.cairo_create (surface.Handle);
 }
Пример #41
0
 public Context(Surface surface)
     : this(NativeMethods.cairo_create (surface.Handle), true)
 {
 }
Пример #42
0
 public static void SetFill(this Context ctx, Surface surface)
 {
     ctx.SetSource (surface);
 }
Пример #43
0
        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 ();
        }
Пример #44
0
 public void MaskSurface(Surface surface, double surface_x, double surface_y)
 {
     CheckDisposed();
     NativeMethods.cairo_mask_surface(handle, surface.Handle, surface_x, surface_y);
 }