Skip to content

Commit

Permalink
Merge pull request #53 from Mu0n/fix_scaling_again
Browse files Browse the repository at this point in the history
Fix scaling again
  • Loading branch information
dtremblay authored Dec 10, 2023
2 parents 050eb2f + 949dbfb commit 26fc367
Show file tree
Hide file tree
Showing 4 changed files with 277 additions and 173 deletions.
23 changes: 11 additions & 12 deletions Main/Display/Gpu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public unsafe partial class Gpu : UserControl
private int[] lutCache = vs;


//NativeHeight and NativeWidth are no longer used in this fork proposition
//NativeHeight and NativeWidth have been adjusted for C#'s window size conventions
public const int NativeHeight = 480;
public const int NativeWidth = 640;

Expand Down Expand Up @@ -74,27 +74,26 @@ void Gpu_Load(object sender, EventArgs e)
if (ParentForm == null)
return;

MarginHeight = ParentForm.Height - ClientRectangle.Height;
// Calculate the margin width,height
MarginWidth = ParentForm.Width - ClientRectangle.Width;
SetViewSize(NativeWidth, NativeHeight);
MarginHeight = ParentForm.Height - ClientRectangle.Height;

hiresTimer.Start();
}
}

public void SetViewSize(int viewWidth, int viewHeight)
public void SetViewSize(int width, int height)
{
ParentForm.Height = viewHeight + MarginHeight;
ParentForm.Width = viewWidth + MarginWidth;
// Resize the window to what the user had selected
this.Size = new Size(width, height);
ParentForm.Size = new Size(width + MarginWidth, height + MarginHeight);
}

public void SetViewScaling(float scaling, int requiredWidth, int requiredHeight)
{
int viewHeight = (int)((float)requiredHeight * scaling);
int viewWidth = (int)((float)requiredWidth * scaling);

ParentForm.Height = viewHeight + MarginHeight;
ParentForm.Width = viewWidth + MarginWidth;
int viewHeight = (int)((float)requiredHeight * scaling);
this.Size = new Size(viewWidth, viewHeight);
ParentForm.Size = new Size(viewWidth + MarginWidth, viewHeight + MarginHeight);
}

public int GetViewWidth()
Expand Down Expand Up @@ -265,7 +264,7 @@ unsafe void Gpu_Paint(object sender, PaintEventArgs e)
// borderYSize >>= 1; // divide by 2
//}

Rectangle rect = new Rectangle(0, 0, res.X - 1, res.Y - 1);
Rectangle rect = new Rectangle(0, 0, res.X, res.Y);
BitmapData bitmapData = frameBuffer.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
int* bitmapPointer = (int*)bitmapData.Scan0.ToPointer();

Expand Down
Loading

0 comments on commit 26fc367

Please sign in to comment.