private void Form1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { for (int widthTrav = 0; widthTrav < width; widthTrav++) { for (int heightTrav = 0; heightTrav < height; heightTrav++) { if (m_rectangles[widthTrav][heightTrav].boxRec.IntersectsWith(new Rectangle(e.Location, new Size(1, 1)))) { m_lastBoxType = m_rectangles[widthTrav][heightTrav].boxType; m_lastBoxSelect = m_rectangles[widthTrav][heightTrav]; switch (m_lastBoxType) { case BoxType.Normal: case BoxType.Wall: m_rectangles[widthTrav][heightTrav].SwitchBox(); this.Invalidate(); break; case BoxType.Start: case BoxType.End: break; } } } } } }
private void Form1_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { m_lastBoxSelect = null; } }
public GridLine(GridBox iFrom, GridBox iTo) { this.fromX = iFrom.boxRec.X + 9; this.fromY = iFrom.boxRec.Y + 9; this.toX = iTo.boxRec.X + 9; this.toY = iTo.boxRec.Y + 9; pen = new Pen(Color.Yellow); pen.Width = 2; }
public SearchGridForm() { InitializeComponent(); this.DoubleBuffered = true; m_resultBox = new List<ResultBox>(); this.Width = (width+1) * 20; this.Height = (height+1) * 20 +100; this.MaximumSize = new Size(this.Width, this.Height); this.MaximizeBox = false; m_rectangles = new GridBox[width][]; for (int widthTrav = 0; widthTrav < width; widthTrav++) { m_rectangles[widthTrav] = new GridBox[height]; for (int heightTrav = 0; heightTrav < height; heightTrav++) { if(widthTrav==(width/3) && heightTrav==(height/2)) m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 20, heightTrav * 20 + 50, BoxType.Start); else if (widthTrav == 41 && heightTrav == (height / 2)) m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 20 , heightTrav * 20 + 50, BoxType.End); else m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 20, heightTrav * 20 + 50, BoxType.Normal); } } m_resultLine = new List<GridLine>(); //Grid searchGrid=new Grid(width,height,movableMatrix); //BaseGrid searchGrid = new StaticGrid(width, height, movableMatrix); //searchGrid = new DynamicGrid(); searchGrid = new DynamicGridWPool(SingletonHolder<NodePool>.Instance); jumpParam = new JumpPointParam(searchGrid, true, cbCrossCorners.Checked, cbCrossAdjacentPoint.Checked, HeuristicMode.EUCLIDEAN);//new JumpPointParam(searchGrid, startPos, endPos, cbCrossCorners.Checked, HeuristicMode.EUCLIDEANSQR); jumpParam.UseRecursive = cbUseRecursive.Checked; }
public SearchGridForm() { InitializeComponent(); this.DoubleBuffered = true; m_resultBox = new List <ResultBox>(); this.Width = (width + 1) * 20; this.Height = (height + 1) * 20 + 100; this.MaximumSize = new Size(this.Width, this.Height); this.MaximizeBox = false; m_rectangles = new GridBox[width][]; for (int widthTrav = 0; widthTrav < width; widthTrav++) { m_rectangles[widthTrav] = new GridBox[height]; for (int heightTrav = 0; heightTrav < height; heightTrav++) { if (widthTrav == (width / 3) && heightTrav == (height / 2)) { m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 20, heightTrav * 20 + 50, BoxType.Start); } else if (widthTrav == 41 && heightTrav == (height / 2)) { m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 20, heightTrav * 20 + 50, BoxType.End); } else { m_rectangles[widthTrav][heightTrav] = new GridBox(widthTrav * 20, heightTrav * 20 + 50, BoxType.Normal); } } } m_resultLine = new List <GridLine>(); //Grid searchGrid=new Grid(width,height,movableMatrix); //BaseGrid searchGrid = new StaticGrid(width, height, movableMatrix); //searchGrid = new DynamicGrid(); searchGrid = new DynamicGridWPool(SingletonHolder <NodePool> .Instance); jumpParam = new JumpPointParam(searchGrid, true, cbCrossCorners.Checked, cbCrossAdjacentPoint.Checked, HeuristicMode.EUCLIDEAN);//new JumpPointParam(searchGrid, startPos, endPos, cbCrossCorners.Checked, HeuristicMode.EUCLIDEANSQR); jumpParam.UseRecursive = cbUseRecursive.Checked; }
private void Form1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (m_lastBoxSelect == null) { for (int widthTrav = 0; widthTrav < width; widthTrav++) { for (int heightTrav = 0; heightTrav < height; heightTrav++) { if (m_rectangles[widthTrav][heightTrav].boxRec.IntersectsWith(new Rectangle(e.Location, new Size(1, 1)))) { m_lastBoxType = m_rectangles[widthTrav][heightTrav].boxType; m_lastBoxSelect = m_rectangles[widthTrav][heightTrav]; switch (m_lastBoxType) { case BoxType.Normal: case BoxType.Wall: m_rectangles[widthTrav][heightTrav].SwitchBox(); this.Invalidate(); break; case BoxType.Start: case BoxType.End: break; } } } } return; } else { for (int widthTrav = 0; widthTrav < width; widthTrav++) { for (int heightTrav = 0; heightTrav < height; heightTrav++) { if (m_rectangles[widthTrav][heightTrav].boxRec.IntersectsWith(new Rectangle(e.Location, new Size(1, 1)))) { if (m_rectangles[widthTrav][heightTrav] == m_lastBoxSelect) { return; } else { switch (m_lastBoxType) { case BoxType.Normal: case BoxType.Wall: if (m_rectangles[widthTrav][heightTrav].boxType == m_lastBoxType) { m_rectangles[widthTrav][heightTrav].SwitchBox(); m_lastBoxSelect = m_rectangles[widthTrav][heightTrav]; this.Invalidate(); } break; case BoxType.Start: m_lastBoxSelect.SetNormalBox(); m_lastBoxSelect = m_rectangles[widthTrav][heightTrav]; m_lastBoxSelect.SetStartBox(); this.Invalidate(); break; case BoxType.End: m_lastBoxSelect.SetNormalBox(); m_lastBoxSelect = m_rectangles[widthTrav][heightTrav]; m_lastBoxSelect.SetEndBox(); this.Invalidate(); break; } } } } } } } }