diff --git a/src/Eve-O-Mock/Eve-O-Mock.csproj b/src/Eve-O-Mock/Eve-O-Mock.csproj index b811999..85f03b0 100644 --- a/src/Eve-O-Mock/Eve-O-Mock.csproj +++ b/src/Eve-O-Mock/Eve-O-Mock.csproj @@ -1,6 +1,6 @@  - net6.0-windows + net8.0-windows8.0 WinExe EveOMock ExeFile diff --git a/src/Eve-O-Preview/Eve-O-Preview.csproj b/src/Eve-O-Preview/Eve-O-Preview.csproj index d0c3f9a..f4c3187 100644 --- a/src/Eve-O-Preview/Eve-O-Preview.csproj +++ b/src/Eve-O-Preview/Eve-O-Preview.csproj @@ -1,7 +1,7 @@  LINUX - net6.0-windows + net8.0-windows8.0 WinExe true true diff --git a/src/Eve-O-Preview/View/Implementation/MainForm.cs b/src/Eve-O-Preview/View/Implementation/MainForm.cs index 1ae589d..afd483e 100644 --- a/src/Eve-O-Preview/View/Implementation/MainForm.cs +++ b/src/Eve-O-Preview/View/Implementation/MainForm.cs @@ -41,6 +41,10 @@ namespace EveOPreview.View { this.InitFormSize(); this.AnimationStyleCombo.DataSource = Enum.GetValues(typeof(AnimationStyle)); + + // Add mouse wheel event handlers for aspect ratio maintenance + this.ThumbnailsWidthNumericEdit.MouseWheel += ThumbnailSizeNumeric_MouseWheel; + this.ThumbnailsHeightNumericEdit.MouseWheel += ThumbnailSizeNumeric_MouseWheel; } public bool MinimizeToTray { @@ -437,18 +441,105 @@ namespace EveOPreview.View { return; } - // Perform some View work that is not properly done in the Control - this._suppressEvents = true; - Size thumbnailSize = this.ThumbnailSize; - thumbnailSize.Width = Math.Min(Math.Max(thumbnailSize.Width, this._minimumSize.Width), this._maximumSize.Width); - thumbnailSize.Height = - Math.Min(Math.Max(thumbnailSize.Height, this._minimumSize.Height), this._maximumSize.Height); - this.ThumbnailSize = thumbnailSize; - this._suppressEvents = false; + // Check if shift is held down for aspect ratio maintenance + bool maintainAspectRatio = ModifierKeys.HasFlag(Keys.Shift); + + if (maintainAspectRatio && sender is NumericUpDown changedControl) { + // Calculate the aspect ratio from the current size before the change + double aspectRatio = + (double)this.ThumbnailsWidthNumericEdit.Value / (double)this.ThumbnailsHeightNumericEdit.Value; + + // Determine which control was changed and update the other accordingly + if (changedControl == this.ThumbnailsWidthNumericEdit) { + int newWidth = (int)changedControl.Value; + int newHeight = (int)(newWidth / aspectRatio); + + // Apply size constraints + newWidth = Math.Min(Math.Max(newWidth, this._minimumSize.Width), this._maximumSize.Width); + newHeight = Math.Min(Math.Max(newHeight, this._minimumSize.Height), this._maximumSize.Height); + + this._suppressEvents = true; + this.ThumbnailsWidthNumericEdit.Value = newWidth; + this.ThumbnailsHeightNumericEdit.Value = newHeight; + this._suppressEvents = false; + } else if (changedControl == this.ThumbnailsHeightNumericEdit) { + int newHeight = (int)changedControl.Value; + int newWidth = (int)(newHeight * aspectRatio); + + // Apply size constraints + newWidth = Math.Min(Math.Max(newWidth, this._minimumSize.Width), this._maximumSize.Width); + newHeight = Math.Min(Math.Max(newHeight, this._minimumSize.Height), this._maximumSize.Height); + + this._suppressEvents = true; + this.ThumbnailsWidthNumericEdit.Value = newWidth; + this.ThumbnailsHeightNumericEdit.Value = newHeight; + this._suppressEvents = false; + } + } else { + // Normal behavior without aspect ratio maintenance + this._suppressEvents = true; + Size thumbnailSize = this.ThumbnailSize; + thumbnailSize.Width = + Math.Min(Math.Max(thumbnailSize.Width, this._minimumSize.Width), this._maximumSize.Width); + thumbnailSize.Height = + Math.Min(Math.Max(thumbnailSize.Height, this._minimumSize.Height), this._maximumSize.Height); + this.ThumbnailSize = thumbnailSize; + this._suppressEvents = false; + } this.ThumbnailsSizeChanged?.Invoke(); } + private void ThumbnailSizeNumeric_MouseWheel(object sender, MouseEventArgs e) { + if (this._suppressEvents) { + return; + } + + // Check if shift is held down for aspect ratio maintenance + bool maintainAspectRatio = ModifierKeys.HasFlag(Keys.Shift); + + if (maintainAspectRatio && sender is NumericUpDown control) { + // Calculate the aspect ratio from the current size + double aspectRatio = + (double)this.ThumbnailsWidthNumericEdit.Value / (double)this.ThumbnailsHeightNumericEdit.Value; + + // Determine scroll direction and increment + int increment = e.Delta > 0 ? (int)control.Increment : -(int)control.Increment; + + // Determine which control was scrolled and update both accordingly + if (control == this.ThumbnailsWidthNumericEdit) { + int newWidth = (int)control.Value + increment; + int newHeight = (int)(newWidth / aspectRatio); + + // Apply size constraints + newWidth = Math.Min(Math.Max(newWidth, this._minimumSize.Width), this._maximumSize.Width); + newHeight = Math.Min(Math.Max(newHeight, this._minimumSize.Height), this._maximumSize.Height); + + this._suppressEvents = true; + this.ThumbnailsWidthNumericEdit.Value = newWidth; + this.ThumbnailsHeightNumericEdit.Value = newHeight; + this._suppressEvents = false; + } else if (control == this.ThumbnailsHeightNumericEdit) { + int newHeight = (int)control.Value + increment; + int newWidth = (int)(newHeight * aspectRatio); + + // Apply size constraints + newWidth = Math.Min(Math.Max(newWidth, this._minimumSize.Width), this._maximumSize.Width); + newHeight = Math.Min(Math.Max(newHeight, this._minimumSize.Height), this._maximumSize.Height); + + this._suppressEvents = true; + this.ThumbnailsWidthNumericEdit.Value = newWidth; + this.ThumbnailsHeightNumericEdit.Value = newHeight; + this._suppressEvents = false; + } + + // Prevent the default scroll behavior + ((HandledMouseEventArgs)e).Handled = true; + + this.ThumbnailsSizeChanged?.Invoke(); + } + } + private void ActiveClientHighlightColorButton_Click(object sender, EventArgs e) { using (ColorDialog dialog = new ColorDialog()) { dialog.Color = this.ActiveClientHighlightColor;