/// <summary> /// If the given control shall be visible, an invisible placeholder is added to this form at a new, random location. /// In the next iteration, the actual control will replace the placeholder at that location. /// </summary> /// <param name="control"></param> /// <param name="isVisible"></param> private void PreparePlaceholderControl(Control control, bool isVisible) { if (control == null) { return; } if (!isVisible) { control.Visible = false; return; } // Add the control and a placeholder of the same size to their respective lists. visibleControls.Add(control); Control placeholder = new Control("", control.Left, control.Top, control.Width, control.Height); placeholderControls.Add(placeholder); // Place the placeholder at a random location. placeholder.Location = InfoPanelPainter.SuggestLocation(control.Size, this.Size, this.random); // Add the invisible placeholder control to this form. placeholder.Visible = false; this.Controls.Add(placeholder); }
/// <summary> /// Creates a ScreenSaverController instance, /// draws an initial maze /// and starts an AriadneController. /// </summary> /// <param name="windowHandleArg">The MazePainter will draw on this window.</param> /// <remarks> /// If this is not the primary screen, no cotroller is started, /// the application will terminate and the screen will stay blank. /// </remarks> public ScreenSaverController(string windowHandleArg) { #region Evaluate the given window's properties. var windowHandle = (IntPtr)UInt32.Parse(windowHandleArg); var targetGraphics = Graphics.FromHwnd(windowHandle); var targetRectangle = Platform.GetClientRectangle(windowHandle); //Log.WriteLine("targetRectangle = " + targetRectangle, true); // {X=0,Y=0,Width=1366,Height=768} #endregion #if true #region Blank secondary screen(s). // ... because more than one of these mazes is just too distracting. :-) if (!IsOnPrimaryScreen(windowHandle)) { // We don't have to do anything, really. // xscreensaver has given us a blank (black) window and we may // terminate the application //Log.WriteLine("Goodbye on " + targetRectangle, true); //Application.Run(); Application.Exit(); } #endregion #endif // Create an ImageLoader, now that it is clear that we will need it. Directory.ResultValidForSeconds = -1; var imageLoader = ImageLoader.GetScreenSaverImageLoader(Screen.PrimaryScreen.Bounds); #region Create a MazePainter. this.painter = new MazePainter(targetGraphics, targetRectangle, this as IMazePainterClient); #endregion #region Create a MazeUserControl. this.mazeUserControl = new MazeUserControl(painter, targetRectangle.Size); this.mazeUserControl.ImageLoader = imageLoader; this.mazeUserControl.MazeForm = this; #endregion #region Apply some registered options. if (RegisteredOptions.GetBoolSetting(RegisteredOptions.OPT_PAINT_ALL_WALLS) == false) { painter.RandomizeWallVisibility = true; } ContourImage.DisplayProcessedImage = RegisteredOptions.GetBoolSetting(RegisteredOptions.OPT_IMAGE_SUBTRACT_BACKGROUND); // Load background images. if (RegisteredOptions.GetBoolSetting(RegisteredOptions.OPT_BACKGROUND_IMAGES)) { string imageFolder = RegisteredOptions.GetStringSetting(RegisteredOptions.OPT_BACKGROUND_IMAGE_FOLDER); if (imageFolder == "") { imageFolder = RegisteredOptions.GetStringSetting(RegisteredOptions.OPT_IMAGE_FOLDER); } int percentage = ((RegisteredOptions.GetIntSetting(RegisteredOptions.OPT_IMAGE_NUMBER) > 0) ? 20 : 100); painter.CreateBackgroundImageLoader(imageFolder, percentage); } if (RegisteredOptions.GetBoolSetting(RegisteredOptions.OPT_SHOW_DETAILS_BOX)) { this.infoPanelPainter = new InfoPanelPainter(painter); } #endregion // Create and display the first maze. this.OnNew(null, null); #region Create and start an AriadneController. SolverController controller = new SolverController(this, painter, null); this.ariadneController = new AriadneController(this, controller); ariadneController.RepeatMode = true; ariadneController.Start(); #endregion }