상속: 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
파일: Context.cs 프로젝트: knocte/gtk-sharp
 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
파일: Context.cs 프로젝트: knocte/gtk-sharp
 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
파일: Context.cs 프로젝트: knocte/gtk-sharp
 public void SetSource(Surface source)
 {
     NativeMethods.cairo_set_source_surface (handle, source.Handle, 0, 0);
 }
예제 #23
0
파일: Context.cs 프로젝트: knocte/gtk-sharp
 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
파일: Context.cs 프로젝트: knocte/gtk-sharp
 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
파일: Context.cs 프로젝트: knocte/gtk-sharp
 //[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
파일: Context.cs 프로젝트: knocte/gtk-sharp
 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);
 }