private void TilesetControl_MouseMove(object sender, MouseEventArgs e) { int w = Width / tile_width * tile_width; int h = Height / tile_height * tile_height; if (_is_multi && _multi_select && e.X > 0 && e.Y > 0 && e.X < w && e.Y < h) { short Current = GetTileIndexAt(e.X, e.Y); if (Current != -1 && !SelectedTiles.Contains(Current)) { SelectedTiles.Add(Current); SelectedX.Add(e.X / tile_width / Zoom); SelectedY.Add(e.Y / tile_height / Zoom); Refresh(); } } if (CanDrag && do_drag && _selection != -1) { int xx = drag_start.X - e.X; int yy = drag_start.Y - e.Y; if (Math.Sqrt(xx * xx + yy * yy) > 4) { Frame frame = new Frame(); frame.Index = (short)_selection; DoDragDrop(new DataObject("ImageFrame", frame), DragDropEffects.All); do_drag = false; } } }
// very important!! public void CompileSelectedTiles() { List <short> list = new List <short>(); // remove invalid tiles from map: while (SelectedTiles.Contains(-1)) { SelectedTiles.Remove(-1); } SelectedTiles.Sort(); SelectedX.Sort(); SelectedY.Sort(); int index = 0; int woz = (Width / twz); int width = SelectedX[SelectedX.Count - 1] - SelectedX[0] + 1; int height = SelectedY[SelectedY.Count - 1] - SelectedY[0] + 1; int h = height * tile_height, w = width * tile_width; if (SelectedMap != null) { SelectedMap.Dispose(); } SelectedMap = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(SelectedMap); for (int y = SelectedY[0]; y < SelectedY[0] + height; ++y) { for (int x = SelectedX[0]; x < SelectedX[0] + width; ++x) { if (index < SelectedTiles.Count && SelectedTiles[index] != x + y * woz) { SelectedTiles.Insert(index, -1); } index++; } } index = 0; for (int y = 0; y < h; y += tile_height) { for (int x = 0; x < w; x += tile_width) { if (index < SelectedTiles.Count && SelectedTiles[index] != -1) { g.DrawImage(tiles[SelectedTiles[index]].Graphic, x, y, tile_width, tile_height); list.Add(SelectedTiles[index]); } else { g.FillRectangle(Brushes.Gray, x, y, tile_width, tile_height); list.Add(-1); } ++index; } } g.Dispose(); SelectedIndices = list.ToArray(); }
private void TilesetControl_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right) { drag_start = e.Location; do_drag = true; if (!_ctrl) { SelectedTiles.Clear(); // if no ctrl-click, clear the selection. SelectedX.Clear(); SelectedY.Clear(); SelectedIndices = SelectedTiles.ToArray(); } short Current = GetTileIndexAt(e.X, e.Y); if (Current != -1) { if (!_is_multi) { _selection = Current; } if (!SelectedTiles.Contains(Current)) { SelectedTiles.Add(Current); SelectedX.Add(e.X / tile_width / Zoom); SelectedY.Add(e.Y / tile_height / Zoom); } else if (_ctrl) { SelectedTiles.Remove(Current); SelectedX.Remove(e.X / tile_width / Zoom); SelectedY.Remove(e.Y / tile_height / Zoom); } } _multi_select = true; Refresh(); } }