Beispiel #1
0
        /// <summary>
        /// Right mouse button action that  choses shape
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DrawCanvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            int count = 0;

            Point t = e.GetPosition((UIElement)sender);

            for (int i = 0; i < collection.Count; ++i)
            {
                HitTestResult result = VisualTreeHelper.HitTest(collection[i].shape, t);
                if (result != null)
                {
                    IsDraw = true;
                    count++;
                    MessageBox.Show("Found!");
                    //i.IsChosen = !i.IsChosen;
                    polygonCanvas.CurrentPolygon        = collection[i];
                    polygonCanvas.CurrentPolygon.Stroke = MyPolygon.FromBrush(Brushes.Red); break;
                }
                else
                {
                    polygonCanvas.CurrentPolygon = new MyPolygon();
                }
            }
            if (count == 0)
            {
                IsDraw = false;
            }
        }
Beispiel #2
0
 public MainWindow()
 {
     IsDraw = false;
     polygonCanvas.Canvas.Children.Add(currentPolygon.shape);
     currentPolygon = new MyPolygon();
     this.InitializeComponent();
     this.DataContext          = this;
     this.polygonCanvas.Canvas = this.DrawCanvs;
 }
 public void AddPolygon(MyPolygon pol)
 {
     this.polygons.Add(pol);
     Canvas.SetZIndex(pol.shape, 0);
     Canvas.SetLeft(pol.shape, pol.TopLeft.X);
     Canvas.SetTop(pol.shape, pol.TopLeft.Y);
     this.Canvas.Children.Add(pol.shape);
     this.OnEllipseAdded?.Invoke(this, new PolygonListChangedEventArgs(pol, this));
 }
        public void RemovePolygon(MyPolygon pol)
        {
            this.polygons.Remove(pol);
            if (ReferenceEquals(this.currentPolygon, pol))
            {
                this.currentPolygon = null;
            }

            Canvas.Children.Remove(pol.shape);
            this.OnEllipseRemoved?.Invoke(this, new PolygonListChangedEventArgs(pol, this));
        }
        public void Clear()
        {
            foreach (MyPolygon pol in this.Polygons)
            {
                this.OnEllipseRemoved?.Invoke(this, new PolygonListChangedEventArgs(pol, this));
            }

            this.currentPolygon = null;
            this.polygons.Clear();
            Canvas.Children.Clear();
        }
Beispiel #6
0
 /// <summary>
 /// Draws canvas
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void DrawCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     if (!IsDraw)
     {
         Point pp = new Point();
         pp = Mouse.GetPosition(this);
         polcol.Add(pp);
         double tempX = (Mouse.GetPosition(this).X) / 6;
         double tempY = (Mouse.GetPosition(this).Y) / 6;
         Point  pt    = new Point(tempX, tempY);
         points.Add(pt);
         ++i;
         if (i > 4)
         {
             MyPolygon newP = new MyPolygon();
             Polygon   tt   = new Polygon
             {
                 Name   = "",
                 Stroke = Brushes.Black,
                 Fill   = Brushes.Yellow,
                 Points = polcol
             };
             Polygon temp = new Polygon
             {
                 Name   = "",
                 Stroke = Brushes.Black,
                 Fill   = Brushes.Yellow,
                 Points = points
             };
             newP.shape = tt;
             ColorDialog a = new ColorDialog(newP);
             a.Owner = this;
             a.Show();
             polygonCanvas.AddPolygon(newP);
             collection.Add(newP);
             temp.Fill = newP.shape.Fill;
             MainMenuAdd(temp);
             polcol = new PointCollection();
             points = new PointCollection();
             i      = 0;
             z++;
         }
     }
 }
        private void button_Click(object sender, RoutedEventArgs e)
        {
            int q = comboBox.SelectedIndex;

            switch (q)
            {
            case 0: testPolygon.Fill = MyPolygon.FromBrush(Brushes.Purple); break;

            case 1: testPolygon.Fill = MyPolygon.FromBrush(Brushes.Black); break;

            case 2: testPolygon.Fill = MyPolygon.FromBrush(Brushes.Red); break;

            case 3: testPolygon.Fill = MyPolygon.FromBrush(Brushes.Green); break;

            case 4: testPolygon.Fill = MyPolygon.FromBrush(Brushes.Pink); break;

            default:
                break;
            }
            this.Close();
        }
Beispiel #8
0
        /// <summary>
        /// Moves shape
        /// </summary>
        /// <param name="pol"></param>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Move(MyPolygon pol, object sender, MouseButtonEventArgs e)
        {
            Point pt = e.GetPosition((UIElement)sender);

            pol.TopLeft = pt;
        }
 public PolygonCanvas()
 {
     this.PolTemp        = new MyPolygon();
     this.PolTemp.Stroke = MyPolygon.FromBrush(Brushes.Green);
     this.PolTemp.shape.StrokeThickness = MyPolygon.DefaultStrokeThickness;
 }
 public void bind(MyPolygon a)
 {
     a = currentPolygon;
 }
 public PolygonListChangedEventArgs(MyPolygon pol, PolygonCanvas canvas)
 {
     this.P      = pol;
     this.Canvas = canvas;
 }
 public ColorDialog(MyPolygon pol)
 {
     InitializeComponent();
     testPolygon = pol;
 }