Added window scaling

This commit is contained in:
2026-05-16 00:49:55 +01:00
parent ec40e04ff3
commit aa9cc552e6
6 changed files with 71 additions and 13 deletions

View File

@@ -15,6 +15,14 @@
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<StartupObject>Desktop.Program</StartupObject>
<AssemblyName>Parsons Master System</AssemblyName>
<ApplicationIcon>favicon.ico</ApplicationIcon>
<Title>Sega Master System EMulator 2026</Title>
<Version>0.9</Version>
<Authors>Marc Parsons</Authors>
<Company>Parsons Limited</Company>
<Description>Parsons Master System 2026</Description>
<Copyright>Copyright 2026 Marc Parsons</Copyright>
<PackageIcon>logo1.bmp</PackageIcon>
</PropertyGroup>
<ItemGroup>
@@ -103,6 +111,10 @@
<None Remove="ROMS\zexdoc.sms" />
</ItemGroup>
<ItemGroup>
<Content Include="favicon.ico" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ROMS\After Burner (UE) [!].sms">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
@@ -353,6 +365,13 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="..\logo1.bmp">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="NAudio" Version="2.3.0" />
<PackageReference Include="Vortice.XInput" Version="3.8.3" />

View File

@@ -53,7 +53,7 @@ namespace Desktop
this.Text = $"Parsons Master System - {_currentRomName}";
// Safe to initialize hardware and files here!
this.BackColor = Color.Black;
_machine = new SmsMachine();
_audioPlayer = new NAudioPlayer();
_machine.AudioProcessor.AudioDevice = _audioPlayer;
@@ -72,27 +72,37 @@ namespace Desktop
}
protected override void OnPaint(PaintEventArgs e)
{
// Always call the base method so Windows can draw your MenuStrip!
base.OnPaint(e);
// THE FIX: We MUST ensure the designer has actually built the menu strip before asking for its height!
if (_screenBitmap != null && menuStrip1 != null)
{
// 1. Set the rendering mode for perfect, chunky retro pixels!
// 1. Maintain perfect, chunky retro pixels
e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
e.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
// 2. Calculate the drawing area.
// We start drawing BELOW the MenuStrip so it doesn't get covered up.
// 2. Calculate the actual usable window space
int topOffset = menuStrip1.Height;
Rectangle renderArea = new Rectangle(
0,
topOffset,
this.ClientSize.Width,
this.ClientSize.Height - topOffset
);
int availableWidth = this.ClientSize.Width;
int availableHeight = this.ClientSize.Height - topOffset;
// 3. Blast the bitmap directly onto the graphics card buffer!
// 3. Calculate the maximum scale factor that fits perfectly
float scaleX = (float)availableWidth / 256f;
float scaleY = (float)availableHeight / 192f;
// Pick the smaller scale so the image never bleeds off the edge
float scale = Math.Min(scaleX, scaleY);
// 4. Calculate the new physical pixel dimensions
int newWidth = (int)(256 * scale);
int newHeight = (int)(192 * scale);
// 5. Center the image (Letterboxing / Pillarboxing)
int offsetX = (availableWidth - newWidth) / 2;
int offsetY = topOffset + ((availableHeight - newHeight) / 2);
Rectangle renderArea = new Rectangle(offsetX, offsetY, newWidth, newHeight);
// 6. Draw the scaled image
e.Graphics.DrawImage(_screenBitmap, renderArea);
}
}

BIN
Desktop/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB