private void OnPctbClick(object sender, MouseEventArgs e) { var pctb = (PictureBox)tbcMain.SelectedTab.Controls[0]; var ti = TileHandler.GetTileImage((TileTab)tbcMain.SelectedIndex); var tileSize = ti.TileSize; var xStart = pctb.Width / 2 - TileHandler.GetWidth((TileTab)tbcMain.SelectedIndex) / 2; var yStart = pctb.Height / 2 - TileHandler.GetHeight((TileTab)tbcMain.SelectedIndex) / 2; int xPos = (e.X - xStart) / tileSize; int yPos = (e.Y - yStart) / tileSize; TileHandler.SelectTile(xPos, yPos, (TileTab)tbcMain.SelectedIndex, e.Clicks); lblSelectedTile.Text = "Selected Tile: " + TileHandler.SelectedTile; //Init the selected tile neighbor test. pctb.Invalidate(); ReloadSelectedTilesPanel(); }
private void pctbMain_MouseMove(object sender, MouseEventArgs e) { var pctb = _PictureBoxes[tbcMain.SelectedIndex]; var grid = (TileTab)tbcMain.SelectedIndex == TileTab.Randomized ? TileHandler.RandomizedMap : TileHandler.RuleTestMap; var xStart = pctb.Image.Width / 2 - TileHandler.GetWidth((TileTab)tbcMain.SelectedIndex) / 2; var yStart = pctb.Image.Height / 2 - TileHandler.GetHeight((TileTab)tbcMain.SelectedIndex) / 2; int xPos = (e.X - xStart) / TileHandler.TileSize; int yPos = (e.Y - yStart) / TileHandler.TileSize; if (tbcMain.SelectedIndex != 0 && (xPos >= grid.GetLength(0) || yPos >= grid.GetLength(1))) { return; } if (tbcMain.SelectedIndex == 0) { stlblTileId.Text = (TileHandler.GetTileIndex(xPos, yPos, (TileTab)tbcMain.SelectedIndex)).ToString(); } else { stlblTileId.Text = grid[xPos, yPos].ToString(); } }
private void OnMainPaint(object sender, PaintEventArgs e) { if (!_EnableGrid) { return; } var tileSize = TileHandler.GetTileImage((TileTab)tbcMain.SelectedIndex).TileSize; var pctb = (PictureBox)tbcMain.SelectedTab.Controls[0]; var ti = TileHandler.GetTileImage((TileTab)tbcMain.SelectedIndex); var xStart = pctb.Width / 2 - TileHandler.GetWidth((TileTab)tbcMain.SelectedIndex) / 2; var yStart = pctb.Height / 2 - TileHandler.GetHeight((TileTab)tbcMain.SelectedIndex) / 2; Graphics g = e.Graphics; int xCount = ti.Image.Width / tileSize + 1; int yCount = ti.Image.Height / tileSize + 1; Pen p = new Pen(Color.Black); Brush red = new SolidBrush(Color.FromArgb(50, 255, 10, 10)); Brush blue = new SolidBrush(Color.FromArgb(50, 10, 10, 255)); Brush green = new SolidBrush(Color.FromArgb(50, 10, 255, 10)); Brush gray = new SolidBrush(Color.FromArgb(100, 10, 10, 10)); //Draw grid. for (int y = 0; y < yCount; y++) { g.DrawLine(p, xStart, yStart + y * tileSize, xStart + (xCount - 1) * tileSize, yStart + y * tileSize); } for (int x = 0; x < xCount; x++) { g.DrawLine(p, xStart + x * tileSize, yStart, xStart + x * tileSize, yStart + (yCount - 1) * tileSize); } //Draw cell groups. foreach (var t in ti.GetTiles()) { var x = xStart + (t.Index % ti.ColumnsPerRow) * ti.TileSize; var y = yStart + (t.Index / ti.ColumnsPerRow) * ti.TileSize; if (t.SelectionGroup == TileSelectionGroups.Blue) { g.FillRectangle(blue, x, y, tileSize, tileSize); } else if (t.SelectionGroup == TileSelectionGroups.Green) { g.FillRectangle(green, x, y, tileSize, tileSize); } else if (t.SelectionGroup == TileSelectionGroups.Red) { g.FillRectangle(red, x, y, tileSize, tileSize); } if (TileHandler.SelectedTiles.Contains(t.Index)) { g.FillRectangle(gray, x, y, tileSize, tileSize); } } //Draw cell selections. foreach (var t in TileHandler.SelectedTiles) { var x = xStart + (t % ti.ColumnsPerRow) * ti.TileSize; var y = yStart + (t / ti.ColumnsPerRow) * ti.TileSize; if (TileHandler.SelectedTiles.Contains(t)) { g.FillRectangle(gray, x, y, tileSize, tileSize); } } }