public override void MouseUp(EditorContext context, MouseButtonEventArgs args) { if (isPressed) { isPressed = false; context.EditorControl.Images.Remove(previewLayer); Point mousePosition = context.EditorControl.MouseToPixelCoords(context, args); EditorImageLayer lyr = context.EditorControl.Images[context.CurrentLayer]; int minX = (int)Math.Min(previousPoint.X, mousePosition.X), maxX = (int)Math.Max(previousPoint.X, mousePosition.X); int minY = (int)Math.Min(previousPoint.Y, mousePosition.Y), maxY = (int)Math.Max(previousPoint.Y, mousePosition.Y); void ContinueWithAction() { if (brushIsSquare) { if (useIndexColor) { lyr.pixlmap.DrawLineSquare(previousPoint, mousePosition, brushWidth, indexColor); } else { lyr.pixlmap.DrawLineSquare(context, previousPoint, mousePosition, brushWidth, drawColor); } } else { if (useIndexColor) { lyr.pixlmap.DrawLineCircle(previousPoint, mousePosition, brushWidth, indexColor); } else { lyr.pixlmap.DrawLineCircle(context, previousPoint, mousePosition, brushWidth, drawColor); } } lyr.image = lyr.pixlmap.GetImage(context); context.EditorControl.UpdateImageLayers = true; } Int32Rect rect = new Int32Rect(Math.Max(minX - brushWidth * 2, 0), Math.Max(minY - brushWidth * 2, 0), (int)Math.Min(maxX - minX + brushWidth * 4, context.CanvasSize.Width), (int)Math.Min(maxY - minY + brushWidth * 4, context.CanvasSize.Width)); ChangePartUndo undo = new ChangePartUndo(lyr, rect, ContinueWithAction); context.AddUndo(undo); } }
public override void MouseUp(EditorContext context, MouseButtonEventArgs args) { if (isPressed) { isPressed = false; context.EditorControl.Images.Remove(previewLayer); if (points.Count <= 0) { return; } EditorImageLayer lyr = context.EditorControl.Images[context.CurrentLayer]; void ContinueWithAction() { if (pixelPerfect) { if (brushIsSquare) { if (useIndexColor) { lyr.pixlmap.DrawPerfectPathSquare(points, brushWidth, indexColor); } else { lyr.pixlmap.DrawPerfectPathSquare(context, points, brushWidth, drawColor); } } else { if (useIndexColor) { lyr.pixlmap.DrawPerfectPathCircle(points, brushWidth, indexColor); } else { lyr.pixlmap.DrawPerfectPathCircle(context, points, brushWidth, drawColor); } } } else { if (brushIsSquare) { if (useIndexColor) { lyr.pixlmap.DrawPathSquare(points, brushWidth, indexColor); } else { lyr.pixlmap.DrawPathSquare(context, points, brushWidth, drawColor); } } else { if (useIndexColor) { lyr.pixlmap.DrawPathCircle(points, brushWidth, indexColor); } else { lyr.pixlmap.DrawPathCircle(context, points, brushWidth, drawColor); } } } lyr.image = lyr.pixlmap.GetImage(context); context.EditorControl.UpdateImageLayers = true; } int minX = (int)points[0].X, minY = (int)points[0].Y, maxX = (int)points[0].X, maxY = (int)points[0].Y; foreach (Point p in points) { if (p.X < minX) { minX = (int)p.X; } if (p.Y < minY) { minY = (int)p.Y; } if (p.X > maxX) { maxX = (int)p.X; } if (p.Y > maxY) { maxY = (int)p.Y; } } Int32Rect rect = new Int32Rect(Math.Max(minX - brushWidth * 2, 0), Math.Max(minY - brushWidth * 2, 0), (int)Math.Min(maxX - minX + brushWidth * 4, context.CanvasSize.Width), (int)Math.Min(maxY - minY + brushWidth * 4, context.CanvasSize.Width)); ChangePartUndo undo = new ChangePartUndo(lyr, rect, ContinueWithAction); context.AddUndo(undo); } }