Example #1
0
        public void DoubleClickAction(Point p)
        {
            if (dragging && points.Count > 1)
            {
                dragging = false;
                double distX = p.X - points[0].X;
                double distY = p.Y - points[0].Y;
                double dist  = Math.Sqrt(distX * distX + distY * distY);

                if (dist <= 3)
                {
                    points.RemoveAt(points.Count - 1);
                }
                Polygon polygon = new Polygon();
                foreach (Point point in points)
                {
                    polygon.Points.Add(point);
                }
                points.RemoveAll(x => true);
                view.RemoveTempShape();
                model.AddShape(polygon, new Point(0, 0));
                view.RefreshCanvas();
                view.RefreshTable();
            }
        }
Example #2
0
        public static CanvasModel ReadFromFile(string fileName)
        {
            CanvasModel model = new CanvasModel();

            string[] content = File.ReadAllLines(fileName);
            model.CurrentImagePath = content[0];
            try
            {
                model.LoadImage(new BitmapImage(new Uri(content[0])));
            }
            catch (FileNotFoundException e)
            {
                throw new BindedImageFileNotFoundException(content[0]);
            }

            for (int i = 1; i < content.Length; i++)
            {
                string[] tempArr = content[i].Split(';');
                Shape    s       = null;
                Point    p       = new Point();

                if (tempArr[0] == "0")
                {
                    s        = new Ellipse();
                    p        = new Point(double.Parse(tempArr[1]), double.Parse(tempArr[2]));
                    s.Width  = double.Parse(tempArr[3]);
                    s.Height = double.Parse(tempArr[4]);
                }
                else if (tempArr[0] == "1")
                {
                    s        = new Rectangle();
                    p        = new Point(double.Parse(tempArr[1]), double.Parse(tempArr[2]));
                    s.Width  = double.Parse(tempArr[3]);
                    s.Height = double.Parse(tempArr[4]);
                }
                else if (tempArr[0] == "2")
                {
                    s = new Polygon();
                    Polygon pol = (Polygon)s;
                    p = new Point(double.Parse(tempArr[1]), double.Parse(tempArr[2]));

                    for (int j = 3; j < tempArr.Length; j += 2)
                    {
                        if (!string.IsNullOrEmpty(tempArr[j]))
                        {
                            pol.Points.Add(new Point(double.Parse(tempArr[j]), double.Parse(tempArr[j + 1])));
                        }
                    }
                }

                if (s != null)
                {
                    model.AddShape(s, p);
                }
            }
            return(model);
        }
Example #3
0
 public void StopDragAction(Point p)
 {
     if (dragging)
     {
         dragging = false;
         view.RemoveTempShape();
         model.AddShape(rectangle, new Point(Math.Min(p.X, startPoint.X), Math.Min(p.Y, startPoint.Y)));
         view.RefreshCanvas();
         view.RefreshTable();
     }
 }