handle dpi properly in NES ppu viewer

- also fixes #4246
This commit is contained in:
Morilli 2025-03-04 10:35:32 +01:00
parent a64d7627ce
commit 843051a2fd
4 changed files with 43 additions and 44 deletions

View File

@ -171,7 +171,7 @@ namespace BizHawk.Client.EmuHawk
this.PatternImageToClipboardMenuItem,
this.PatternRefreshMenuItem});
this.PatternContext.Name = "PatternContext";
this.PatternContext.Size = new System.Drawing.Size(166, 70);
this.PatternContext.Size = new System.Drawing.Size(177, 70);
//
// PatternSaveImageMenuItem
//
@ -220,7 +220,7 @@ namespace BizHawk.Client.EmuHawk
this.PaletteImageToClipboardMenuItem,
this.PaletteRefreshMenuItem});
this.PaletteContext.Name = "PaletteContext";
this.PaletteContext.Size = new System.Drawing.Size(166, 70);
this.PaletteContext.Size = new System.Drawing.Size(177, 70);
//
// PaletteSaveImageMenuItem
//
@ -345,7 +345,7 @@ namespace BizHawk.Client.EmuHawk
this.SpriteImageToClipboardMenuItem,
this.SpriteRefreshMenuItem});
this.SpriteContext.Name = "SpriteContext";
this.SpriteContext.Size = new System.Drawing.Size(166, 70);
this.SpriteContext.Size = new System.Drawing.Size(177, 70);
//
// SpriteSaveImageMenuItem
//
@ -609,7 +609,7 @@ namespace BizHawk.Client.EmuHawk
// toolStripStatusLabel1
//
this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
this.toolStripStatusLabel1.Size = new System.Drawing.Size(319, 17);
this.toolStripStatusLabel1.Size = new System.Drawing.Size(347, 17);
this.toolStripStatusLabel1.Text = "Use CTRL+C to copy the pane under the mouse to the clipboard.";
//
// Messagetimer
@ -657,8 +657,8 @@ namespace BizHawk.Client.EmuHawk
//
// NesPPU
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.ClientSize = new System.Drawing.Size(854, 371);
this.Controls.Add(this.CHRROMGroup);
this.Controls.Add(this.NesPPUStatusBar);

View File

@ -548,10 +548,7 @@ namespace BizHawk.Client.EmuHawk
private void HandleSpriteViewMouseMove(Point e)
{
if (e.X < SpriteView.ClientRectangle.Left) return;
if (e.Y < SpriteView.ClientRectangle.Top) return;
if (e.X >= SpriteView.ClientRectangle.Right) return;
if (e.Y >= SpriteView.ClientRectangle.Bottom) return;
var p = UIHelper.Unscale(e);
byte[] oam = _ppu.GetOam();
byte[] ppuBus = _ppu.GetPPUBus(); // caching is quicker, but not really correct in this case
@ -559,8 +556,8 @@ namespace BizHawk.Client.EmuHawk
bool is8x16 = _ppu.SPTall;
//figure out which sprite we're over
int spriteSlotY = e.Y / 8;
int spriteSlotX = e.X / 8;
int spriteSlotY = p.Y / 8;
int spriteSlotX = p.X / 8;
//exclude mouse over empty area (vertical). this depends on how big the sprites are
if (is8x16)
@ -638,12 +635,12 @@ namespace BizHawk.Client.EmuHawk
if (is8x16)
{
ZoomBox.Image = Section(
SpriteView.Sprites, new Rectangle(new Point((e.X / 8) * 8, (e.Y / 24) * 24), new Size(8, 16)), true);
SpriteView.Sprites, new Rectangle(new Point((p.X / 8) * 8, (p.Y / 24) * 24), new Size(8, 16)), true);
}
else
{
ZoomBox.Image = Section(
SpriteView.Sprites, new Rectangle(new Point((e.X / 8) * 8, (e.Y / 8) * 8), new Size(8, 8)), false);
SpriteView.Sprites, new Rectangle(new Point((p.X / 8) * 8, (p.Y / 8) * 8), new Size(8, 8)), false);
}
}
@ -666,19 +663,17 @@ namespace BizHawk.Client.EmuHawk
private void HandlePaletteViewMouseMove(Point e)
{
if (e.X < PaletteView.ClientRectangle.Left) return;
if (e.Y < PaletteView.ClientRectangle.Top) return;
if (e.X >= PaletteView.ClientRectangle.Right) return;
if (e.Y >= PaletteView.ClientRectangle.Bottom) return;
var p = UIHelper.Unscale(e);
if (p.X < 0 || p.X >= 256 || p.Y < 0 || p.Y >= 32) return;
int baseAddr = 0x3F00;
if (e.Y > 16)
if (p.Y > 16)
{
baseAddr += 16;
}
int column = e.X / 16;
int addr = column + baseAddr;
int column = p.X / 16;
int addr = baseAddr + column;
AddressLabel.Text = $"Address: 0x{addr:X4}";
int val;
@ -748,27 +743,28 @@ namespace BizHawk.Client.EmuHawk
private void PatternView_MouseMove(object sender, MouseEventArgs e)
{
var p = UIHelper.Unscale(e.Location);
int table = 0;
int address;
int tile;
if (e.X > PatternView.Width / 2)
if (p.X > PatternView.Width / 2)
{
table = 1;
}
if (table == 0)
{
tile = (e.X - 1) / 8;
tile = (p.X - 1) / 8;
address = tile * 16;
}
else
{
tile = (e.X - 128) / 8;
tile = (p.X - 128) / 8;
address = 0x1000 + (tile * 16);
}
address += (e.Y / 8) * 256;
tile += (e.Y / 8) * 16;
address += (p.Y / 8) * 256;
tile += (p.Y / 8) * 16;
var usage = "Usage: ";
if (_ppu.BGBaseHigh == address >= 0x1000) // bghigh
@ -790,7 +786,7 @@ namespace BizHawk.Client.EmuHawk
Value3Label.Text = $"Tile {tile:X2}";
Value4Label.Text = usage;
ZoomBox.Image = Section(PatternView.Pattern, new Rectangle(new Point((e.X / 8) * 8, (e.Y / 8) * 8), new Size(8, 8)), false);
ZoomBox.Image = Section(PatternView.Pattern, new Rectangle(new Point((p.X / 8) * 8, (p.Y / 8) * 8), new Size(8, 8)), false);
}
private void ScanlineTextBox_TextChanged(object sender, EventArgs e)
@ -812,7 +808,7 @@ namespace BizHawk.Client.EmuHawk
private void CalculateFormSize()
{
Width = ChrRomView ? 861 : 580;
ClientSize = ClientSize with { Width = UIHelper.ScaleX(ChrRomView ? 850 : 570) };
}
private void ChrRomViewReload()

View File

@ -123,11 +123,11 @@
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="PatternView.Pattern" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAQAAAACACAYAAADktbcKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsAAAA7AAWrWiQkAAACWSURBVHhe7cExAQAAAMKg9U9tDQ8gAAAAAAAAAAAAAAAA
iVBORw0KGgoAAAANSUhEUgAAAQAAAACACAYAAADktbcKAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
vwAADr8BOAVTJAAAAJZJREFUeF7twTEBAAAAwqD1T20NDyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAs1AJ4A
AT4xyOEAAAAASUVORK5CYII=
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACACzUAngABPjHI4QAAAABJRU5E
rkJggg==
</value>
</data>
<metadata name="PaletteContext.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
@ -138,10 +138,10 @@
</metadata>
<data name="SpriteView.Sprites" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAQAAAABgCAYAAADy8ayIAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsAAAA7AAWrWiQkAAAB2SURBVHhe7cExAQAAAMKg9U9tCy8gAAAAAAAAAAAAAAAA
iVBORw0KGgoAAAANSUhEUgAAAQAAAABgCAYAAADy8ayIAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
vwAADr8BOAVTJAAAAHZJREFUeF7twTEBAAAAwqD1T20LLyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOaoBvAAG82XG2AAAAAElFTkSuQmCC
AAAAAAAAAAAAAA5qgG8AAbzZcbYAAAAASUVORK5CYII=
</value>
</data>
<metadata name="NesPPUMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
@ -155,11 +155,11 @@
</metadata>
<data name="CHRROMView.Pattern" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAQAAAACACAYAAADktbcKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsAAAA7AAWrWiQkAAACWSURBVHhe7cExAQAAAMKg9U9tDQ8gAAAAAAAAAAAAAAAA
iVBORw0KGgoAAAANSUhEUgAAAQAAAACACAYAAADktbcKAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
vwAADr8BOAVTJAAAAJZJREFUeF7twTEBAAAAwqD1T20NDyAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAs1AJ4A
AT4xyOEAAAAASUVORK5CYII=
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACACzUAngABPjHI4QAAAABJRU5E
rkJggg==
</value>
</data>
</root>

View File

@ -51,12 +51,15 @@ namespace BizHawk.Client.EmuHawk
private void PaletteViewer_Paint(object sender, PaintEventArgs e)
{
for (int x = 0; x < 16; x++)
int size = UIHelper.ScaleX(16);
for (int i = 0; i < 16; i++)
{
BgPalettesBrush.Color = BgPalettes[x].Color;
SpritePalettesBrush.Color = SpritePalettes[x].Color;
e.Graphics.FillRectangle(BgPalettesBrush, new Rectangle(x * 16, 0, 16, 16));
e.Graphics.FillRectangle(SpritePalettesBrush, new Rectangle(x * 16, 16, 16, 16));
int x = UIHelper.ScaleX(16 * i);
int y = UIHelper.ScaleY(16);
BgPalettesBrush.Color = BgPalettes[i].Color;
SpritePalettesBrush.Color = SpritePalettes[i].Color;
e.Graphics.FillRectangle(BgPalettesBrush, new Rectangle(x, 0, size, size));
e.Graphics.FillRectangle(SpritePalettesBrush, new Rectangle(x, y, size, size));
}
}