private void CreateThemeImages(Image sourceImage) { int dimension = Constants.PUZZLE_SIZES[list.SelectedIndex]; int fragmentWidth = (int)((double)sourceImage.Width / dimension); int fragmentHeight = (int)((double)sourceImage.Height / dimension); int numImages = dimension * dimension; string theme = titleField.Text; PuzzleIO.DeleteTheme(theme); Graphics g; Bitmap bitmap; for (int i = 0; i < numImages; i++) { int horIndex = i % dimension; int vertIndex = i / dimension; bitmap = new Bitmap(fragmentWidth, fragmentHeight); g = Graphics.FromImage(bitmap); g.DrawImage(sourceImage, new Rectangle(0, 0, fragmentWidth, fragmentHeight), new Rectangle(horIndex * fragmentWidth, vertIndex * fragmentHeight, fragmentWidth, fragmentHeight), GraphicsUnit.Pixel); g.Dispose(); PuzzleIO.WriteThemeImage(theme, bitmap, i); } }
public void ResetTiles() { removedTile = null; blankTile = null; Controls.Clear(); theme = PuzzleIO.ReadCurrentTheme(); string[] imageNames = PuzzleIO.ReadThemeImageNames(theme); dimension = (int)Math.Sqrt(imageNames.Length); Tile currentTile; int index = 0; foreach (string imageName in imageNames) { currentTile = new Tile(index, imageName, this); currentTile.Location = GetTileStartingLocation(currentTile); Controls.Add(currentTile); if (index == 0) { Width = currentTile.Width * dimension; Height = currentTile.Height * dimension; } index++; } Invalidate(); }
protected override void DoRefreshList() { string currentTheme = PuzzleIO.ReadCurrentTheme(); string[] themes = PuzzleIO.ReadAllThemes(); int index = 0; foreach (string theme in themes) { list.Items.Add(theme); if (theme.Equals(currentTheme)) { list.SetSelected(index, true); } index++; } }
protected override bool DoApplyChanges() { PuzzleIO.WriteCurrentTheme((string)list.SelectedItem); return(true); }