diff --git a/OnTopReplica/AspectRatioForm.cs b/OnTopReplica/AspectRatioForm.cs
index 6c31476..e243f2d 100644
--- a/OnTopReplica/AspectRatioForm.cs
+++ b/OnTopReplica/AspectRatioForm.cs
@@ -71,6 +71,13 @@ namespace OnTopReplica {
}
}
+ protected override void OnHandleCreated(EventArgs e) {
+ base.OnHandleCreated(e);
+
+ //When created, use first size of the window as aspect ratio
+ SetAspectRatio(ClientSize, false);
+ }
+
///
/// Forces the form to update its height based on the current aspect ratio setting.
///
@@ -155,47 +162,55 @@ namespace OnTopReplica {
}
}
+ protected virtual void OnResizing(EventArgs e) {
+
+ }
+
///
/// Override WM_SIZING message to restrict resizing.
/// Taken from: http://www.vcskicks.com/maintain-aspect-ratio.php
/// Improved with code from: http://stoyanoff.info/blog/2010/06/27/resizing-forms-while-keeping-aspect-ratio/
///
protected override void WndProc(ref Message m) {
- if (KeepAspectRatio && m.Msg == WM.SIZING) {
- var clientSizeConversion = ClientWindowDifference;
+ if (m.Msg == WM.SIZING) {
+ this.OnResizing(EventArgs.Empty);
- var rc = (Native.NRectangle)Marshal.PtrToStructure(m.LParam, typeof(Native.NRectangle));
- int res = m.WParam.ToInt32();
+ if (KeepAspectRatio) {
+ var clientSizeConversion = ClientWindowDifference;
- int width = (rc.Right - rc.Left) - clientSizeConversion.Width - ExtraPadding.Horizontal;
- int height = (rc.Bottom - rc.Top) - clientSizeConversion.Height - ExtraPadding.Vertical;
+ var rc = (Native.NRectangle)Marshal.PtrToStructure(m.LParam, typeof(Native.NRectangle));
+ int res = m.WParam.ToInt32();
- if (res == WMSZ.LEFT || res == WMSZ.RIGHT) {
- //Left or right resize, adjust top and bottom
- int targetHeight = (int)(width / AspectRatio);
- int diffHeight = height - targetHeight;
+ int width = (rc.Right - rc.Left) - clientSizeConversion.Width - ExtraPadding.Horizontal;
+ int height = (rc.Bottom - rc.Top) - clientSizeConversion.Height - ExtraPadding.Vertical;
- rc.Top += (int)(diffHeight / 2.0);
- rc.Bottom = rc.Top + targetHeight + ExtraPadding.Vertical + clientSizeConversion.Height;
+ if (res == WMSZ.LEFT || res == WMSZ.RIGHT) {
+ //Left or right resize, adjust top and bottom
+ int targetHeight = (int)(width / AspectRatio);
+ int diffHeight = height - targetHeight;
+
+ rc.Top += (int)(diffHeight / 2.0);
+ rc.Bottom = rc.Top + targetHeight + ExtraPadding.Vertical + clientSizeConversion.Height;
+ }
+ else if (res == WMSZ.TOP || res == WMSZ.BOTTOM) {
+ //Up or down resize, adjust left and right
+ int targetWidth = (int)(height * AspectRatio);
+ int diffWidth = width - targetWidth;
+
+ rc.Left += (int)(diffWidth / 2.0);
+ rc.Right = rc.Left + targetWidth + ExtraPadding.Horizontal + clientSizeConversion.Width;
+ }
+ else if (res == WMSZ.RIGHT + WMSZ.BOTTOM || res == WMSZ.LEFT + WMSZ.BOTTOM) {
+ //Lower corner resize, adjust bottom
+ rc.Bottom = rc.Top + (int)(width / AspectRatio) + ExtraPadding.Vertical + clientSizeConversion.Height;
+ }
+ else if (res == WMSZ.LEFT + WMSZ.TOP || res == WMSZ.RIGHT + WMSZ.TOP) {
+ //Upper corner resize, adjust top
+ rc.Top = rc.Bottom - (int)(width / AspectRatio) - ExtraPadding.Vertical - clientSizeConversion.Height;
+ }
+
+ Marshal.StructureToPtr(rc, m.LParam, false);
}
- else if (res == WMSZ.TOP || res == WMSZ.BOTTOM) {
- //Up or down resize, adjust left and right
- int targetWidth = (int)(height * AspectRatio);
- int diffWidth = width - targetWidth;
-
- rc.Left += (int)(diffWidth / 2.0);
- rc.Right = rc.Left + targetWidth + ExtraPadding.Horizontal + clientSizeConversion.Width;
- }
- else if (res == WMSZ.RIGHT + WMSZ.BOTTOM || res == WMSZ.LEFT + WMSZ.BOTTOM) {
- //Lower corner resize, adjust bottom
- rc.Bottom = rc.Top + (int)(width / AspectRatio) + ExtraPadding.Vertical + clientSizeConversion.Height;
- }
- else if (res == WMSZ.LEFT + WMSZ.TOP || res == WMSZ.RIGHT + WMSZ.TOP) {
- //Upper corner resize, adjust top
- rc.Top = rc.Bottom - (int)(width / AspectRatio) - ExtraPadding.Vertical - clientSizeConversion.Height;
- }
-
- Marshal.StructureToPtr(rc, m.LParam, false);
}
base.WndProc(ref m);
diff --git a/OnTopReplica/MainForm.cs b/OnTopReplica/MainForm.cs
index 811abdb..dae4008 100644
--- a/OnTopReplica/MainForm.cs
+++ b/OnTopReplica/MainForm.cs
@@ -101,6 +101,13 @@ namespace OnTopReplica {
RefreshScreenLock();
}
+ protected override void OnResizing(EventArgs e) {
+ //Update aspect ratio from thumbnail while resizing (but do not refresh, resizing does that anyway)
+ if (_thumbnailPanel.IsShowingThumbnail) {
+ SetAspectRatio(_thumbnailPanel.ThumbnailPixelSize, false);
+ }
+ }
+
protected override void OnActivated(EventArgs e) {
base.OnActivated(e);
@@ -127,8 +134,13 @@ namespace OnTopReplica {
base.OnMouseWheel(e);
if (!FullscreenManager.IsFullscreen) {
+ if (_thumbnailPanel.IsShowingThumbnail) {
+ SetAspectRatio(_thumbnailPanel.ThumbnailPixelSize, false);
+ }
+
int change = (int)(e.Delta / 6.0); //assumes a mouse wheel "tick" is in the 80-120 range
AdjustSize(change);
+
RefreshScreenLock();
}
}