private void MainForm_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.F2) { furnitures = new List <Furniture>(); selectedBtn = null; listFurniture.Items.Clear(); listFurniture.Refresh(); widthMap = flowLayoutPanelLeft.Width - 15; heightMap = flowLayoutPanelLeft.Height - 15; bitmap = new Bitmap(flowLayoutPanelLeft.Width - 15, flowLayoutPanelLeft.Height - 15); pictureBox.Image = bitmap; this.DoubleBuffered = true; Graphics graphics = Graphics.FromImage(bitmap); int white = 11; graphics.FillRectangle(Brushes.White, 0, white, flowLayoutPanelLeft.Width - 15, flowLayoutPanelLeft.Height - 15); pictureBox.Image = bitmap; } if (e.KeyCode == Keys.Delete) { for (int i = 0; i < furnitures.Count; i++) { if (furnitures[i].isSelected) { furnitures.RemoveAt(i); listFurniture.Items.RemoveAt(i); previousFurniture = null; DrawFurnitures(); listFurniture.Refresh(); break; } } } }
private void openBluprintToolStripMenuItem_Click(object sender, EventArgs e) { SendKeys.SendWait("{F2}"); string localFilePath = ""; OpenFileDialog ofd = new OpenFileDialog(); JsonSerializer serializer = new JsonSerializer(); ComponentResourceManager resources = new ComponentResourceManager(typeof(MainForm)); if (Thread.CurrentThread.CurrentUICulture.ToString().Trim() == "zh-CN") { SetThreadUILanguage(2052); } else { SetThreadUILanguage(1033); } ofd.Filter = resources.GetString("bpp files (*.bpp)|*.bpp", Thread.CurrentThread.CurrentCulture); ofd.FilterIndex = 1; ofd.RestoreDirectory = true; if (ofd.ShowDialog() == DialogResult.OK) { localFilePath = ofd.FileName.ToString(); using (Stream s = File.Open(ofd.FileName, FileMode.Open)) using (StreamReader sr = new StreamReader(s)) { string line = ""; while (!sr.EndOfStream) { line = sr.ReadLine(); Furniture furniture = JsonConvert.DeserializeObject <Furniture>(line); if (furniture.Name == "Coffee") { furniture.Image = buttonCoffee.BackgroundImage; } if (furniture.Name == "Table") { furniture.Image = buttonTable.BackgroundImage; } if (furniture.Name == "Sofa") { furniture.Image = buttonSofa.BackgroundImage; } if (furniture.Name == "Bed") { furniture.Image = buttonBed.BackgroundImage; } if (furniture.Name == "Walls") { furniture.Image = buttonWalls.BackgroundImage; } furnitures.Add(furniture); string position = "{X=" + furniture.Points.First().X + ", Y=" + furniture.Points.First().Y + "}"; listFurniture.Items.Add(new ListViewItem(new[] { resources.GetString(furniture.Name, Thread.CurrentThread.CurrentCulture), position })); listFurniture.Refresh(); SetSize(); DrawFurnitures(); } MessageBox.Show(resources.GetString("LoadSuccessfully", Thread.CurrentThread.CurrentCulture)); } } }
private void pictureBox_MouseDown(object sender, MouseEventArgs e) { if (bitmap != null && selectedBtn == null && furnitures.Count > 0) { foreach (Furniture furniture in furnitures) { if (furniture.Image != buttonWalls.BackgroundImage) { if (e.Location.X <= furniture.Points.First().X + 2 * (furniture.Image.Width / 2) && e.Location.X >= furniture.Points.First().X&& e.Location.Y <= furniture.Points.First().Y + 2 * (furniture.Image.Height / 2) && e.Location.Y >= furniture.Points.First().Y) { if (previousFurniture == null) { furniture.isSelected = true; previousFurniture = furniture; break; } else { if (furniture == previousFurniture) { continue; } furniture.isSelected = true; previousFurniture.isSelected = false; previousFurniture = furniture; break; } } else { if (previousFurniture != null) { previousFurniture.isSelected = false; previousFurniture = null; } } } if (furniture.Image == buttonWalls.BackgroundImage) { Point minPoint = new Point(furniture.Points.First().X, furniture.Points.First().Y); Point maxPoint = new Point(furniture.Points.First().X, furniture.Points.First().Y); foreach (Point point in furniture.Points) { Point newPoint = RotatePoint(furniture.Points.First(), point, furniture.Angle); if (newPoint.X < minPoint.X) { minPoint.X = newPoint.X; } if (newPoint.X > maxPoint.X) { maxPoint.X = newPoint.X; } if (newPoint.Y < minPoint.Y) { minPoint.Y = newPoint.Y; } if (newPoint.Y > maxPoint.Y) { maxPoint.Y = newPoint.Y; } } if (e.Location.X <= maxPoint.X && e.Location.X >= minPoint.X && e.Location.Y <= maxPoint.Y && e.Location.Y >= minPoint.Y) { if (previousFurniture == null) { furniture.isSelected = true; previousFurniture = furniture; break; } else { if (furniture == previousFurniture) { continue; } furniture.isSelected = true; previousFurniture.isSelected = false; previousFurniture = furniture; break; } } else { if (previousFurniture != null) { previousFurniture.isSelected = false; previousFurniture = null; } } } } dragFlag = true; mouseOffset = e.Location; DrawFurnitures(); } }