From 07b4db466606bf47e315ee5217a5f8327829bb25 Mon Sep 17 00:00:00 2001 From: Lorenz Cuno Klopfenstein Date: Wed, 23 Jun 2010 17:09:16 +0200 Subject: [PATCH] Added basic resizing with mouse wheel (bugged still). --- OnTopReplica/AspectRatioForm.cs | 26 ++++++++++++++++++-------- OnTopReplica/MainForm.cs | 6 ++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/OnTopReplica/AspectRatioForm.cs b/OnTopReplica/AspectRatioForm.cs index e8a94ed..bfd4c39 100644 --- a/OnTopReplica/AspectRatioForm.cs +++ b/OnTopReplica/AspectRatioForm.cs @@ -70,6 +70,24 @@ namespace OnTopReplica { ClientSize = new Size(newWidth, newHeight); } + public void AdjustSize(double delta) { + int newWidth = Math.Max((int)(ClientSize.Width + delta), MinimumSize.Width); + int newHeight = (int)((newWidth - ExtraPadding.Horizontal) / AspectRatio + ExtraPadding.Vertical); + + //Readjust if we go lower than minimal height + if (newHeight < MinimumSize.Height) { + newHeight = MinimumSize.Height; + newWidth = (int)((newHeight - ExtraPadding.Vertical) * AspectRatio + ExtraPadding.Horizontal); + } + + //Compute movement to re-center + int deltaX = newWidth - ClientSize.Width; + int deltaY = newHeight - ClientSize.Height; + + ClientSize = new Size(newWidth, newHeight); + Location = new Point(Location.X - (deltaX / 2), Location.Y - (deltaY / 2)); + } + /// /// Updates the aspect ratio of the form and forces a refresh. /// @@ -146,14 +164,6 @@ namespace OnTopReplica { return new Size(size.Width - clientSizeConversionWidth, size.Height - clientSizeConversionHeight); } - /*private void ClientSizeInit() { - if (clientSizeConversionSet) - return; - - clientSizeConversionWidth = this.Size.Width - this.ClientSize.Width; - clientSizeConversionHeight = this.ClientSize.Width - this.ClientSize.Height; - }*/ - protected override void OnShown(EventArgs e) { base.OnShown(e); diff --git a/OnTopReplica/MainForm.cs b/OnTopReplica/MainForm.cs index fa943a6..3b26e50 100644 --- a/OnTopReplica/MainForm.cs +++ b/OnTopReplica/MainForm.cs @@ -229,6 +229,12 @@ namespace OnTopReplica { new Margins(-1); } + protected override void OnMouseWheel(MouseEventArgs e) { + base.OnMouseWheel(e); + + AdjustSize(e.Delta); + } + protected override void OnShown(EventArgs e) { base.OnShown(e);