private void tilesetsViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "Selected") { // WARNING: see TilesetsViewModel.cs - Selected property. BrushBucket brushBucket = editor.GetBrushBucketForSelectedTileset(); if (brushBucket != null) { // Generate view models, set selected. brushes = new ObservableCollection <BrushViewModel>(brushBucket.Brushes.Select(b => new BrushViewModel(b))); selected = brushes.FirstOrDefault(b => b.WrapsBrush(brushBucket.SelectedBrush)); } else { // Clear data. brushes = null; selected = null; } if (PropertyChanged != null) { // Notify users. PropertyChanged(this, new PropertyChangedEventArgs("Brushes")); PropertyChanged(this, new PropertyChangedEventArgs("Selected")); } } }
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(); }