public override void SaveDrawing(HashSet <Point> mousePositions) { var temPoints = new List <IBPoint>(); var mousePointsCount = mousePositions.Count; for (int i = 0; i < mousePointsCount - 1; i++) { var startPoint = mousePositions.ElementAt(i); var endPoint = mousePositions.ElementAt(i + 1); var linePoints = _bresenhamLine.GetPointsOnLine(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); foreach (var point in linePoints) { mousePositions.Add(new Point(point.X, point.Y)); } } var finalPoints = new List <IBPoint>(); foreach (var point in mousePositions) { finalPoints.Add(new BPoint(point.X, point.Y)); } var penLine = new PenLine(finalPoints); _penLines.Add(penLine); }
public override void PreviewDrawing(HashSet <Point> mousePositions) { if (mousePositions.Count == 1) { _lastPreviewPoints = new HashSet <IBPoint>(); } var startPoint = mousePositions.ElementAt(0); var endPoint = mousePositions.ElementAt(mousePositions.Count - 1); var linePoints = _bresenhamLine.GetPointsOnLine(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); if (mousePositions.Count == 1) { _lastPreviewPoints = new HashSet <IBPoint>(); } foreach (var point in _lastPreviewPoints) { _bitmap.SetPixel(point.X, point.Y, point.Color); } _lastPreviewPoints = new HashSet <IBPoint>(); var pixelSize = Setting.SelectedPixelSize; var pixelColor = Setting.SelectedColor; foreach (var point in linePoints) { for (int i = point.X - pixelSize; i < point.X + pixelSize; i++) { for (int j = point.Y - pixelSize; j < point.Y + pixelSize; j++) { if (CanvasValidator.IsCursorOutsideCanvas(new Point(i, j))) { continue; } var newPoint = new BPoint(i, j, pixelColor); var currentPixel = _bitmap.GetPixel(i, j); var bPoint = new BPoint(i, j, Color.FromArgb(currentPixel.A, currentPixel.R, currentPixel.G, currentPixel.B)); _lastPreviewPoints.Add(bPoint); _bitmap.SetPixel(newPoint); } } } }
public override void PreviewDrawing(HashSet <Point> mousePositions) { if (mousePositions.Count == 1) { _lastPreviewPoints = new HashSet <IBPoint>(); } foreach (var point in _lastPreviewPoints) { _bitmap.SetPixel(point.X, point.Y, point.Color); } var startPoint = mousePositions.ElementAt(0); var endPoint = mousePositions.ElementAt(mousePositions.Count - 1); var radius = (int)BPoint.GetDistance(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y); var leftPoint = new BPoint(0, 0); var rightPoint = new BPoint(0, 0); //Check if mouse is under start point or above if (startPoint.Y > endPoint.Y) { leftPoint = new BPoint(startPoint.X - radius, startPoint.Y - radius); rightPoint = new BPoint(startPoint.X + radius, startPoint.Y - radius); } else { leftPoint = new BPoint(startPoint.X - radius, startPoint.Y + radius); rightPoint = new BPoint(startPoint.X + radius, startPoint.Y + radius); } var pointsFromStartToLeft = _bresenhamLine.GetPointsOnLine(startPoint.X, startPoint.Y, leftPoint.X, leftPoint.Y); var pointsFromStartToRight = _bresenhamLine.GetPointsOnLine(startPoint.X, startPoint.Y, rightPoint.X, rightPoint.Y); var pointsFromLeftToRight = _bresenhamLine.GetPointsOnLine(leftPoint.X, leftPoint.Y, rightPoint.X, rightPoint.Y); var megredPoints = pointsFromStartToLeft.Concat(pointsFromStartToRight); megredPoints = megredPoints.Concat(pointsFromLeftToRight); foreach (var point in megredPoints) { var pixelSize = Setting.SelectedPixelSize; var pointX = point.X; var pointY = point.Y; for (int i = pointX - pixelSize; i < pointX + pixelSize; i++) { for (int j = pointY - pixelSize; j < pointY + pixelSize; j++) { if (CanvasValidator.IsCursorOutsideCanvas(new Point(i, j))) { continue; } var newPoint = new BPoint(i, j, Setting.SelectedColor); var currentPixel = _bitmap.GetPixel(i, j); var bPoint = new BPoint(i, j, Color.FromArgb(currentPixel.A, currentPixel.R, currentPixel.G, currentPixel.B)); _lastPreviewPoints.Add(bPoint); _bitmap.SetPixel(newPoint); } } } }