Beispiel #1
0
        private void LeftMouseClicked(object sender, MouseButtonEventArgs e)//za poligon,ako je levi klik u funkciji
        {
            PolygonWindow polygonWindow = new PolygonWindow();

            if (PolygonClicked && listaTacaka.Count > 0)//dialog se otvara samo ako je pre tog kliknut poligon u menu, i ako ima izabranih tacaka
            {
                polygonWindow.ShowDialog();

                if (!polygonWindow.isClosed)
                {
                    Polygon polygon = new Polygon();
                    for (int i = 0; i < listaTacaka.Count; i++)
                    {
                        points.Add(listaTacaka[i]);
                    }

                    polygon.Points = points;
                    listaTacaka.Clear();
                    polygon.Fill            = new BrushConverter().ConvertFromString(polygonWindow.fillForPolygon) as Brush;
                    polygon.Stroke          = new BrushConverter().ConvertFromString(polygonWindow.borderColorForPolygon) as Brush;
                    polygon.StrokeThickness = polygonWindow.borderThickness;
                    CanvasMain.Children.Add(polygon);
                    idOfClicked = 0;
                }
                else
                {
                    idOfClicked = 0;
                    this.Show();
                }
            }
            else
            {
                if (e.Source is Shape)
                {
                    var whatIsClickedOn = (Shape)(e.Source);
                    if (whatIsClickedOn is Ellipse)
                    {
                        EllipseWindow ellipseWindow = new EllipseWindow();

                        ellipseWindow.TextBoxRadiusX.IsReadOnly = true;
                        ellipseWindow.TextBoxRadiusY.IsReadOnly = true;
                        ellipseWindow.ShowDialog();
                        if (!ellipseWindow.isClosed)
                        {
                            if (ellipseWindow.ColorPickerForFill.SelectedColor == null)
                            {
                                whatIsClickedOn.Fill   = whatIsClickedOn.Fill;
                                whatIsClickedOn.Stroke = new BrushConverter().ConvertFromString(ellipseWindow.borderColorForEllipse) as Brush;
                            }
                            else if (ellipseWindow.ColorPickerForBorder.SelectedColor == null)
                            {
                                whatIsClickedOn.Fill   = new BrushConverter().ConvertFromString(ellipseWindow.fillForEllipse) as Brush;
                                whatIsClickedOn.Stroke = whatIsClickedOn.Stroke;
                            }
                            else
                            {
                                whatIsClickedOn.Fill   = new BrushConverter().ConvertFromString(ellipseWindow.fillForEllipse) as Brush;
                                whatIsClickedOn.Stroke = new BrushConverter().ConvertFromString(ellipseWindow.borderColorForEllipse) as Brush;
                            }
                            if (string.IsNullOrEmpty(ellipseWindow.TextBoxForThickness.Text))
                            {
                                whatIsClickedOn.StrokeThickness = whatIsClickedOn.StrokeThickness;
                            }
                            else
                            {
                                whatIsClickedOn.StrokeThickness = ellipseWindow.borderThickness;
                            }
                        }
                        else
                        {
                            this.Show();
                        }
                    }

                    else if (whatIsClickedOn is Rectangle)
                    {
                        RectangleWindow rectangleWindow = new RectangleWindow();

                        rectangleWindow.TextBoxHeight.IsReadOnly = true;
                        rectangleWindow.TextBoxWidth.IsReadOnly  = true;
                        rectangleWindow.ShowDialog();
                        if (!rectangleWindow.isClosed)
                        {
                            if (rectangleWindow.ColorPickerForFill.SelectedColor == null)
                            {
                                whatIsClickedOn.Fill   = whatIsClickedOn.Fill;
                                whatIsClickedOn.Stroke = new BrushConverter().ConvertFromString(rectangleWindow.borderColorForRectangle) as Brush;
                            }
                            else if (rectangleWindow.ColorPickerForBorder.SelectedColor == null)
                            {
                                whatIsClickedOn.Fill   = new BrushConverter().ConvertFromString(rectangleWindow.fillForRectangle) as Brush;
                                whatIsClickedOn.Stroke = whatIsClickedOn.Stroke;
                            }
                            else
                            {
                                whatIsClickedOn.Fill   = new BrushConverter().ConvertFromString(rectangleWindow.fillForRectangle) as Brush;
                                whatIsClickedOn.Stroke = new BrushConverter().ConvertFromString(rectangleWindow.borderColorForRectangle) as Brush;
                            }
                            if (string.IsNullOrEmpty(rectangleWindow.TextBoxForThickness.Text))
                            {
                                whatIsClickedOn.StrokeThickness = whatIsClickedOn.StrokeThickness;
                            }
                            else
                            {
                                whatIsClickedOn.StrokeThickness = rectangleWindow.borderThickness;
                            }
                        }
                        else
                        {
                            this.Show();
                        }
                    }
                    else if (whatIsClickedOn is Polygon)
                    {
                        PolygonWindow poly = new PolygonWindow();
                        poly.ShowDialog();
                        if (!poly.isClosed)
                        {
                            if (poly.ColorPickerForFill.SelectedColor == null)
                            {
                                whatIsClickedOn.Fill   = whatIsClickedOn.Fill;
                                whatIsClickedOn.Stroke = new BrushConverter().ConvertFromString(poly.borderColorForPolygon) as Brush;
                            }
                            else if (poly.ColorPickerForBorder.SelectedColor == null)
                            {
                                whatIsClickedOn.Fill   = new BrushConverter().ConvertFromString(poly.fillForPolygon) as Brush;
                                whatIsClickedOn.Stroke = whatIsClickedOn.Stroke;
                            }
                            else
                            {
                                whatIsClickedOn.Fill   = new BrushConverter().ConvertFromString(poly.fillForPolygon) as Brush;
                                whatIsClickedOn.Stroke = new BrushConverter().ConvertFromString(poly.borderColorForPolygon) as Brush;
                            }
                            if (string.IsNullOrEmpty(poly.TextBoxForBorderThickness.Text))
                            {
                                whatIsClickedOn.StrokeThickness = whatIsClickedOn.StrokeThickness;
                            }
                            else
                            {
                                whatIsClickedOn.StrokeThickness = poly.borderThickness;
                            }
                        }
                        else
                        {
                            this.Show();
                        }
                    }
                }
                else if (e.Source is Image)
                {
                    OpenFileDialog op = new OpenFileDialog();
                    op.Title  = "Select a picture";
                    op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
                                "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
                                "Portable Network Graphic (*.png)|*.png";

                    Image image = (Image)e.Source;

                    if (op.ShowDialog() == true)
                    {
                        image.Source = new BitmapImage(new Uri(op.FileName));
                    }

                    this.Show();
                }
                else
                {
                    this.Show();
                    return;
                }
            }
        }
Beispiel #2
0
        private void CanvasClickedRight(object sender, MouseButtonEventArgs e)
        {
            //ako je kliknuta elipsa
            if (idOfClicked == 1)
            {
                Point         pointofMouse  = e.GetPosition(CanvasMain);//pozicijaKliknutanaCanvasu
                EllipseWindow ellipseWindow = new EllipseWindow();
                ellipseWindow.ShowDialog();

                if (!ellipseWindow.isClosed)
                {
                    Ellipse ellipse = new Ellipse();

                    //preuzimanje svih vrednosti iz prozora
                    ellipse.Height          = ellipseWindow.radiusX;
                    ellipse.Width           = ellipseWindow.radiusY;
                    ellipse.Fill            = new BrushConverter().ConvertFromString(ellipseWindow.fillForEllipse) as Brush;
                    ellipse.Stroke          = new BrushConverter().ConvertFromString(ellipseWindow.borderColorForEllipse) as Brush;
                    ellipse.StrokeThickness = ellipseWindow.borderThickness;
                    Canvas.SetLeft(ellipse, pointofMouse.X);
                    Canvas.SetTop(ellipse, pointofMouse.Y);
                    CanvasMain.Children.Add(ellipse);

                    idOfClicked = 0;
                }
                else
                {
                    idOfClicked = 0;
                    this.Show();
                }
            }
            //ako je kliknut rectangle
            else if (idOfClicked == 2)
            {
                Point           pointofMouse = e.GetPosition(CanvasMain);//pozicijaKliknutanaCanvasu
                RectangleWindow rectWindow   = new RectangleWindow();
                rectWindow.ShowDialog();

                if (!rectWindow.isClosed)
                {
                    Rectangle rect = new Rectangle();
                    //preuzimanje svih vrednosti iz prozora
                    rect.Height          = rectWindow.height;
                    rect.Width           = rectWindow.width;
                    rect.Fill            = new BrushConverter().ConvertFromString(rectWindow.fillForRectangle) as Brush;
                    rect.Stroke          = new BrushConverter().ConvertFromString(rectWindow.borderColorForRectangle) as Brush;
                    rect.StrokeThickness = rectWindow.borderThickness;
                    Canvas.SetLeft(rect, pointofMouse.X);
                    Canvas.SetTop(rect, pointofMouse.Y);
                    CanvasMain.Children.Add(rect);
                    idOfClicked = 0;
                }
                else
                {
                    idOfClicked = 0;
                    this.Show();
                }
            }
            //ako je kliknut polygon
            else if (idOfClicked == 3)
            {
                points = new PointCollection();
                Point pointofMouse = e.GetPosition(CanvasMain);//pozicijaKliknutanaCanvasu
                listaTacaka.Add(pointofMouse);
                points.Clear();
            }
            //ako je kliknuta slika
            else if (idOfClicked == 4)
            {
                Point       pointofMouse = e.GetPosition(CanvasMain);//pozicijaKliknutanaCanvasu
                ImageWindow imageWindow  = new ImageWindow();
                imageWindow.ShowDialog();
                if (!imageWindow.isClosedW)
                {
                    Image image = new Image();
                    image.Height = imageWindow.height;
                    image.Width  = imageWindow.width;

                    BitmapImage bitmap = new BitmapImage();
                    bitmap.BeginInit();
                    bitmap.UriSource         = new Uri(imageWindow.path);
                    bitmap.DecodePixelHeight = (int)imageWindow.height;
                    bitmap.DecodePixelWidth  = (int)imageWindow.width;
                    bitmap.EndInit();
                    image.Source = bitmap;
                    Canvas.SetLeft(image, pointofMouse.X);
                    Canvas.SetTop(image, pointofMouse.Y);
                    CanvasMain.Children.Add(image);
                    idOfClicked = 0;
                }
                else
                {
                    idOfClicked = 0;
                    this.Show();
                }
            }
            else
            {
                return;
            }
        }