コード例 #1
0
        // Called from asynchronously from Renderer.OnCompletion ()
        void HandleCancel()
        {
            Debug.WriteLine("LivePreviewManager.HandleCancel()");

            FireLivePreviewEndedEvent(RenderStatus.Canceled, null);
            live_preview_enabled = false;

            live_preview_surface?.Dispose();
            live_preview_surface = null !;

            PintaCore.Workspace.Invalidate();
            CleanUp();
        }
コード例 #2
0
        void OnExpose(object sender, ExposeEventArgs args)
        {
            DrawingArea area = (DrawingArea)sender;

            Cairo.Context cairoContext = Gdk.CairoHelper.Create(area.GdkWindow);

            int width  = area.Allocation.Width;
            int height = area.Allocation.Height;

            PixelDimensions = new Vector2i(width, height);

            AxisAlignedBox2d bounds = DrawingBounds;

            double sx = (double)width / bounds.Width;
            double sy = (double)height / bounds.Height;

            float scale = (float)Math.Min(sx, sy);

            // we apply this translate after scaling to pixel coords
            Vector2f pixC      = Zoom * scale * (Vector2f)bounds.Center;
            Vector2f translate = new Vector2f(width / 2, height / 2) - pixC;


            using (var bitmap = new SKBitmap(width, height, SkiaUtil.ColorType(), SKAlphaType.Premul)) {
                IntPtr len;
                using (var skSurface = SKSurface.Create(bitmap.Info.Width, bitmap.Info.Height, SkiaUtil.ColorType(), SKAlphaType.Premul, bitmap.GetPixels(out len), bitmap.Info.RowBytes)) {
                    var canvas = skSurface.Canvas;

                    // update scene xform
                    Func <Vector2d, Vector2f> ViewTransformF = (pOrig) => {
                        Vector2f pNew = (Vector2f)pOrig - (Vector2f)bounds.Center;
                        pNew   = Zoom * scale * pNew;
                        pNew  += (Vector2f)pixC;
                        pNew  += translate + Zoom * PixelTranslate;
                        pNew.y = canvas.ClipBounds.Height - pNew.y;
                        return(pNew);
                    };

                    DrawScene(canvas, ViewTransformF);

                    Cairo.Surface cairoSurf = new Cairo.ImageSurface(
                        bitmap.GetPixels(out len),
                        Cairo.Format.Argb32,
                        bitmap.Width, bitmap.Height,
                        bitmap.Width * 4);

                    cairoSurf.MarkDirty();
                    cairoContext.SetSourceSurface(cairoSurf, 0, 0);
                    cairoContext.Paint();

                    cairoSurf.Dispose();
                }
            }

            cairoContext.Dispose();

            //return true;
        }
コード例 #3
0
ファイル: AsciiFont.cs プロジェクト: bpatterson-gh/ArtSCII
        /// <summary>
        /// Creates a bitmap for each character in the font.
        /// Characters that the font does not include will not be assigned a bitmap.
        /// </summary>
        private void CreateBitmaps()
        {
            characters = new Dictionary <char, PixelSet>();
            ImageSurface surface = new ImageSurface(Format.RGB24, 1, 1);
            Context      context = new Context(surface);

            context.SelectFontFace(FontName, FontSlant.Normal, FontWeight.Normal);
            context.SetFontSize(Font.Size);
            TextExtents ext   = context.TextExtents("@");
            int         charW = (int)Math.Ceiling(ext.Width);
            int         charH = (int)Math.Ceiling(ext.Height);

            context.Dispose();
            surface.Dispose();

            surface = new ImageSurface(Format.RGB24, charW, charH);
            context = new Context(surface);
            PixelSet missingChar = null;

            for (int i = 0; i < asciiString.Length; i++)
            {
                // Render one character into a PixelSet
                string asciiChar = string.Empty + asciiString[i];
                context.SelectFontFace(FontName, FontSlant.Normal, FontWeight.Normal);
                context.SetFontSize(Font.Size);
                context.SetSourceRGB(0.067, 0.067, 0.067);
                context.Paint();
                context.SetSourceRGB(1, 1, 1);
                ext = context.TextExtents(asciiChar);
                context.MoveTo(ext.XBearing, ext.YBearing * -1);
                context.ShowText(asciiChar);
                PixelSet ch = new PixelSet(surface);

                // Filter out characters the font doesn't include
                // The first character is always unprintable, and serves as
                // a reference for what unprintable characters look like in this font
                if (i == 0)
                {
                    missingChar = ch;
                    continue;
                }
                else if (ch == missingChar)
                {
                    continue;
                }
                characters.Add(asciiString[i], ch);
            }
            context.Dispose();
            surface.Dispose();

            // Add the space manually if it wasn't included
            if (!characters.ContainsKey(' '))
            {
                var en = characters.Values.GetEnumerator();
                en.MoveNext();
                characters.Add(' ', new PixelSet(en.Current.Width, en.Current.Height));
            }
        }
コード例 #4
0
        public void Dispose()
        {
            if (this.Path == null)
            {
                Path   = _context.CopyPath();
                Bounds = _context.FillExtents().ToAvalonia();
            }

            _context.Dispose();
            _surf.Dispose();
        }
コード例 #5
0
ファイル: GraphicsHandler.cs プロジェクト: pcdummy/Eto
        protected override void Dispose(bool disposing)
        {
            if (image != null)
            {
                Flush();
                image = null;
            }
            if (surface != null)
            {
                surface.Dispose();
                surface = null;
            }

            base.Dispose(disposing);
        }
コード例 #6
0
ファイル: TestDrawing.cs プロジェクト: bvssvni/csharp-utils
        public void TestDrawLine()
        {
            var bytes = new byte[1024 * 4];
            var format = Cairo.Format.ARGB32;
            var image = new Cairo.ImageSurface (bytes, format, 32, 32, 32 * 4);
            var shape = new LineShape (0.0, 0.0, 32.0, 32.0);
            var look = new Look (SolidBrush.Red, SolidPen.Black);
            var op = new ShapeTree (look, shape);
            using (var context = new Cairo.Context (image)) {
                op.Draw (context);
            }

            image.WriteToPng ("testimages/line.png");
            image.Dispose ();
        }
コード例 #7
0
ファイル: TestDrawing.cs プロジェクト: bvssvni/csharp-utils
        public void TestDrawEllipse()
        {
            var bytes = new byte[1024 * 4];
            var format = Cairo.Format.ARGB32;
            var image = new Cairo.ImageSurface (bytes, format, 32, 32, 32 * 4);
            var shape = new EllipseShape ();
            shape.Rectangle = new Rectangle () {
                X = 10.0,
                Y = 4.0,
                Width = 12.0,
                Height = 18.0
            };
            var look = new Look (SolidBrush.Red, SolidPen.Black);
            var op = new ShapeTree (look, shape);
            using (var context = new Cairo.Context (image)) {
                op.Draw (context);
            }

            image.WriteToPng ("testimages/ellipse.png");
            image.Dispose ();
        }
コード例 #8
0
        protected override bool OnDrawn(Cairo.Context context)
        {
            base.OnDrawn(context);

            var scale = document.Workspace.Scale;

            var x = (int)document.Workspace.Offset.X;
            var y = (int)document.Workspace.Offset.Y;

            // Translate our expose area for the whole drawingarea to just our canvas
            var       canvas_bounds = new Rectangle(x, y, document.Workspace.CanvasSize.Width, document.Workspace.CanvasSize.Height);
            Rectangle expose_rect;

            if (Gdk.CairoHelper.GetClipRectangle(context, out expose_rect))
            {
                canvas_bounds.Intersect(expose_rect);
            }

            if (canvas_bounds.IsEmpty)
            {
                return(true);
            }

            canvas_bounds.X -= x;
            canvas_bounds.Y -= y;

            // Resize our offscreen surface to a surface the size of our drawing area
            if (canvas == null || canvas.Width != canvas_bounds.Width || canvas.Height != canvas_bounds.Height)
            {
                canvas?.Dispose();
                canvas = CairoExtensions.CreateImageSurface(Cairo.Format.Argb32, canvas_bounds.Width, canvas_bounds.Height);
            }

            cr.Initialize(document.ImageSize, document.Workspace.CanvasSize);

            var g = context;

            // Draw our canvas drop shadow
            g.DrawRectangle(new Cairo.Rectangle(x - 1, y - 1, document.Workspace.CanvasSize.Width + 2, document.Workspace.CanvasSize.Height + 2), new Cairo.Color(.5, .5, .5), 1);
            g.DrawRectangle(new Cairo.Rectangle(x - 2, y - 2, document.Workspace.CanvasSize.Width + 4, document.Workspace.CanvasSize.Height + 4), new Cairo.Color(.8, .8, .8), 1);
            g.DrawRectangle(new Cairo.Rectangle(x - 3, y - 3, document.Workspace.CanvasSize.Width + 6, document.Workspace.CanvasSize.Height + 6), new Cairo.Color(.9, .9, .9), 1);

            // Set up our clip rectangle
            g.Rectangle(new Cairo.Rectangle(x, y, document.Workspace.CanvasSize.Width, document.Workspace.CanvasSize.Height));
            g.Clip();

            g.Translate(x, y);

            // Render all the layers to a surface
            var layers = document.Layers.GetLayersToPaint();

            if (layers.Count == 0)
            {
                canvas.Clear();
            }

            cr.Render(layers, canvas, canvas_bounds.Location);

            // Paint the surface to our canvas
            g.SetSourceSurface(canvas, canvas_bounds.X + (int)(0 * scale), canvas_bounds.Y + (int)(0 * scale));
            g.Paint();

            // Selection outline
            if (document.Selection.Visible)
            {
                var tool_name     = PintaCore.Tools.CurrentTool?.GetType().Name ?? string.Empty;
                var fillSelection = tool_name.Contains("Select") && !tool_name.Contains("Selected");
                document.Selection.Draw(g, scale, fillSelection);
            }

            return(true);
        }
コード例 #9
0
 public void Dispose()
 {
     _context.Dispose();
     _surf.Dispose();
 }