Пример #1
0
        protected override void OnMouseUp(Gtk.DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            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.SelectionPath = g.CopyPath();
            }

            doc.Selection.SelectionPolygons.Clear();
            doc.Selection.SelectionPolygons.Add(lasso_polygon.ToList());
            SelectionModeHandler.PerformSelectionMode(combine_mode,
                                                      DocumentSelection.ConvertToPolygonSet(doc.Selection.SelectionPolygons));
            doc.Workspace.Invalidate();

            if (hist != null)
            {
                doc.History.PushNewItem(hist);
                hist = null;
            }

            lasso_polygon.Clear();
            is_drawing = false;
        }
Пример #2
0
        protected override void OnMouseMove(object o, MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            if (!is_drawing)
            {
                CheckHandlerCursor(point.X, point.Y);

                if (!isResizing)
                {
                    return;
                }
            }
            else
            {
                double x = Utility.Clamp(point.X, 0, doc.ImageSize.Width - 1);
                double y = Utility.Clamp(point.Y, 0, doc.ImageSize.Height - 1);

                shape_end = new PointD(x, y);

                ReDraw(args.Event.State);
            }

            if (doc.Selection != null)
            {
                doc.selHandler.PerformSelectionMode(DocumentSelection.ConvertToPolygonSet(doc.Selection.SelectionPolygons));
                PintaCore.Workspace.Invalidate();
            }
        }
Пример #3
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);
                lasso_polygon.Add(new IntPoint((long)x, (long)y));

                path = g.CopyPath();

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

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

            doc.Selection.SelectionPolygons.Clear();
            doc.Selection.SelectionPolygons.Add(lasso_polygon.ToList());
            SelectionModeHandler.PerformSelectionMode(combine_mode,
                                                      DocumentSelection.ConvertToPolygonSet(doc.Selection.SelectionPolygons));
            doc.Workspace.Invalidate();
        }
Пример #4
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();
        }
Пример #5
0
        protected override void OnMouseUp(DrawingArea canvas, ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            // If the user didn't move the mouse, they want to deselect
            int tolerance = 0;

            if (Math.Abs(reset_origin.X - args.Event.X) <= tolerance && Math.Abs(reset_origin.Y - args.Event.Y) <= tolerance)
            {
                PintaCore.Actions.Edit.Deselect.Activate();
                if (hist != null)
                {
                    hist.Dispose();
                    hist = null;
                }
                doc.ToolLayer.Clear();
            }
            else
            {
                ReDraw(args.Event.State);
                if (doc.Selection != null)
                {
                    SelectionModeHandler.PerformSelectionMode(combine_mode,
                                                              DocumentSelection.ConvertToPolygonSet(doc.Selection.SelectionPolygons));

                    doc.Selection.selEnd = shape_end;
                    PintaCore.Workspace.Invalidate();
                }
                if (hist != null)
                {
                    doc.History.PushNewItem(hist);
                    hist = null;
                }
            }

            is_drawing     = false;
            active_control = null;

            // Update the mouse cursor.
            CheckHandlerCursor(point);
        }
Пример #6
0
        protected override void OnMouseUp(DrawingArea canvas, ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            // If the user didn't move the mouse, they want to deselect
            int tolerance = 0;

            if (Math.Abs(reset_origin.X - args.Event.X) <= tolerance && Math.Abs(reset_origin.Y - args.Event.Y) <= tolerance)
            {
                PintaCore.Actions.Edit.Deselect.Activate();
                hist.Dispose();
                hist           = null;
                handler_active = false;

                doc.ToolLayer.Clear();
            }
            else
            {
                ReDraw(args.Event.State);

                if (doc.Selection != null)
                {
                    doc.selHandler.PerformSelectionMode(DocumentSelection.ConvertToPolygonSet(doc.Selection.SelectionPolygons));
                    PintaCore.Workspace.Invalidate();
                }

                if (hist != null)
                {
                    doc.History.PushNewItem(hist);
                }

                handler_active = true;
                hist.Dispose();
                hist = null;
            }

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

            if (!is_drawing)
            {
                CheckHandlerCursor(point);
                return;
            }

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

            controls[active_control.Value].HandleMouseMove(x, y, args.Event.State);

            ReDraw(args.Event.State);

            if (doc.Selection != null)
            {
                SelectionModeHandler.PerformSelectionMode(combine_mode,
                                                          DocumentSelection.ConvertToPolygonSet(doc.Selection.SelectionPolygons));
                PintaCore.Workspace.Invalidate();
            }
        }
Пример #8
0
        protected override void OnFillRegionComputed(Point[][] polygonSet)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            SelectionHistoryItem undoAction = new SelectionHistoryItem(this.Icon, this.Name);

            undoAction.TakeSnapshot();

            //Convert Pinta's passed in Polygon Set to a Clipper Polygon collection.
            List <List <IntPoint> > newPolygons = DocumentSelection.ConvertToPolygons(polygonSet);

            using (Context g = new Context(PintaCore.Layers.CurrentLayer.Surface))
            {
                //Make sure time isn't wasted if the CombineMode is Replace - Replace is much simpler than the other 4 selection modes.
                if (combineMode == CombineMode.Replace)
                {
                    //Clear any previously stored Polygons.
                    doc.Selection.SelectionPolygons.Clear();

                    //Set the resulting selection path to the new selection path.
                    doc.Selection.SelectionPolygons = newPolygons;
                    doc.Selection.SelectionPath     = g.CreatePolygonPath(polygonSet);
                }
                else
                {
                    List <List <IntPoint> > resultingPolygons = new List <List <IntPoint> >();

                    //Specify the Clipper Subject (the previous Polygons) and the Clipper Clip (the new Polygons).
                    //Note: for Union, ignore the Clipper Library instructions - the new polygon(s) should be Clips, not Subjects!
                    doc.Selection.SelectionClipper.AddPolygons(doc.Selection.SelectionPolygons, PolyType.ptSubject);
                    doc.Selection.SelectionClipper.AddPolygons(newPolygons, PolyType.ptClip);

                    switch (combineMode)
                    {
                    case CombineMode.Xor:
                        //Xor means "Combine both Polygon sets, but leave out any areas of intersection between the two."
                        doc.Selection.SelectionClipper.Execute(ClipType.ctXor, resultingPolygons);
                        break;

                    case CombineMode.Exclude:
                        //Exclude == Difference

                        //Exclude/Difference means "Subtract any overlapping areas of the new Polygon set from the old Polygon set."
                        doc.Selection.SelectionClipper.Execute(ClipType.ctDifference, resultingPolygons);
                        break;

                    case CombineMode.Intersect:
                        //Intersect means "Leave only the overlapping areas between the new and old Polygon sets."
                        doc.Selection.SelectionClipper.Execute(ClipType.ctIntersection, resultingPolygons);
                        break;

                    default:
                        //Default should only be *CombineMode.Union*, but just in case...

                        //Union means "Combine both Polygon sets, and keep any overlapping areas as well."
                        doc.Selection.SelectionClipper.Execute(ClipType.ctUnion, resultingPolygons);
                        break;
                    }

                    //After using Clipper, it has to be cleared so there are no conflicts with its next usage.
                    doc.Selection.SelectionClipper.Clear();

                    //Set the resulting selection path to the calculated ("clipped") selection path.
                    doc.Selection.SelectionPolygons = resultingPolygons;
                    doc.Selection.SelectionPath     = g.CreatePolygonPath(DocumentSelection.ConvertToPolygonSet(resultingPolygons));
                }
            }

            doc.History.PushNewItem(undoAction);
            doc.Workspace.Invalidate();
        }