Exemplo n.º 1
0
        private void SetupEnviroment() // prepare the application before main execution
        {
            // reads user config file
            FileHandler.ReadAppConfig();

            // gets window size properties
            int[] dimensions   = GraphicsHandler.GetDimensions();
            int   width        = dimensions[0];
            int   height       = dimensions[1];
            int   borderSize   = GLOBAL.AppConfig.border_size;
            int   displayScale = GLOBAL.AppConfig.display_scale;

            // gets the user's display resolution
            int windowWidth  = Screen.FromControl(this).Bounds.Width;
            int windowHeight = Screen.FromControl(this).Bounds.Height;

            // gets the wanted size for the window
            int newWidth  = (width + (borderSize * 2)) * displayScale;
            int newHeight = (height + (borderSize * 2)) * displayScale;

            if (newWidth > windowWidth || newHeight > windowHeight - 50) // if resulting window would be larger than resolution, -50 height accounting for the taskbar
            {
                // reset the scale to the default value
                ErrorHandler.ShowSystemError(6);
                GLOBAL.AppConfig.display_scale = 3;

                // calculate a new size
                displayScale = GLOBAL.AppConfig.display_scale;
                newWidth     = (width + (borderSize * 2)) * displayScale;
                newHeight    = (height + (borderSize * 2)) * displayScale;
            }

            // changes GUI elements depending on the display scale value and border width
            displayPictureBox.Size = new Size(newWidth, newHeight);  // the area showing the main program
            this.Size     = new Size(newWidth + 15, newHeight + 88); // the window size. extra size accounts for window border and buttons
            zoomedDisplay = new Bitmap(newWidth, newHeight);         // final image the user sees

            // changes button location based on display scale and border width
            int newY           = newHeight;    // right below main program area
            int newButtonWidth = newWidth / 4; // 4 buttons

            // location
            toggleKeyboardButton.Location = new Point(newButtonWidth * 0, newY);
            toggleDebugButton.Location    = new Point(newButtonWidth * 1, newY);
            LoadProgramButton.Location    = new Point(newButtonWidth * 2, newY);
            SaveProgramButton.Location    = new Point(newButtonWidth * 3, newY);
            // dimensions
            toggleKeyboardButton.Size = new Size(newButtonWidth, 50);
            toggleDebugButton.Size    = new Size(newButtonWidth, 50);
            LoadProgramButton.Size    = new Size(newButtonWidth, 50);
            SaveProgramButton.Size    = new Size(newButtonWidth, 50);

            GLOBAL.C64_ROM.LoadCharsetData(); // loads character set
            GLOBAL.VRAM.FillContents(0x20);   // fills the vram (characters on screen) with spaces, hex 0x20

            // setup display and print the default text on boot
            displayPictureBox.Image = GraphicsHandler.GetDisplay();
            GLOBAL.C64_ROM.ShowStartupText();
            GLOBAL.cursorPos = new int[] { 0, 32 };
            PrintReady(8);
            GLOBAL.cursorPos = new int[] { 0, 48 };

            // sets up the performance monitoring object
            string currentProcessName = Process.GetCurrentProcess().ProcessName;

            cpuUsage = new PerformanceCounter("Process", "% Processor Time", currentProcessName, true);
            ramUsage = new PerformanceCounter("Process", "Private Bytes", currentProcessName, true);

            // cursor fires CursorTick_Event three times a second
            cursorTick.Interval = 333;
            cursorTick.Tick    += new EventHandler(CursorTick_Event);
            cursorTick.Enabled  = true;
        }