Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CoreBoy.Windows/WinFormsEmulatorSurface.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion CoreBoy.Windows/WinFormsEmulatorSurface.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Threading;
using System.Windows.Forms;
Expand Down Expand Up @@ -52,7 +53,7 @@ public WinFormsEmulatorSurface()
}
});

Controls.Add(_pictureBox = new PictureBox
Controls.Add(_pictureBox = new PixelBox
{
Top = _menu.Height,
Width = BitmapDisplay.DisplayWidth * 5,
Expand Down Expand Up @@ -207,4 +208,22 @@ protected override void OnFormClosed(FormClosedEventArgs e)
_pictureBox.Dispose();
}
}

public class PixelBox : PictureBox
{
public InterpolationMode Interpolation { get => InterpolationMode.NearestNeighbor; }

protected override void OnPaint(PaintEventArgs pe)
{
var graphics = pe.Graphics;
graphics.InterpolationMode = this.Interpolation;

if(graphics.InterpolationMode == InterpolationMode.NearestNeighbor)
{
graphics.PixelOffsetMode = PixelOffsetMode.Half;
}

base.OnPaint(pe);
}
}
}