示例#1
0
        private void canvasMapa_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            start = e.GetPosition(this.canvasMapa);
            Dogadjaj d = razdaljina(start);


            if (d != null)
            {
                if (System.Windows.Forms.MessageBox.Show("Potvrdom ce se odabrani dogadjaj ukloniti sa mape. ", "potvrda", System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Question, System.Windows.Forms.MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.OK)
                {
                    for (int i = 0; i < mapaIkonica.Count; i++)
                    {
                        if (mapaIkonica[i].Do.Equals(d))
                        {
                            Ikonica tempS = mapaIkonica[i];
                            canvasMapa.Children.RemoveAt(i);

                            foreach (Tip t in Tipovi.listaTipova)  //vrati ga u stablo
                            {
                                if (t.Oznaka.Equals(d.Tip))
                                {
                                    t.DogadjajiTipa.Add(d);
                                }
                            }

                            mapaIkonica.RemoveAt(i);
                            break;
                        }
                    }
                }
            }
        }
示例#2
0
        private bool CanDrop(double x, double y, Ikonica ikonica)
        {
            foreach (Ikonica ic in mapaIkonica)
            {
                if (ic != ikonica)
                {
                    if (Math.Abs(ic.X - x) < 15 && Math.Abs(ic.Y - y) < 20)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#3
0
        private void canvasMapa_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("myFormat"))
            {
                Dogadjaj sp = e.Data.GetData("myFormat") as Dogadjaj;

                foreach (Tip t in Tipovi.listaTipova)
                {
                    foreach (Dogadjaj dog in t.DogadjajiTipa)
                    {
                        if (dog.Equals(sp))
                        {
                            t.DogadjajiTipa.Remove(dog);
                            break;
                        }
                    }
                }

                Image ikonica = new Image();
                ikonica.Height = 20;
                ikonica.Width  = 20;
                ikonica.Name   = sp.Oznaka;
                ImageSourceConverter imgConv = new ImageSourceConverter();
                string      path             = sp.Ikona;
                ImageSource imageSource      = (ImageSource)imgConv.ConvertFromString(path);
                ikonica.Source  = imageSource;
                ikonica.ToolTip = "Oznaka: " + sp.Oznaka + "\nIme: " + sp.Ime + "\nTip: " + sp.Tip;
                if (!promena)
                {
                    this.canvasMapa.Children.Add(ikonica);

                    Point p = e.GetPosition(this.canvasMapa);

                    Ikonica saCanvasa = new Ikonica(e.GetPosition(this.canvasMapa).X, e.GetPosition(this.canvasMapa).Y, sp);

                    if (CanDrop(e.GetPosition(this.canvasMapa).X, e.GetPosition(this.canvasMapa).Y, saCanvasa))
                    {
                        Canvas.SetLeft(ikonica, p.X);
                        Canvas.SetTop(ikonica, p.Y);

                        Ikonica icon = new Ikonica(p.X, p.Y, sp);
                        mapaIkonica.Add(icon);
                    }
                    else
                    {
                        foreach (Tip t in Tipovi.listaTipova)
                        {
                            if (t.Oznaka.Equals(sp.Tip))
                            {
                                t.DogadjajiTipa.Add(sp);
                            }
                        }

                        this.canvasMapa.Children.Remove(ikonica);
                        MessageBox.Show("Izaberite drugu lokaciju.");
                    }
                }
                else
                {
                    Point p = e.GetPosition(this.canvasMapa);
                    for (int i = 0; i < mapaIkonica.Count; i++)
                    {
                        if (mapaIkonica[i].Do.Oznaka.Equals(sp.Oznaka))
                        {
                            Ikonica saCanvasa = mapaIkonica[i];
                            canvasMapa.Children.RemoveAt(i);
                            canvasMapa.Children.Insert(i, ikonica);

                            int flagg = 0;
                            if (!CanDrop(e.GetPosition(this.canvasMapa).X, e.GetPosition(this.canvasMapa).Y, saCanvasa))
                            {
                                p.X   = saCanvasa.X;
                                p.Y   = saCanvasa.Y;
                                flagg = 1;
                            }

                            Canvas.SetLeft(ikonica, p.X);
                            Canvas.SetTop(ikonica, p.Y);

                            mapaIkonica[i].X = p.X;
                            mapaIkonica[i].Y = p.Y;


                            if (flagg == 1)
                            {
                                MessageBox.Show("Izaberite drugu lokaciju.");
                            }

                            break;
                        }
                    }
                }
            }
        }