protected override void OnActivated(object sender, EventArgs args) { // Recover from tombstoning bool newlyCreated = false; diskTexture = Texture2DExtensions.LoadFromPhoneServiceState(this.GraphicsDevice, "disk"); // Or create the Texture2D if (diskTexture == null) { Rectangle clientBounds = this.GraphicsDevice.Viewport.Bounds; int textureDimension = Math.Min(clientBounds.Width, clientBounds.Height); diskTexture = new Texture2D(this.GraphicsDevice, textureDimension, textureDimension); newlyCreated = true; } pixels = new uint[diskTexture.Width * diskTexture.Height]; radius = diskTexture.Width / 2; textureCenter = new Vector2(radius, radius); if (newlyCreated) { ClearPixelArray(); } else { diskTexture.GetData <uint>(pixels); } base.OnActivated(sender, args); }
protected override void OnActivated(object sender, EventArgs args) { PhoneApplicationService appService = PhoneApplicationService.Current; if (appService.State.ContainsKey("xOrigin") && appService.State.ContainsKey("yOrigin") && appService.State.ContainsKey("resolution")) { PixelInfo.xPixelCoordAtComplexOrigin = (double)appService.State["xOrigin"]; PixelInfo.yPixelCoordAtComplexOrigin = (double)appService.State["yOrigin"]; PixelInfo.unitsPerPixel = (double)appService.State["resolution"]; } else { // Program running from beginning PixelInfo.xPixelCoordAtComplexOrigin = 2 * viewport.Width / 3f; PixelInfo.yPixelCoordAtComplexOrigin = viewport.Height / 2; PixelInfo.unitsPerPixel = Math.Max(2.5 / viewport.Height, 3.0 / viewport.Width); } UpdateCoordinateText(); // Restore bitmap from tombstoning or recreate it texture = Texture2DExtensions.LoadFromPhoneServiceState(this.GraphicsDevice, "mandelbrotBitmap"); if (texture == null) { texture = new Texture2D(this.GraphicsDevice, viewport.Width, viewport.Height); } // Get texture information and pixels array PixelInfo.pixelWidth = texture.Width; PixelInfo.pixelHeight = texture.Height; int numPixels = PixelInfo.pixelWidth * PixelInfo.pixelHeight; pixels = new uint[numPixels]; texture.GetData <uint>(pixels); // Create and initialize PixelInfo array pixelInfos = new PixelInfo[numPixels]; InitializePixelInfo(pixels); // Start up the calculation thread Thread thread = new Thread(PixelSetterThread); thread.Start(); base.OnActivated(sender, args); }
protected override void OnActivated(object sender, EventArgs args) { // Recover from tombstoning bool newlyCreated = false; canvas = Texture2DExtensions.LoadFromPhoneServiceState(this.GraphicsDevice, "canvas"); if (canvas == null) { // Otherwise create new Texture2D canvas = new Texture2D(this.GraphicsDevice, (int)canvasSize.X, (int)canvasSize.Y); newlyCreated = true; } // Create pixels array pixels = new uint[canvas.Width * canvas.Height]; canvas.GetData <uint>(pixels); if (newlyCreated) { ClearPixelArray(); } // Get drawing color from State, initialize selected ColorBlock if (PhoneApplicationService.Current.State.ContainsKey("color")) { drawingColor = (Color)PhoneApplicationService.Current.State["color"]; } foreach (ColorBlock colorBlock in colorBlocks) { colorBlock.IsSelected = colorBlock.Color == drawingColor; } base.OnActivated(sender, args); }