Ejemplo n.º 1
0
        private void areaMap1_DragDrop(object sender, DragEventArgs e)
        {
            Shape2 shape = null;
            Area   area  = null;

            if (e.Data.GetDataPresent(typeof(Polygon2)))
            {
                shape = (Polygon2)e.Data.GetData(typeof(Polygon2));
            }
            else
            {
                if (e.Data.GetDataPresent(typeof(Area)))
                {
                    area = (Area)e.Data.GetData(typeof(Area));
                }
                else
                {
                    shape = (Circle)e.Data.GetData(typeof(Circle));
                }
            }

            Point mapDropPoint = AreaMapComponent.PointToClient(new Point(e.X, e.Y));

            mapDropPoint.Offset(GeoConverter.ConvertRound(AreaMapComponent.Offset * -1));

            if (shape != null)
            {
                shape.Offset((new Vector2(mapDropPoint.X, mapDropPoint.Y)) * (1f / AreaMapComponent.Scaling));
                shape.Clamp(0, AreaMapComponent.Dimensions.Width, 0, AreaMapComponent.Dimensions.Height);
                AreaMapComponent.AddShape(shape);
                RefreshListBox();
            }
            else if (area != null)
            {
                //Has a picture with path relative to library
                if (area.ImgPath != "" && area.ImgPath != libraryUCtrl1.AreaMapComp.CurrentAreaMap.GetAbsolutePath(area.ImgPath))
                {
                    if (AreaMapComponent.CurrentAreaMap.Path != "")
                    {
                        area.Map = libraryUCtrl1.AreaMapComp.CurrentAreaMap;
                        AreaMapComponent.Migrate(area, PathHelper.GetFolderPath(AreaMapComponent.CurrentAreaMap.Path));
                    }
                    else
                    {
                        MessageBox.Show("You must save your AreaMap to be able to use library items with relative pictures !", "File not saved");
                        return;
                    }
                }

                area.Center = (new Vector2(mapDropPoint.X, mapDropPoint.Y)) * (1f / AreaMapComponent.Scaling);
                area.Clamp(0, AreaMapComponent.Dimensions.Width, 0, AreaMapComponent.Dimensions.Height);
                area.SetRefCenter();
                AreaMapComponent.AddArea(area);
                RefreshListBox();
            }
        }
Ejemplo n.º 2
0
        private void shapeSymYBT_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItems.Count > 0)
            {
                string areaText = "";

                List <Area> selectedAreas = new List <Area>();
                foreach (object areaObj in listBox1.SelectedItems)
                {
                    Area area = areaObj as Area;
                    if (!area.IsSubComponent)
                    {
                        area = area.Clone();
                        AreaMapComponent.AddArea(area);
                        AreaMapComponent.SymmetrizeY(area);

                        //Search if Area already exists
                        int  index        = 0;
                        Area existingArea = null;
                        foreach (Area oldArea in AreaMapComponent.CurrentAreaMap.Areas)
                        {
                            if (oldArea.Name == area.Name && area != oldArea)
                            {
                                existingArea = oldArea;
                                break;
                            }
                            index++;
                        }

                        if (existingArea != null)
                        {
                            AreaMapComponent.RemoveAreas(new List <Area> {
                                existingArea
                            });

                            if (index < AreaMapComponent.CurrentAreaMap.Areas.Count - 1)
                            {
                                AreaMapComponent.CurrentAreaMap.Areas.Remove(area);
                                AreaMapComponent.CurrentAreaMap.Areas.Insert(index, area);
                            }
                        }
                    }
                }

                RefreshListBox();
            }
        }