/// <summary> /// Create a new TileSheet from the image located at 'filePath'. /// Returns the The ID associated with the new sheet, or -1 on failure. /// </summary> public SheetError CreateNewSheet(string filePath, int tileSize, ref int sheetID) { TileSheet newSheet = new TileSheet(filePath, tileSize, m_nextId); // Check Error Code and pass message to user if needed SheetError err = newSheet.GetError(); if (err == SheetError.SUCCESS || err == SheetError.SIZE_MISMATCH) { m_sheets.Add(newSheet); m_idMap.Add(m_nextId, m_sheets.Count - 1); // Map the ID to the index sheetID = m_nextId; ++m_nextId; } else { sheetID = -1; } return(err); }
public void AddTileSheet(TileSheet sheet) { const int MAX_COLS = 4; // Create Grid int numTiles = sheet.GetNumTiles(); int numRows = numTiles / MAX_COLS; if (numTiles % MAX_COLS > 0) { ++numRows; } Grid sheetGrid = new Grid(); // Add Rows for (int index = 0; index < numRows; ++index) { RowDefinition row = new RowDefinition(); row.Height = GridLength.Auto; sheetGrid.RowDefinitions.Add(row); } // Add Cols for (int index = 0; index < MAX_COLS; ++index) { ColumnDefinition col = new ColumnDefinition(); col.Width = GridLength.Auto; sheetGrid.ColumnDefinitions.Add(col); } // Add Images int currCol = 0; int currRow = 0; Int32Rect srcRect = new Int32Rect(0, 0, TileSheet.TILE_DISPLAY_SIZE, TileSheet.TILE_DISPLAY_SIZE); BitmapSizeOptions opts = BitmapSizeOptions.FromEmptyOptions(); for (int index = 0; index < numTiles; ++index) { IntPtr srcBits = (sheet.GetTileSourceAt(index)); if (srcBits == IntPtr.Zero) { UpdateSysMsg("Error loading Image Source for Sheet: " + sheet.GetFileName() + " Index: " + index.ToString()); continue; } var bmpSrc = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(srcBits, IntPtr.Zero, srcRect, opts); TileImage nextImg = new TileImage(sheet.GetID(), index); nextImg.Margin = new Thickness(3); nextImg.Source = bmpSrc; nextImg.MouseLeftButtonUp += TileButtonClicked; sheetGrid.Children.Add(nextImg); Grid.SetRow(nextImg, currRow); Grid.SetColumn(nextImg, currCol); ++currCol; if (currCol >= MAX_COLS) { currCol = 0; ++currRow; } } // Create Expander Expander sheetExpander = new Expander(); sheetExpander.Header = sheet.GetFileName(); sheetExpander.Content = sheetGrid; tileStackPanel.Children.Add(sheetExpander); }