Example #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.SelectionPolygons.Clear();
            doc.Selection.SelectionPolygons.Add(lasso_polygon.ToList());
            SelectionModeHandler.PerformSelectionMode(combine_mode, doc.Selection.SelectionPolygons);
            doc.Workspace.Invalidate();

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

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

            if (!is_drawing)
            {
                UpdateCursor(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);

            ClearHandles(doc.ToolLayer);
            RefreshHandler();
            ReDraw(args.Event.State);

            if (doc.Selection != null)
            {
                SelectionModeHandler.PerformSelectionMode(combine_mode, doc.Selection.SelectionPolygons);
                PintaCore.Workspace.Invalidate();
            }
        }
Example #3
0
        protected override void OnMouseUp(Document document, ToolMouseEventArgs e)
        {
            var surf = document.Layers.SelectionLayer.Surface;

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

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

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

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

            lasso_polygon.Clear();
            is_drawing = false;
        }
Example #4
0
        protected override void OnMouseMove(Document document, ToolMouseEventArgs e)
        {
            if (!is_drawing)
            {
                UpdateCursor(document, e.PointDouble);
                return;
            }

            var x = Utility.Clamp(e.PointDouble.X, 0, document.ImageSize.Width - 1);
            var y = Utility.Clamp(e.PointDouble.Y, 0, document.ImageSize.Height - 1);

            // Should always be true, set in OnMouseDown
            if (active_control.HasValue)
            {
                controls[active_control.Value].HandleMouseMove(x, y, e.State);
            }

            ClearHandles(document.Layers.ToolLayer);
            RefreshHandler();

            var dirty = ReDraw(document, e.IsShiftPressed);

            if (document.Selection != null)
            {
                SelectionModeHandler.PerformSelectionMode(combine_mode, document.Selection.SelectionPolygons);
                document.Workspace.Invalidate(dirty.Union(last_dirty));
            }

            last_dirty = dirty;
        }
Example #5
0
        protected override void OnMouseUp(Document document, ToolMouseEventArgs e)
        {
            // If the user didn't move the mouse, they want to deselect
            var tolerance = 0;

            if (Math.Abs(reset_origin.X - e.WindowPoint.X) <= tolerance && Math.Abs(reset_origin.Y - e.WindowPoint.Y) <= tolerance)
            {
                // Mark as being done interactive drawing before invoking the deselect action.
                // This will allow AfterSelectionChanged() to clear the selection.
                is_drawing = false;

                if (hist != null)
                {
                    // Roll back any changes made to the selection, e.g. in OnMouseDown().
                    hist.Undo();

                    hist.Dispose();
                    hist = null;
                }

                PintaCore.Actions.Edit.Deselect.Activate();
            }
            else
            {
                ClearHandles(document.Layers.ToolLayer);

                var dirty = ReDraw(document, e.IsShiftPressed);

                if (document.Selection != null)
                {
                    SelectionModeHandler.PerformSelectionMode(combine_mode, document.Selection.SelectionPolygons);

                    document.Selection.Origin = shape_origin;
                    document.Selection.End    = shape_end;
                    document.Workspace.Invalidate(last_dirty.Union(dirty));
                    last_dirty = dirty;
                }
                if (hist != null)
                {
                    document.History.PushNewItem(hist);
                    hist = null;
                }
            }

            is_drawing     = false;
            active_control = null;

            // Update the mouse cursor.
            UpdateCursor(document, e.PointDouble);
        }
Example #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)
            {
                // Mark as being done interactive drawing before invoking the deselect action.
                // This will allow AfterSelectionChanged() to clear the selection.
                is_drawing = false;

                if (hist != null)
                {
                    // Roll back any changes made to the selection, e.g. in OnMouseDown().
                    hist.Undo();

                    hist.Dispose();
                    hist = null;
                }

                PintaCore.Actions.Edit.Deselect.Activate();
            }
            else
            {
                ClearHandles(doc.ToolLayer);
                ReDraw(args.Event.State);
                if (doc.Selection != null)
                {
                    SelectionModeHandler.PerformSelectionMode(combine_mode, doc.Selection.SelectionPolygons);

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

            is_drawing     = false;
            active_control = null;

            // Update the mouse cursor.
            UpdateCursor(point);
        }
Example #7
0
        protected override void OnFillRegionComputed(Document document, Point[][] polygonSet)
        {
            var undoAction = new SelectionHistoryItem(Icon, Name);

            undoAction.TakeSnapshot();

            document.PreviousSelection.Dispose();
            document.PreviousSelection = document.Selection.Clone();

            document.Selection.SelectionPolygons.Clear();
            SelectionModeHandler.PerformSelectionMode(combine_mode, DocumentSelection.ConvertToPolygons(polygonSet));

            document.History.PushNewItem(undoAction);
            document.Workspace.Invalidate();
        }
Example #8
0
        protected override void OnFillRegionComputed(Point[][] polygonSet)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

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

            undoAction.TakeSnapshot();

            doc.PreviousSelection.Dispose();
            doc.PreviousSelection = doc.Selection.Clone();

            doc.Selection.SelectionPolygons.Clear();
            SelectionModeHandler.PerformSelectionMode(combine_mode, polygonSet);

            doc.History.PushNewItem(undoAction);
            doc.Workspace.Invalidate();
        }
Example #9
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();
        }
Example #10
0
        protected override void OnMouseMove(Document document, ToolMouseEventArgs e)
        {
            if (!is_drawing)
            {
                return;
            }

            var x = Utility.Clamp(e.PointDouble.X, 0, document.ImageSize.Width - 1);
            var y = Utility.Clamp(e.PointDouble.Y, 0, document.ImageSize.Height - 1);

            document.Selection.Visible = true;

            var surf = document.Layers.SelectionLayer.Surface;

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

                if (path != null)
                {
                    g.AppendPath(path);
                    path.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();
            }

            document.Selection.SelectionPolygons.Clear();
            document.Selection.SelectionPolygons.Add(lasso_polygon.ToList());

            SelectionModeHandler.PerformSelectionMode(combine_mode, document.Selection.SelectionPolygons);

            document.Workspace.Invalidate();
        }
Example #11
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
            {
                ClearHandles(doc.ToolLayer);
                ReDraw(args.Event.State);
                if (doc.Selection != null)
                {
                    SelectionModeHandler.PerformSelectionMode(combine_mode, doc.Selection.SelectionPolygons);

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

            is_drawing     = false;
            active_control = null;

            // Update the mouse cursor.
            UpdateCursor(point);
        }