private void ReconstructSelectionGrid() { int width = 0; int height = 0; // Can only reconstruct if there is a brush and layer selected. if (brushesViewModel.Selected != null && tilesetsViewModel.Selected != null) { width = brushesViewModel.Selected.Width * tilesetsViewModel.Selected.TileWidth; height = brushesViewModel.Selected.Height * tilesetsViewModel.Selected.TileHeight; } BrushBucket bucket = editor.GetBrushBucketForSelectedTileset(); TileBrush brush = bucket.SelectedBrush; selectionGridManager.Reconstruct(width, height, tilesetsViewModel.Selected.TileWidth, tilesetsViewModel.Selected.TileHeight, brush.SelectedIndexX * tilesetsViewModel.Selected.TileWidth, brush.SelectedIndexY * tilesetsViewModel.Selected.TileHeight); // Resize view. selectionBorder.Width = width; selectionBorder.Height = height; // "Generate" cells. Fill the grid with colored rectangles. // Remove old rectangles. if (rectangles.Count > 0) { for (int i = 0; i < rectangles.Count; i++) { selectionGrid.Children.Remove(rectangles[i]); } rectangles.Clear(); } // Generate new rectangles. for (int i = 0; i < selectionGrid.RowDefinitions.Count; i++) { for (int j = 0; j < selectionGrid.ColumnDefinitions.Count; j++) { Rectangle rectangle = new Rectangle() { Fill = Brushes.Transparent, Stroke = Brushes.Red }; // Add new rect to lists. rectangles.Add(rectangle); selectionGrid.Children.Add(rectangle); // Set its row and column. Grid.SetRow(rectangle, i); Grid.SetColumn(rectangle, j); } } }
public void SelectBrush(string name) { if (string.IsNullOrEmpty(name)) { selectedBrush = null; return; } selectedBrush = brushes.FirstOrDefault(b => b.Name == name); }
public BrushBucket(Tileset owner) { this.owner = owner; // TODO: add all brushes by hand. brushes = new TileBrush[] { new SingleTileBrush(owner), new SingleIndexMultipleTilesBrush(2, 2, BrushResizeMode.NoResize, "Multi: 2x2", owner), new SingleIndexMultipleTilesBrush(4, 4, BrushResizeMode.NoResize, "Multi: 4x4", owner), new SingleIndexMultipleTilesBrush(4, 4, BrushResizeMode.NoResize, "Multi: Resizable", owner), new MultipleIndicesMultipleTilesBrush(2, 2, BrushResizeMode.NoResize, "Stamp: 2x2", owner), new MultipleIndicesMultipleTilesBrush(4, 4, BrushResizeMode.NoResize, "Stamp: 4x4", owner), new MultipleIndicesMultipleTilesBrush(4, 4, BrushResizeMode.NoResize, "Stamp: Resizable", owner), }; // Select first brush in the list. selectedBrush = brushes.Last(); }
private void sheetCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { // Check if there is brush selected and tile set selected. if (tilesetsViewModel.Selected == null) { return; } if (brushesViewModel.Selected == null) { return; } // Get mouse position System.Windows.Point position = Mouse.GetPosition(gridBorder); int positionX = (int)position.X / tilesetsViewModel.Selected.TileWidth; int positionY = (int)position.Y / tilesetsViewModel.Selected.TileHeight; // Get bucket. BrushBucket brushBucket = editor.GetBrushBucketForSelectedTileset(); // Keep selected brush in bounds. TileBrush brush = brushBucket.SelectedBrush; if (positionX + brush.DisplayWidth > tilesetsViewModel.Selected.Columns) { positionX = tilesetsViewModel.Selected.Columns - brush.DisplayWidth; } if (positionY + brush.DisplayHeight > tilesetsViewModel.Selected.Rows) { positionY = tilesetsViewModel.Selected.Rows - brush.DisplayHeight; } // Select wanted index. brush.SelectIndex(positionX, positionY); // Reconstruct selection grid. ReconstructSelectionGrid(); }