AppendPath() публичный Метод

public AppendPath ( Path path ) : void
path Path
Результат void
Пример #1
0
        public void Draw(ImageSurface dst)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("PlacedSurface");
            }

            using (Cairo.Context g = new Cairo.Context(dst)) {
                g.Save();

                Rectangle r = what.GetBounds().ToCairoRectangle();

                // We need to use the source operator to fully replace the old
                // data.  Or else we may paint transparent on top of it and
                // it will still be visible.  [Bug #670411]
                using (Path p = g.CreateRectanglePath(new Rectangle(where.X, where.Y, r.Width, r.Height))) {
                    g.AppendPath(p);
                    g.Clip();
                    g.Operator = Operator.Source;
                    g.DrawPixbuf(what.ToPixbuf(), new Cairo.Point(where.X, where.Y));
                }

                g.Restore();
            }
        }
Пример #2
0
        protected unsafe override void OnFillRegionComputed(Point[][] polygonSet)
        {
            SimpleHistoryItem hist = new SimpleHistoryItem (Icon, Name);
            hist.TakeSnapshotOfLayer (PintaCore.Layers.CurrentLayer);

            PintaCore.Layers.ToolLayer.Clear ();
            ImageSurface surface = PintaCore.Layers.ToolLayer.Surface;

            ColorBgra* surf_data_ptr = (ColorBgra*)surface.DataPtr;
            int surf_width = surface.Width;

            for (int x = 0; x < stencil.Width; x++)
                for (int y = 0; y < stencil.Height; y++)
                    if (stencil.GetUnchecked (x, y))
                        surface.SetPixel (surf_data_ptr, surf_width, x, y, fill_color);

            using (Context g = new Context (PintaCore.Layers.CurrentLayer.Surface)) {
                g.AppendPath (PintaCore.Layers.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.Antialias = Antialias.Subpixel;

                g.SetSource (surface);
                g.Paint ();
            }

            PintaCore.History.PushNewItem (hist);
            PintaCore.Workspace.Invalidate ();
        }
Пример #3
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            if (!is_dragging)
            {
                return;
            }

            Document doc = PintaCore.Workspace.ActiveDocument;

            PointD new_offset = new PointD(point.X, point.Y);

            double dx = origin_offset.X - new_offset.X;
            double dy = origin_offset.Y - new_offset.Y;

            Path path = doc.SelectionPath;

            using (Cairo.Context g = new Cairo.Context(doc.CurrentLayer.Surface)) {
                g.AppendPath(path);
                g.Translate(dx, dy);
                doc.SelectionPath = g.CopyPath();
            }

            (path as IDisposable).Dispose();

            doc.SelectionLayer.Offset = new PointD(doc.SelectionLayer.Offset.X - dx, doc.SelectionLayer.Offset.Y - dy);

            origin_offset = new_offset;

            (o as Gtk.DrawingArea).GdkWindow.Invalidate();
        }
Пример #4
0
        private void HandlePintaCoreActionsEditEraseSelectionActivated(object sender, EventArgs e)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            PintaCore.Tools.Commit();

            Cairo.ImageSurface old = doc.Layers.CurrentUserLayer.Surface.Clone();

            using (var g = new Cairo.Context(doc.Layers.CurrentUserLayer.Surface)) {
                g.AppendPath(doc.Selection.SelectionPath);
                g.FillRule = FillRule.EvenOdd;

                g.Operator = Cairo.Operator.Clear;
                g.Fill();
            }

            doc.Workspace.Invalidate();

            if (sender is string && (sender as string) == "Cut")
            {
                doc.History.PushNewItem(new SimpleHistoryItem(Resources.StandardIcons.EditCut, Translations.GetString("Cut"), old, doc.Layers.CurrentUserLayerIndex));
            }
            else
            {
                doc.History.PushNewItem(new SimpleHistoryItem(Resources.Icons.EditSelectionErase, Translations.GetString("Erase Selection"), old, doc.Layers.CurrentUserLayerIndex));
            }
        }
Пример #5
0
        public void Draw(Cairo.Context g, double scale, bool fillSelection)
        {
            g.Save();
            g.Translate(0.5, 0.5);
            g.Scale(scale, scale);

            g.AppendPath(selection_path);

            if (fillSelection)
            {
                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();
        }
Пример #6
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            if (!is_dragging)
            {
                return;
            }

            Document doc = PintaCore.Workspace.ActiveDocument;

            PointD new_offset = point;

            double dx = origin_offset.X - new_offset.X;
            double dy = origin_offset.Y - new_offset.Y;

            using (Cairo.Context g = new Cairo.Context(doc.CurrentLayer.Surface)) {
                Path old = doc.SelectionPath;
                g.FillRule = FillRule.EvenOdd;
                g.AppendPath(doc.SelectionPath);
                g.Translate(dx, dy);
                doc.SelectionPath = g.CopyPath();
                (old as IDisposable).Dispose();
            }

            origin_offset     = new_offset;
            doc.ShowSelection = true;

            (o as Gtk.DrawingArea).GdkWindow.Invalidate();
        }
Пример #7
0
        protected override void OnStartTransform()
        {
            base.OnStartTransform();

            Document doc = PintaCore.Workspace.ActiveDocument;

            // If there is no selection, select the whole image.
            if (doc.Selection.SelectionPolygons.Count == 0)
            {
                doc.Selection.CreateRectangleSelection(
                    new Cairo.Rectangle(0, 0, doc.ImageSize.Width, doc.ImageSize.Height));
            }

            original_selection = doc.Selection.Clone();
            original_transform.InitMatrix(doc.SelectionLayer.Transform);

            hist = new MovePixelsHistoryItem(Icon, Name, doc);
            hist.TakeSnapshot(!doc.ShowSelectionLayer);

            if (!doc.ShowSelectionLayer)
            {
                // Copy the selection to the temp layer
                doc.CreateSelectionLayer();
                doc.ShowSelectionLayer = true;
                //Use same BlendMode, Opacity and Visibility for SelectionLayer
                doc.SelectionLayer.BlendMode = doc.CurrentUserLayer.BlendMode;
                doc.SelectionLayer.Opacity   = doc.CurrentUserLayer.Opacity;
                doc.SelectionLayer.Hidden    = doc.CurrentUserLayer.Hidden;

                using (Cairo.Context g = new Cairo.Context(doc.SelectionLayer.Surface)) {
                    g.AppendPath(doc.Selection.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.SetSource(doc.CurrentUserLayer.Surface);
                    g.Clip();
                    g.Paint();
                }

                Cairo.ImageSurface surf = doc.CurrentUserLayer.Surface;

                using (Cairo.Context g = new Cairo.Context(surf)) {
                    g.AppendPath(doc.Selection.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    if (is_alt_pressed)
                    {
                        g.Operator = Cairo.Operator.Clear;
                    }
                    else
                    {
                        g.Operator = Operator.Source;
                        g.SetSourceColor(PintaCore.Palette.SecondaryColor);
                    }
                    g.Fill();
                }
            }

            PintaCore.Workspace.Invalidate();
        }
Пример #8
0
        public static Path Clone(this Path path)
        {
            Path newpath;

            using (Context g = new Context (PintaCore.Layers.CurrentLayer.Surface)) {
                g.AppendPath (path);
                newpath = g.CopyPath ();
            }

            return newpath;
        }
Пример #9
0
        /// <summary>
        /// Erase the handle that was drawn in a previous call to Render ().
        /// </summary>
        public void Clear (Context g)
        {
            g.Save ();

            var rect = GetHandleRect ().Inflate (2, 2);
            using (var path = g.CreateRectanglePath (rect))
                g.AppendPath (path);
            g.Operator = Operator.Clear;
            g.Fill ();

            g.Restore ();
        }
        private void Render(Clutter.CairoTexture texture, int with_state, bool outwards)
        {
            texture.Clear();
            Cairo.Context context = texture.Create();

            double lwidth  = 1;
            double hlwidth = lwidth * 0.5;

            //Draw outline rectangles:
            context.Rectangle(hlwidth, hlwidth, texture.Width - lwidth, texture.Height - lwidth);
            context.SetSourceRGB(1.0, 1.0, 1.0);
            context.LineWidth = lwidth;
            context.StrokePreserve();
            double sat = (with_state == 0 ? 0.4 : (with_state == 1 ? 0.6 : 0.8));

            context.SetSourceRGB(sat, sat, sat);
            context.Fill();

            double dim = 4;

            context.MoveTo(-dim, 0);
            context.LineTo(outwards ? 0 : -dim, outwards ? 0 : dim);
            context.LineTo(0, dim);
            context.MoveTo(-dim, dim);
            context.LineTo(0, 0);
            context.ClosePath();
            Cairo.Path arrow = context.CopyPath();
            context.NewPath();

            double margin = 2 + hlwidth;
            PointD center = new PointD(texture.Width * 0.5, texture.Height * 0.5);
            PointD transl = new PointD(center.X - margin, -(center.Y - margin));

            context.LineWidth = lwidth;
            sat = (with_state == 1 ? 0.0 : 1.0);
            context.SetSourceRGB(sat, sat, sat);

            context.Translate(center.X, center.Y);
            for (int i = 0; i < 4; i++)
            {
                context.Rotate(Math.PI * 0.5 * i);
                context.Translate(transl.X, transl.Y);
                context.AppendPath(arrow);
                context.Stroke();
                context.Translate(-transl.X, -transl.Y);
            }

            ((IDisposable)arrow).Dispose();
            ((IDisposable)context.Target).Dispose();
            ((IDisposable)context).Dispose();
        }
Пример #11
0
        public ImageSurface GetClippedLayer(int index)
        {
            Cairo.ImageSurface surf = new Cairo.ImageSurface(Cairo.Format.Argb32, ImageSize.Width, ImageSize.Height);

            using (Cairo.Context g = new Cairo.Context(surf)) {
                g.AppendPath(Selection.SelectionPath);
                g.Clip();

                g.SetSource(UserLayers[index].Surface);
                g.Paint();
            }

            return(surf);
        }
Пример #12
0
        protected unsafe override void OnFillRegionComputed(Point[][] polygonSet)
        {
            SimpleHistoryItem hist = new SimpleHistoryItem (Icon, Name);
            hist.TakeSnapshotOfLayer (PintaCore.Layers.CurrentLayer);

            using (Context g = new Context (PintaCore.Layers.CurrentLayer.Surface)) {
                g.AppendPath (PintaCore.Layers.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                // Reset FillRule to the default
                g.FillRule = FillRule.Winding;
                g.AppendPath (g.CreatePolygonPath (polygonSet));

                g.Antialias = Antialias.Subpixel;

                g.Color = fill_color;
                g.Fill ();
            }

            PintaCore.History.PushNewItem (hist);
            PintaCore.Workspace.Invalidate ();
        }
Пример #13
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            if (!is_dragging)
            {
                return;
            }

            Document doc = PintaCore.Workspace.ActiveDocument;

            PointD new_offset = new PointD(point.X, point.Y);

            double dx = origin_offset.X - new_offset.X;
            double dy = origin_offset.Y - new_offset.Y;

            using (Cairo.Context g = new Cairo.Context(doc.CurrentLayer.Surface)) {
                g.AppendPath(doc.Selection.SelectionPath);
                g.Translate(dx, dy);
                doc.Selection.DisposeSelectionPreserve();
                doc.Selection.SelectionPath = g.CopyPath();
            }


            List <List <IntPoint> > newSelectionPolygons = new List <List <IntPoint> >();

            foreach (List <IntPoint> ipL in doc.Selection.SelectionPolygons)
            {
                List <IntPoint> newPolygon = new List <IntPoint>();

                foreach (IntPoint ip in ipL)
                {
                    newPolygon.Add(new IntPoint(ip.X - (long)dx, ip.Y - (long)dy));
                }

                newSelectionPolygons.Add(newPolygon);
            }


            doc.Selection.SelectionPolygons = newSelectionPolygons;


            doc.SelectionLayer.Offset = new PointD(doc.SelectionLayer.Offset.X - dx, doc.SelectionLayer.Offset.Y - dy);

            origin_offset = new_offset;

            (o as Gtk.DrawingArea).GdkWindow.Invalidate();
        }
Пример #14
0
        protected override void OnStartTransform()
        {
            base.OnStartTransform();

            Document doc = PintaCore.Workspace.ActiveDocument;

            // If there is no selection, select the whole image.
            if (doc.Selection.SelectionPolygons.Count == 0)
            {
                doc.Selection.CreateRectangleSelection(
                    doc.SelectionLayer.Surface, new Cairo.Rectangle(0, 0, doc.ImageSize.Width, doc.ImageSize.Height));
            }

            original_selection = new List <List <IntPoint> > (doc.Selection.SelectionPolygons);
            original_transform.InitMatrix(doc.SelectionLayer.Transform);

            hist = new MovePixelsHistoryItem(Icon, Name, doc);
            hist.TakeSnapshot(!doc.ShowSelectionLayer);

            if (!doc.ShowSelectionLayer)
            {
                // Copy the selection to the temp layer
                doc.CreateSelectionLayer();
                doc.ShowSelectionLayer = true;

                using (Cairo.Context g = new Cairo.Context(doc.SelectionLayer.Surface)) {
                    g.AppendPath(doc.Selection.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.SetSource(doc.CurrentUserLayer.Surface);
                    g.Clip();
                    g.Paint();
                }

                Cairo.ImageSurface surf = doc.CurrentUserLayer.Surface;

                using (Cairo.Context g = new Cairo.Context(surf)) {
                    g.AppendPath(doc.Selection.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.Operator = Cairo.Operator.Clear;
                    g.Fill();
                }
            }

            PintaCore.Workspace.Invalidate();
        }
Пример #15
0
        protected override Rectangle DrawShape(Rectangle rect, Layer l)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            Rectangle dirty;

            using (Context g = new Context (l.Surface)) {
                g.AppendPath (doc.Selection.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;

                dirty = g.DrawLine (shape_origin, current_point , outline_color, BrushWidth);
            }

            return dirty;
        }
Пример #16
0
        private void HandlePintaCoreActionsEditFillSelectionActivated(object sender, EventArgs e)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            PintaCore.Tools.Commit();

            Cairo.ImageSurface old = doc.CurrentLayer.Surface.Clone();

            using (var g = new Cairo.Context(doc.CurrentLayer.Surface)) {
                g.AppendPath(doc.Selection.SelectionPath);
                g.FillRule = FillRule.EvenOdd;

                g.Color = PintaCore.Palette.PrimaryColor;
                g.Fill();
            }

            doc.Workspace.Invalidate();
            doc.History.PushNewItem(new SimpleHistoryItem("Menu.Edit.FillSelection.png", Catalog.GetString("Fill Selection"), old, doc.CurrentLayerIndex));
        }
Пример #17
0
        private void HandlePintaCoreActionsEditFillSelectionActivated(object sender, EventArgs e)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            PintaCore.Tools.Commit();

            Cairo.ImageSurface old = doc.Layers.CurrentUserLayer.Surface.Clone();

            using (var g = new Cairo.Context(doc.Layers.CurrentUserLayer.Surface)) {
                g.AppendPath(doc.Selection.SelectionPath);
                g.FillRule = FillRule.EvenOdd;

                g.SetSourceColor(PintaCore.Palette.PrimaryColor);
                g.Fill();
            }

            doc.Workspace.Invalidate();
            doc.History.PushNewItem(new SimpleHistoryItem(Resources.Icons.EditSelectionFill, Translations.GetString("Fill Selection"), old, doc.Layers.CurrentUserLayerIndex));
        }
Пример #18
0
        protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
        {
            // If we are already drawing, ignore any additional mouse down events
            if (is_dragging)
            {
                return;
            }

            Document doc = PintaCore.Workspace.ActiveDocument;

            origin_offset = point;
            is_dragging   = true;

            hist = new MovePixelsHistoryItem(Icon, Name, doc);
            hist.TakeSnapshot(!doc.ShowSelectionLayer);

            if (!doc.ShowSelectionLayer)
            {
                // Copy the selection to the temp layer
                doc.CreateSelectionLayer();
                doc.ShowSelectionLayer = true;

                using (Cairo.Context g = new Cairo.Context(doc.SelectionLayer.Surface)) {
                    g.AppendPath(doc.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.SetSource(doc.CurrentLayer.Surface);
                    g.Clip();
                    g.Paint();
                }

                Cairo.ImageSurface surf = doc.CurrentLayer.Surface;

                using (Cairo.Context g = new Cairo.Context(surf)) {
                    g.AppendPath(doc.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.Operator = Cairo.Operator.Clear;
                    g.Fill();
                }
            }

            canvas.GdkWindow.Invalidate();
        }
Пример #19
0
        protected override void OnUpdateTransform(Matrix transform)
        {
            base.OnUpdateTransform(transform);

            List <List <IntPoint> > newSelectionPolygons = DocumentSelection.Transform(original_selection, transform);

            Document doc = PintaCore.Workspace.ActiveDocument;

            doc.Selection.SelectionClipper.Clear();
            doc.Selection.SelectionPolygons = newSelectionPolygons;
            using (var g = new Cairo.Context(doc.CurrentUserLayer.Surface)) {
                doc.Selection.SelectionPath = g.CreatePolygonPath(DocumentSelection.ConvertToPolygonSet(newSelectionPolygons));
                g.FillRule = FillRule.EvenOdd;
                g.AppendPath(doc.Selection.SelectionPath);
            }

            doc.ShowSelection = true;

            PintaCore.Workspace.Invalidate();
        }
Пример #20
0
        protected override Rectangle DrawShape(Rectangle rect, Layer l)
        {
            Rectangle dirty;

            using (Context g = new Context (l.Surface)) {
                g.AppendPath (PintaCore.Layers.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.Antialias = Antialias.Subpixel;

                if (FillShape && StrokeShape)
                    dirty = g.FillStrokedRectangle (rect, fill_color, outline_color, BrushWidth);
                else if (FillShape)
                    dirty = g.FillRectangle (rect, outline_color);
                else
                    dirty = g.DrawRectangle (rect, outline_color, BrushWidth);
            }

            return dirty;
        }
Пример #21
0
        private void Form1_Shown(object sender, EventArgs e)
        {
            Debug.WriteLine("Form1_Shown");

            surface = new Win32Surface(this.CreateGraphics().GetHdc());
            context = new Context(surface);

            textFormat = DWriteCairo.CreateTextFormat(
                "Consolas",
                FontWeight.Normal,
                FontStyle.Normal,
                FontStretch.Normal,
                12);

            textFormat.TextAlignment = TextAlignment.Center;
            
            float left, top, width, height;

            // get actual size of the text
            var measureLayout = DWriteCairo.CreateTextLayout(s, textFormat, 4096, 4096);
            measureLayout.GetRect(out left, out top, out width, out height);
            measureLayout.Dispose();

            // build text context against the size and format
            textLayout = DWriteCairo.CreateTextLayout(s, textFormat, (int)Math.Ceiling(width), (int)Math.Ceiling(height));

            Debug.WriteLine("showing layout");
            Path path = DWriteCairo.RenderLayoutToCairoPath(context, textLayout);
            context.AppendPath(path);
            context.Fill();

            textLayout.GetRect(out left, out top, out width, out height);
            textRect = new System.Drawing.RectangleF(left, top, width, height);
            context.Rectangle(left, top, width, height);
            context.Stroke();

            context.GetTarget().Flush();
        }
Пример #22
0
        protected override Rectangle DrawShape(Rectangle rect, Layer l)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            Rectangle dirty;

            using (Context g = new Context (l.Surface)) {
                g.AppendPath (doc.Selection.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;

                if (FillShape && StrokeShape)
                    dirty = g.FillStrokedRectangle (rect, fill_color, outline_color, BrushWidth);
                else if (FillShape)
                    dirty = g.FillRectangle (rect, outline_color);
                else
                    dirty = g.DrawRectangle (rect, outline_color, BrushWidth);
            }

            return dirty;
        }
Пример #23
0
        public unsafe void HueSaturation(int hueDelta, int satDelta, int lightness)
        {
            ImageSurface dest = Surface.Clone ();
            ColorBgra* dstPtr = (ColorBgra*)dest.DataPtr;

            int len = Surface.Data.Length / 4;

            // map the range [0,100] -> [0,100] and the range [101,200] -> [103,400]
            if (satDelta > 100)
                satDelta = ((satDelta - 100) * 3) + 100;

            UnaryPixelOp op;

            if (hueDelta == 0 && satDelta == 100 && lightness == 0)
                op = new UnaryPixelOps.Identity ();
            else
                op = new UnaryPixelOps.HueSaturationLightness (hueDelta, satDelta, lightness);

            op.Apply (dstPtr, len);

            using (Context g = new Context (Surface)) {
                g.AppendPath (PintaCore.Layers.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.SetSource (dest);
                g.Paint ();
            }

            (dest as IDisposable).Dispose ();
        }
Пример #24
0
        private void HandlePintaCoreActionsEditFillSelectionActivated(object sender, EventArgs e)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            PintaCore.Tools.Commit ();

            Cairo.ImageSurface old = doc.CurrentLayer.Surface.Clone ();

            using (var g = new Cairo.Context (doc.CurrentLayer.Surface)) {
                g.AppendPath (doc.SelectionPath);
                g.FillRule = FillRule.EvenOdd;

                g.Color = PintaCore.Palette.PrimaryColor;
                g.Fill ();
            }

            doc.Workspace.Invalidate ();
            doc.History.PushNewItem (new SimpleHistoryItem ("Menu.Edit.FillSelection.png", Catalog.GetString ("Fill Selection"), old, doc.CurrentLayerIndex));
        }
Пример #25
0
        private void HandlePintaCoreActionsEditEraseSelectionActivated(object sender, EventArgs e)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            PintaCore.Tools.Commit ();

            Cairo.ImageSurface old = doc.CurrentLayer.Surface.Clone ();

            using (var g = new Cairo.Context (doc.CurrentLayer.Surface)) {
                g.AppendPath (doc.SelectionPath);
                g.FillRule = FillRule.EvenOdd;

                g.Operator = Cairo.Operator.Clear;
                g.Fill ();
            }

            doc.Workspace.Invalidate ();

            if (sender is string && (sender as string) == "Cut")
                doc.History.PushNewItem (new SimpleHistoryItem (Stock.Cut, Catalog.GetString ("Cut"), old, doc.CurrentLayerIndex));
            else
                doc.History.PushNewItem (new SimpleHistoryItem ("Menu.Edit.EraseSelection.png", Catalog.GetString ("Erase Selection"), old, doc.CurrentLayerIndex));
        }
Пример #26
0
        private void HandlerPintaCoreActionsEditCutActivated(object sender, EventArgs e)
        {
            PintaCore.Layers.FinishSelection ();

            // Copy selection
            HandlerPintaCoreActionsEditCopyActivated (sender, e);

            // Erase selection
            Cairo.ImageSurface old = PintaCore.Layers.CurrentLayer.Surface.Clone ();

            using (Cairo.Context g = new Cairo.Context (PintaCore.Layers.CurrentLayer.Surface)) {
                g.AppendPath (PintaCore.Layers.SelectionPath);
                g.FillRule = Cairo.FillRule.EvenOdd;
                g.Operator = Cairo.Operator.Clear;
                g.Fill ();
            }

            PintaCore.Workspace.Invalidate ();
            PintaCore.History.PushNewItem (new SimpleHistoryItem ("Menu.Edit.EraseSelection.png", Mono.Unix.Catalog.GetString ("Cut"), old, PintaCore.Layers.CurrentLayerIndex));
        }
Пример #27
0
        private void HandlePintaCoreActionsEditFillSelectionActivated(object sender, EventArgs e)
        {
            PintaCore.Layers.FinishSelection ();

            Cairo.ImageSurface old = PintaCore.Layers.CurrentLayer.Surface.Clone ();

            using (Cairo.Context g = new Cairo.Context (PintaCore.Layers.CurrentLayer.Surface)) {
                g.AppendPath (PintaCore.Layers.SelectionPath);
                g.FillRule = Cairo.FillRule.EvenOdd;
                g.Color = PintaCore.Palette.PrimaryColor;
                g.Fill ();
            }

            PintaCore.Workspace.Invalidate ();
            PintaCore.History.PushNewItem (new SimpleHistoryItem ("Menu.Edit.FillSelection.png", Mono.Unix.Catalog.GetString ("Fill Selection"), old, PintaCore.Layers.CurrentLayerIndex));
        }
Пример #28
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            if (mouse_button == 1) {
                StrokeColor = PintaCore.Palette.PrimaryColor;
                FillColor = PintaCore.Palette.SecondaryColor;
            } else if (mouse_button == 3) {
                StrokeColor = PintaCore.Palette.SecondaryColor;
                FillColor = PintaCore.Palette.PrimaryColor;
            } else {
                LastPoint = point_empty;
                return;
            }

            // TODO: also multiply by pressure
            StrokeColor = new Color (StrokeColor.R, StrokeColor.G, StrokeColor.B,
                StrokeColor.A * active_brush.StrokeAlphaMultiplier);

            int x = (int)point.X;
            int y = (int)point.Y;

            if (LastPoint.Equals (point_empty))
                LastPoint = new Point (x, y);

            if (doc.Workspace.PointInCanvas (point))
                surface_modified = true;

            var surf = doc.CurrentUserLayer.Surface;
            var invalidate_rect = Gdk.Rectangle.Zero;
            var brush_width = BrushWidth;

            Surface = surf;

            using (Drawable = new Context (surf)) {
                Drawable.AppendPath (doc.Selection.SelectionPath);
                Drawable.FillRule = FillRule.EvenOdd;
                Drawable.Clip ();

                Drawable.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;
                Drawable.LineWidth = brush_width;
                Drawable.LineJoin = LineJoin.Round;
                Drawable.LineCap = BrushWidth == 1 ? LineCap.Butt : LineCap.Round;
                Drawable.Color = StrokeColor;

                invalidate_rect = active_brush.DoMouseMove (Drawable, StrokeColor, Surface,
                                                            x, y, LastPoint.X, LastPoint.Y);
            }

            Surface = null;
            Drawable = null;

            // If we draw partially offscreen, Cairo gives us a bogus
            // dirty rectangle, so redraw everything.
            if (doc.Workspace.IsPartiallyOffscreen (invalidate_rect)) {
                doc.Workspace.Invalidate ();
            } else {
                doc.Workspace.Invalidate (doc.ClampToImageSize (invalidate_rect));
            }

            LastPoint = new Point (x, y);
        }
Пример #29
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            if (!is_dragging)
                return;

            Document doc = PintaCore.Workspace.ActiveDocument;

            PointD new_offset = point;

            double dx = origin_offset.X - new_offset.X;
            double dy = origin_offset.Y - new_offset.Y;

            using (Cairo.Context g = new Cairo.Context (doc.CurrentLayer.Surface)) {
                Path old = doc.SelectionPath;
                g.FillRule = FillRule.EvenOdd;
                g.AppendPath (doc.SelectionPath);
                g.Translate (dx, dy);
                doc.SelectionPath = g.CopyPath ();
                (old as IDisposable).Dispose ();
            }

            origin_offset = new_offset;
            doc.ShowSelection = true;

            (o as Gtk.DrawingArea).GdkWindow.Invalidate ();
        }
Пример #30
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            if (mouse_button == 1) {
                StrokeColor = PintaCore.Palette.PrimaryColor;
                FillColor = PintaCore.Palette.SecondaryColor;
            } else if (mouse_button == 3) {
                StrokeColor = PintaCore.Palette.SecondaryColor;
                FillColor = PintaCore.Palette.PrimaryColor;
            } else {
                LastPoint = point_empty;
                return;
            }

            // TODO: also multiply by pressure
            StrokeColor = new Color (StrokeColor.R, StrokeColor.G, StrokeColor.B,
                StrokeColor.A * active_brush.StrokeAlphaMultiplier);

            int x = (int)point.X;
            int y = (int)point.Y;

            if (LastPoint.Equals (point_empty))
                LastPoint = new Point (x, y);

            if (PintaCore.Workspace.PointInCanvas (point))
                surface_modified = true;

            var surf = PintaCore.Layers.CurrentLayer.Surface;
            var invalidate_rect = Gdk.Rectangle.Zero;
            var brush_width = BrushWidth;

            using (Drawable = new Context (surf)) {
                Drawable.AppendPath (PintaCore.Workspace.ActiveDocument.SelectionPath);
                Drawable.FillRule = FillRule.EvenOdd;
                Drawable.Clip ();

                Drawable.Antialias = Antialias.Subpixel;
                Drawable.LineWidth = brush_width;
                Drawable.LineJoin = LineJoin.Round;
                Drawable.LineCap = BrushWidth == 1 ? LineCap.Butt : LineCap.Round;
                Drawable.Color = StrokeColor;

                Drawable.Translate (brush_width / 2.0, brush_width / 2.0);

                active_brush.Tool = this;
                invalidate_rect = active_brush.DoMouseMove (x, y, LastPoint.X, LastPoint.Y);
                active_brush.Tool = null;
            }

            Drawable = null;

            if (invalidate_rect.IsEmpty) {
                PintaCore.Workspace.Invalidate ();
            } else {
                PintaCore.Workspace.Invalidate (invalidate_rect);
            }

            LastPoint = new Point (x, y);
        }
Пример #31
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            if (!is_drawing)
                return;

            double x = Utility.Clamp (point.X, 0, PintaCore.Workspace.ImageSize.Width - 1);
            double y = Utility.Clamp (point.Y, 0, PintaCore.Workspace.ImageSize.Height - 1);

            PintaCore.Layers.ShowSelection = true;

            ImageSurface surf = PintaCore.Layers.ToolLayer.Surface;

            using (Context g = new Context (surf)) {
                g.Antialias = Antialias.Subpixel;

                if (path != null) {
                    g.AppendPath (path);
                    (path as IDisposable).Dispose ();
                }

                g.LineTo (x, y);

                path = g.CopyPath ();

                g.FillRule = FillRule.EvenOdd;
                g.ClosePath ();

                Path old = PintaCore.Layers.SelectionPath;

                PintaCore.Layers.SelectionPath = g.CopyPath ();
                (old as IDisposable).Dispose ();
            }

            PintaCore.Workspace.Invalidate ();
        }
        private void Draw(DrawingArea drawingarea1, Color tool_color, Cairo.PointD point, bool first_pixel)
        {
            int x = (int)point.X;
            int y = (int) point.Y;

            if (last_point.Equals (point_empty)) {
                last_point = new Point (x, y);

                if (!first_pixel)
                    return;
            }

            Document doc = PintaCore.Workspace.ActiveDocument;

            if (doc.Workspace.PointInCanvas (point))
                surface_modified = true;

            ImageSurface surf = PintaCore.Layers.CurrentLayer.Surface;

            if (first_pixel) {
                // Does Cairo really not support a single-pixel-long single-pixel-wide line?
                surf.Flush ();
                int shiftedX = (int)point.X;
                int shiftedY = (int)point.Y;
                ColorBgra source = surf.GetColorBgraUnchecked (shiftedX, shiftedY);
                source = UserBlendOps.NormalBlendOp.ApplyStatic (source, tool_color.ToColorBgra ());
                surf.SetColorBgra (source, shiftedX, shiftedY);
                surf.MarkDirty ();
            } else {
                using (Context g = new Context (surf)) {
                    g.AppendPath (doc.Selection.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.Clip ();

                    g.Antialias = Antialias.None;

                    // Adding 0.5 forces cairo into the correct square:
                    // See https://bugs.launchpad.net/bugs/672232
                    g.MoveTo (last_point.X + 0.5, last_point.Y + 0.5);
                    g.LineTo (x + 0.5, y + 0.5);

                    g.Color = tool_color;
                    g.LineWidth = 1;
                    g.LineCap = LineCap.Square;

                    g.Stroke ();
                }
            }

            Gdk.Rectangle r = GetRectangleFromPoints (last_point, new Point (x, y));

            doc.Workspace.Invalidate (r);

            last_point = new Point (x, y);
        }
Пример #33
0
        protected override void OnMouseUp(Gtk.DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            base.OnMouseUp (canvas, args, point);

            ImageSurface surf = doc.SelectionLayer.Surface;

            using (Context g = new Context (surf)) {
                if (path != null) {
                    g.AppendPath (path);
                    (path as IDisposable).Dispose ();
                    path = null;
                }

                g.FillRule = FillRule.EvenOdd;
                g.ClosePath ();

                doc.Selection.DisposeSelectionPreserve();

                doc.Selection.SelectionPath = g.CopyPath ();
            }

            doc.Selection.SelectionPolygons.Add(lassoPolygon.ToList());
            lassoPolygon.Clear();

            doc.Workspace.Invalidate ();
        }
Пример #34
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            if (!is_drawing)
                return;

            double x = Utility.Clamp (point.X, 0, doc.ImageSize.Width - 1);
            double y = Utility.Clamp (point.Y, 0, doc.ImageSize.Height - 1);

            doc.ShowSelection = true;

            ImageSurface surf = doc.SelectionLayer.Surface;

            using (Context g = new Context (surf)) {
                g.Antialias = Antialias.Subpixel;

                if (path != null) {
                    g.AppendPath (path);
                    (path as IDisposable).Dispose ();
                } else {
                    g.MoveTo (x, y);
                }

                g.LineTo (x, y);
                lassoPolygon.Add(new IntPoint((long)x, (long)y));

                path = g.CopyPath ();

                g.FillRule = FillRule.EvenOdd;
                g.ClosePath ();

                doc.Selection.DisposeSelectionPreserve();

                doc.Selection.SelectionPath = g.CopyPath ();
            }

            doc.Workspace.Invalidate ();
        }
Пример #35
0
        protected override void OnMouseUp(Gtk.DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            base.OnMouseUp (canvas, args, point);

            ImageSurface surf = PintaCore.Layers.CurrentLayer.Surface;

            using (Context g = new Context (surf)) {
                if (path != null) {
                    g.AppendPath (path);
                    (path as IDisposable).Dispose ();
                    path = null;
                }

                g.FillRule = FillRule.EvenOdd;
                g.ClosePath ();

                Path old = PintaCore.Layers.SelectionPath;

                PintaCore.Layers.SelectionPath = g.CopyPath ();
                (old as IDisposable).Dispose ();
            }

            PintaCore.Workspace.Invalidate ();
        }
Пример #36
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Color tool_color;

            if ((args.Event.State & Gdk.ModifierType.Button1Mask) == Gdk.ModifierType.Button1Mask)
                tool_color = PintaCore.Palette.PrimaryColor;
            else if ((args.Event.State & Gdk.ModifierType.Button3Mask) == Gdk.ModifierType.Button3Mask)
                tool_color = PintaCore.Palette.SecondaryColor;
            else {
                last_point = point_empty;
                return;
            }

            DrawingArea drawingarea1 = (DrawingArea)o;

            int x = (int)point.X;
            int y = (int)point.Y;

            if (last_point.Equals (point_empty)) {
                last_point = new Point (x, y);
                return;
            }

            if (PintaCore.Workspace.PointInCanvas (point))
                surface_modified = true;

            ImageSurface surf = PintaCore.Layers.CurrentLayer.Surface;

            using (Context g = new Context (surf)) {
                g.AppendPath (PintaCore.Layers.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.Antialias = Antialias.None;

                g.MoveTo (last_point.X, last_point.Y);
                g.LineTo (x, y);

                g.Color = tool_color;
                g.LineWidth = 1;
                g.LineCap = LineCap.Square;

                g.Stroke ();
            }

            Gdk.Rectangle r = GetRectangleFromPoints (last_point, new Point (x, y));

            PintaCore.Workspace.Invalidate (r);

            last_point = new Point (x, y);
        }
Пример #37
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            base.OnMouseMove (o, args, point);
            if (tracking) {

                UserBlendOps.NormalBlendOp normalBlendOp = new UserBlendOps.NormalBlendOp();
                GradientRenderer gr = null;
                switch (GradientType) {
                    case eGradientType.Linear:
                        gr = new GradientRenderers.LinearClamped (GradientColorMode  == GradientColorMode.Transparency, normalBlendOp);
                    break;
                    case eGradientType.LinearReflected:
                        gr = new GradientRenderers.LinearReflected (GradientColorMode  == GradientColorMode.Transparency, normalBlendOp);
                    break;
                    case eGradientType.Radial:
                        gr = new GradientRenderers.Radial (GradientColorMode  == GradientColorMode.Transparency, normalBlendOp);
                    break;
                    case eGradientType.Diamond:
                        gr = new GradientRenderers.LinearDiamond (GradientColorMode  == GradientColorMode.Transparency, normalBlendOp);
                    break;
                    case eGradientType.Conical:
                        gr = new GradientRenderers.Conical (GradientColorMode  == GradientColorMode.Transparency, normalBlendOp);
                    break;
                }
                if (button == 3) {//right
                    gr.StartColor = PintaCore.Palette.SecondaryColor.ToColorBgra ();
                    gr.EndColor = PintaCore.Palette.PrimaryColor.ToColorBgra ();
                }
                else {//1 left
                    gr.StartColor = PintaCore.Palette.PrimaryColor.ToColorBgra ();
                    gr.EndColor = PintaCore.Palette.SecondaryColor.ToColorBgra ();
                }

                gr.StartPoint = startpoint;
                gr.EndPoint = point;
                gr.AlphaBlending = UseAlphaBlending;

                gr.BeforeRender ();

                Gdk.Rectangle selection_bounds = PintaCore.Layers.SelectionPath.GetBounds ();
                ImageSurface scratch_layer = PintaCore.Layers.ToolLayer.Surface;

                gr.Render (scratch_layer, new Gdk.Rectangle[] { selection_bounds });

                using (Context g = new Context (PintaCore.Layers.CurrentLayer.Surface)) {
                    g.AppendPath (PintaCore.Layers.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.Clip ();

                    g.SetSource (scratch_layer);
                    g.Paint ();
                }

                selection_bounds.Inflate (5, 5);
                PintaCore.Workspace.Invalidate (selection_bounds);
            }
        }
Пример #38
0
        protected override void OnUpdateTransform(Matrix transform)
        {
            base.OnUpdateTransform (transform);

            List<List<IntPoint>> newSelectionPolygons = DocumentSelection.Transform (original_selection, transform);

            Document doc = PintaCore.Workspace.ActiveDocument;
            doc.Selection.SelectionClipper.Clear ();
            doc.Selection.SelectionPolygons = newSelectionPolygons;
            using (var g = new Cairo.Context (doc.CurrentUserLayer.Surface)) {
                doc.Selection.SelectionPath = g.CreatePolygonPath (DocumentSelection.ConvertToPolygonSet (newSelectionPolygons));
                g.FillRule = FillRule.EvenOdd;
                g.AppendPath (doc.Selection.SelectionPath);
            }

            doc.ShowSelection = true;
            doc.SelectionLayer.Transform.InitMatrix (original_transform);
            doc.SelectionLayer.Transform.Multiply (transform);

            PintaCore.Workspace.Invalidate ();
        }
Пример #39
0
        protected unsafe override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            ColorBgra old_color;
            ColorBgra new_color;

            if (mouse_button == 1) {
                old_color = PintaCore.Palette.PrimaryColor.ToColorBgra ();
                new_color = PintaCore.Palette.SecondaryColor.ToColorBgra ();
            } else if (mouse_button == 3) {
                old_color = PintaCore.Palette.SecondaryColor.ToColorBgra ();
                new_color = PintaCore.Palette.PrimaryColor.ToColorBgra ();
            } else {
                last_point = point_empty;
                return;
            }

            int x = (int)point.X;
            int y = (int)point.Y;

            if (last_point.Equals (point_empty))
                last_point = new Point (x, y);

            if (doc.Workspace.PointInCanvas (point))
                surface_modified = true;

            ImageSurface surf = doc.CurrentLayer.Surface;
            ImageSurface tmp_layer = doc.ToolLayer.Surface;

            Gdk.Rectangle roi = GetRectangleFromPoints (last_point, new Point (x, y));

            roi = PintaCore.Workspace.ClampToImageSize (roi);
            myTolerance = (int)(Tolerance * 256);

            tmp_layer.Flush ();

            ColorBgra* tmp_data_ptr = (ColorBgra*)tmp_layer.DataPtr;
            int tmp_width = tmp_layer.Width;
            ColorBgra* surf_data_ptr = (ColorBgra*)surf.DataPtr;
            int surf_width = surf.Width;

            // The stencil lets us know if we've already checked this
            // pixel, providing a nice perf boost
            // Maybe this should be changed to a BitVector2DSurfaceAdapter?
            for (int i = roi.X; i <= roi.GetRight (); i++)
                for (int j = roi.Y; j <= roi.GetBottom (); j++) {
                    if (stencil[i, j])
                        continue;

                    if (IsColorInTolerance (new_color, surf.GetColorBgra (surf_data_ptr, surf_width, i, j)))
                        *tmp_layer.GetPointAddressUnchecked (tmp_data_ptr, tmp_width, i, j) = AdjustColorDifference (new_color, old_color, surf.GetColorBgra (surf_data_ptr, surf_width, i, j));

                    stencil[i, j] = true;
                }

            tmp_layer.MarkDirty ();

            using (Context g = new Context (surf)) {
                g.AppendPath (doc.Selection.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;

                g.MoveTo (last_point.X, last_point.Y);
                g.LineTo (x, y);

                g.LineWidth = BrushWidth;
                g.LineJoin = LineJoin.Round;
                g.LineCap = LineCap.Round;

                g.SetSource (tmp_layer);

                g.Stroke ();
            }

            doc.Workspace.Invalidate (roi);

            last_point = new Point (x, y);
        }
Пример #40
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            if (mouse_button <= 0) {
                last_point = point_empty;
                return;
            }

            DrawingArea drawingarea1 = (DrawingArea)o;

            int x = (int)point.X;
            int y = (int)point.Y;

            if (last_point.Equals (point_empty))
                last_point = new Point (x, y);

            if (PintaCore.Workspace.PointInCanvas (point))
                surface_modified = true;

            ImageSurface surf = PintaCore.Layers.CurrentLayer.Surface;

            using (Context g = new Context (surf)) {
                g.AppendPath (PintaCore.Layers.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.Antialias = Antialias.Subpixel;

                g.MoveTo (last_point.X, last_point.Y);
                g.LineTo (x, y);

                g.Operator = Operator.Clear;
                g.LineWidth = BrushWidth;
                g.LineJoin = LineJoin.Round;
                g.LineCap = LineCap.Round;

                g.Stroke ();
            }

            Gdk.Rectangle r = GetRectangleFromPoints (last_point, new Point (x, y));

            PintaCore.Workspace.Invalidate (r);

            last_point = new Point (x, y);
        }
Пример #41
0
        public void Crop(Gdk.Rectangle rect, Path path)
        {
            ImageSurface dest = new ImageSurface (Format.Argb32, rect.Width, rect.Height);

            using (Context g = new Context (dest)) {
                // Move the selected content to the upper left
                g.Translate (-rect.X, -rect.Y);
                g.Antialias = Antialias.None;

                // Respect the selected path
                g.AppendPath (path);
                g.FillRule = Cairo.FillRule.EvenOdd;
                g.Clip ();

                g.SetSource (Surface);
                g.Paint ();
            }

            (Surface as IDisposable).Dispose ();
            Surface = dest;
        }
Пример #42
0
 public void Clip(Context g)
 {
     g.AppendPath (selection_path);
     g.FillRule = FillRule.EvenOdd;
     g.Clip ();
 }
Пример #43
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            if (mouse_button <= 0) {
                last_point = point_empty;
                return;
            }

            int x = (int)point.X;
            int y = (int)point.Y;

            if (last_point.Equals (point_empty))
                last_point = new Point (x, y);

            if (doc.Workspace.PointInCanvas (point))
                surface_modified = true;

            ImageSurface surf = doc.CurrentUserLayer.Surface;

            using (Context g = new Context (surf)) {
                g.AppendPath (doc.Selection.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;

                // Adding 0.5 forces cairo into the correct square:
                // See https://bugs.launchpad.net/bugs/672232
                g.MoveTo (last_point.X + 0.5, last_point.Y + 0.5);
                g.LineTo (x + 0.5, y + 0.5);

                // Right-click is erase to background color, left-click is transparent
                if (mouse_button == 3)
                    g.SetSourceRGBA(PintaCore.Palette.SecondaryColor);
                else
                    g.Operator = Operator.Clear;

                g.LineWidth = BrushWidth;
                g.LineJoin = LineJoin.Round;
                g.LineCap = LineCap.Round;

                g.Stroke ();
            }

            Gdk.Rectangle r = GetRectangleFromPoints (last_point, new Point (x, y));

            if (doc.Workspace.IsPartiallyOffscreen (r)) {
                doc.Workspace.Invalidate ();
            } else {
                doc.Workspace.Invalidate (doc.ClampToImageSize (r));
            }

            last_point = new Point (x, y);
        }
Пример #44
0
        public static Gdk.Rectangle GetBounds(this Path path)
        {
            Rectangle rect;

            using (Context g = new Context (PintaCore.Layers.CurrentLayer.Surface)) {
                g.AppendPath (path);

                // We don't want the bounding box to include a stroke width
                // of 1, but setting it to 0 returns an empty rectangle.  Set
                // it to a sufficiently small width and rounding takes care of it
                g.LineWidth = .01;
                rect = g.FixedStrokeExtents ();
            }

            int x = (int)Math.Round (rect.X);
            int y = (int)Math.Round (rect.Y);
            int w = (int)Math.Round (rect.Width);
            int h = (int)Math.Round (rect.Height);

            return new Gdk.Rectangle (x, y, w, h);
        }