public override void DrawLine(BitmapWrap bmp, int x1, int y1, int x2, int y2, bool drawFirstDot = false) { PathCalculator lineCalc = new PathCalculator(); List <Tuple <int, int> > dotList = lineCalc.CalculateLinePath(x1, y1, x2, y2); if (drawFirstDot) { DrawDot(bmp, dotList[0].Item1, dotList[0].Item2); } for (int i = 1; i < dotList.Count; i++) { if (dotList[i].Item1 < dotList[i - 1].Item1) { DrawDotBorder(bmp, dotList[i].Item1, dotList[i].Item2, Direction.Left); } if (dotList[i].Item1 > dotList[i - 1].Item1) { DrawDotBorder(bmp, dotList[i].Item1, dotList[i].Item2, Direction.Right); } if (dotList[i].Item2 < dotList[i - 1].Item2) { DrawDotBorder(bmp, dotList[i].Item1, dotList[i].Item2, Direction.Up); } if (dotList[i].Item2 > dotList[i - 1].Item2) { DrawDotBorder(bmp, dotList[i].Item1, dotList[i].Item2, Direction.Down); } } }
public override void DrawDot(BitmapWrap bmp, int x, int y) { //x1 y1 левый верхний угол //x2 y2 правый нижний int x1 = x - BrushSize / 2; int x2 = x1 + BrushSize - 1; int y1 = y - BrushSize / 2; int y2 = y1 + BrushSize - 1; //координаты центра double xCenter = (x1 + x2) / (double)2; double yCenter = (y1 + y2) / (double)2; double radius = BrushSize / (double)2; //заполняем с проверкой на расстояние от центра for (int i = x1; i <= x2; i++) { for (int j = y1; j <= y2; j++) { if ((i - xCenter) * (i - xCenter) + (j - yCenter) * (j - yCenter) <= radius * radius) { bmp.SetPixel(i, j, BrushColor); } } } }
private void DrawBorder(BitmapWrap bmp, int x, int y) { //x1 y1 левый верхний угол //x2 y2 правый нижний int x1 = x - BrushSize / 2; int x2 = x1 + BrushSize - 1; int y1 = y - BrushSize / 2; int y2 = y1 + BrushSize - 1; //координаты центра double xCenter = (x1 + x2) / (double)2; double yCenter = (y1 + y2) / (double)2; double radius = BrushSize / (double)2; int margin = (int)(BrushSize * 0.5 * (1 - Math.Sqrt(2) / 2)); //проходим по оси x for (int i = x1 + margin; i <= x2 - margin; i++) { double sqrt = Math.Sqrt(radius * radius - (i - xCenter) * (i - xCenter)); bmp.SetPixel(i, (int)(yCenter + sqrt), BrushColor); bmp.SetPixel(i, (int)(yCenter + sqrt - 1), BrushColor); bmp.SetPixel(i, (int)(yCenter - sqrt), BrushColor); bmp.SetPixel(i, (int)(yCenter - sqrt + 1), BrushColor); } //проходим по оси y for (int j = y1 + margin; j <= y2 - margin; j++) { double sqrt = Math.Sqrt(radius * radius - (j - yCenter) * (j - yCenter)); bmp.SetPixel((int)(xCenter + sqrt), j, BrushColor); bmp.SetPixel((int)(xCenter + sqrt - 1), j, BrushColor); bmp.SetPixel((int)(xCenter - sqrt), j, BrushColor); bmp.SetPixel((int)(xCenter - sqrt + 1), j, BrushColor); } }
public void AddToBmpList(PictureBox a) { BitmapWrap bmp = (BitmapWrap)Bmp.Clone(); bitmapList.Add(bmp); m = bitmapList.Count - 1; Bmp = bitmapList[m]; }
public void Render() { Bmp = new BitmapWrap(Width, Height); foreach (Drawfigure f in figures) { f.Draw(this); } }
public void Init(int width, int height) { Bmp = new BitmapWrap(width, height); Cache = new BitmapWrap(width, height); Width = width; Height = height; figures = new List <Drawfigure>(); figuresTmp = new List <Drawfigure>(); }
public void Init(int width, int height) { bitmapList = new List <BitmapWrap>(); Bmp = new BitmapWrap(width, height); Cache = new BitmapWrap(width, height); bitmapList.Add((BitmapWrap)Bmp.Clone()); m = bitmapList.Count - 1; Width = width; Height = height; }
public object Clone() { BitmapWrap bitmapWrap = new BitmapWrap(); bitmapWrap.Bmp = (Bitmap)Bmp.Clone(); bitmapWrap.Width = Bmp.Width; bitmapWrap.Height = Bmp.Height; bitmapWrap.isLocked = false; return(bitmapWrap); }
public void RenderExceptFigure(Drawfigure df) { Bmp = new BitmapWrap(Width, Height); foreach (Drawfigure f in figures) { if (df != f) { f.Draw(this); } } }
//===================================================== Попытка реализовать смещение вершин public int FindPointByPoint(Point p) { Bmp = new BitmapWrap(Width, Height); foreach (Drawfigure f in figures) { if (f.figure.dotlist.Contains(p)) { return(f.figure.dotlist.IndexOf(p)); } } return(-1); }
public Drawfigure FindFigureByPoint(Point p) { Bmp = new BitmapWrap(Width, Height); foreach (Drawfigure f in figures) { if (f.figure.dotlist.Contains(p)) { return(f); } } return(null); }
public override void DrawLine(BitmapWrap bmp, int x1, int y1, int x2, int y2, bool drawFirstDot = false) { PathCalculator lineCalc = new PathCalculator(); List <Tuple <int, int> > dotList = lineCalc.CalculateLinePath(x1, y1, x2, y2); if (drawFirstDot) { DrawDot(bmp, dotList[0].Item1, dotList[0].Item2); } for (int i = 1; i < dotList.Count; i++) { DrawBorder(bmp, dotList[i].Item1, dotList[i].Item2); } }
public override void Fill(BitmapWrap bmp, Point startingPoint) { if (startingPoint.X < 0 || startingPoint.X >= bmp.Width || startingPoint.Y < 0 || startingPoint.Y >= bmp.Height) { return; } Color startingColor = bmp.GetPixel(startingPoint.X, startingPoint.Y); if (startingColor.ToArgb() == FillColor.ToArgb()) { return; } Point point = startingPoint; Queue <Point> pointsToCheck = new Queue <Point>(); pointsToCheck.Enqueue(point); while (pointsToCheck.Count > 0) { point = new Point(pointsToCheck.Peek().X, pointsToCheck.Peek().Y); pointsToCheck.Dequeue(); if (point.X > 0 && bmp.GetPixel(point.X - 1, point.Y).ToArgb() == startingColor.ToArgb()) { bmp.SetPixel(point.X - 1, point.Y, FillColor); pointsToCheck.Enqueue(new Point(point.X - 1, point.Y)); } if (point.X < bmp.Width - 1 && bmp.GetPixel(point.X + 1, point.Y).ToArgb() == startingColor.ToArgb()) { bmp.SetPixel(point.X + 1, point.Y, FillColor); pointsToCheck.Enqueue(new Point(point.X + 1, point.Y)); } if (point.Y > 0 && bmp.GetPixel(point.X, point.Y - 1).ToArgb() == startingColor.ToArgb()) { bmp.SetPixel(point.X, point.Y - 1, FillColor); pointsToCheck.Enqueue(new Point(point.X, point.Y - 1)); } if (point.Y < bmp.Height - 1 && bmp.GetPixel(point.X, point.Y + 1).ToArgb() == startingColor.ToArgb()) { bmp.SetPixel(point.X, point.Y + 1, FillColor); pointsToCheck.Enqueue(new Point(point.X, point.Y + 1)); } } }
public override void DrawDot(BitmapWrap bmp, int x, int y) { //x1 y1 левый верхний угол //x2 y2 правый нижний int x1 = x - BrushSize / 2; int x2 = x1 + BrushSize - 1; int y1 = y - BrushSize / 2; int y2 = y1 + BrushSize - 1; //заполняем for (int i = x1; i <= x2; i++) { for (int j = y1; j <= y2; j++) { bmp.SetPixel(i, j, BrushColor); } } }
public void Draw(AbstractCanvas canvas) { //случай линии if (figure.dotlist.Count == 2) { Drawline drawer = new Drawline(figure.dotlist[0].X, figure.dotlist[0].Y, figure.dotlist[1].X, figure.dotlist[1].Y, brush, true); drawer.Draw(canvas); return; } BitmapWrap tmp = new BitmapWrap(canvas.Width, canvas.Height); tmp.Lock(); IBrush tmpBrush = new SquareBrush(1, fill.FillColor); tmpBrush.DrawLine(tmp, figure.dotlist[0].X, figure.dotlist[0].Y, figure.dotlist[1].X, figure.dotlist[1].Y, true); for (int i = 1; i < figure.dotlist.Count - 1; i++) { tmpBrush.DrawLine(tmp, figure.dotlist[i].X, figure.dotlist[i].Y, figure.dotlist[i + 1].X, figure.dotlist[i + 1].Y); } tmpBrush.DrawLine(tmp, figure.dotlist[figure.dotlist.Count - 1].X, figure.dotlist[figure.dotlist.Count - 1].Y, figure.dotlist[0].X, figure.dotlist[0].Y); if (figure.IsInside(figure.center)) { fill.Fill(tmp, figure.center); } if (!(fill is OnlyFill)) { brush.DrawLine(tmp, figure.dotlist[0].X, figure.dotlist[0].Y, figure.dotlist[1].X, figure.dotlist[1].Y, true); for (int i = 1; i < figure.dotlist.Count - 1; i++) { brush.DrawLine(tmp, figure.dotlist[i].X, figure.dotlist[i].Y, figure.dotlist[i + 1].X, figure.dotlist[i + 1].Y); } brush.DrawLine(tmp, figure.dotlist[figure.dotlist.Count - 1].X, figure.dotlist[figure.dotlist.Count - 1].Y, figure.dotlist[0].X, figure.dotlist[0].Y); } tmp.Unlock(); Graphics g = Graphics.FromImage(canvas.Bmp.Bmp); g.DrawImage(tmp.Bmp, new System.Drawing.Rectangle(0, 0, canvas.Width, canvas.Height)); }
private void DrawDotBorder(BitmapWrap bmp, int x, int y, Direction direction) { int x1 = x - BrushSize / 2; int x2 = x1 + BrushSize - 1; int y1 = y - BrushSize / 2; int y2 = y1 + BrushSize - 1; if (direction == Direction.Up) { for (int i = x1; i <= x2; i++) { bmp.SetPixel(i, y1, BrushColor); } } if (direction == Direction.Down) { for (int i = x1; i <= x2; i++) { bmp.SetPixel(i, y2, BrushColor); } } if (direction == Direction.Left) { for (int j = y1; j <= y2; j++) { bmp.SetPixel(x1, j, BrushColor); } } if (direction == Direction.Right) { for (int j = y1; j <= y2; j++) { bmp.SetPixel(x2, j, BrushColor); } } }
abstract public void DrawDot(BitmapWrap bmp, int x, int y);
public void SaveToCache() { Cache = (BitmapWrap)Bmp.Clone(); //Graphics g = Graphics.FromImage(Cache.Bmp); //g.DrawImage(Bmp.Bmp, new System.Drawing.Rectangle(0, 0, Width, Height)); }
public override void Fill(BitmapWrap bmp, Point point) { //ничего не делаем return; }
abstract public void DrawLine(BitmapWrap bmp, int x1, int y1, int x2, int y2, bool drawFirstDot = false);
public abstract void Fill(BitmapWrap bmp, Point point);