protected override void OnTileBrushChanged() { base.OnTileBrushChanged(); var currentlyUsingShader = this.useTileShader; this.useTileShader = this.TileBrush is GradientBrush; if (!this.useTileShader) { var tileImages = TileBoardBase.CreateTileImage(this.TileBrush, this.TileSize); this.tileUnsetData = tileImages.Item1.GetPixelData(); this.tileSetData = tileImages.Item2.GetPixelData(); this.tileSetBrush = new ImageBrush(tileImages.Item2); if (this.boardTopVisual != null) { this.proxy = new WriteableBitmapProxy(this.boardBitmap); this.InitBoard(); return; } this.DrawBoard(); } else { this.tileUnsetData = TileBoard.defaultTileUnsetData; this.tileSetData = TileBoard.defaultTileSetData; this.tileSetBrush = new ImageBrush(TileBoardBase.DefaultTileSetImage); this.InitBoard(); } }
private void ApplyShaderAndUpdateRemainingTiles(ConcurrentStack <Point <int> > tilesToDrawAfterShading) { this.boardTop = new WriteableBitmap(this.boardBitmap.PixelWidth, this.boardBitmap.PixelHeight, this.boardBitmap.DpiX, this.boardBitmap.DpiY, this.boardBitmap.Format, this.boardBitmap.Palette); this.proxy = new WriteableBitmapProxy(this.boardTop); if (tilesToDrawAfterShading.Count > 0) { this.boardTop.Lock(); foreach (var tilePoint in tilesToDrawAfterShading) { this.DrawTile(tilePoint.X, tilePoint.Y, true); } this.boardTop.Unlock(); } }
private void InitBoard() { var minesweeper = this.Minesweeper; if (minesweeper == null) { return; } double time1 = 0, time2 = 0; var sw = Stopwatch.StartNew(); this.boardTiles = minesweeper.Tiles; double newWidth = this.boardTiles.Width * this.TileSize.Width; double newHeight = this.boardTiles.Height * this.TileSize.Height; bool resizeControl = this.Width != newWidth || this.Height != newHeight; if (resizeControl) { this.Width = this.boardTiles.Width * this.TileSize.Width; this.Height = this.boardTiles.Height * this.TileSize.Height; } if (this.boardBitmap == null || resizeControl) { this.boardBitmap = new WriteableBitmap((int)this.Width, (int)this.Height, 96d, 96d, PixelFormats.Bgra32, null); this.proxy = new WriteableBitmapProxy(this.boardBitmap); } this.Visuals.ForEach(this.RemoveVisualChild); this.Visuals.Clear(); time1 = sw.Elapsed.TotalMilliseconds; this.DrawBoard(); time2 = sw.Elapsed.TotalMilliseconds; this.AddVisuals(); sw.Stop(); Console.WriteLine("1) Resizing/Clearing Visuals: " + time1.ToString("0.0000")); Console.WriteLine("2) Drawing Board: " + (time2 - time1).ToString("0.0000")); Console.WriteLine("3) Adding Visuals: " + (sw.Elapsed.TotalMilliseconds - time2).ToString("0.0000")); }
private void ApplyShaderAndUpdateRemainingTiles(ConcurrentStack<Point<int>> tilesToDrawAfterShading) { this.boardTop = new WriteableBitmap(this.boardBitmap.PixelWidth, this.boardBitmap.PixelHeight, this.boardBitmap.DpiX, this.boardBitmap.DpiY, this.boardBitmap.Format, this.boardBitmap.Palette); this.proxy = new WriteableBitmapProxy(this.boardTop); if (tilesToDrawAfterShading.Count > 0) { this.boardTop.Lock(); foreach (var tilePoint in tilesToDrawAfterShading) { this.DrawTile(tilePoint.X, tilePoint.Y, true); } this.boardTop.Unlock(); } }