Example #1
0
        private void KeyboardWindow_Load(object sender, EventArgs e)
        {
            int    scale           = 4;
            Bitmap originalCharset = Properties.Resources.default_charset;
            int    width           = originalCharset.Width;
            int    height          = originalCharset.Height;
            Bitmap zoomedDisplay   = new Bitmap(originalCharset.Width * scale, originalCharset.Height * scale);
            Bitmap newBitmap       = new Bitmap(width + scale * ((width / 8) - 1), height + scale * ((height / 7) - 1));

            textCharactersImage.Size = new Size(zoomedDisplay.Width, zoomedDisplay.Height);
            this.Size = new Size(zoomedDisplay.Width + 36, zoomedDisplay.Height + 32);

            int x = 0;
            int y = 0;

            for (int i = 0; i < textCharactersLayout.Length; i++)
            {
                if (i == 0x30) // skip a space at the start of the 3rd row
                {
                    x++;
                }

                GraphicsHandler.DrawChar(x * 8 + x * scale, y * 8 + y * scale, textCharactersLayout[i], newBitmap);
                x++;
                if (x > 15)
                {
                    x = 0;
                    y++;
                }
            }

            textCharactersImage.Image = newBitmap;
            Graphics graphics = Graphics.FromImage(zoomedDisplay);

            graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
            // draw the upscaled image to the screen
            graphics.DrawImage(textCharactersImage.Image, 0, 0, 128 * scale, 64 * scale);
            textCharactersImage.Image = zoomedDisplay;
            // update screen and clear memory
            textCharactersImage.Refresh();
            graphics.Dispose();
        }
Example #2
0
        private void UpdateDisplay() // redraws the display to the screen, cannot be in GraphicsHandler due to drawing to the forms elements
        {
            // start timer to see how long frame takes
            Stopwatch frameDrawTime = Stopwatch.StartNew();

            // draws the black borders around the main window
            GraphicsHandler.DrawBorder();

            int[] vram = GLOBAL.VRAM.GetContents(); // gets the characters on screen

            // draw each character to the screen
            for (int i = 0; i < vram.Length; i++)
            {
                GraphicsHandler.DrawChar(i % 40, i / 40, vram[i]); // i % 40, i / 40 turns the 1D vram array to 2D co-ordinates for the GraphicsHandler object
            }

            // 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;

            // upscales the output by displayScale with nearest neighbour (for no blurring pixels)
            displayPictureBox.Image = GraphicsHandler.DrawCursor(GraphicsHandler.GetDisplay(), GLOBAL.cursorPos[0], GLOBAL.cursorPos[1], cursorVisible);
            Graphics graphics = Graphics.FromImage(zoomedDisplay);

            graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
            // draw the upscaled image to the screen
            graphics.DrawImage(displayPictureBox.Image, 0, 0, (width + (borderSize * 2)) * displayScale, (height + (borderSize * 2)) * displayScale);
            displayPictureBox.Image = zoomedDisplay;
            // update screen and clear memory
            displayPictureBox.Refresh();
            graphics.Dispose();

            // store how long it took to draw that drame
            frameDrawTime.Stop();
            lastFrameTime = frameDrawTime.Elapsed.TotalMilliseconds;
        }