Beispiel #1
0
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right && buttonSwitch is FigureChangingButton == false)
            {
                currentColor = pictureBoxPrevColor.BackColor;
            }


            formCanvas.tmpBitmap = new Bitmap(formCanvas.currentBitmap);
            formCanvas.AddToTmp();
            drawStartFinishFlag = buttonSwitch.ActivateButton(new Point(e.X, e.Y), pictureBox1, ref currentColor, ref currentPainter);
            if (drawStartFinishFlag)
            {
                currentPainter = currentFactory.CreatePainter(currentForm, currentColor, size, new Point(e.X, e.Y), currentFilling);

                //if (currentPainter.typeOfFilling is TotalFilling)
                //{
                //    currentPainter.typeOfFilling.fillingColor = currentColor;
                //}
                //else if (currentPainter.typeOfFilling is InsideFilling)
                //{
                //    currentPainter.typeOfFilling.fillingColor = pictureBoxPrevColor.BackColor;
                //}

                if (PointPolygonPainter.first.X != -1)
                {
                    currentPainter.DrawDynamicFigure(new Point(e.X, e.Y), pictureBox1, shift);
                }
            }


            //fillingColor = pictureBoxPrevColor.BackColor;
        }
Beispiel #2
0
        public void DrawAllFigures(PictureBox pictureBox)
        {
            currentBitmap = new Bitmap(pictureBox.Width, pictureBox.Height);


            //foreach (AbstractPainter f in figures)
            for (int i = figures.Count - 1; i >= 0; i--)
            {
                AbstractPainter f         = figures[i];
                Bitmap          newBitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
                Graphics        g         = Graphics.FromImage(currentBitmap);
                f.brush.DrawFigure(f.formFigure, newBitmap, pictureBox, f.points);
                f.typeOfFilling.Fill(f.formFigure.GetCenter(f.points), pictureBox, newBitmap);
                g.DrawImage(newBitmap, 0, 0, pictureBox.Width - 1, pictureBox.Height - 1);
                pictureBox.Image = currentBitmap;
            }
        }
Beispiel #3
0
        private void ScaleFigure(int dX, int dY, AbstractPainter currentPainter)
        {
            for (int i = 0; i < currentPainter.points.Count; i++)
            {
                if (Math.Abs(tmpPoint.X - currentPainter.points[i].X) <= 10)
                {
                    currentPainter.points[i] = new Point(currentPainter.points[i].X
                                                         + dX, currentPainter.points[i].Y);
                    if (currentPainter.formFigure is FormFigure.IsoTriangleForm)
                    {
                        currentPainter.points[0] = new Point((currentPainter.points[1].X
                                                              + currentPainter.points[2].X) / 2, currentPainter.points[0].Y);
                    }
                }

                if (Math.Abs(tmpPoint.Y - currentPainter.points[i].Y) <= 10)
                {
                    currentPainter.points[i] = new Point(currentPainter.points[i].X,
                                                         currentPainter.points[i].Y + dY);
                }
            }
        }
Beispiel #4
0
        public void RotateFigure(int angle, AbstractPainter currentPainter)
        {
            Point  center   = currentPainter.formFigure.GetCenter(currentPainter.points);
            double angleRad = angle * Math.PI / 180;

            if (tmpPointList.Count == 0)
            {
                for (int i = 0; i < currentPainter.points.Count; i++)
                {
                    tmpPointList.Add(((currentPainter.points[i].X - center.X) * Math.Cos(angleRad) -
                                      (currentPainter.points[i].Y - center.Y) * Math.Sin(angleRad) + center.X));
                    tmpPointList.Add(((currentPainter.points[i].X - center.X) * Math.Sin(angleRad) +
                                      (currentPainter.points[i].Y - center.Y) * Math.Cos(angleRad) + center.Y));
                    //currentPainter.points[i] = new Point((int)x, (int)y);
                }
            }
            else
            {
                for (int i = 0; i < tmpPointList.Count - 1; i += 2)
                {
                    double tmpX = tmpPointList[i];

                    tmpPointList[i] = ((tmpPointList[i] - center.X) * Math.Cos(angleRad) -
                                       (tmpPointList[i + 1] - center.Y) * Math.Sin(angleRad) + center.X);

                    tmpPointList[i + 1] = ((tmpX - center.X) * Math.Sin(angleRad) +
                                           (tmpPointList[i + 1] - center.Y) * Math.Cos(angleRad) + center.Y);
                }
            }

            currentPainter.points.Clear();

            for (int i = 0; i < tmpPointList.Count - 1; i += 2)
            {
                currentPainter.points.Add(new Point((int)(tmpPointList[i]), (int)(tmpPointList[i + 1])));
            }
        }
Beispiel #5
0
        public override void Move(Point p1, PictureBox pictureBox, AbstractPainter currentPainter)
        {
            if (ChangingFlag && currentPainter != null)
            {
                if (Control.ModifierKeys != Keys.Shift && Control.MouseButtons == MouseButtons.Left)
                {
                    currentPainter.MoveFigure(p1.X - tmpPoint.X, p1.Y - tmpPoint.Y);
                }
                else if (Control.ModifierKeys == Keys.Shift)
                {
                    int dY = (int)((p1.Y - tmpPoint.Y) * 1.5);
                    RotateFigure(dY, currentPainter);
                }
                else if (Control.MouseButtons == MouseButtons.Right)
                {
                    int dX = p1.X - tmpPoint.X;
                    int dY = p1.Y - tmpPoint.Y;
                    ScaleFigure(dX, dY, currentPainter);
                }

                tmpPoint = p1;
                Canvas.GetCanvas.DrawAllFigures(pictureBox);
            }
        }
Beispiel #6
0
        public override void Move(Point p1, PictureBox pictureBox, AbstractPainter currentPainter)
        {
            if (ChangingFlag && currentPainter != null && currentPainter.formFigure is EllipseForm)
            {
                if (tmpPoint.X == currentPainter.startPoint.X) //&& tmpPoint.Y != currentPainter.startPoint.Y)
                {
                    foreach (Point f in currentPainter.points)
                    {
                        if (f.Y == currentPainter.startPoint.Y && f.X != currentPainter.startPoint.X)
                        {
                            if (ellipseFlag)
                            {
                                x           = f.X;
                                ellipseFlag = false;
                            }
                            y = p1.Y;

                            break;
                        }
                    }
                }

                if (tmpPoint.Y == currentPainter.startPoint.Y) //&& tmpPoint.X != currentPainter.startPoint.X)
                {
                    foreach (Point f in currentPainter.points)
                    {
                        if (f.X == currentPainter.startPoint.X)
                        {
                            if (ellipseFlag)
                            {
                                y           = f.Y;
                                ellipseFlag = false;
                            }
                            x = p1.X;

                            break;
                        }
                    }
                }

                //foreach(Point f in currentPainter.points)
                //{
                //    if (f.X == currentPainter.startPoint.X)
                //    {
                //        if (((currentPainter.startPoint.Y < f.Y) && (currentPainter.startPoint.Y < tmpPoint.Y)) || ((currentPainter.startPoint.Y > f.Y) && (currentPainter.startPoint.Y > tmpPoint.Y)))
                //        {
                //            y = f.Y;
                //        }
                //    }
                //    else if((f.Y == currentPainter.startPoint.Y))
                //    if (((currentPainter.startPoint.X < f.X) && (currentPainter.startPoint.X < tmpPoint.X)) || ((currentPainter.startPoint.X > f.X) && (currentPainter.startPoint.X > tmpPoint.X)))
                //        {
                //            x = f.X;
                //        }

                //}
                //int dX = (int)(x / tmpPoint.X);
                //int dY = (int)(y / tmpPoint.Y);
                //x += (p1.X - tmpPoint.X) * dX;
                //y += p1.Y - tmpPoint.Y * dY;

                //if (y == currentPainter.startPoint.Y)
                //    y++;
                //if (new Point(x,y) != currentPainter.startPoint)
                pointForResize = new Point(x, y);

                currentPainter.points = currentPainter.formFigure.CalculateFigure(currentPainter.startPoint, pointForResize);
                Canvas.GetCanvas.DrawAllFigures(pictureBox);
            }
            else if (ChangingFlag && currentPainter != null && currentPainter.formFigure is CircleForm)
            {
                currentPainter.points = currentPainter.formFigure.CalculateFigure(currentPainter.startPoint, p1);
                Canvas.GetCanvas.DrawAllFigures(pictureBox);
            }
            else if (ChangingFlag && currentPainter != null)
            {
                currentPainter.points[tmpIndex] = p1;
                Canvas.GetCanvas.DrawAllFigures(pictureBox);
            }
            Canvas.GetCanvas.PointChangeMode(pictureBox);
        }
Beispiel #7
0
 public override bool ActivateButton(Point p1, PictureBox pictureBox, ref Color currentColor, ref AbstractPainter currentPainter)
 {
     currentPainter = Canvas.GetCanvas.FindFigureByPoint1(p1, ref tmpPoint);
     tmpIndex       = Canvas.GetCanvas.FindPointByPoint(tmpPoint);
     ChangingFlag   = true;
     return(false);
 }
Beispiel #8
0
 public override bool ActivateButton(Point p1, PictureBox pictureBox, ref Color currentColor, ref AbstractPainter currentPainter)
 {
     currentPainter = Canvas.GetCanvas.FindFigureByPoint1(p1);
     if (currentPainter != null)
     {
         currentPainter.brush.currentColor = currentColor;
     }
     tmpPoint     = p1;
     ChangingFlag = true;
     return(false);
 }
Beispiel #9
0
 public override void Move(Point p1, PictureBox pictureBox, AbstractPainter currentPainter)
 {
 }
Beispiel #10
0
        public override bool ActivateButton(Point p1, PictureBox pictureBox, ref Color currentColor, ref AbstractPainter currentPainter)
        {
            AbstractFilling filler = new TotalFilling(currentColor);

            filler.Fill(p1, pictureBox, Canvas.GetCanvas.currentBitmap);

            return(false);
        }
Beispiel #11
0
 public override bool ActivateButton(Point p1, PictureBox pictureBox, ref Color currentColor, ref AbstractPainter abstractPainter)
 {
     currentColor = Canvas.GetCanvas.currentBitmap.GetPixel(p1.X, p1.Y);
     return(false);
 }
Beispiel #12
0
 public override bool ActivateButton(Point p1, PictureBox pictureBox, ref Color currentColor, ref AbstractPainter abstractPainter)
 {
     return(true);
 }
Beispiel #13
0
 public abstract void Move(Point p1, PictureBox pictureBox, AbstractPainter currentPainter);
Beispiel #14
0
 public abstract bool ActivateButton(Point p1, PictureBox pictureBox, ref Color currentColor, ref AbstractPainter abstractPainter);
Beispiel #15
0
        //AbstractPainter tmpPainter;


        public override bool ActivateButton(Point p1, PictureBox pictureBox, ref Color currentColor, ref AbstractPainter abstractPainter)
        {
            foreach (AbstractPainter f in Canvas.GetCanvas.figures)
            {
                for (int i = 0; i < f.points.Count; i++)
                {
                    if (i != f.points.Count - 1)
                    {
                        tmpPoint = GetLinePoints(f.points[i], f.points[i + 1], p1);
                        if (tmpPoint.X != -1)
                        {
                            //tmpPainter = f;
                            f.points.Insert(i + 1, tmpPoint);
                            //tmpIndex = i;
                            break;
                        }
                    }
                    else
                    {
                        tmpPoint = GetLinePoints(f.points[i], f.points[0], p1);
                        if (tmpPoint.X != -1)
                        {
                            //tmpPainter = f;
                            f.points.Insert(i + 1, tmpPoint);
                            //tmpIndex = i;
                            break;
                        }
                    }
                }
                if (tmpPoint.X != -1)
                {
                    break;
                }
            }
            Canvas.GetCanvas.DrawAllFigures(pictureBox);
            return(false);
        }
Beispiel #16
0
        public override void Move(Point p1, PictureBox pictureBox, AbstractPainter currentPainter)
        {
            if (ChangingFlag && currentPainter != null)
            {
                Point  checkPoint = currentPainter.points[0];
                double minSum     = 100000000000;


                for (int i = 0; i < currentPainter.points.Count - 1; i++)
                {
                    if (Math.Abs((currentPainter.points[i].X + currentPainter.points[i].Y) - (tmpPoint.X + tmpPoint.Y)) < minSum)

                    {
                        minSum     = Math.Abs((currentPainter.points[i].X + currentPainter.points[i].Y) - (tmpPoint.X + tmpPoint.Y));
                        checkPoint = currentPainter.points[i];
                    }
                }
                // checkPoint = currentPainter.points[_i];

                for (int i = 0; i < currentPainter.points.Count - 1; i++)
                {
                    double A = currentPainter.points[i].Y - checkPoint.Y;
                    double B = checkPoint.X - currentPainter.points[i].X;
                    double C = currentPainter.points[i].X * checkPoint.Y - checkPoint.X * currentPainter.points[i].Y;


                    if ((tmpPoint.X * A + tmpPoint.Y * B + C < 3) && (tmpPoint.X * A + tmpPoint.Y * B + C > -3))
                    {
                        pictureBox.BackColor = Color.Red;

                        checkPoint = new Point();
                        currentPainter.points[i] = new Point();

                        //checkPoint = new Point(checkPoint.X+Math.Abs(checkPoint.X - tmpPoint.X), checkPoint.Y + Math.Abs(checkPoint.Y - tmpPoint.Y));
                        // currentPainter.points[i] = new Point(currentPainter.points [i].X+ Math.Abs( currentPainter.points[i].X - tmpPoint.X), currentPainter.points[i].Y + Math.Abs(currentPainter.points[i].Y - tmpPoint.Y));
                    }
                }
                //{
                //    Point first = currentPainter.points[i];
                //    int j = i + 1;
                //    while (j< currentPainter.points.Count - 1)
                //    {
                //        Point second = currentPainter.points[j];

                //        double A = second.Y - first.Y;
                //        double B = first.X - second.X;
                //        double C = second.X * first.Y - first.X * second.Y;

                //        if (tmpPoint.X*A+tmpPoint.Y*B+C==0)
                //        {
                //            pictureBox.BackColor = Color.Red;
                //            currentPainter.points[i] = new Point(first.X+50, first.Y);
                //            currentPainter.points[j] = new Point(second.X+50, second.Y);
                //        }
                //        j++;
                //    }

                //}

                //Point p2; // = tmpIndex+1 != currentPainter.points.Count? currentPainter.points[tmpIndex + 1] : currentPainter.points[0];
                //int p2Index;
                //if (tmpIndex + 1 < currentPainter.points.Count)
                //{
                //    p2 = currentPainter.points[tmpIndex + 1];
                //    p2Index = tmpIndex + 1;
                //}
                //else
                //{
                //    p2 = currentPainter.points[0];
                //    p2Index = 0;
                //}
                //Point p1New = p1 + dx;
                ////Point p2New = p2 + dy;
                //p1.X = tmpPoint.X + p1.X;
                //p1.Y  = tmpPoint.Y  + p1.Y ;
                //p2.X = tmpPoint.X + p2.X;
                //p2.Y  = tmpPoint.Y  + p2.Y ;



                //if (k>0)
                //{
                //    int d= Math.Abs(b-)
                //}

                //if ( tmpPoint.X == p2.X)
                //{
                //    int dx =  tmpPoint.X-p1.X;
                //    currentPainter.points[tmpIndex] = new Point(p1.X+ dx, p1.Y);
                //    currentPainter.points[p2Index] = new Point(p2.X + dx, p2.Y);
                //}
                //else if (tmpPoint.Y == p2.Y)
                //{\
                //    int dy = tmpPoint.Y-p1.Y ;
                //    currentPainter.points[tmpIndex] = new Point(p1.X, p1.Y+dy);
                //    currentPainter.points[p2Index] = new Point(p2.X, p2.Y+dy);
                //}

                //else if ((tmpPoint.Y != p2.Y) && (tmpPoint.X != p2.X))
                //{
                //    //double k = (p2.Y - tmpPoint.Y) / (tmpPoint.X - p2.X);
                //   // double b = -(p2.X * tmpPoint.Y - tmpPoint.X * p2.Y) / (tmpPoint.X - p2.X);

                //    // int d = Convert.ToInt32(b-(-((p2.X * p1.Y - p1.X * p2.Y) / (p1.X - p2.X))) );

                //   // int d = Convert.ToInt32( b - p1.X);
                //    currentPainter.points[tmpIndex] = new Point(tmpPoint.X, p1.Y);
                //    currentPainter.points[p2Index] = new Point(tmpPoint.X, p2.Y);


                //}



                //tmpPoint = p1;
                //currentPainter.points[tmpIndex] = p1;
            }

            Canvas.GetCanvas.DrawAllFigures(pictureBox);
        }