Ejemplo n.º 1
0
        /// <summary>
        /// Saves the current canvas to an <see cref="Image"/>
        /// </summary>
        public Image Save()
        {
            Area roi;

            ClearSelection();
            drawing.Freehand = backbuffer.Copy();
            roi = RegionOfInterest;
            if (roi == null || roi.Empty)
            {
                roi = new Area(0, 0, Background.Width, Background.Height);
            }
            return(tk.Copy(this, roi));
        }
 public static IBody2 ToSheetBody(this ISurface surface, bool transferOwnership = false)
 => SwAddinBase.Active.Modeler.CreateSurfaceBody(transferOwnership ? surface : (ISurface)surface.Copy());
Ejemplo n.º 3
0
        public void ProcessMouse(MouseConsoleState info, ISurface surface, bool isInBounds)
        {
            _previousSurface = surface;

            if (cancelled)
            {
                // wait until left button is released...
                if (info.Mouse.LeftButtonDown)
                {
                    return;
                }
                else
                {
                    cancelled = false;
                }
            }

            if (_panel.State == SelectionToolPanel.CloneState.SelectingPoint1)
            {
                if (info.Mouse.LeftButtonDown)
                {
                    if (!firstPoint.HasValue)
                    {
                        firstPoint = info.ConsolePosition;
                        return;
                    }
                    else
                    {
                        // Check for right click cancel.
                        if (info.Mouse.RightButtonDown)
                        {
                            cancelled  = true;
                            firstPoint = null;
                            return;
                        }

                        secondPoint = info.ConsolePosition;

                        // Draw the line (erase old) to where the mouse is
                        // create the animation frame
                        int width  = Math.Max(firstPoint.Value.X, secondPoint.X) - Math.Min(firstPoint.Value.X, secondPoint.X) + 1;
                        int height = Math.Max(firstPoint.Value.Y, secondPoint.Y) - Math.Min(firstPoint.Value.Y, secondPoint.Y) + 1;

                        Point p1;

                        if (firstPoint.Value.X > secondPoint.X)
                        {
                            if (firstPoint.Value.Y > secondPoint.Y)
                            {
                                p1 = Point.Zero;
                            }
                            else
                            {
                                p1 = new Point(0, height - 1);
                            }
                        }
                        else
                        {
                            if (firstPoint.Value.Y > secondPoint.Y)
                            {
                                p1 = new Point(width - 1, 0);
                            }
                            else
                            {
                                p1 = new Point(width - 1, height - 1);
                            }
                        }

                        finalPostion = info.ConsolePosition + new Point(1);
                        MakeBoxAnimation(width, height, p1);
                    }
                }
                else if (firstPoint.HasValue)
                {
                    // We let go outside of bounds
                    if (!isInBounds)
                    {
                        cancelled = true;
                        Brush.ShowSelectedSurface = false;
                        Brush.IsVisible           = false;
                        Brush.Animation           = Brush.Animations[AnimationSingle];
                        return;
                    }

                    secondPoint = info.ConsolePosition + info.Console.TextSurface.RenderArea.Location;
                    firstPoint  = firstPoint.Value + info.Console.TextSurface.RenderArea.Location;

                    // Copy data to new animation
                    AnimatedSurface cloneAnimation = new AnimatedSurface("clone", Brush.Animation.Width, Brush.Animation.Height, SadConsoleEditor.Settings.Config.ScreenFont);
                    var             frame          = cloneAnimation.CreateFrame();
                    Point           topLeftPoint   = new Point(Math.Min(firstPoint.Value.X, secondPoint.X), Math.Min(firstPoint.Value.Y, secondPoint.Y));
                    surface.Copy(topLeftPoint.X, topLeftPoint.Y, cloneAnimation.Width, cloneAnimation.Height, frame, 0, 0);

                    if (_altPanel.SkipEmptyCells && _altPanel.UseAltEmptyColor)
                    {
                        foreach (var cell in frame.Cells)
                        {
                            if (cell.Glyph == 0 && cell.Background == _altPanel.AltEmptyColor)
                            {
                                cell.Background = Color.Transparent;
                            }
                        }
                    }

                    cloneAnimation.Center = Brush.Animation.Center;

                    Brush.SelectedSurface.Animation = cloneAnimation;

                    Brush.Position = finalPostion;

                    _panel.State = SelectionToolPanel.CloneState.Selected;
                }
            }

            if (info.Mouse.RightClicked)
            {
                _panel.State = SelectionToolPanel.CloneState.SelectingPoint1;
                firstPoint   = null;
            }

            if (_panel.State == SelectionToolPanel.CloneState.Selected)
            {
                Brush.Position  = finalPostion;
                Brush.IsVisible = true;
            }
            if (info.Mouse.LeftClicked && isInBounds)
            {
                if (_panel.State == SelectionToolPanel.CloneState.Stamp)
                {
                    StampBrush(info.ConsolePosition.X, info.ConsolePosition.Y, surface);
                }
                else if (_panel.State == SelectionToolPanel.CloneState.Move)
                {
                    StampBrush(info.ConsolePosition.X, info.ConsolePosition.Y, surface);
                    _panel.State = SelectionToolPanel.CloneState.SelectingPoint1;
                }
            }
        }