Example #1
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();
        }
Example #2
0
        protected override void OnMouseUp(Gtk.DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            is_dragging = false;

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

            hist = null;
        }
Example #3
0
        protected override void OnFinishTransform()
        {
            base.OnFinishTransform();

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

            hist = null;
            original_selection = null;
            original_transform.InitIdentity();
        }
Example #4
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();
        }
Example #5
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();
        }
Example #6
0
        protected override void OnFinishTransform(Matrix transform)
        {
            base.OnFinishTransform(transform);

            // Also transform the base selection used for the various select modes.
            var doc = PintaCore.Workspace.ActiveDocument;

            using (var prev_selection = doc.PreviousSelection)
                doc.PreviousSelection = prev_selection.Transform(transform);

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

            hist = null;
            original_selection.Dispose();
            original_selection = null;
            original_transform.InitIdentity();
        }