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); } } }
private void ReconstructGrid() { // Cant reconstruct if image is null. if (image == null) { return; } // Calculate columns. int columns = 0; if (CellWidth == 0) { return; } columns = (int)((image.Width - GridOffsetX) / CellWidth); // Calculate rows. int rows = 0; if (CellHeight == 0) { return; } rows = (int)((image.Height - GridOffsetY) / CellHeight); // Calculate row modulo. int modRows = (int)(image.Height - GridOffsetY) % CellHeight; modRows = modRows > 0 ? 1 : 0; // Calculate column modulo. int modColumns = (int)(image.Width - GridOffsetX) % CellWidth; modColumns = modColumns > 0 ? 1 : 0; // Calculate width and height. int width = (modColumns + columns) * CellWidth; int height = (modRows + rows) * CellHeight; tileGridManager.Reconstruct(width, height, CellWidth, CellHeight, GridOffsetX, GridOffsetY); // Set borders size. gridBorder.Width = width; gridBorder.Height = height; }
private void ReconstructGrid(Tileset tileset) { int width = 0; int height = 0; sheetImage.Source = null; // If we have tileset selected, we can reconstruct the grid. Else, just reset it. if (tileset != null) { // Reconstruct grid. string pathToImage = editor.GetTexturePath(tileset.Texture); BitmapImage image = ImageHelper.LoadToMemory(pathToImage); sheetImage.Source = image; // Calculate area size. width = tileset.SourceSize.X * tileset.IndicesCount.X; height = tileset.SourceSize.Y * tileset.IndicesCount.Y; } // Keep offset at zero, we don't want to move the grid but the image instead. tileGridManager.Reconstruct(width, height, tileset.SourceSize.X, tileset.SourceSize.Y, 0, 0); Canvas.SetLeft(sheetImage, -tileset.Offset.X); Canvas.SetTop(sheetImage, -tileset.Offset.Y); // Set view size. sheetCanvas.Width = width; sheetCanvas.Height = height; // Set border size. gridBorder.Width = width; gridBorder.Height = height; // Set image size. Adjust it to the size of the view. sheetImage.Width = Math.Min(width, sheetImage.Source.Width); sheetImage.Height = Math.Min(height, sheetImage.Source.Height); }