Esempio n. 1
0
        public MainWindow()
        {
            InitializeComponent();
            drawingField.Background = new SolidColorBrush(Colors.White);
            this.figureLb.SelectionChanged+=(s,e) =>
                {
                    if (currentPlacing!=null)
                    {
                        drawingField.Children.Remove(currentPlacing);
                    }
                    draging = null;
                    resize = null;
                    foreach (Figuur fig in selected)
                    {
                        drawingField.Children.Remove(fig.getSizeAdorner());
                        fig.getGraphics().Stroke = new SolidColorBrush(Colors.Black);
                        fig.getGraphics().StrokeThickness = 2;
                    }
                    selected.Clear();
                };
            this.KeyDown += (s, e) =>
                {
                    if(e.Key == Key.Delete)
                    {

                        if (selected !=null && selected.Count != 0)
                        {
                            foreach(Figuur fig in selected)
                            {
                                drawingField.Children.Remove(fig.getGraphics());
                                drawingField.Children.Remove(fig.getSizeAdorner());
                                this.shapes.Remove(fig);
                            }
                            selected.Clear();
                        }

                    }

                };
        }
Esempio n. 2
0
        private void drawingField_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (currentPlacing != null)
            {
                //figuur te klein om te plaatsen
                if (currentPlacing.Height < 10 && currentPlacing.Width < 10 || Double.IsNaN(currentPlacing.Height)|| Double.IsNaN(currentPlacing.Width))
                {
                    drawingField.Children.Remove(currentPlacing);
                }
                else
                {
                    //vierkant plaatsen
                    if (currentPlacing is Rectangle)
                    {
                        shapes.Add(new Vierkant(Canvas.GetLeft(currentPlacing), Canvas.GetTop(currentPlacing), currentPlacing.Width, currentPlacing.Height, currentPlacing));
                    }
                    else if (currentPlacing is Ellipse)
                    {
                        //rondje plaatsen
                        shapes.Add(new Rondje(Canvas.GetLeft(currentPlacing), Canvas.GetTop(currentPlacing), currentPlacing.Width, currentPlacing.Height, currentPlacing));
                    }
                }
                currentPlacing = null;
            }
            else if (selectionRectangle != null)
            {
                //Selectie uitrekenen 
              double x =   Canvas.GetLeft(selectionRectangle);
              double y = Canvas.GetTop(selectionRectangle);
              double width = selectionRectangle.Width;
              double height = selectionRectangle.Height;
       
              drawingField.Children.Remove(selectionRectangle);
              selectionRectangle = null;
                                double max_x = x+width;
                double max_y = y+height;
                if (width < 10 && height < 10 || (Double.IsNaN(width) || Double.IsNaN(height)))
              {
                      foreach (Figuur fig in shapes)
                      {
                          //Controleren of op een figuur is geklikt in plaats van kader eromheen getrokken
                          if (x >= fig.X  && x < fig.X + fig.Width  
                              && y>= fig.Y  && y < fig.Y + fig.Height )
                          {
                              selected.Add(fig);
                              drawingField.Children.Add(fig.getSizeAdorner());
                              fig.getGraphics().Stroke = new SolidColorBrush(Colors.Red);
                              fig.getGraphics().StrokeThickness = 5;
                          }
                      }
              }
              else {
               //Controleren welke figuren binnen selectie vallen, gebeurd nu nog weinig mee.
               foreach(Figuur fig in shapes)
               {
                   if(fig.X > x && fig.X+ fig.Width <max_x
                       && fig.Y > y && fig.Y+ fig.Height <max_y)
                   {
                           selected.Add(fig);
                           drawingField.Children.Add(fig.getSizeAdorner());
                           fig.getGraphics().Stroke = new SolidColorBrush(Colors.Red);
                           fig.getGraphics().StrokeThickness = 5;
                   }
               }
              }



            }
            else if(draging!=null)
            {
                draging = null;
            }
            else if(resize !=null)
            {
                resize = null;
            }

        }
Esempio n. 3
0
        private void drawingField_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                Point positionOfMouse = e.GetPosition(drawingField);
                if (figureLb.SelectedIndex == 0)
                {
                    if (selected.Count == 1 &&
                        positionOfMouse.X >= selected[0].X  && positionOfMouse.X <= selected[0].X + selected[0].Width
                        &&
                             positionOfMouse.Y >= selected[0].Y && positionOfMouse.Y <= selected[0].Y + selected[0].Height)
                    {
                        draging = selected[0];
                        draging.getGraphics().Stroke = new SolidColorBrush(Colors.RoyalBlue);

                    }
                    else if (selected.Count == 1 && 
                        positionOfMouse.X >= selected[0].X+selected[0].Width && positionOfMouse.X <= selected[0].X + selected[0].Width+10
                        &&
                             positionOfMouse.Y >= selected[0].Y + selected[0].Height && positionOfMouse.Y <= selected[0].Y + selected[0].Height + 10)
                    {
                        resize = selected[0];
                        positionOfMouse.X = resize.X;
                        positionOfMouse.Y = resize.Y;

                        this.startingPoint = positionOfMouse;
                    }
                    else
                    {
                       foreach(Figuur fig in selected)
                       {
                           drawingField.Children.Remove(fig.getSizeAdorner());
                           fig.getGraphics().Stroke = new SolidColorBrush(Colors.Black);
                           fig.getGraphics().StrokeThickness = 2;
                       }
                       selected.Clear();
                        //selection tool geselecteerd
                        startingPoint = positionOfMouse;
                        selectionRectangle = new Rectangle();
                        selectionRectangle.Stroke = new SolidColorBrush(Colors.Black);
                        selectionRectangle.StrokeThickness = 5;
                        selectionRectangle.StrokeDashArray = new DoubleCollection { 5, 10 };
                        selectionRectangle.Fill = new SolidColorBrush(Colors.Blue);
                        selectionRectangle.Opacity = 0.25f;

                        drawingField.Children.Add(selectionRectangle);
                        Canvas.SetLeft(selectionRectangle, positionOfMouse.X);
                        Canvas.SetTop(selectionRectangle, positionOfMouse.Y);
                        this.startingPoint = positionOfMouse;
                    }
                    
                }
                else
                {
                    if (figureLb.SelectedIndex == 1)
                    {
                        //rectangle geselecteerd
                        currentPlacing = new Rectangle();
                    }
                    else if (figureLb.SelectedIndex == 2)
                    {
                        //ellipse geselecteerd
                        currentPlacing = new Ellipse();
                    }
                    currentPlacing.Stroke = new SolidColorBrush(Colors.Black);
                    currentPlacing.StrokeThickness = 2;
                    currentPlacing.Fill = new SolidColorBrush(random_colors[(int)positionOfMouse.X % random_colors.Length]);
                    drawingField.Children.Add(currentPlacing);
                    Canvas.SetLeft(currentPlacing, positionOfMouse.X);
                    Canvas.SetTop(currentPlacing, positionOfMouse.Y);
                    this.startingPoint = positionOfMouse;
                }
            }
        }