/// <summary> /// Constructor. /// Creates and starts an AriadneController. /// </summary> /// <param name="windowHandleArg"></param> private ScreenSaverPreviewController(string windowHandleArg) { // Get the window in which we are supposed to paint. this.parentHwnd = (IntPtr)UInt32.Parse(windowHandleArg); this.targetRectangle = Platform.GetClientRectangle(parentHwnd); //Log.WriteLine("targetRectangle = " + targetRectangle); // Create a MazePainter. this.targetGraphics = Graphics.FromHwnd(parentHwnd); this.painter = new MazePainter(targetGraphics, targetRectangle, this as IMazePainterClient, true); // Create and display the first maze. this.OnNew(null, null); // Create an AriadneController. SolverController controller = new SolverController(null, painter, null); this.ariadneController = new AriadneController(this, controller); ariadneController.RepeatMode = true; // Start the AriadneController. ariadneController.Start(); // Start a supervisor timer. CreateSupervisorTimer(); }
/// <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 }