public NATIVE_CONSOLE_CONFIG(string sWindowTitle, int iWindowWidthPx, int iWindowHeightPx, bool blApplyOnDemand) : base(sWindowTitle, iWindowWidthPx, iWindowHeightPx) { if (mnccEmptyConfig == null) { mnccEmptyConfig = new NATIVE_CONSOLE_CONFIG( ); } msWindowTitle = sWindowTitle; miWindowWidthPx = iWindowWidthPx; miWindowHeightPx = iWindowHeightPx; if (mopProcess == null) { mopProcess = Process.GetCurrentProcess( ); } if (mogGraphics == null) { mogGraphics = Graphics.FromHdc(STR_ConsoleSupport.NATIVE_METHODS.GetDC(mopProcess.MainWindowHandle)); } Console.CursorVisible = false; if (mobgcContext == null) { mobgcContext = BufferedGraphicsManager.Current; } this.WindowWidthColumns = Convert.ToInt32(( float )Math.Floor(( decimal )(Console.LargestWindowWidth * (iWindowWidthPx / 1920f)))); this.WindowHeightRows = Convert.ToInt32(( float )Math.Floor(( decimal )(Console.LargestWindowHeight * (iWindowHeightPx / 1080f)))); if (blApplyOnDemand) { if (mnccCurrentConfig != null) { miLastWindowWidthColumns = mnccCurrentConfig.WindowWidthColumns; miLastWindowHeightRows = mnccCurrentConfig.WindowHeightRows; mnccLastConfig = mnccCurrentConfig; } this.Apply( ); } else { mnccCurrentConfig = null; } }
public override STR_ApplicationConfig Apply(STR_ApplicationConfig nccConfig) { if (miWindowWidthPx <= 0 || miWindowHeightPx <= 0) { return(mnccEmptyConfig); } miLastWindowWidthColumns = Console.WindowWidth; miLastWindowHeightRows = Console.WindowHeight; int iNewWindowWidthColumn = Convert.ToInt32(( float )Math.Floor(( decimal )(Console.LargestWindowWidth * (miWindowWidthPx / 1920f)))); int iNewWindowHeightRows = Convert.ToInt32((( float )Math.Floor(( decimal )(Console.LargestWindowHeight * (miWindowHeightPx / 1080f))))); // ) > Console.LargestWindowHeight ? Console.LargestWindowHeight : ( Console.LargestWindowHeight * ( iWindowHeightPx / 1080 ) ); Console.WindowWidth = iNewWindowWidthColumn > Console.LargestWindowWidth ? Console.LargestWindowWidth : iNewWindowWidthColumn; Console.WindowHeight = iNewWindowHeightRows > Console.LargestWindowHeight ? Console.LargestWindowHeight : iNewWindowHeightRows; Debug.WriteLine(string.Format("CW: {0}, PX: {1}, RATIO: {2} | CH: {3}, PX: {4}, RATIO: {5}", Console.WindowWidth, miWindowWidthPx, miWindowWidthPx / Console.WindowWidth, Console.WindowHeight, miWindowHeightPx, miWindowHeightPx / Console.WindowHeight)); mbHasBeenApplied = true; mnccCurrentConfig = (STR_ConsoleSupport.NATIVE_CONSOLE_CONFIG)nccConfig; return(mnccCurrentConfig); }