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 ); }
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(); } } } }
public RemoveLayerAction( ImageInfo image, int index, Layer layer ) : base(image) { myLayerIndex = index; myLabel = layer.Label; myPixels = (Pixel[,]) layer.Pixels.Clone(); }
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; } } }
public EditLayerAction( ImageInfo image, Layer layer ) : base(image) { myLayerIndex = image.Layers.IndexOf( layer ); myPixels = (Pixel[,]) layer.Pixels.Clone(); }
public AddLayerAction( ImageInfo image, Layer layer ) : base(image) { myLayerIndex = image.Layers.IndexOf( layer ); myLabel = layer.Label; }
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(); } } } }
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; } } }
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(); }