示例#1
0
        /// <summary>
        /// Creates a thumbnail image preview of a document.
        /// </summary>
        private Cairo.ImageSurface CreateImagePreview(Document doc)
        {
            var surface = new Cairo.ImageSurface(Cairo.Format.Argb32, PreviewWidth, PreviewHeight);

            canvas_renderer.Initialize(doc.ImageSize, new Gdk.Size(PreviewWidth, PreviewHeight));
            canvas_renderer.Render(doc.GetLayersToPaint(), surface, Gdk.Point.Zero);
            return(surface);
        }
示例#2
0
        public void Reset()
        {
            store.Clear();

            if (active_layer_surface != null)
            {
                (active_layer_surface as IDisposable).Dispose();
                active_layer_surface = null;
            }

            if (!PintaCore.Workspace.HasOpenDocuments)
            {
                return;
            }

            var doc = PintaCore.Workspace.ActiveDocument;

            foreach (var layer in (doc.UserLayers as IEnumerable <Layer>).Reverse())
            {
                var surf = layer.Surface;

                // Draw the selection layer on top of the active layer.
                if (layer == doc.CurrentUserLayer && doc.ShowSelectionLayer)
                {
                    active_layer_surface = new Cairo.ImageSurface(Cairo.Format.Argb32, thumbnail_width,
                                                                  thumbnail_height);
                    canvas_renderer.Initialize(doc.ImageSize,
                                               new Gdk.Size(thumbnail_width, thumbnail_height));

                    var layers = new List <Layer> {
                        layer, doc.SelectionLayer
                    };
                    canvas_renderer.Render(layers, active_layer_surface, Gdk.Point.Zero);

                    surf = active_layer_surface;
                }

                store.AppendValues(surf, layer.Name, !layer.Hidden, layer);
            }

            SelectLayerInTreeView(PintaCore.Layers.Count - PintaCore.Layers.CurrentLayerIndex - 1);
        }
示例#3
0
        private void Reset()
        {
            store.Clear();

            if (active_layer_surface != null)
            {
                (active_layer_surface as IDisposable).Dispose();
                active_layer_surface = null;
            }

            if (!PintaCore.Workspace.HasOpenDocuments)
            {
                return;
            }

            var doc = PintaCore.Workspace.ActiveDocument;

            foreach (var layer in doc.Layers.UserLayers.Reverse())
            {
                var surf = layer.Surface;

                // If this is the currently selected layer, we may need to draw the
                // selection layer over it, like when dragging a selection.
                if (layer == doc.Layers.CurrentUserLayer && doc.Layers.ShowSelectionLayer)
                {
                    active_layer_surface = CairoExtensions.CreateImageSurface(Cairo.Format.Argb32, thumbnail_width, thumbnail_height);
                    canvas_renderer.Initialize(doc.ImageSize, new Gdk.Size(thumbnail_width, thumbnail_height));

                    var layers = new List <Layer> {
                        layer, doc.Layers.SelectionLayer
                    };
                    canvas_renderer.Render(layers, active_layer_surface, Gdk.Point.Zero);

                    surf = active_layer_surface;
                }

                store.AppendValues(surf, layer.Name, !layer.Hidden, layer);
            }

            SelectLayerInTreeView(doc.Layers.Count() - doc.Layers.CurrentUserLayerIndex - 1);
        }
示例#4
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);
        }
示例#5
0
        protected override bool OnExposeEvent(EventExpose e)
        {
            base.OnExposeEvent(e);

            if (!PintaCore.Workspace.HasOpenDocuments)
            {
                return(true);
            }

            double scale = PintaCore.Workspace.Scale;

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

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

            canvas_bounds.Intersect(e.Area);

            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)
            {
                if (canvas != null)
                {
                    (canvas as IDisposable).Dispose();
                }

                canvas = new Cairo.ImageSurface(Cairo.Format.Argb32, canvas_bounds.Width, canvas_bounds.Height);
            }

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

            using (Cairo.Context g = CairoHelper.Create(GdkWindow)) {
                // Draw our 1 px black border
                g.DrawRectangle(new Cairo.Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width + 1, PintaCore.Workspace.CanvasSize.Height + 1), new Cairo.Color(0, 0, 0), 1);

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

                g.Translate(x, y);

                bool checker = true;

                // Resize each layer and paint it to the screen
                foreach (Layer layer in PintaCore.Layers.GetLayersToPaint())
                {
                    cr.Render(layer.Surface, canvas, canvas_bounds.Location, checker);
                    g.SetSourceSurface(canvas, canvas_bounds.X + (int)(layer.Offset.X * scale), canvas_bounds.Y + (int)(layer.Offset.Y * scale));
                    g.PaintWithAlpha(layer.Opacity);

                    if (layer == PintaCore.Layers.CurrentLayer && PintaCore.LivePreview.IsEnabled)
                    {
                        cr.Render(PintaCore.LivePreview.LivePreviewSurface, canvas, canvas_bounds.Location, checker);

                        g.Save();
                        g.Scale(scale, scale);
                        g.AppendPath(PintaCore.Layers.SelectionPath);
                        g.Clip();

                        g.Scale(1 / scale, 1 / scale);
                        g.SetSourceSurface(canvas, canvas_bounds.X, canvas_bounds.Y);
                        g.PaintWithAlpha(layer.Opacity);

                        g.Restore();
                    }

                    checker = false;
                }

                // If we are at least 200% and grid is requested, draw it
                if (PintaCore.Actions.View.PixelGrid.Active && cr.ScaleFactor.Ratio <= 0.5d)
                {
                    gr.Render(canvas, canvas_bounds.Location);
                    g.SetSourceSurface(canvas, canvas_bounds.X, canvas_bounds.Y);
                    g.Paint();
                }

                // Selection outline
                if (PintaCore.Layers.ShowSelection)
                {
                    g.Save();
                    g.Translate(0.5, 0.5);
                    g.Scale(scale, scale);

                    g.AppendPath(PintaCore.Layers.SelectionPath);

                    if (PintaCore.Tools.CurrentTool.Name.Contains("Select") && !PintaCore.Tools.CurrentTool.Name.Contains("Selected"))
                    {
                        g.Color    = new Cairo.Color(0.7, 0.8, 0.9, 0.2);
                        g.FillRule = Cairo.FillRule.EvenOdd;
                        g.FillPreserve();
                    }

                    g.LineWidth = 1 / scale;

                    // Draw a white line first so it shows up on dark backgrounds
                    g.Color = new Cairo.Color(1, 1, 1);
                    g.StrokePreserve();

                    // Draw a black dashed line over the white line
                    g.SetDash(new double[] { 2 / scale, 4 / scale }, 0);
                    g.Color = new Cairo.Color(0, 0, 0);

                    g.Stroke();
                    g.Restore();
                }
            }

            return(true);
        }
示例#6
0
        protected override bool OnExposeEvent(EventExpose e)
        {
            base.OnExposeEvent(e);

            if (!PintaCore.Workspace.HasOpenDocuments)
            {
                return(true);
            }

            double scale = PintaCore.Workspace.Scale;

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

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

            canvas_bounds.Intersect(e.Area);

            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)
            {
                if (canvas != null)
                {
                    (canvas as IDisposable).Dispose();
                }

                canvas = new Cairo.ImageSurface(Cairo.Format.Argb32, canvas_bounds.Width, canvas_bounds.Height);
            }

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

            using (Cairo.Context g = CairoHelper.Create(GdkWindow)) {
                // Draw our canvas drop shadow
                g.DrawRectangle(new Cairo.Rectangle(x - 1, y - 1, PintaCore.Workspace.CanvasSize.Width + 2, PintaCore.Workspace.CanvasSize.Height + 2), new Cairo.Color(.5, .5, .5), 1);
                g.DrawRectangle(new Cairo.Rectangle(x - 2, y - 2, PintaCore.Workspace.CanvasSize.Width + 4, PintaCore.Workspace.CanvasSize.Height + 4), new Cairo.Color(.8, .8, .8), 1);
                g.DrawRectangle(new Cairo.Rectangle(x - 3, y - 3, PintaCore.Workspace.CanvasSize.Width + 6, PintaCore.Workspace.CanvasSize.Height + 6), new Cairo.Color(.9, .9, .9), 1);

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

                g.Translate(x, y);

                // Render all the layers to a surface
                var layers = PintaCore.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 (PintaCore.Layers.ShowSelection)
                {
                    bool fillSelection = PintaCore.Tools.CurrentTool.Name.Contains("Select") &&
                                         !PintaCore.Tools.CurrentTool.Name.Contains("Selected");
                    PintaCore.Workspace.ActiveDocument.Selection.Draw(g, scale, fillSelection);
                }
            }

            return(true);
        }
示例#7
0
        protected override bool OnExposeEvent(EventExpose e)
        {
            base.OnExposeEvent(e);

            if (!PintaCore.Workspace.HasOpenDocuments)
            {
                return(true);
            }

            double scale = PintaCore.Workspace.Scale;

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

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

            canvas_bounds.Intersect(e.Area);

            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)
            {
                if (canvas != null)
                {
                    (canvas as IDisposable).Dispose();
                }

                canvas = new Cairo.ImageSurface(Cairo.Format.Argb32, canvas_bounds.Width, canvas_bounds.Height);
            }

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

            using (Cairo.Context g = CairoHelper.Create(GdkWindow)) {
                // Draw our canvas drop shadow
                g.DrawRectangle(new Cairo.Rectangle(x, y, PintaCore.Workspace.CanvasSize.Width + 1, PintaCore.Workspace.CanvasSize.Height + 1), new Cairo.Color(.5, .5, .5), 1);
                g.DrawRectangle(new Cairo.Rectangle(x - 1, y - 1, PintaCore.Workspace.CanvasSize.Width + 3, PintaCore.Workspace.CanvasSize.Height + 3), new Cairo.Color(.8, .8, .8), 1);
                g.DrawRectangle(new Cairo.Rectangle(x - 2, y - 2, PintaCore.Workspace.CanvasSize.Width + 5, PintaCore.Workspace.CanvasSize.Height + 5), new Cairo.Color(.9, .9, .9), 1);

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

                g.Translate(x, y);

                // Render all the layers to a surface
                var layers = PintaCore.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 (PintaCore.Layers.ShowSelection)
                {
                    g.Save();
                    g.Translate(0.5, 0.5);
                    g.Scale(scale, scale);

                    g.AppendPath(PintaCore.Workspace.ActiveDocument.Selection.SelectionPath);

                    if (PintaCore.Tools.CurrentTool.Name.Contains("Select") && !PintaCore.Tools.CurrentTool.Name.Contains("Selected"))
                    {
                        g.Color    = new Cairo.Color(0.7, 0.8, 0.9, 0.2);
                        g.FillRule = Cairo.FillRule.EvenOdd;
                        g.FillPreserve();
                    }

                    g.LineWidth = 1 / scale;

                    // Draw a white line first so it shows up on dark backgrounds
                    g.Color = new Cairo.Color(1, 1, 1);
                    g.StrokePreserve();

                    // Draw a black dashed line over the white line
                    g.SetDash(new double[] { 2 / scale, 4 / scale }, 0);
                    g.Color = new Cairo.Color(0, 0, 0);

                    g.Stroke();
                    g.Restore();
                }
            }

            return(true);
        }