Example #1
0
        protected override void OnMouseMove( MouseEventArgs e )
        {
            int x = (int) ( ( e.X - ClientRectangle.Left ) / Image.ZoomScale );
            int y = (int) ( ( e.Y - ClientRectangle.Top ) / Image.ZoomScale );

            if ( myMovingSelected )
            {
                if ( myMovingLayer && myTempLayer == null && ( x != myAnchorPos.X || y != myAnchorPos.Y ) )
                {
                    myTempLayer = new Layer( Image );
                    bool noSelection = mySelectedArea == 0;
                    for ( int px = 0; px < Image.Width; ++px )
                    {
                        for ( int py = 0; py < Image.Height; ++py )
                        {
                            if ( noSelection || mySelectedPixels[ px, py ] )
                            {
                                PixelSelect( px, py, CurrentLayer.Pixels[ px, py ] == Pixel.Empty );
                                myTempLayer.SetPixel( px, py, CurrentLayer.Pixels[ px, py ] );

                                if( !ModifierKeys.HasFlag( Keys.Control ) )
                                    CurrentLayer.SetPixel( px, py, Pixel.Empty );
                            }
                        }
                    }
                }

                UpdateMovedRect( x, y );
            }

            if ( myDrawingPencil )
            {
                if ( MouseButtons.HasFlag( MouseButtons.Left ) )
                    DrawPencil( x, y, Image.CurrentPixel );
                else
                    DrawPencil( x, y, Pixel.Empty );
            }

            if ( mySelectingPixels || myDrawingBox )
                UpdateBoxPreview( x, y );
        }
Example #2
0
        protected override void OnMouseUp( MouseEventArgs e )
        {
            if ( e.Button == MouseButtons.Left || e.Button == MouseButtons.Right )
            {
                int x = (int) ( ( e.X - ClientRectangle.Left ) / Image.ZoomScale );
                int y = (int) ( ( e.Y - ClientRectangle.Top ) / Image.ZoomScale );

                if ( myMovingSelected )
                {
                    if ( myTempLayer != null || !myMovingLayer )
                    {
                        bool[,] selected = (bool[,]) mySelectedPixels.Clone();

                        AllSelect( true );

                        int dx = x - myAnchorPos.X;
                        int dy = y - myAnchorPos.Y;

                        for ( int px = 0; px < Image.Width; ++px )
                        {
                            for ( int py = 0; py < Image.Height; ++py )
                            {
                                int tx = Wrap( px - dx, Image.Width );
                                int ty = Wrap( py - dy, Image.Height );

                                if ( Image.InBounds( tx, ty ) && selected[ tx, ty ] )
                                {
                                    PixelSelect( px, py );

                                    if( myMovingLayer )
                                        CurrentLayer.SetPixel( px, py, myTempLayer.Pixels[ tx, ty ] );
                                }
                            }
                        }
                    }

                    myTempLayer = null;
                    myMovingLayer = false;
                    myMovingSelected = false;

                    Image.PushState();

                    SendImageChange();
                }

                if ( myDrawingPencil )
                {
                    myDrawingPencil = false;
                    Image.PushState();
                }

                if ( myDrawingBox || mySelectingPixels )
                {
                    if ( mySelectingPixels )
                    {
                        AreaSelect( x, y, e.Button == MouseButtons.Right );

                        mySelectingPixels = false;
                    }

                    if ( myDrawingBox )
                    {
                        if ( e.Button == MouseButtons.Left )
                            DrawBox( x, y, Image.CurrentPixel );
                        else
                            DrawBox( x, y, Pixel.Empty );

                        myDrawingBox = false;
                        Image.PushState();
                    }
                }
            }
        }
Example #3
0
 public RemoveLayerAction( ImageInfo image, int index, Layer layer )
     : base(image)
 {
     myLayerIndex = index;
     myLabel = layer.Label;
     myPixels = (Pixel[,]) layer.Pixels.Clone();
 }
Example #4
0
        protected override void OnMouseDown( MouseEventArgs e )
        {
            if ( e.Button == MouseButtons.Left || e.Button == MouseButtons.Right )
            {
                int x = (int) ( ( e.X - ClientRectangle.Left ) / Image.ZoomScale );
                int y = (int) ( ( e.Y - ClientRectangle.Top ) / Image.ZoomScale );

                if( !Image.InBounds( x, y ) )
                    return;

                switch ( myToolPanel.CurrentTool )
                {
                    case Tool.Select:
                        x = Wrap( x, Image.Width );
                        y = Wrap( y, Image.Height );
                        if ( e.Button == MouseButtons.Left )
                        {
                            if ( mySelectedPixels[ x, y ] || ( mySelectedArea == 0 && CurrentLayer.Pixels[ x, y ] != Pixel.Empty ) )
                            {
                                myMovingSelected = myMovingLayer = true;
                                myTempLayer = null;
                                myAnchorPos = new Point( x, y );
                            }
                        }
                        else if( mySelectedPixels[ x, y ] )
                        {
                            myMovingSelected = true;
                            myAnchorPos = new Point( x, y );
                        }
                        break;
                    case Tool.Wand:
                        WandSelect( x, y, e.Button == MouseButtons.Right );
                        break;
                    case Tool.Area:
                        mySelectingPixels = true;
                        myAnchorPos = new Point( x, y );
                        myBoxPreview = new Rectangle( x, y, 1, 1 );
                        break;
                    case Tool.Pencil:
                        myDrawingPencil = true;
                        myAnchorPos = new Point( x, y );

                        DrawPencil( x, y, e.Button == MouseButtons.Left ? Image.CurrentPixel : Pixel.Empty );
                        break;
                    case Tool.Fill:
                        Fill( x, y, e.Button == MouseButtons.Left ? Image.CurrentPixel : Pixel.Empty );
                        Image.PushState();
                        break;
                    case Tool.Box:
                        myDrawingBox = true;
                        myAnchorPos = new Point( x, y );
                        myBoxPreview = new Rectangle( x, y, 1, 1 );
                        break;
                }
            }
        }
Example #5
0
 public EditLayerAction( ImageInfo image, Layer layer )
     : base(image)
 {
     myLayerIndex = image.Layers.IndexOf( layer );
     myPixels = (Pixel[,]) layer.Pixels.Clone();
 }
Example #6
0
 public AddLayerAction( ImageInfo image, Layer layer )
     : base(image)
 {
     myLayerIndex = image.Layers.IndexOf( layer );
     myLabel = layer.Label;
 }
Example #7
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
            {
                int x = (int)((e.X - ClientRectangle.Left) / Image.ZoomScale);
                int y = (int)((e.Y - ClientRectangle.Top) / Image.ZoomScale);

                if (myMovingSelected)
                {
                    if (myTempLayer != null || !myMovingLayer)
                    {
                        bool[,] selected = (bool[, ])mySelectedPixels.Clone();

                        AllSelect(true);

                        int dx = x - myAnchorPos.X;
                        int dy = y - myAnchorPos.Y;

                        for (int px = 0; px < Image.Width; ++px)
                        {
                            for (int py = 0; py < Image.Height; ++py)
                            {
                                int tx = Wrap(px - dx, Image.Width);
                                int ty = Wrap(py - dy, Image.Height);

                                if (Image.InBounds(tx, ty) && selected[tx, ty])
                                {
                                    PixelSelect(px, py);

                                    if (myMovingLayer)
                                    {
                                        CurrentLayer.SetPixel(px, py, myTempLayer.Pixels[tx, ty]);
                                    }
                                }
                            }
                        }
                    }

                    myTempLayer      = null;
                    myMovingLayer    = false;
                    myMovingSelected = false;

                    Image.PushState();

                    SendImageChange();
                }

                if (myDrawingPencil)
                {
                    myDrawingPencil = false;
                    Image.PushState();
                }

                if (myDrawingBox || mySelectingPixels)
                {
                    if (mySelectingPixels)
                    {
                        AreaSelect(x, y, e.Button == MouseButtons.Right);

                        mySelectingPixels = false;
                    }

                    if (myDrawingBox)
                    {
                        if (e.Button == MouseButtons.Left)
                        {
                            DrawBox(x, y, Image.CurrentPixel);
                        }
                        else
                        {
                            DrawBox(x, y, Pixel.Empty);
                        }

                        myDrawingBox = false;
                        Image.PushState();
                    }
                }
            }
        }
Example #8
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
            {
                int x = (int)((e.X - ClientRectangle.Left) / Image.ZoomScale);
                int y = (int)((e.Y - ClientRectangle.Top) / Image.ZoomScale);

                if (!Image.InBounds(x, y))
                {
                    return;
                }

                switch (myToolPanel.CurrentTool)
                {
                case Tool.Select:
                    x = Wrap(x, Image.Width);
                    y = Wrap(y, Image.Height);
                    if (e.Button == MouseButtons.Left)
                    {
                        if (mySelectedPixels[x, y] || (mySelectedArea == 0 && CurrentLayer.Pixels[x, y] != Pixel.Empty))
                        {
                            myMovingSelected = myMovingLayer = true;
                            myTempLayer      = null;
                            myAnchorPos      = new Point(x, y);
                        }
                    }
                    else if (mySelectedPixels[x, y])
                    {
                        myMovingSelected = true;
                        myAnchorPos      = new Point(x, y);
                    }
                    break;

                case Tool.Wand:
                    WandSelect(x, y, e.Button == MouseButtons.Right);
                    break;

                case Tool.Area:
                    mySelectingPixels = true;
                    myAnchorPos       = new Point(x, y);
                    myBoxPreview      = new Rectangle(x, y, 1, 1);
                    break;

                case Tool.Pencil:
                    myDrawingPencil = true;
                    myAnchorPos     = new Point(x, y);

                    DrawPencil(x, y, e.Button == MouseButtons.Left ? Image.CurrentPixel : Pixel.Empty);
                    break;

                case Tool.Fill:
                    Fill(x, y, e.Button == MouseButtons.Left ? Image.CurrentPixel : Pixel.Empty);
                    Image.PushState();
                    break;

                case Tool.Box:
                    myDrawingBox = true;
                    myAnchorPos  = new Point(x, y);
                    myBoxPreview = new Rectangle(x, y, 1, 1);
                    break;
                }
            }
        }
Example #9
0
        public void AddLayer( int index = -1, string label = null )
        {
            if ( index == -1 )
                index = Layers.Count;

            Layer layer = new Layer( this, label );
            Layers.Insert( index, layer );

            Modified = true;
            PushState();

            UpdateLayers();
        }